Repository navigation
Grid: lay subgrids out in their parent tracks - #2673
Conversation
`grid-template-columns`, `grid-template-rows`, `grid-template`, and Tailwind's `grid-cols-subgrid` take `subgrid <line-name-list>?`, as Blink's ConsumeGridTrackList does, with one `auto-fill` name repeater at most.
Port Blink's subgrid support. GridSizingTree holds a grid and its nested subgrids, BuildGridSizingSubtree appends the items a root grid sizes, the line resolver merges the parent's line names and areas, placement clamps to the subgrid's span, CreateSubgridTrackCollection and CreateSubgridBaselines give a subgrid its parent's tracks with its margin, border, padding, and gap, and the subgrid lays out in the GridLayoutSubtree its constraint space carries.
Eight grid-lanes subgrid tests no longer pass: they passed only because both sides ignored `subgrid`, and their references now lay out a real subgrid that the unsupported grid-lanes container cannot.
Pre-merge checks:
|
takumi leaves a nested subgrid's lines past the parent's auto repeater where they are, exactly as Blink's ExpandAutoRepeatTracksFromParent does, so the note no longer calls it an approximation.
Port Blink's major and minor baseline groups (GridTrackBaselines, GetTrackBaseline, GetExtraMarginForBaseline, the minor branch of ComputeBaselineOffset and GridBaselineAccumulator), CreateSubgridBaselines for subgrids running opposite to their root grid, subgrids measured from their layout subtree in ComputeGridItemBaselines, and the deferred ResolveBaselinesInStandaloneAxes pass. A grid's placement and a subgrid's SubgridMinMaxSizesCache now live on its layout node, as on Blink's LayoutGrid, and persist across its layouts.
@takumi-rs/helpers
@takumi-rs/image-response
takumi-js
@takumi-rs/core
takumi-paint
takumi-pdf
@takumi-rs/wasm
commit: |
Why
grid-template-columns: subgridlaid out asnonewithout a warning, so a nested grid sized its own tracks and rows never lined up across cards. WPTcss-grid/subgridpassed 34 of 89, and those only because their references ignored subgrid too.What
A function-level port of Blink's subgrid support:
subgrid <line-name-list>?parses and computes as Blink'sComputedGridTrackList, and Tailwind gainsgrid-cols-subgrid.GridSizingTree,GridLayoutTree,GridLayoutSubtree, andSubgridMinMaxSizesCachelive in the newgrid_sizing_tree.rs, built byBuildGridSizingSubtreeandForEachSubgrid.GridLineResolver::for_subgridmerges the parent's line names and areas, and placement clamps items to the subgrid's area.ComputeSubgridIntrinsicSizesizes a subgrid's standalone axis. A subgrid'sgapreplaces its parent's in its span.ConstraintSpace::grid_layout_subtreeand skips its own sizing, as Blink returns early inComputeGridGeometry.The code marks where it departs from Blink. takumi lays out horizontally only, so every subgrid is parallel to its parent, and a subgrid keeps its placement on its sizing-tree node since takumi has no
LayoutGrid.Results
subgridpasses 69 of 89. The rest need vertical writing modes,last baseline, container queries, or sticky positioning.grid-lanessubgrid tests stop passing: their references now lay out a real subgrid, which an unsupportedgrid-lanescontainer cannot match.grid_subgridpins rows lined up across three cards and a strip using named lines and its own gap. Every other golden stays byte-identical.Stacked on the named-line PR.
Follow-up
The approximations are gone except horizontal-only layout:
CreateSubgridBaselinesswaps them for a subgrid running opposite its root.SubgridMinMaxSizesCachelive on a newlayout_grid.rsnode that persists across layout passes, as on Blink'sLayoutGrid.WPT, goldens, and timing are unchanged by the follow-up: every subgrid baseline test still failing also needs a vertical writing mode.