layout: Support stretch cross size for automatic min size in flexbox (#35652)

The computation of the automatic minimum size may involve transferring
a definite cross size into the main axis through the aspect ratio.
We were only considering numeric sizes as definite, but `stretch` can
also be definite.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2025-02-26 17:30:36 +01:00 committed by GitHub
parent 9d5171f3c5
commit 6aae4df909
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 93 additions and 5 deletions

View file

@ -2530,14 +2530,16 @@ impl FlexItemBox {
Direction::Block
};
let cross_stretch_size = containing_block_size
.cross
.map(|v| v - pbm_auto_is_zero.cross);
let cross_size = SizeConstraint::new(
if content_box_size.cross.is_initial() && auto_cross_size_stretches_to_container_size {
containing_block_size
.cross
.map(|v| v - pbm_auto_is_zero.cross)
cross_stretch_size
} else {
// TODO(#32853): handle size keywords.
content_box_size.cross.to_numeric()
content_box_size
.cross
.maybe_resolve_extrinsic(cross_stretch_size)
},
min_size.cross.auto_is(Au::zero),
max_size.cross,

View file

@ -246687,6 +246687,32 @@
{}
]
],
"flexbox-auto-minimum-001.html": [
"626b18deae189b3c97c106968758164405786941",
[
null,
[
[
"/css/reference/ref-filled-green-200px-square.html",
"=="
]
],
{}
]
],
"flexbox-auto-minimum-002.html": [
"d5e590346ee36a7cb613e6fa89c1c999c2cccfb5",
[
null,
[
[
"/css/reference/ref-filled-green-200px-square.html",
"=="
]
],
{}
]
],
"min-width-1.html": [
"a1a39073e88d4626be7c469611e3593415849e7a",
[

View file

@ -0,0 +1,30 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Automatic minimum size of flex item with stretch cross size</title>
<link rel="author" title="Oriol Brufau" href="mailto:obrufau@igalia.com">
<link rel="help" href="https://drafts.csswg.org/css-sizing-4/#stretch-fit-sizing">
<link rel="help" href="https://drafts.csswg.org/css-flexbox-1/#min-size-auto">
<link rel="match" href="../../reference/ref-filled-green-200px-square.html">
<meta assert="A definite `stretch` cross size can be transferred through the
aspect ratio when computing the automatic minimum size of a flex item.">
<style>
div {
display: flex;
flex-direction: column;
height: 200px;
width: 200px;
background: red;
}
canvas {
width: stretch;
align-self: start;
flex-basis: 0;
background: green;
}
</style>
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
<div class="flex">
<canvas width="100" height="100"></canvas>
</div>

View file

@ -0,0 +1,30 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Automatic minimum size of flex item with stretch cross size</title>
<link rel="author" title="Oriol Brufau" href="mailto:obrufau@igalia.com">
<link rel="help" href="https://drafts.csswg.org/css-sizing-4/#stretch-fit-sizing">
<link rel="help" href="https://drafts.csswg.org/css-flexbox-1/#min-size-auto">
<link rel="match" href="../../reference/ref-filled-green-200px-square.html">
<meta assert="A definite `stretch` cross size can be transferred through the
aspect ratio when computing the automatic minimum size of a flex item.">
<style>
div {
display: flex;
flex-direction: row;
height: 200px;
width: 200px;
background: red;
}
canvas {
height: stretch;
align-self: start;
flex-basis: 0;
background: green;
}
</style>
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
<div class="flex">
<canvas width="100" height="100"></canvas>
</div>