diff options
author | Moonchild <mcwerewolf@gmail.com> | 2018-07-20 11:06:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-20 11:06:08 +0200 |
commit | edc1da82d86d3c86512f42403c84ee68a4f682a3 (patch) | |
tree | 8a3afcc91a120e0c93d79075759dcf228b1f1f92 /layout/generic | |
parent | 1475cd93165891136da67490312c164d0bb180cd (diff) | |
parent | 1b153b3f2a70b65fffe6e5a70616681b7aa3ecb6 (diff) | |
download | UXP-edc1da82d86d3c86512f42403c84ee68a4f682a3.tar UXP-edc1da82d86d3c86512f42403c84ee68a4f682a3.tar.gz UXP-edc1da82d86d3c86512f42403c84ee68a4f682a3.tar.lz UXP-edc1da82d86d3c86512f42403c84ee68a4f682a3.tar.xz UXP-edc1da82d86d3c86512f42403c84ee68a4f682a3.zip |
Merge pull request #650 from janekptacijarabaci/css_layout_flex-grid_1
Align Css layout flex grid with latest spec
Diffstat (limited to 'layout/generic')
-rw-r--r-- | layout/generic/ReflowInput.cpp | 64 | ||||
-rw-r--r-- | layout/generic/ReflowInput.h | 30 | ||||
-rw-r--r-- | layout/generic/nsFrame.cpp | 14 | ||||
-rw-r--r-- | layout/generic/nsFrame.h | 2 |
4 files changed, 30 insertions, 80 deletions
diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp index a8756cea2..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,16 +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"); - LogicalSize cbSize(aContainingBlockWritingMode, aContainingBlockISize, - aContainingBlockISize); ReflowInputFlags flags; - InitOffsets(aContainingBlockWritingMode, cbSize, mFrame->GetType(), flags); + InitOffsets(aContainingBlockWritingMode, aContainingBlockISize, + mFrame->GetType(), flags); } // Initialize a reflow state for a child frame's reflow. Some state @@ -2132,27 +2120,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) -{ - 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; - } - - return offsetPercentBasis; -} - // XXX refactor this code to have methods for each set of properties // we are computing: width,height,line-height; margin; offsets @@ -2173,7 +2140,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. @@ -2230,8 +2197,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 @@ -2505,7 +2471,7 @@ UpdateProp(FrameProperties& aProps, void SizeComputationInput::InitOffsets(WritingMode aWM, - const LogicalSize& aPercentBasis, + nscoord aPercentBasis, nsIAtom* aFrameType, ReflowInputFlags aFlags, const nsMargin* aBorder, @@ -2876,7 +2842,7 @@ ReflowInput::CalcLineHeight(nsIContent* aContent, bool SizeComputationInput::ComputeMargin(WritingMode aWM, - const LogicalSize& aPercentBasis) + nscoord aPercentBasis) { // SVG text frames have no margin. if (mFrame->IsSVGText()) { @@ -2893,17 +2859,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); @@ -2924,7 +2890,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. @@ -2945,17 +2911,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 09c980b72..1d2df6af6 100644 --- a/layout/generic/ReflowInput.h +++ b/layout/generic/ReflowInput.h @@ -245,7 +245,7 @@ public: static void* DisplayInitOffsetsEnter( nsIFrame* aFrame, SizeComputationInput* aState, - const mozilla::LogicalSize& aPercentBasis, + nscoord aPercentBasis, const nsMargin* aBorder, const nsMargin* aPadding); static void DisplayInitOffsetsExit(nsIFrame* aFrame, @@ -260,19 +260,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 @@ -280,25 +273,18 @@ 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, nsIAtom* aFrameType); protected: void InitOffsets(mozilla::WritingMode aWM, - const mozilla::LogicalSize& aPercentBasis, + nscoord aPercentBasis, nsIAtom* aFrameType, ReflowInputFlags aFlags, const nsMargin* aBorder = nullptr, diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index 418fa16b7..fa5b24d40 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -10289,8 +10289,8 @@ DR_init_constraints_cookie::~DR_init_constraints_cookie() DR_init_offsets_cookie::DR_init_offsets_cookie( nsIFrame* aFrame, - SizeComputationInput* aState, - const LogicalSize& aPercentBasis, + SizeComputationInput* aState, + nscoord aPercentBasis, const nsMargin* aMargin, const nsMargin* aPadding) : mFrame(aFrame) @@ -11243,7 +11243,7 @@ ReflowInput::DisplayInitConstraintsExit(nsIFrame* aFrame, /* static */ void* SizeComputationInput::DisplayInitOffsetsEnter(nsIFrame* aFrame, SizeComputationInput* aState, - const LogicalSize& aPercentBasis, + nscoord aPercentBasis, const nsMargin* aBorder, const nsMargin* aPadding) { @@ -11258,12 +11258,10 @@ SizeComputationInput::DisplayInitOffsetsEnter(nsIFrame* aFrame, if (treeNode && treeNode->mDisplay) { DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent); - char horizPctBasisStr[16]; - char vertPctBasisStr[16]; + char pctBasisStr[16]; WritingMode wm = aState->GetWritingMode(); - DR_state->PrettyUC(aPercentBasis.ISize(wm), horizPctBasisStr, 16); - DR_state->PrettyUC(aPercentBasis.BSize(wm), vertPctBasisStr, 16); - printf("InitOffsets pct_basis=%s,%s", horizPctBasisStr, vertPctBasisStr); + 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 f996f57d7..af1c95ef2 100644 --- a/layout/generic/nsFrame.h +++ b/layout/generic/nsFrame.h @@ -845,7 +845,7 @@ public: struct DR_init_offsets_cookie { DR_init_offsets_cookie(nsIFrame* aFrame, mozilla::SizeComputationInput* aState, - const mozilla::LogicalSize& aPercentBasis, + nscoord aPercentBasis, const nsMargin* aBorder, const nsMargin* aPadding); ~DR_init_offsets_cookie(); |