Fix simple grid content widths#2749
Open
moreaki wants to merge 2 commits into
Open
Conversation
Contributor
Author
|
I added the exact flex-column/grid sample from the #2354 issue comment as One note for review: this standalone sample already lays out as a stretched flex item on current Validation after the added test:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
This adds a small intrinsic-width helper for grid containers used by preferred width calculations.
Before this change,
min_content_width()andmax_content_width()treatedGridContainerBoxlike a regular block container. That means shrink-to-fit contexts, such as floats and flex/grid items using intrinsic size contributions, could see a multi-column grid as if its intrinsic width were just the width of one child block. In the minimal example discussed in #2354/#2145, a two-column grid containingabc deftwice reported a width close to oneabc def, causing each grid item to wrap toabc/def.The new helper handles simple, non-spanning row-flow grid containers by summing per-track intrinsic contributions and gutters. It is deliberately conservative: it improves common grid content width cases without attempting to implement the complete CSS Grid intrinsic sizing algorithm.
Investigation summary
I followed the #2354 link chain and related work before making this patch:
aspect-rationot supported in CSS #1891:aspect-ratiois unsupported.row-gapandgapproperties in flex layout #1665: flexgapsupport, later handled by the flex rewrite.box-sizing: border-box#2628/Handlebox-sizing: border-boxin grid layout #2643 (box-sizing: border-boxin grid layout, merged), and Support grid-auto-flow: column #2142/Support grid-auto-flow: column #2162 (grid-auto-flow: column, merged).What this fixes
The PR fixes the maintainer’s minimal intrinsic-size example from #2354/#2145:
With this patch, the float’s max-content width includes both grid tracks, and the two
abc defitems no longer wrap as if the grid were one child block wide.The PR now also includes the exact flex-column/grid sample from the #2354 issue comment as
test_grid_container_in_flex_column. On current main, that standalone sample already lays out as a stretched flex item, so this test is included as related reference coverage; the behavior-changing regression remains the shrink-to-fit grid content width case above.What this does not fix
This is not full CSS Grid intrinsic sizing support. In particular, this PR does not claim to solve:
aspect-ratiosupport (aspect-rationot supported in CSS #1891);min-content/max-contentcases;auto-fit/auto-fill;automargins for grid items;min-*/max-*constraints on grid items;The intent is to provide a small reviewable base for one narrow part of #2354: simple grid containers contributing a sensible min/max-content width in shrink-to-fit contexts.
Tests
venv/bin/python -m ruff check weasyprint/layout/grid.py weasyprint/layout/preferred.py tests/layout/test_grid.pyvenv/bin/python -m pytest tests/layout/test_grid.pyvenv/bin/python -m pytest tests/layout/test_preferred.py tests/layout/test_flex.pyvenv/bin/python -m pytest-> 4027 passed, 40 xfailedAddresses part of #2354.
Related to #2145, #2644, #2342, #1891, #1665, #1652, #2362, #2628, #2647.