Bug 400813. Lines with actual content that just happens to be zero-width should be treated as non-empty. r+sr=dbaron

This commit is contained in:
roc+@cs.cmu.edu 2008-01-29 23:12:26 -08:00
parent b97f3fcb4a
commit 81d839b21e
7 changed files with 38 additions and 8 deletions

View File

@ -395,6 +395,7 @@ nsLineLayout::NewPerSpanData(PerSpanData** aResult)
psd->mLastFrame = nsnull;
psd->mContainsFloat = PR_FALSE;
psd->mZeroEffectiveSpanBox = PR_FALSE;
psd->mHasNonemptyContent = PR_FALSE;
#ifdef DEBUG
mSpansAllocated++;
@ -887,11 +888,11 @@ nsLineLayout::ReflowFrame(nsIFrame* aFrame,
else if (nsGkAtoms::textFrame == frameType) {
// Note non-empty text-frames for inline frame compatibility hackery
pfd->SetFlag(PFD_ISTEXTFRAME, PR_TRUE);
// XXX An empty text frame at the end of the line seems not
// to have zero width.
if (metrics.width) {
nsTextFrame* textFrame = static_cast<nsTextFrame*>(pfd->mFrame);
if (textFrame->HasNoncollapsedCharacters()) {
psd->mHasNonemptyContent = PR_TRUE;
pfd->SetFlag(PFD_ISNONEMPTYTEXTFRAME, PR_TRUE);
nsIContent* content = pfd->mFrame->GetContent();
nsIContent* content = textFrame->GetContent();
const nsTextFragment* frag = content->GetText();
if (frag) {
@ -921,6 +922,13 @@ nsLineLayout::ReflowFrame(nsIFrame* aFrame,
}
else if (nsGkAtoms::brFrame == frameType) {
pfd->SetFlag(PFD_SKIPWHENTRIMMINGWHITESPACE, PR_TRUE);
psd->mHasNonemptyContent = PR_TRUE;
} else if (pfd->mSpan) {
if (pfd->mSpan->mHasNonemptyContent || !pfd->mFrame->IsSelfEmpty()) {
psd->mHasNonemptyContent = PR_TRUE;
}
} else {
psd->mHasNonemptyContent = PR_TRUE;
}
}
@ -1304,7 +1312,9 @@ nsLineLayout::PlaceFrame(PerFrameData* pfd, nsHTMLReflowMetrics& aMetrics)
// Count the number of non-empty frames on the line...
if (!emptyFrame) {
mTotalPlacedFrames++;
NS_ASSERTION(psd->mHasNonemptyContent, "We should have detected this nonempty content");
}
// XXX roc why not just check !emptyFrame again here?
if (psd->mX != psd->mLeftEdge || pfd->mBounds.x != psd->mLeftEdge) {
// As soon as a frame placed on the line advances an X coordinate
// of any span we can no longer place a float on the line.
@ -2057,7 +2067,7 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd)
}
}
if (applyMinLH) {
if ((psd->mX != psd->mLeftEdge) || preMode || foundLI) {
if (psd->mHasNonemptyContent || preMode || foundLI) {
#ifdef NOISY_VERTICAL_ALIGN
printf(" [span]==> adjusting min/maxY: currentValues: %d,%d", minY, maxY);
#endif

View File

@ -468,6 +468,7 @@ protected:
PRPackedBool mChangedFrameDirection;
PRPackedBool mZeroEffectiveSpanBox;
PRPackedBool mContainsFloat;
PRPackedBool mHasNonemptyContent;
nscoord mLeftEdge;
nscoord mX;

View File

@ -58,6 +58,10 @@
class nsTextPaintStyle;
class PropertyProvider;
// This state bit is set on frames that have some non-collapsed characters after
// reflow
#define TEXT_HAS_NONCOLLAPSED_CHARACTERS 0x02000000
class nsTextFrame : public nsFrame {
public:
friend class nsContinuingTextFrame;
@ -189,6 +193,14 @@ public:
*/
PRBool IsAtEndOfLine() const;
/**
* Call this only after reflow the frame. Returns true if non-collapsed
* characters are present.
*/
PRBool HasNoncollapsedCharacters() const {
return (GetStateBits() & TEXT_HAS_NONCOLLAPSED_CHARACTERS) != 0;
}
#ifdef ACCESSIBILITY
NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
#endif

View File

@ -145,7 +145,10 @@
#define TEXT_REFLOW_FLAGS \
(TEXT_FIRST_LETTER|TEXT_START_OF_LINE|TEXT_END_OF_LINE|TEXT_HYPHEN_BREAK| \
TEXT_TRIMMED_TRAILING_WHITESPACE)
TEXT_TRIMMED_TRAILING_WHITESPACE|TEXT_HAS_NONCOLLAPSED_CHARACTERS)
// defined in nsTextFrame.h
// #define TEXT_HAS_NONCOLLAPSED_CHARACTERS 0x02000000
// Cache bits for IsEmpty().
// Set this bit if the textframe is known to be only collapsible whitespace.
@ -5513,6 +5516,7 @@ nsTextFrame::Reflow(nsPresContext* aPresContext,
// frame to accumulate with trimmable width from this frame.)
if (transformedCharsFit > 0) {
lineLayout.SetTrimmableWidth(NSToCoordFloor(trimmableWidth));
AddStateBits(TEXT_HAS_NONCOLLAPSED_CHARACTERS);
}
if (charsFit > 0 && charsFit == length &&
HasSoftHyphenBefore(frag, mTextRun, offset, end)) {
@ -5860,7 +5864,7 @@ nsIAtom*
nsTextFrame::GetType() const
{
return nsGkAtoms::textFrame;
}
}
/* virtual */ PRBool
nsTextFrame::IsEmpty()

View File

@ -2,7 +2,8 @@
<html>
<body>
<div style="height:100px; background-color:blue;"></div>
<div style="height:200px;"></div>
<div style="padding:100px 0; opacity:0;">blank line</div>
<div style="height:100px; background-color:blue;"></div>
</body>
</html>

View File

@ -1,3 +1,4 @@
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css"> p { margin: 5px 1em; width: 0; white-space: nowrap; } p > span { background-color: silver; } </style>

View File

@ -1,3 +1,4 @@
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css"> p { margin: 5px 1em; width: 0; } p > span { background-color: silver; } </style>