Skip to content

Truly independent web browser

LibWeb: Clamp the inner cross size of early stretched flex items

Andreas Kling8e5fe93cd389
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 8b0132518be..af80967bf00 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -4031,23 +4031,15 @@ impl<'pass> FlexFormattingContext<'pass> {
if !self.flex_item_is_stretched(index) {
continue;
}
- let min_size = if self.has_cross_min_size(index) {
- self.specified_cross_min_size(index)
- } else {
- CssPixels::default()
- };
- let max_size = if self.has_cross_max_size(index) {
- self.specified_cross_max_size(index)
- } else {
- CssPixels::from_raw(i32::MAX)
- };
- let outer = css_clamp(container_cross_size, min_size, max_size);
+ let (min_size, max_size) = self.cross_size_limits(index);
let item = &self.flex_items[index];
- let inner = outer
+ let stretched = container_cross_size
- item.margins.cross_before
- item.margins.cross_after
- item.borders_and_padding.cross_before
- item.borders_and_padding.cross_after;
+ // NB: The min and max cross sizes are inner sizes, so they clamp the inner size of the item.
+ let inner = css_clamp(stretched, min_size, max_size);
self.set_cross_size(index, inner);
self.set_has_definite_cross_size(index);
}
diff --git a/Tests/LibWeb/Layout/expected/flex/stretched-column-item-with-padding-and-max-width.txt b/Tests/LibWeb/Layout/expected/flex/stretched-column-item-with-padding-and-max-width.txt
new file mode 100644
index 00000000000..06c3c2f8d77
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/flex/stretched-column-item-with-padding-and-max-width.txt
@@ -0,0 +1,11 @@
+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 320 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [0,0] [0+0+0 200 0+0+600] [0+0+0 320 0+0+0] children: not-inline
+ Box <div.column> at [0,0] flex-container(column) [0+0+0 200 0+0+0] [0+0+0 320 0+0+0] [FFC] children: not-inline
+ BlockContainer <div.item.border-box> at [10,10] flex-item [0+0+10 180 10+0+0] [0+0+10 180 10+0+0] [BFC] children: not-inline
+ BlockContainer <div.square> at [10,10] [0+0+0 180 0+0+0] [0+0+0 180 0+0+0] children: not-inline
+ BlockContainer <div.item.content-box> at [10,210] flex-item [0+0+10 100 10+0+0] [0+0+10 100 10+0+0] [BFC] children: not-inline
+ BlockContainer <div.square> at [10,210] [0+0+0 100 0+0+0] [0+0+0 100 0+0+0] children: not-inline
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x320] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/input/flex/stretched-column-item-with-padding-and-max-width.html b/Tests/LibWeb/Layout/input/flex/stretched-column-item-with-padding-and-max-width.html
new file mode 100644
index 00000000000..577426a1194
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/flex/stretched-column-item-with-padding-and-max-width.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<style>
+ body { margin: 0; width: 200px; }
+ .column { display: flex; flex-direction: column; }
+ .item { padding: 10px; }
+ .border-box { box-sizing: border-box; max-width: 100%; }
+ .content-box { max-width: 100px; }
+ .square { aspect-ratio: 1; }
+</style>
+<div class="column">
+ <div class="item border-box"><div class="square"></div></div>
+ <div class="item content-box"><div class="square"></div></div>
+</div>