Skip to content

Truly independent web browser

LibWeb: Treat intrinsic minimum block sizes of flex items as auto

sideshowbarker4c40eebf6eff
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 3a9ff151976..3ef91d8e396 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -151,14 +151,25 @@ impl<'pass> FlexItemDetails<'pass> {
const _: () = assert!(size_of::<FlexItem>() <= 128);
impl FlexItem {
- fn new(box_: Node, alignment_facts: FlexItemAlignmentFacts, inputs: &FlexItemInputs<'_>) -> Self {
+ fn new(
+ box_: Node,
+ alignment_facts: FlexItemAlignmentFacts,
+ inputs: &FlexItemInputs<'_>,
+ main_axis_is_horizontal: bool,
+ ) -> Self {
+ // https://drafts.csswg.org/css-sizing-3/#valdef-width-min-content
+ // NB: In a box's block axis, min-content, max-content and fit-content are equivalent to its automatic size, so
+ // such a minimum main size is an automatic minimum size where the main axis is the item's block axis.
+ let main_axis_is_block_axis = main_axis_is_horizontal != inputs.inline_axis_is_horizontal;
+ let main_min_size_is_auto = inputs.min_main_size.is_auto()
+ || (main_axis_is_block_axis && inputs.min_main_size.is_intrinsic_sizing_constraint());
Self {
box_,
alignment_facts,
cross_size_is_stretch: inputs.preferred_cross_size.is_stretch(),
cross_size_is_calc_size: inputs.preferred_cross_size.calc_size().is_some(),
cross_min_or_max_size_is_stretch: inputs.min_cross_size.is_stretch() || inputs.max_cross_size.is_stretch(),
- main_min_size_is_auto: inputs.min_main_size.is_auto(),
+ main_min_size_is_auto,
main_min_size_is_calc_size: inputs.min_main_size.calc_size().is_some(),
max_main_size_is_none: false,
max_cross_size_is_none: false,
@@ -1215,7 +1226,12 @@ impl<'pass> FlexFormattingContext<'pass> {
let (inputs, alignment_facts) = self.resolve_item_inputs(child);
let order = self.order_of_item(inputs.style);
items_have_different_orders |= *order_of_first_item.get_or_insert(order) != order;
- self.flex_items.push(FlexItem::new(child, alignment_facts, &inputs));
+ self.flex_items.push(FlexItem::new(
+ child,
+ alignment_facts,
+ &inputs,
+ self.main_axis_is_horizontal(),
+ ));
self.items_to_fork.take();
self.flex_item_details.push(FlexItemDetails::new(inputs, cells));
self.populate_specified_margins(self.flex_items.len() - 1);
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-flexbox/flex-minimum-height-flex-items-023.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-flexbox/flex-minimum-height-flex-items-023.html
new file mode 100644
index 00000000000..095ff55878b
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-flexbox/flex-minimum-height-flex-items-023.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<title>Flex minimum height of image with intrinsic min-height specified</title>
+<link rel="author" title="[email protected]" href="mailto:[email protected]" />
+<link rel="help" href="https://drafts.csswg.org/css-flexbox/#min-size-auto" />
+<link rel="help" href="https://drafts.csswg.org/css-sizing-3/#valdef-width-min-content" />
+<link rel="match" href="../../../../expected/wpt-import/css/css-flexbox/../reference/ref-filled-green-100px-square-only.html" />
+<link rel="bookmark" href="https://crbug.com/1088223">
+<meta name="assert" content="Flex uses automatic minimum sizes when item specifies min-height:intrinsic, because that is treated as auto.">
+
+<p>Test passes if there is a filled green square.</p>
+
+<!--
+Here's the spec trail why the height of this item is 100px.
+
+1. The column flexbox has height:0, and the item has flex-shrink: 1. So
+ min-height will determine the item's flexed height.
+
+2. The min-content value of the min-height property is equivalent to the
+ automatic size, per https://drafts.csswg.org/css-sizing-3/#valdef-width-min-content,
+ because it's in the item's block dimension. (Blink legacy flex disagrees here)
+
+3. Per https://drafts.csswg.org/css-flexbox/#min-size-auto, the used value of a
+ main axis automatic minimum size on a flex item that is not a scroll container
+ is a content-based minimum size.
+
+4. The content-based min size of this item is min(content size suggestion,
+ specified size suggestion). We ignore transferred size suggestion because
+ this item has a specified size.
+
+5. content size suggestion = 50px because the stretched width of 100px is sent
+ through the 2:1 aspect ratio to determine the image's min-content size in the
+ block axis.
+
+ 5a. This flex container qualifies for 9.8.3:
+
+ If a single-line flex container has a definite cross size, the automatic
+ preferred outer cross size of any stretched flex items is the flex
+ container's inner cross size (clamped to the flex item's min and max cross
+ size) and is considered definite.
+
+ So the preferred width of the image is 100px.
+ 5b. The float specified by the min-content calculation from css-sizing 5.1 is
+ <img src="support/300x150-green.png" style="width: 100px; float: left;" />
+ This element gets height 50px.
+
+6. specified size suggestion = 100px because that's what's specified.
+
+7. So content-based min size = min(50, 100) = 50px. That becomes its flexed
+ height (see #1).
+
+8. Then, the item stretches its width to 100px. The item has an aspect ratio,
+ so does the new width change the height? Not according to
+ https://drafts.csswg.org/css-flexbox/#algo-stretch, which says "Note that
+ this step does not affect the main size of the flex item, even if it has an
+ intrinsic aspect ratio." The height remains 50px.
+-->
+
+<div style="height: 50px; width: 100px; background: green;"></div>
+<div style="display: flex; flex-direction: column; width:100px; height: 0px;">
+ <img src="support/300x150-green.png" style="min-height: min-content; height: 100px;" />
+</div>