From bb857cabb0f89a9af7b2bbedb46185f73b0e724e Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Fri, 24 Oct 2014 12:24:38 +0100 Subject: [PATCH] Bug 1086883 - Convert writing modes where necessary for orthogonal flows when collapsing margins in nsBlockReflowContext methods. r=smontagu --- layout/generic/nsBlockFrame.cpp | 22 +++++++++++----------- layout/generic/nsBlockReflowContext.cpp | 10 ++++++---- layout/generic/nsBlockReflowContext.h | 18 ++++++++++-------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/layout/generic/nsBlockFrame.cpp b/layout/generic/nsBlockFrame.cpp index 9061361734da..55450d82185a 100644 --- a/layout/generic/nsBlockFrame.cpp +++ b/layout/generic/nsBlockFrame.cpp @@ -3065,10 +3065,10 @@ nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState, // Now compute the collapsed margin-block-start value into // aState.mPrevBEndMargin, assuming that all child margins // collapse down to clearanceFrame. - nsBlockReflowContext::ComputeCollapsedBStartMargin(reflowState, - &aState.mPrevBEndMargin, - clearanceFrame, - &mayNeedRetry); + brc.ComputeCollapsedBStartMargin(reflowState, + &aState.mPrevBEndMargin, + clearanceFrame, + &mayNeedRetry); // XXX optimization; we could check the collapsing children to see if they are sure // to require clearance, and so avoid retrying them @@ -3101,10 +3101,10 @@ nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState, // Compute the collapsed margin again, ignoring the incoming margin this time mayNeedRetry = false; - nsBlockReflowContext::ComputeCollapsedBStartMargin(reflowState, - &aState.mPrevBEndMargin, - clearanceFrame, - &mayNeedRetry); + brc.ComputeCollapsedBStartMargin(reflowState, + &aState.mPrevBEndMargin, + clearanceFrame, + &mayNeedRetry); } } @@ -5855,9 +5855,9 @@ nsBlockFrame::ReflowFloat(nsBlockReflowState& aState, floatRS.mDiscoveredClearance = nullptr; // Only first in flow gets a top margin. if (!aFloat->GetPrevInFlow()) { - nsBlockReflowContext::ComputeCollapsedBStartMargin(floatRS, &margin, - clearanceFrame, - &mayNeedRetry); + brc.ComputeCollapsedBStartMargin(floatRS, &margin, + clearanceFrame, + &mayNeedRetry); if (mayNeedRetry && !clearanceFrame) { floatRS.mDiscoveredClearance = &clearanceFrame; diff --git a/layout/generic/nsBlockReflowContext.cpp b/layout/generic/nsBlockReflowContext.cpp index c96e5dbd6284..f296e23e8e80 100644 --- a/layout/generic/nsBlockReflowContext.cpp +++ b/layout/generic/nsBlockReflowContext.cpp @@ -57,8 +57,10 @@ nsBlockReflowContext::ComputeCollapsedBStartMargin(const nsHTMLReflowState& aRS, bool* aBlockIsEmpty) { WritingMode wm = aRS.GetWritingMode(); - // Include frame's block-start margin - aMargin->Include(aRS.ComputedLogicalMargin().BStart(wm)); + WritingMode parentWM = mMetrics.GetWritingMode(); + + // Include block-start element of frame's margin + aMargin->Include(aRS.ComputedLogicalMargin().ConvertTo(parentWM, wm).BStart(parentWM)); // The inclusion of the block-end margin when empty is done by the caller // since it doesn't need to be done by the top-level (non-recursive) @@ -174,8 +176,8 @@ nsBlockReflowContext::ComputeCollapsedBStartMargin(const nsHTMLReflowState& aRS, if (isEmpty) { WritingMode innerWM = innerReflowState.GetWritingMode(); LogicalMargin innerMargin = - innerReflowState.ComputedLogicalMargin().ConvertTo(wm, innerWM); - aMargin->Include(innerMargin.BEnd(wm)); + innerReflowState.ComputedLogicalMargin().ConvertTo(parentWM, innerWM); + aMargin->Include(innerMargin.BEnd(parentWM)); } } if (outerReflowState != &aRS) { diff --git a/layout/generic/nsBlockReflowContext.h b/layout/generic/nsBlockReflowContext.h index e948c54bb25b..39b00f3f5fbb 100644 --- a/layout/generic/nsBlockReflowContext.h +++ b/layout/generic/nsBlockReflowContext.h @@ -54,9 +54,11 @@ public: } /** - * Computes the collapsed block-start margin for a block whose reflow state - * is in aRS. - * The computed margin is added into aMargin. + * Computes the collapsed block-start margin (in the context's parent's + * writing mode) for a block whose reflow state is in aRS. + * The computed margin is added into aMargin, whose writing mode is the + * parent's mode as found in mMetrics.GetWritingMode(); note this may not be + * the block's own writing mode as found in aRS. * If aClearanceFrame is null then this is the first optimistic pass which * shall assume that no frames have clearance, and we clear the HasClearance * on all frames encountered. @@ -70,11 +72,11 @@ public: * We return true if we changed the clearance state of any line and marked it * dirty. */ - static bool ComputeCollapsedBStartMargin(const nsHTMLReflowState& aRS, - nsCollapsingMargin* aMargin, - nsIFrame* aClearanceFrame, - bool* aMayNeedRetry, - bool* aIsEmpty = nullptr); + bool ComputeCollapsedBStartMargin(const nsHTMLReflowState& aRS, + nsCollapsingMargin* aMargin, + nsIFrame* aClearanceFrame, + bool* aMayNeedRetry, + bool* aIsEmpty = nullptr); protected: nsPresContext* mPresContext;