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 @@ + + +
+ +