From cd7f73032779a2346ac2eefbfadd57064029b1ca Mon Sep 17 00:00:00 2001 From: "dbaron%fas.harvard.edu" Date: Tue, 8 Oct 2002 01:52:34 +0000 Subject: [PATCH] Don't resolve the positive and negative parts of collapsing margins too early when collapsing through empty blocks. A few bits of other cleanup. b=172892 sr=bzbarsky r=kin git-svn-id: svn://10.0.0.236/trunk@131355 18797224-902f-48f8-a5cc-f745e15eee43 --- .../layout/base/public/nsHTMLReflowMetrics.h | 8 ++++++++ mozilla/layout/generic/nsBlockFrame.cpp | 19 +++++++------------ .../layout/generic/nsBlockReflowContext.cpp | 15 +++++++-------- mozilla/layout/generic/nsBlockReflowContext.h | 4 ++-- mozilla/layout/generic/nsBlockReflowState.cpp | 9 ++++----- mozilla/layout/generic/nsHTMLReflowMetrics.h | 8 ++++++++ mozilla/layout/html/base/src/nsBlockFrame.cpp | 19 +++++++------------ .../html/base/src/nsBlockReflowContext.cpp | 15 +++++++-------- .../html/base/src/nsBlockReflowContext.h | 4 ++-- .../html/base/src/nsBlockReflowState.cpp | 9 ++++----- 10 files changed, 56 insertions(+), 54 deletions(-) diff --git a/mozilla/layout/base/public/nsHTMLReflowMetrics.h b/mozilla/layout/base/public/nsHTMLReflowMetrics.h index 026b59242a0..4f50ae414f7 100644 --- a/mozilla/layout/base/public/nsHTMLReflowMetrics.h +++ b/mozilla/layout/base/public/nsHTMLReflowMetrics.h @@ -96,6 +96,14 @@ struct nsCollapsingMargin { mMostNeg = aCoord; } + void Include(const nsCollapsingMargin& aOther) + { + if (aOther.mMostPos > mMostPos) + mMostPos = aOther.mMostPos; + if (aOther.mMostNeg < mMostNeg) + mMostNeg = aOther.mMostNeg; + } + void Zero() { mMostPos = 0; diff --git a/mozilla/layout/generic/nsBlockFrame.cpp b/mozilla/layout/generic/nsBlockFrame.cpp index 624ef25ee48..8e176380944 100644 --- a/mozilla/layout/generic/nsBlockFrame.cpp +++ b/mozilla/layout/generic/nsBlockFrame.cpp @@ -757,8 +757,8 @@ nsBlockFrame::Reflow(nsIPresContext* aPresContext, containingBlockHeight, handled); - // If the incremental reflow command was handled by the absolute positioning - // code, then we're all done + // If the incremental reflow command was handled by the absolute + // positioning code, then we're all done. if (handled) { // Just return our current size as our desired size. aMetrics.width = mRect.width; @@ -1370,14 +1370,8 @@ nsBlockFrame::ComputeFinalSize(const nsHTMLReflowState& aReflowState, // because we can't shrink any smaller. maxHeight = aMetrics.height; - // Don't carry out a bottom margin when our height is fixed - // unless the bottom of the last line adjoins the bottom of our - // content area. - if (!aState.GetFlag(BRS_ISBOTTOMMARGINROOT)) { - if (aState.mY + aState.mPrevBottomMargin.get() != aMetrics.height) { - aState.mPrevBottomMargin.Zero(); - } - } + // Don't carry out a bottom margin when our height is fixed. + aState.mPrevBottomMargin.Zero(); } else { nscoord autoHeight = aState.mY; @@ -3344,8 +3338,9 @@ nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState, PRBool isAdjacentWithTop = aState.IsAdjacentWithTop(); nsCollapsingMargin collapsedBottomMargin; nsRect combinedArea(0,0,0,0); - *aKeepReflowGoing = brc.PlaceBlock(blockHtmlRS, isAdjacentWithTop, computedOffsets, - collapsedBottomMargin, aLine->mBounds, combinedArea); + *aKeepReflowGoing = brc.PlaceBlock(blockHtmlRS, isAdjacentWithTop, + computedOffsets, collapsedBottomMargin, + aLine->mBounds, combinedArea); aLine->SetCarriedOutBottomMargin(collapsedBottomMargin); if (aState.GetFlag(BRS_SHRINKWRAPWIDTH)) { diff --git a/mozilla/layout/generic/nsBlockReflowContext.cpp b/mozilla/layout/generic/nsBlockReflowContext.cpp index ab967910483..201abfac560 100644 --- a/mozilla/layout/generic/nsBlockReflowContext.cpp +++ b/mozilla/layout/generic/nsBlockReflowContext.cpp @@ -409,7 +409,7 @@ nsBlockReflowContext::ReflowBlock(const nsRect& aSpace, aFrameRS.availableHeight -= aPrevBottomMargin.get(); } } - mTopMargin = aPrevBottomMargin.get(); + mTopMargin = aPrevBottomMargin; // Compute x/y coordinate where reflow will begin. Use the rules // from 10.3.3 to determine what to apply. At this point in the @@ -419,7 +419,7 @@ nsBlockReflowContext::ReflowBlock(const nsRect& aSpace, mStyleMargin = aFrameRS.mStyleMargin; mStylePadding = aFrameRS.mStylePadding; nscoord x; - nscoord y = mSpace.y + mTopMargin; + nscoord y = mSpace.y + mTopMargin.get(); // If it's a right floated element, then calculate the x-offset // differently @@ -687,13 +687,12 @@ nsBlockReflowContext::PlaceBlock(const nsHTMLReflowState& aReflowState, y = mSpace.y; - // Empty blocks do not have anything special done to them and they - // always fit. Note: don't force the width to 0 - nsRect r(x, y, mMetrics.width, 0); - // Now place the frame and complete the reflow process nsContainerFrame::FinishReflowChild(mFrame, mPresContext, &aReflowState, mMetrics, x, y, 0); - aInFlowBounds = r; + + // Empty blocks do not have anything special done to them and they + // always fit. Note: don't force the width to 0 + aInFlowBounds = nsRect(x, y, mMetrics.width, 0); // Retain combined area information in case we contain a floater // and nothing else. @@ -773,7 +772,7 @@ nsBlockReflowContext::PlaceBlock(const nsHTMLReflowState& aReflowState, // auto top/bottom margins are always zero) // XXXldb Should it? - m->height += mTopMargin + mBottomMargin; + m->height += mTopMargin.get() + mBottomMargin; #endif } } diff --git a/mozilla/layout/generic/nsBlockReflowContext.h b/mozilla/layout/generic/nsBlockReflowContext.h index 838f6305463..d31128a651a 100644 --- a/mozilla/layout/generic/nsBlockReflowContext.h +++ b/mozilla/layout/generic/nsBlockReflowContext.h @@ -82,7 +82,7 @@ public: } nscoord GetTopMargin() const { - return mTopMargin; + return mTopMargin.get(); } const nsMargin& GetMargin() const { @@ -128,7 +128,7 @@ protected: nsMargin mMargin; nscoord mX, mY; nsHTMLReflowMetrics mMetrics; - nscoord mTopMargin; + nsCollapsingMargin mTopMargin; nsSize mMaxElementSize; PRPackedBool mIsTable; PRPackedBool mComputeMaximumWidth; diff --git a/mozilla/layout/generic/nsBlockReflowState.cpp b/mozilla/layout/generic/nsBlockReflowState.cpp index 1c4ae0200a6..84dcf843c4b 100644 --- a/mozilla/layout/generic/nsBlockReflowState.cpp +++ b/mozilla/layout/generic/nsBlockReflowState.cpp @@ -448,11 +448,10 @@ nsBlockReflowState::ReconstructMarginAbove(nsLineList::iterator aLine) mPrevBottomMargin.Zero(); nsBlockFrame *block = mBlock; - const nsStyleText* styleText = NS_STATIC_CAST(const nsStyleText*, - block->mStyleContext->GetStyleData(eStyleStruct_Text)); - PRBool isPre = - ((NS_STYLE_WHITESPACE_PRE == styleText->mWhiteSpace) || - (NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == styleText->mWhiteSpace)); + const nsStyleText* styleText; + ::GetStyleData(block, &styleText); + PRBool isPre = NS_STYLE_WHITESPACE_PRE == styleText->mWhiteSpace || + NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == styleText->mWhiteSpace; nsCompatibility mode; mPresContext->GetCompatibilityMode(&mode); diff --git a/mozilla/layout/generic/nsHTMLReflowMetrics.h b/mozilla/layout/generic/nsHTMLReflowMetrics.h index 026b59242a0..4f50ae414f7 100644 --- a/mozilla/layout/generic/nsHTMLReflowMetrics.h +++ b/mozilla/layout/generic/nsHTMLReflowMetrics.h @@ -96,6 +96,14 @@ struct nsCollapsingMargin { mMostNeg = aCoord; } + void Include(const nsCollapsingMargin& aOther) + { + if (aOther.mMostPos > mMostPos) + mMostPos = aOther.mMostPos; + if (aOther.mMostNeg < mMostNeg) + mMostNeg = aOther.mMostNeg; + } + void Zero() { mMostPos = 0; diff --git a/mozilla/layout/html/base/src/nsBlockFrame.cpp b/mozilla/layout/html/base/src/nsBlockFrame.cpp index 624ef25ee48..8e176380944 100644 --- a/mozilla/layout/html/base/src/nsBlockFrame.cpp +++ b/mozilla/layout/html/base/src/nsBlockFrame.cpp @@ -757,8 +757,8 @@ nsBlockFrame::Reflow(nsIPresContext* aPresContext, containingBlockHeight, handled); - // If the incremental reflow command was handled by the absolute positioning - // code, then we're all done + // If the incremental reflow command was handled by the absolute + // positioning code, then we're all done. if (handled) { // Just return our current size as our desired size. aMetrics.width = mRect.width; @@ -1370,14 +1370,8 @@ nsBlockFrame::ComputeFinalSize(const nsHTMLReflowState& aReflowState, // because we can't shrink any smaller. maxHeight = aMetrics.height; - // Don't carry out a bottom margin when our height is fixed - // unless the bottom of the last line adjoins the bottom of our - // content area. - if (!aState.GetFlag(BRS_ISBOTTOMMARGINROOT)) { - if (aState.mY + aState.mPrevBottomMargin.get() != aMetrics.height) { - aState.mPrevBottomMargin.Zero(); - } - } + // Don't carry out a bottom margin when our height is fixed. + aState.mPrevBottomMargin.Zero(); } else { nscoord autoHeight = aState.mY; @@ -3344,8 +3338,9 @@ nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState, PRBool isAdjacentWithTop = aState.IsAdjacentWithTop(); nsCollapsingMargin collapsedBottomMargin; nsRect combinedArea(0,0,0,0); - *aKeepReflowGoing = brc.PlaceBlock(blockHtmlRS, isAdjacentWithTop, computedOffsets, - collapsedBottomMargin, aLine->mBounds, combinedArea); + *aKeepReflowGoing = brc.PlaceBlock(blockHtmlRS, isAdjacentWithTop, + computedOffsets, collapsedBottomMargin, + aLine->mBounds, combinedArea); aLine->SetCarriedOutBottomMargin(collapsedBottomMargin); if (aState.GetFlag(BRS_SHRINKWRAPWIDTH)) { diff --git a/mozilla/layout/html/base/src/nsBlockReflowContext.cpp b/mozilla/layout/html/base/src/nsBlockReflowContext.cpp index ab967910483..201abfac560 100644 --- a/mozilla/layout/html/base/src/nsBlockReflowContext.cpp +++ b/mozilla/layout/html/base/src/nsBlockReflowContext.cpp @@ -409,7 +409,7 @@ nsBlockReflowContext::ReflowBlock(const nsRect& aSpace, aFrameRS.availableHeight -= aPrevBottomMargin.get(); } } - mTopMargin = aPrevBottomMargin.get(); + mTopMargin = aPrevBottomMargin; // Compute x/y coordinate where reflow will begin. Use the rules // from 10.3.3 to determine what to apply. At this point in the @@ -419,7 +419,7 @@ nsBlockReflowContext::ReflowBlock(const nsRect& aSpace, mStyleMargin = aFrameRS.mStyleMargin; mStylePadding = aFrameRS.mStylePadding; nscoord x; - nscoord y = mSpace.y + mTopMargin; + nscoord y = mSpace.y + mTopMargin.get(); // If it's a right floated element, then calculate the x-offset // differently @@ -687,13 +687,12 @@ nsBlockReflowContext::PlaceBlock(const nsHTMLReflowState& aReflowState, y = mSpace.y; - // Empty blocks do not have anything special done to them and they - // always fit. Note: don't force the width to 0 - nsRect r(x, y, mMetrics.width, 0); - // Now place the frame and complete the reflow process nsContainerFrame::FinishReflowChild(mFrame, mPresContext, &aReflowState, mMetrics, x, y, 0); - aInFlowBounds = r; + + // Empty blocks do not have anything special done to them and they + // always fit. Note: don't force the width to 0 + aInFlowBounds = nsRect(x, y, mMetrics.width, 0); // Retain combined area information in case we contain a floater // and nothing else. @@ -773,7 +772,7 @@ nsBlockReflowContext::PlaceBlock(const nsHTMLReflowState& aReflowState, // auto top/bottom margins are always zero) // XXXldb Should it? - m->height += mTopMargin + mBottomMargin; + m->height += mTopMargin.get() + mBottomMargin; #endif } } diff --git a/mozilla/layout/html/base/src/nsBlockReflowContext.h b/mozilla/layout/html/base/src/nsBlockReflowContext.h index 838f6305463..d31128a651a 100644 --- a/mozilla/layout/html/base/src/nsBlockReflowContext.h +++ b/mozilla/layout/html/base/src/nsBlockReflowContext.h @@ -82,7 +82,7 @@ public: } nscoord GetTopMargin() const { - return mTopMargin; + return mTopMargin.get(); } const nsMargin& GetMargin() const { @@ -128,7 +128,7 @@ protected: nsMargin mMargin; nscoord mX, mY; nsHTMLReflowMetrics mMetrics; - nscoord mTopMargin; + nsCollapsingMargin mTopMargin; nsSize mMaxElementSize; PRPackedBool mIsTable; PRPackedBool mComputeMaximumWidth; diff --git a/mozilla/layout/html/base/src/nsBlockReflowState.cpp b/mozilla/layout/html/base/src/nsBlockReflowState.cpp index 1c4ae0200a6..84dcf843c4b 100644 --- a/mozilla/layout/html/base/src/nsBlockReflowState.cpp +++ b/mozilla/layout/html/base/src/nsBlockReflowState.cpp @@ -448,11 +448,10 @@ nsBlockReflowState::ReconstructMarginAbove(nsLineList::iterator aLine) mPrevBottomMargin.Zero(); nsBlockFrame *block = mBlock; - const nsStyleText* styleText = NS_STATIC_CAST(const nsStyleText*, - block->mStyleContext->GetStyleData(eStyleStruct_Text)); - PRBool isPre = - ((NS_STYLE_WHITESPACE_PRE == styleText->mWhiteSpace) || - (NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == styleText->mWhiteSpace)); + const nsStyleText* styleText; + ::GetStyleData(block, &styleText); + PRBool isPre = NS_STYLE_WHITESPACE_PRE == styleText->mWhiteSpace || + NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == styleText->mWhiteSpace; nsCompatibility mode; mPresContext->GetCompatibilityMode(&mode);