Skip to content

layout: Consider aspect-ratio block sizes when collapsing margins - #50247

Merged
Loirooriol merged 6 commits into
servo:mainfrom
yezhizhen:ar
Nov 27, 2026
Merged

Loirooriol merged 6 commits into
servo:mainfrom
yezhizhen:ar

Conversation

@yezhizhen

Copy link
Copy Markdown
Member

tentative_block_size is used to decide margin collapse. Since it was resolved before inline size known,
it didn't include block size derived from aspect-ratio.

Testing: Existing tests. Tested with #47980 (comment).
Fixes: Part of #32802

@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 26, 2026

@Loirooriol Loirooriol left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the logic works. But I have realized that there was another problem around here:

<!-- quirks -->
<div style="height: 200px">
  <div style="width: 100px; aspect-ratio: 1">
    <div style="height: stretch; border: solid"></div>
  </div>
</div>

has_quirky_block_size becomes true, so we don't resolve stretch.

I guess has_quirky_block_size should be set to false when overriding block_size_for_children due to a ratio.

Probably best for a follow-up PR that adds a new test.

Comment thread components/layout/flow/mod.rs Outdated
Comment on lines +1922 to +1923
// A block size that is definite due to the aspect ratio
// doesn't allow margins to collapse through the box.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would merge this comment with the one above, e.g.

// If there is a preferred aspect ratio, adjust tentative_block_size for margin collapse
// purposes, and block_size_for_children so that children can resolve block percentages.

Note that the aspect ratio can still allow margin collapse if the resulting block size is a definite 0:

<!DOCTYPE html>
<div style="border: solid; width: 50px">
  <div style="width: 0px; aspect-ratio: 1; margin: 50px 0"></div>
</div>

(in this regard we align with Blink and WebKit, not with Firefox).

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Nov 26, 2026
Signed-off-by: Euclid Ye <[email protected]>
Signed-off-by: Euclid Ye <[email protected]>
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 27, 2026
@yezhizhen
yezhizhen enabled auto-merge November 27, 2026 03:17
@yezhizhen

yezhizhen commented Nov 27, 2026 •

Copy link
Copy Markdown
Member Author

@Loirooriol I have also added compatibility comment in 17b57d2 where we decide margin collapsing.

As for quirks, checked with other browsers: https://servo.zulipchat.com/#narrow/channel/263398-general/topic/.E2.9C.94.20Looking.20for.20simple.20WebKit.20test/with/644025073
It seems only Chromium would stretch with height resolved from aspect-ratio, and we are aligning with Gecko/WebKit.

Probably open an issue and add a tentative test?

@yezhizhen
yezhizhen added this pull request to the merge queue Nov 27, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Nov 27, 2026
@Loirooriol
Loirooriol removed this pull request from the merge queue due to a manual request Nov 27, 2026
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Nov 27, 2026
Comment thread components/layout/flow/mod.rs Resolved
Signed-off-by: Euclid Ye <[email protected]>
This reverts commit 17b57d2.

Signed-off-by: Euclid Ye <[email protected]>
@Loirooriol
Loirooriol enabled auto-merge November 27, 2026 04:11
@Loirooriol
Loirooriol added this pull request to the merge queue Nov 27, 2026
Merged via the queue into servo:main with commit 6665562 Nov 27, 2026
32 checks passed
@yezhizhen
yezhizhen deleted the ar branch November 27, 2026 05:08
Flawedsora pushed a commit to Flawedsora/servo that referenced this pull request Nov 28, 2026
…ervo#50271)

Testing: 
- New passing in
`/css/css-position/position-relative-aspect-ratio-002.html`, which is a
position test in quirks mode about percentage resolution in presence of
aspect-ratio.
- Add a _tentative_ test `quirks-mode-stretch-block-size.tentative.html`
for css-sizing, based on
servo#50247 (review).
It mimics the above newly passing test.

Fixes: Part of servo#32802

---------

Signed-off-by: Euclid Ye <[email protected]>
devin-ai-integration Bot added a commit to baigojahanzaib/servo that referenced this pull request Nov 28, 2026
…rvo#50247)

(cherry picked from upstream 6665562 — kept fork's conservative in-flow transfer logic, applied mut binding)

Co-Authored-By: Jahanzaib Baigo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants