From 6aae4df90999b38b17fd89954773ad18be5a772f Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Wed, 26 Feb 2025 17:30:36 +0100 Subject: [PATCH] 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 --- components/layout_2020/flexbox/layout.rs | 12 ++++---- tests/wpt/meta/MANIFEST.json | 26 ++++++++++++++++ .../stretch/flexbox-auto-minimum-001.html | 30 +++++++++++++++++++ .../stretch/flexbox-auto-minimum-002.html | 30 +++++++++++++++++++ 4 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 tests/wpt/tests/css/css-sizing/stretch/flexbox-auto-minimum-001.html create mode 100644 tests/wpt/tests/css/css-sizing/stretch/flexbox-auto-minimum-002.html diff --git a/components/layout_2020/flexbox/layout.rs b/components/layout_2020/flexbox/layout.rs index 74b42e6bc8d..ed88bcca120 100644 --- a/components/layout_2020/flexbox/layout.rs +++ b/components/layout_2020/flexbox/layout.rs @@ -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, diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json index ef97c1ac50c..696426f649d 100644 --- a/tests/wpt/meta/MANIFEST.json +++ b/tests/wpt/meta/MANIFEST.json @@ -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", [ diff --git a/tests/wpt/tests/css/css-sizing/stretch/flexbox-auto-minimum-001.html b/tests/wpt/tests/css/css-sizing/stretch/flexbox-auto-minimum-001.html new file mode 100644 index 00000000000..626b18deae1 --- /dev/null +++ b/tests/wpt/tests/css/css-sizing/stretch/flexbox-auto-minimum-001.html @@ -0,0 +1,30 @@ + + +Automatic minimum size of flex item with stretch cross size + + + + + + + + +

Test passes if there is a filled green square and no red.

+
+ +
diff --git a/tests/wpt/tests/css/css-sizing/stretch/flexbox-auto-minimum-002.html b/tests/wpt/tests/css/css-sizing/stretch/flexbox-auto-minimum-002.html new file mode 100644 index 00000000000..d5e590346ee --- /dev/null +++ b/tests/wpt/tests/css/css-sizing/stretch/flexbox-auto-minimum-002.html @@ -0,0 +1,30 @@ + + +Automatic minimum size of flex item with stretch cross size + + + + + + + + +

Test passes if there is a filled green square and no red.

+
+ +