diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index c3cc092aaf82..2f2ae0717e89 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -5988,7 +5988,7 @@ nsGridContainerFrame::Reflow(nsPresContext* aPresContext, const nscoord computedBSize = aReflowInput.ComputedBSize(); const nscoord computedISize = aReflowInput.ComputedISize(); const WritingMode& wm = gridReflowInput.mWM; - LogicalSize computedSize(wm, computedISize, computedBSize); + const LogicalSize computedSize(wm, computedISize, computedBSize); nscoord consumedBSize = 0; nscoord bSize = 0; @@ -5999,18 +5999,28 @@ nsGridContainerFrame::Reflow(nsPresContext* aPresContext, gridReflowInput.CalculateTrackSizes(grid, computedSize, SizingConstraint::eNoConstraint); - // Note: we can't use GridLineEdge here since we haven't calculated - // the rows' mPosition yet (happens in AlignJustifyContent below). - for (const auto& sz : gridReflowInput.mRows.mSizes) { - bSize += sz.mBase; + // XXX Technically incorrect: We're ignoring our row sizes, when really + // we should use them but *they* should be computed as if we had no + // children. To be fixed in bug 1488878. + if (!aReflowInput.mStyleDisplay->IsContainSize()) { + // Note: we can't use GridLineEdge here since we haven't calculated + // the rows' mPosition yet (happens in AlignJustifyContent below). + for (const auto& sz : gridReflowInput.mRows.mSizes) { + bSize += sz.mBase; + } + bSize += gridReflowInput.mRows.SumOfGridGaps(); } - bSize += gridReflowInput.mRows.SumOfGridGaps(); } else { consumedBSize = ConsumedBSize(wm); gridReflowInput.InitializeForContinuation(this, consumedBSize); - const uint32_t numRows = gridReflowInput.mRows.mSizes.Length(); - bSize = gridReflowInput.mRows.GridLineEdge(numRows, - GridLineSide::eAfterGridGap); + // XXX Technically incorrect: We're ignoring our row sizes, when really + // we should use them but *they* should be computed as if we had no + // children. To be fixed in bug 1488878. + if (!aReflowInput.mStyleDisplay->IsContainSize()) { + const uint32_t numRows = gridReflowInput.mRows.mSizes.Length(); + bSize = gridReflowInput.mRows.GridLineEdge(numRows, + GridLineSide::eAfterGridGap); + } } if (computedBSize == NS_AUTOHEIGHT) { bSize = NS_CSS_MINMAX(bSize, @@ -6476,7 +6486,9 @@ nsGridContainerFrame::GetMinISize(gfxContext* aRC) { DISPLAY_MIN_WIDTH(this, mCachedMinISize); if (mCachedMinISize == NS_INTRINSIC_WIDTH_UNKNOWN) { - mCachedMinISize = IntrinsicISize(aRC, nsLayoutUtils::MIN_ISIZE); + mCachedMinISize = StyleDisplay()->IsContainSize() + ? 0 + : IntrinsicISize(aRC, nsLayoutUtils::MIN_ISIZE); } return mCachedMinISize; } @@ -6486,7 +6498,9 @@ nsGridContainerFrame::GetPrefISize(gfxContext* aRC) { DISPLAY_PREF_WIDTH(this, mCachedPrefISize); if (mCachedPrefISize == NS_INTRINSIC_WIDTH_UNKNOWN) { - mCachedPrefISize = IntrinsicISize(aRC, nsLayoutUtils::PREF_ISIZE); + mCachedPrefISize = StyleDisplay()->IsContainSize() + ? 0 + : IntrinsicISize(aRC, nsLayoutUtils::PREF_ISIZE); } return mCachedPrefISize; } diff --git a/layout/reftests/w3c-css/submitted/contain/contain-size-grid-001-ref.html b/layout/reftests/w3c-css/submitted/contain/contain-size-grid-001-ref.html new file mode 100644 index 000000000000..b2fdf4b88769 --- /dev/null +++ b/layout/reftests/w3c-css/submitted/contain/contain-size-grid-001-ref.html @@ -0,0 +1,49 @@ + + + + + CSS Reftest Reference + + + + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ + diff --git a/layout/reftests/w3c-css/submitted/contain/contain-size-grid-001.html b/layout/reftests/w3c-css/submitted/contain/contain-size-grid-001.html new file mode 100644 index 000000000000..a85b0a3138de --- /dev/null +++ b/layout/reftests/w3c-css/submitted/contain/contain-size-grid-001.html @@ -0,0 +1,72 @@ + + + + + CSS Test: 'contain: size' on grid elements should cause them to be sized and baseline-aligned as if they had no contents. + + + + + + + +
inner
+
+ + +
inner
+
+ + +
inner
+
+ + +
inner
+
+ + +
inner
+
+ + +
inner
+
+ + +
inner
+ + diff --git a/layout/reftests/w3c-css/submitted/contain/reftest.list b/layout/reftests/w3c-css/submitted/contain/reftest.list index d2d4685348e9..c3836767cdab 100644 --- a/layout/reftests/w3c-css/submitted/contain/reftest.list +++ b/layout/reftests/w3c-css/submitted/contain/reftest.list @@ -22,6 +22,7 @@ pref(layout.css.overflow-clip-box.enabled,true) == contain-paint-clip-006.html c == contain-size-inline-block-001.html contain-size-inline-block-001-ref.html == contain-size-flex-001.html contain-size-flex-001-ref.html fuzzy-if(webrender&&winWidget,0-3,0-2) == contain-size-inline-flex-001.html contain-size-inline-flex-001-ref.html # bug 1474093 +== contain-size-grid-001.html contain-size-grid-001-ref.html == contain-size-multicol-001.html contain-size-multicol-001-ref.html == contain-size-fieldset-001.html contain-size-fieldset-001-ref.html == contain-size-fieldset-002.html contain-size-fieldset-002-ref.html