From b12973bc9aa26f548549306eaec4146bf60d65d5 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Fri, 20 Jul 2018 09:09:36 +0200 Subject: Bug 958714 Remove special case for flex & grid items' percent block-axis margin/padding resolution, to align with other browsers --- layout/generic/ReflowInput.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'layout/generic/ReflowInput.cpp') diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp index a8756cea2..72624d55c 100644 --- a/layout/generic/ReflowInput.cpp +++ b/layout/generic/ReflowInput.cpp @@ -2142,14 +2142,11 @@ 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; - if (MOZ_LIKELY(!aFrame->GetParent() || - !aFrame->GetParent()->IsFlexOrGridContainer())) { - offsetPercentBasis.BSize(aWM) = offsetPercentBasis.ISize(aWM); - } else if (offsetPercentBasis.BSize(aWM) == NS_AUTOHEIGHT) { - offsetPercentBasis.BSize(aWM) = 0; - } - + offsetPercentBasis.BSize(aWM) = offsetPercentBasis.ISize(aWM); return offsetPercentBasis; } -- cgit v1.2.3 From 83459c927715bd6d2be1e339ff723b4feb3e5fe7 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Fri, 20 Jul 2018 09:13:56 +0200 Subject: Bug 958714 Simplify percent-margin/padding resolution code to pass around a single length as the percent basis --- layout/generic/ReflowInput.cpp | 50 +++++++++++++----------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) (limited to 'layout/generic/ReflowInput.cpp') diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp index 72624d55c..04f4ef3e5 100644 --- a/layout/generic/ReflowInput.cpp +++ b/layout/generic/ReflowInput.cpp @@ -173,10 +173,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->GetType(), flags); + InitOffsets(aContainingBlockWritingMode, aContainingBlockISize, + mFrame->Type(), flags); } // Initialize a reflow state for a child frame's reflow. Some state @@ -2132,24 +2131,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 @@ -2170,7 +2151,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); // Override mComputedMargin since reflow roots start from the // frame's boundary, which is inside the margin. @@ -2227,8 +2208,7 @@ ReflowInput::InitConstraints(nsPresContext* aPresContext, // For calculating positioning offsets, margins, borders and // padding, we use the writing mode of the containing block WritingMode cbwm = cbrs->GetWritingMode(); - InitOffsets(cbwm, OffsetPercentBasis(mFrame, cbwm, - cbSize.ConvertTo(cbwm, wm)), + InitOffsets(cbwm, cbSize.ConvertTo(cbwm, wm).ISize(cbwm), aFrameType, mFlags, aBorder, aPadding); // For calculating the size of this box, we use its own writing mode @@ -2502,7 +2482,7 @@ UpdateProp(FrameProperties& aProps, void SizeComputationInput::InitOffsets(WritingMode aWM, - const LogicalSize& aPercentBasis, + nscoord aPercentBasis, nsIAtom* aFrameType, ReflowInputFlags aFlags, const nsMargin* aBorder, @@ -2873,7 +2853,7 @@ ReflowInput::CalcLineHeight(nsIContent* aContent, bool SizeComputationInput::ComputeMargin(WritingMode aWM, - const LogicalSize& aPercentBasis) + nscoord aPercentBasis) { // SVG text frames have no margin. if (mFrame->IsSVGText()) { @@ -2890,17 +2870,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); @@ -2921,7 +2901,7 @@ SizeComputationInput::ComputeMargin(WritingMode aWM, bool SizeComputationInput::ComputePadding(WritingMode aWM, - const LogicalSize& aPercentBasis, + nscoord aPercentBasis, nsIAtom* aFrameType) { // If style can provide us the padding directly, then use it. @@ -2942,17 +2922,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); -- cgit v1.2.3 From 1b153b3f2a70b65fffe6e5a70616681b7aa3ecb6 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Fri, 20 Jul 2018 09:15:48 +0200 Subject: Bug 958714 Remove obsolete assertion & comment + Used "mFrame->GetType()" instead of "mFrame->Type()" --- layout/generic/ReflowInput.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'layout/generic/ReflowInput.cpp') diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp index 04f4ef3e5..bbff77ad4 100644 --- a/layout/generic/ReflowInput.cpp +++ b/layout/generic/ReflowInput.cpp @@ -154,11 +154,6 @@ FontSizeInflationListMarginAdjustment(const nsIFrame* aFrame) return 0; } -// NOTE: If we ever want to use SizeComputationInput for a flex item or a -// grid item, we need to make it take the containing-block block-size as -// well as the inline-size, since flex items and grid items resolve -// block-direction percent margins and padding against the -// containing-block block-size, rather than its inline-size. SizeComputationInput::SizeComputationInput(nsIFrame *aFrame, nsRenderingContext *aRenderingContext, WritingMode aContainingBlockWritingMode, @@ -167,15 +162,9 @@ SizeComputationInput::SizeComputationInput(nsIFrame *aFrame, , mRenderingContext(aRenderingContext) , mWritingMode(aFrame->GetWritingMode()) { - MOZ_ASSERT(!aFrame->IsFlexOrGridItem(), - "We're about to resolve percent margin & padding " - "values against CB inline size, which is incorrect for " - "flex/grid items. " - "Additionally for grid items, this path doesn't handle baseline " - "padding contribution - see SizeComputationInput::InitOffsets"); ReflowInputFlags flags; InitOffsets(aContainingBlockWritingMode, aContainingBlockISize, - mFrame->Type(), flags); + mFrame->GetType(), flags); } // Initialize a reflow state for a child frame's reflow. Some state -- cgit v1.2.3