Bug 1944423 Part 1 - Resolve grid row sizes when computing grid container's intrinsic inline-size. r=dholbert

The idea behind this patch is to allow grid items with percent-valued
block-sizes to resolve against definite grid rows and then transfer that
resolved block-size as their inline contribution to the grid container's
intrinsic inline-size.

Differential Revision: https://phabricator.services.mozilla.com/D246466
This commit is contained in:
Ting-Yu Lin
2025-05-03 21:17:17 +00:00
committed by aethanyc@gmail.com
parent c80b0fbf17
commit 46b8529e34

View File

@@ -7628,10 +7628,20 @@ LogicalSize nsGridContainerFrame::GridReflowInput::PercentageBasisFor(
}
if (aAxis == LogicalAxis::Inline || !mCols.mCanResolveLineRangeSize) {
if (StaticPrefs::layout_css_grid_multi_pass_track_sizing_enabled() &&
aAxis == LogicalAxis::Inline && mRows.mCanResolveLineRangeSize) {
// When resolving the column sizes with definite row sizes, get row size
// for the grid area occupied by aGridItem.
const nscoord colSize = NS_UNCONSTRAINEDSIZE;
const nscoord rowSize = aGridItem.mArea.mRows.ToLength(mRows.mSizes);
return !wm.IsOrthogonalTo(mWM) ? LogicalSize(wm, colSize, rowSize)
: LogicalSize(wm, rowSize, colSize);
}
return LogicalSize(wm, NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
}
// Note: for now, we only resolve transferred percentages to row sizing.
// We may need to adjust these assertions once we implement bug 1300366.
// Tracked in Bug 1957503.
MOZ_ASSERT(!mRows.mCanResolveLineRangeSize);
nscoord colSize = aGridItem.mArea.mCols.ToLength(mCols.mSizes);
nscoord rowSize = NS_UNCONSTRAINEDSIZE;
@@ -10007,6 +10017,34 @@ nscoord nsGridContainerFrame::ComputeIntrinsicISize(
gridRI.CalculateTrackSizesForAxis(LogicalAxis::Inline, grid,
NS_UNCONSTRAINEDSIZE, constraint);
if (StaticPrefs::layout_css_grid_multi_pass_track_sizing_enabled()) {
const nscoord contentBoxBSize =
aInput.mPercentageBasisForChildren
? aInput.mPercentageBasisForChildren->BSize(gridRI.mWM)
: NS_UNCONSTRAINEDSIZE;
// Resolve row sizes so that when we re-resolve the column sizes, grid items
// with percent-valued block-sizes (and aspect ratios) have definite row
// sizes as the percentage basis. Their resolved block-size can then
// transfer to the inline-axis, contributing correctly to the grid
// container's intrinsic inline-size.
gridRI.CalculateTrackSizesForAxis(LogicalAxis::Block, grid, contentBoxBSize,
SizingConstraint::NoConstraint);
// Reset the track sizing bits before re-resolving the column sizes.
for (auto& item : gridRI.mGridItems) {
item.ResetTrackSizingBits(LogicalAxis::Inline);
}
gridRI.mCols.mCanResolveLineRangeSize = false;
// Re-resolve the column sizes, using the resolved row sizes establish
// above. See 12.1.3 of the Grid Sizing Algorithm for more scenarios where
// re-resolving the column sizes is necessary:
// https://drafts.csswg.org/css-grid-2/#algo-grid-sizing
gridRI.CalculateTrackSizesForAxis(LogicalAxis::Inline, grid,
NS_UNCONSTRAINEDSIZE, constraint);
}
if (MOZ_LIKELY(!IsSubgrid())) {
return gridRI.mCols.SumOfGridTracksAndGaps();
}