layout: Restrict stretch alignment to flex items with computed auto size (#36288)

We were allowing `align-self: stretch` to stretch flex items whose cross
size behaves as `auto`, including cyclic percentages.

However, https://github.com/w3c/csswg-drafts/issues/4525 resolved that
stretching should only happen when the cross size computes to `auto`.

So this patch exposes this information in `ContentBoxSizesAndPBM`, and
refactors the flexbox stretching logic.

Fixes: #36285

Testing:
 - `/css/css-flexbox/quirks-auto-block-size-with-percentage-item.html`
 - `/css/css-flexbox/stretch-requires-computed-auto-size.html`

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2025-04-04 03:15:40 -07:00 committed by GitHub
parent c19c7b2ed8
commit 202cac900d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 94 additions and 67 deletions

View file

@ -235,6 +235,7 @@ pub(crate) struct ContentBoxSizesAndPBM {
pub content_box_sizes: LogicalVec2<Sizes>,
pub pbm: PaddingBorderMargin,
pub depends_on_block_constraints: bool,
pub preferred_size_computes_to_auto: LogicalVec2<bool>,
}
#[derive(Clone, Debug, PartialEq)]
@ -1000,6 +1001,8 @@ impl LayoutStyle<'_> {
let box_size = style.box_size(writing_mode);
let min_size = style.min_box_size(writing_mode);
let max_size = style.max_box_size(writing_mode);
let preferred_size_computes_to_auto = box_size.map(|size| size.is_initial());
let depends_on_block_constraints = |size: &Size<LengthPercentage>| {
match size {
// fit-content is like clamp(min-content, stretch, max-content), but currently
@ -1014,7 +1017,6 @@ impl LayoutStyle<'_> {
_ => false,
}
};
let depends_on_block_constraints = depends_on_block_constraints(&box_size.block) ||
depends_on_block_constraints(&min_size.block) ||
depends_on_block_constraints(&max_size.block) ||
@ -1045,6 +1047,7 @@ impl LayoutStyle<'_> {
},
pbm,
depends_on_block_constraints,
preferred_size_computes_to_auto,
}
}