From 4ac397c7fbdf0788e0511cdc9d5527bfe8bea452 Mon Sep 17 00:00:00 2001 From: Daniel Holbert Date: Tue, 30 Jan 2018 22:24:55 -0500 Subject: [PATCH] Bug 958714 part 2: Simplify percent-margin/padding resolution code to pass around a single length as the percent basis. r=mats MozReview-Commit-ID: J1EPYMQ5lP4 --HG-- extra : rebase_source : cc5970093ddc7515089b291027000532fd6d19ce --- layout/generic/ReflowInput.cpp | 50 ++++++++++------------------------ layout/generic/ReflowInput.h | 30 ++++++-------------- layout/generic/nsFrame.cpp | 14 ++++------ layout/generic/nsFrame.h | 2 +- 4 files changed, 29 insertions(+), 67 deletions(-) diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp index d5fe438660a8..4bd39b03dd45 100644 --- a/layout/generic/ReflowInput.cpp +++ b/layout/generic/ReflowInput.cpp @@ -175,10 +175,9 @@ SizeComputationInput::SizeComputationInput(nsIFrame *aFrame, "flex/grid items. " "Additionally for grid items, this path doesn't handle baseline " "padding contribution - see SizeComputationInput::InitOffsets"); - LogicalSize cbSize(aContainingBlockWritingMode, aContainingBlockISize, - aContainingBlockISize); ReflowInputFlags flags; - InitOffsets(aContainingBlockWritingMode, cbSize, mFrame->Type(), flags); + InitOffsets(aContainingBlockWritingMode, aContainingBlockISize, + mFrame->Type(), flags); } // Initialize a reflow state for a child frame's reflow. Some state @@ -2208,24 +2207,6 @@ IsSideCaption(nsIFrame* aFrame, const nsStyleDisplay* aStyleDisplay, captionSide == NS_STYLE_CAPTION_SIDE_RIGHT; } -// Flex/grid items resolve block-axis percentage margin & padding against the -// containing block block-size (also for abs/fixed-pos child frames). -// For everything else: the CSS21 spec requires that margin and padding -// percentage values are calculated with respect to the inline-size of the -// containing block, even for margin & padding in the block axis. -static LogicalSize -OffsetPercentBasis(const nsIFrame* aFrame, - WritingMode aWM, - const LogicalSize& aContainingBlockSize) -{ - // XXX The next patch in this series will get rid of this function and have - // the upstream/downstream code just work with the one nscoord value that - // we'll be dealing with now (which is aContainingBlockSize.ISize(aWM)). - LogicalSize offsetPercentBasis = aContainingBlockSize; - offsetPercentBasis.BSize(aWM) = offsetPercentBasis.ISize(aWM); - return offsetPercentBasis; -} - // XXX refactor this code to have methods for each set of properties // we are computing: width,height,line-height; margin; offsets @@ -2246,7 +2227,7 @@ ReflowInput::InitConstraints(nsPresContext* aPresContext, // height equal to the available space if (nullptr == mParentReflowInput || mFlags.mDummyParentReflowInput) { // XXXldb This doesn't mean what it used to! - InitOffsets(wm, OffsetPercentBasis(mFrame, wm, aContainingBlockSize), + InitOffsets(wm, aContainingBlockSize.ISize(wm), aFrameType, mFlags, aBorder, aPadding, mStyleDisplay); // Override mComputedMargin since reflow roots start from the // frame's boundary, which is inside the margin. @@ -2304,8 +2285,7 @@ ReflowInput::InitConstraints(nsPresContext* aPresContext, // For calculating positioning offsets, margins, borders and // padding, we use the writing mode of the containing block WritingMode cbwm = cbri->GetWritingMode(); - InitOffsets(cbwm, OffsetPercentBasis(mFrame, cbwm, - cbSize.ConvertTo(cbwm, wm)), + InitOffsets(cbwm, cbSize.ConvertTo(cbwm, wm).ISize(cbwm), aFrameType, mFlags, aBorder, aPadding, mStyleDisplay); // For calculating the size of this box, we use its own writing mode @@ -2579,7 +2559,7 @@ UpdateProp(nsIFrame* aFrame, void SizeComputationInput::InitOffsets(WritingMode aWM, - const LogicalSize& aPercentBasis, + nscoord aPercentBasis, LayoutFrameType aFrameType, ReflowInputFlags aFlags, const nsMargin* aBorder, @@ -2950,7 +2930,7 @@ ReflowInput::CalcLineHeight(nsIContent* aContent, bool SizeComputationInput::ComputeMargin(WritingMode aWM, - const LogicalSize& aPercentBasis) + nscoord aPercentBasis) { // SVG text frames have no margin. if (nsSVGUtils::IsInSVGTextSubtree(mFrame)) { @@ -2967,17 +2947,17 @@ SizeComputationInput::ComputeMargin(WritingMode aWM, // (http://dev.w3.org/csswg/css-writing-modes-3/#orthogonal-flows) LogicalMargin m(aWM); m.IStart(aWM) = nsLayoutUtils:: - ComputeCBDependentValue(aPercentBasis.ISize(aWM), + ComputeCBDependentValue(aPercentBasis, styleMargin->mMargin.GetIStart(aWM)); m.IEnd(aWM) = nsLayoutUtils:: - ComputeCBDependentValue(aPercentBasis.ISize(aWM), + ComputeCBDependentValue(aPercentBasis, styleMargin->mMargin.GetIEnd(aWM)); m.BStart(aWM) = nsLayoutUtils:: - ComputeCBDependentValue(aPercentBasis.BSize(aWM), + ComputeCBDependentValue(aPercentBasis, styleMargin->mMargin.GetBStart(aWM)); m.BEnd(aWM) = nsLayoutUtils:: - ComputeCBDependentValue(aPercentBasis.BSize(aWM), + ComputeCBDependentValue(aPercentBasis, styleMargin->mMargin.GetBEnd(aWM)); SetComputedLogicalMargin(aWM, m); @@ -2998,7 +2978,7 @@ SizeComputationInput::ComputeMargin(WritingMode aWM, bool SizeComputationInput::ComputePadding(WritingMode aWM, - const LogicalSize& aPercentBasis, + nscoord aPercentBasis, LayoutFrameType aFrameType) { // If style can provide us the padding directly, then use it. @@ -3019,17 +2999,17 @@ SizeComputationInput::ComputePadding(WritingMode aWM, // clamp negative calc() results to 0 LogicalMargin p(aWM); p.IStart(aWM) = std::max(0, nsLayoutUtils:: - ComputeCBDependentValue(aPercentBasis.ISize(aWM), + ComputeCBDependentValue(aPercentBasis, stylePadding->mPadding.GetIStart(aWM))); p.IEnd(aWM) = std::max(0, nsLayoutUtils:: - ComputeCBDependentValue(aPercentBasis.ISize(aWM), + ComputeCBDependentValue(aPercentBasis, stylePadding->mPadding.GetIEnd(aWM))); p.BStart(aWM) = std::max(0, nsLayoutUtils:: - ComputeCBDependentValue(aPercentBasis.BSize(aWM), + ComputeCBDependentValue(aPercentBasis, stylePadding->mPadding.GetBStart(aWM))); p.BEnd(aWM) = std::max(0, nsLayoutUtils:: - ComputeCBDependentValue(aPercentBasis.BSize(aWM), + ComputeCBDependentValue(aPercentBasis, stylePadding->mPadding.GetBEnd(aWM))); SetComputedLogicalPadding(aWM, p); diff --git a/layout/generic/ReflowInput.h b/layout/generic/ReflowInput.h index 469387539f9b..3a79383090de 100644 --- a/layout/generic/ReflowInput.h +++ b/layout/generic/ReflowInput.h @@ -247,7 +247,7 @@ public: static void* DisplayInitOffsetsEnter( nsIFrame* aFrame, SizeComputationInput* aState, - const mozilla::LogicalSize& aPercentBasis, + nscoord aPercentBasis, WritingMode aCBWritingMode, const nsMargin* aBorder, const nsMargin* aPadding); @@ -263,19 +263,12 @@ private: * * @param aWM Writing mode of the containing block * @param aPercentBasis - * Logical size in the writing mode of the containing block to use - * for resolving percentage margin values in the inline and block - * axes. - * The inline size is usually the containing block inline-size - * (width if writing mode is horizontal, and height if vertical). - * The block size is usually the containing block inline-size, per - * CSS21 sec 8.3 (read in conjunction with CSS Writing Modes sec - * 7.2), but may be the containing block block-size, e.g. in CSS3 - * Flexbox and Grid. + * Inline size of the containing block (in its own writing mode), to use + * for resolving percentage margin values in the inline and block axes. * @return true if the margin is dependent on the containing block size. */ bool ComputeMargin(mozilla::WritingMode aWM, - const mozilla::LogicalSize& aPercentBasis); + nscoord aPercentBasis); /** * Computes padding values from the specified padding style information, and @@ -283,24 +276,17 @@ private: * * @param aWM Writing mode of the containing block * @param aPercentBasis - * Logical size in the writing mode of the containing block to use - * for resolving percentage padding values in the inline and block - * axes. - * The inline size is usually the containing block inline-size - * (width if writing mode is horizontal, and height if vertical). - * The block size is usually the containing block inline-size, per - * CSS21 sec 8.3 (read in conjunction with CSS Writing Modes sec - * 7.2), but may be the containing block block-size, e.g. in CSS3 - * Flexbox and Grid. + * Inline size of the containing block (in its own writing mode), to use + * for resolving percentage padding values in the inline and block axes. * @return true if the padding is dependent on the containing block size. */ bool ComputePadding(mozilla::WritingMode aWM, - const mozilla::LogicalSize& aPercentBasis, + nscoord aPercentBasis, mozilla::LayoutFrameType aFrameType); protected: void InitOffsets(mozilla::WritingMode aWM, - const mozilla::LogicalSize& aPercentBasis, + nscoord aPercentBasis, mozilla::LayoutFrameType aFrameType, ReflowInputFlags aFlags, const nsMargin* aBorder = nullptr, diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index 8f15e956f5ce..c2a4c3fa71b4 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -11563,7 +11563,7 @@ DR_init_constraints_cookie::~DR_init_constraints_cookie() DR_init_offsets_cookie::DR_init_offsets_cookie( nsIFrame* aFrame, SizeComputationInput* aState, - const LogicalSize& aPercentBasis, + nscoord aPercentBasis, WritingMode aCBWritingMode, const nsMargin* aMargin, const nsMargin* aPadding) @@ -12523,7 +12523,7 @@ ReflowInput::DisplayInitConstraintsExit(nsIFrame* aFrame, /* static */ void* SizeComputationInput::DisplayInitOffsetsEnter(nsIFrame* aFrame, SizeComputationInput* aState, - const LogicalSize& aPercentBasis, + nscoord aPercentBasis, WritingMode aCBWritingMode, const nsMargin* aBorder, const nsMargin* aPadding) @@ -12539,13 +12539,9 @@ SizeComputationInput::DisplayInitOffsetsEnter(nsIFrame* aFrame, if (treeNode && treeNode->mDisplay) { DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); - char horizPctBasisStr[16]; - char vertPctBasisStr[16]; - DR_state->PrettyUC(aPercentBasis.ISize(aCBWritingMode), - horizPctBasisStr, 16); - DR_state->PrettyUC(aPercentBasis.BSize(aCBWritingMode), - vertPctBasisStr, 16); - printf("InitOffsets pct_basis=%s,%s", horizPctBasisStr, vertPctBasisStr); + char pctBasisStr[16]; + DR_state->PrettyUC(aPercentBasis, pctBasisStr, 16); + printf("InitOffsets pct_basis=%s", pctBasisStr); DR_state->PrintMargin("b", aBorder); DR_state->PrintMargin("p", aPadding); diff --git a/layout/generic/nsFrame.h b/layout/generic/nsFrame.h index b5a8f59f0a79..1e6cb567e878 100644 --- a/layout/generic/nsFrame.h +++ b/layout/generic/nsFrame.h @@ -835,7 +835,7 @@ public: struct DR_init_offsets_cookie { DR_init_offsets_cookie(nsIFrame* aFrame, mozilla::SizeComputationInput* aState, - const mozilla::LogicalSize& aPercentBasis, + nscoord aPercentBasis, mozilla::WritingMode aCBWritingMode, const nsMargin* aBorder, const nsMargin* aPadding);