Bug 403455. Allow prewrap text to record 'last break opportunity'. r=smontagu

This commit is contained in:
roc+@cs.cmu.edu 2007-11-15 17:48:26 -08:00
parent f5a5fee86b
commit 4dcead5d4b
4 changed files with 39 additions and 9 deletions

View File

@ -5358,6 +5358,7 @@ nsTextFrame::Reflow(nsPresContext* aPresContext,
}
gfxFloat trimmableWidth = 0;
PRBool brokeText = forceBreak >= 0 || transformedCharsFit < transformedLength;
if (canTrimTrailingWhitespace) {
// Optimization: if we trimmed trailing whitespace, and we can be sure
// this frame will be at the end of the line, then leave it trimmed off.
@ -5365,7 +5366,7 @@ nsTextFrame::Reflow(nsPresContext* aPresContext,
// the line. (If we actually do end up at the end of the line, we'll have
// to trim it off again in TrimTrailingWhiteSpace, and we'd like to avoid
// having to re-do it.)
if (forceBreak >= 0 || transformedCharsFit < transformedLength) {
if (brokeText) {
// We're definitely going to break so our trailing whitespace should
// definitely be timmed. Record that we've already done it.
AddStateBits(TEXT_TRIMMED_TRAILING_WHITESPACE);
@ -5381,17 +5382,19 @@ nsTextFrame::Reflow(nsPresContext* aPresContext,
// right by trimmdWidth
textMetrics.mBoundingBox.MoveBy(gfxPoint(trimmedWidth, 0));
}
// Since everything fit and no break was forced,
// record the last break opportunity
if (lastBreak >= 0) {
lineLayout.NotifyOptionalBreakPosition(mContent, lastBreak,
textMetrics.mAdvanceWidth <= aReflowState.availableWidth);
}
}
}
if (!brokeText && lastBreak >= 0) {
// Since everything fit and no break was forced,
// record the last break opportunity
NS_ASSERTION(textMetrics.mAdvanceWidth - trimmableWidth <= aReflowState.availableWidth,
"If the text doesn't fit, and we have a break opportunity, why didn't MeasureText use it?");
lineLayout.NotifyOptionalBreakPosition(mContent, lastBreak, PR_TRUE);
}
PRInt32 contentLength = offset + charsFit - GetContentOffset();
/////////////////////////////////////////////////////////////////////
// Compute output metrics
/////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,12 @@
<html><head>
<style>
p { width: 13em; border: 1px solid black; }
p { white-space: nowrap; }
a { color:pink; }
</style>
</head>
<body>
<p><a style="white-space:-moz-pre-wrap;">mmmmmmmmmm <br>m</a>mmmmmmmmm</p>
<p>m <br><a style="white-space:pre;">mmmmmmmmmm</a>mmmmmmmmm</p>
</body>
</html>

View File

@ -0,0 +1,14 @@
<html><head>
<style>
p { width: 13em; border: 1px solid black; }
p span { white-space: nowrap; }
a { color:pink; }
</style>
</head>
<body>
<!-- A prewrap text frame should be able to record a break opportunity -->
<p><a style="white-space:-moz-pre-wrap;">mmmmmmmmmm m</a>mmmmmmmmm</p>
<!-- A 'pre' text frame should be able to record a break opportunity at its start -->
<p>m <a style="white-space:pre;">mmmmmmmmmm</a>mmmmmmmmm</p>
</body>
</html>

View File

@ -455,6 +455,7 @@ fails == 386310-1d.html 386310-1-ref.html
== 403129-3.html 403129-3-ref.html
== 403129-4.html 403129-4-ref.html
== 402338-1.html 402338-1-ref.html
== 403455-1.html 403455-1-ref.html
== 403505-1.xml 403505-1-ref.xul
== 403519-1.html 403519-1-ref.html
== 403656-1.html 403656-1-ref.html