Skip to content

Truly independent web browser

LibWeb: Resolve fit-content stretch bounds from computed edges

Andreas Kling24ae6b83d6ee
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index 773c52a0209..af088df2348 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -2515,21 +2515,6 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
available.to_px_or_zero() - sized.metrics().horizontal_margin_border_padding()
}
- pub(crate) fn calculate_stretch_fit_block_size(&self, sized: SizedBox<'_>, available: AvailableSize) -> CssPixels {
- // https://drafts.csswg.org/css-sizing-3/#stretch-fit-size
- // The size a box would take if its outer size filled the available space in the given axis;
- // in other words, the stretch fit into the available space, if that is definite.
- // Undefined if the available space is indefinite.
- let metrics = sized.metrics();
- available.to_px_or_zero()
- - metrics.margin_top()
- - metrics.margin_bottom()
- - metrics.padding_top()
- - metrics.padding_bottom()
- - metrics.border_top()
- - metrics.border_bottom()
- }
-
/// Whether `node` lays out its contents in a frame orthogonal to the one this context sizes it in.
pub(crate) fn establishes_orthogonal_flow(&self, node: Node) -> bool {
formatting_context::frame_established_by(&self.callbacks, node).is_orthogonal_to(self.callbacks.frame)
@@ -3801,8 +3786,8 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
SizingAxis::Inline => {
// If the available space in a given axis is definite, equal to clamp(min-content size, stretch-fit size,
// max-content size) (i.e. max(min-content size, min(max-content size, stretch-fit size))).
- if matches!(available_space.inline_size, AvailableSize::Definite(_)) {
- let stretch = self.calculate_stretch_fit_inline_size(sized, available_space.inline_size);
+ if let AvailableSize::Definite(basis) = available_space.inline_size {
+ let stretch = self.stretch_fit_inner_size(sized, SizingAxis::Inline, basis, constraints);
let max_content = self.calculate_max_content_inline_size(sized, constraints);
if max_content <= stretch {
return max_content;
@@ -3822,8 +3807,8 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
// If the available space in a given axis is definite,
// equal to clamp(min-content size, stretch-fit size, max-content size)
// (i.e. max(min-content size, min(max-content size, stretch-fit size))).
- if matches!(available_space.block_size, AvailableSize::Definite(_)) {
- let stretch = self.calculate_stretch_fit_block_size(sized, available_space.block_size);
+ if let AvailableSize::Definite(basis) = available_space.block_size {
+ let stretch = self.stretch_fit_inner_size(sized, SizingAxis::Block, basis, constraints);
let max_content = self.calculate_max_content_block_size(sized, inline_size, constraints);
if max_content <= stretch {
return max_content;
diff --git a/Tests/LibWeb/Layout/expected/flex-column-item-with-auto-height-depending-on-auto-width.txt b/Tests/LibWeb/Layout/expected/flex-column-item-with-auto-height-depending-on-auto-width.txt
index b93f973160d..2d456167aa6 100644
--- a/Tests/LibWeb/Layout/expected/flex-column-item-with-auto-height-depending-on-auto-width.txt
+++ b/Tests/LibWeb/Layout/expected/flex-column-item-with-auto-height-depending-on-auto-width.txt
@@ -1,16 +1,16 @@
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 [1,1] [0+1+0 798 0+1+0] [0+1+0 420 0+1+0] [BFC] children: not-inline
Box <body.hero> at [10,10] flex-container(column) [8+1+0 500 0+1+288] [8+1+0 402 0+1+8] [FFC] children: not-inline
- BlockContainer <div.upper> at [10,11] flex-item [0+1+0 500 0+1+0] [0+1+0 400 0+1+0] [BFC] children: inline
- frag 0 from TextNode start: 0, length: 11, rect: [10,11 453.984375x80] baseline: 63.984375
+ BlockContainer <div.upper> at [11,11] flex-item [0+1+0 498 0+1+0] [0+1+0 400 0+1+0] [BFC] children: inline
+ frag 0 from TextNode start: 0, length: 11, rect: [11,11 453.984375x80] baseline: 63.984375
"This entire"
- frag 1 from TextNode start: 12, length: 11, rect: [10,91 455x80] baseline: 63.984375
+ frag 1 from TextNode start: 12, length: 11, rect: [11,91 455x80] baseline: 63.984375
"text should"
- frag 2 from TextNode start: 24, length: 5, rect: [10,171 230.78125x80] baseline: 63.984375
+ frag 2 from TextNode start: 24, length: 5, rect: [11,171 230.78125x80] baseline: 63.984375
"be on"
- frag 3 from TextNode start: 30, length: 6, rect: [10,251 272.109375x80] baseline: 63.984375
+ frag 3 from TextNode start: 30, length: 6, rect: [11,251 272.109375x80] baseline: 63.984375
"orange"
- frag 4 from TextNode start: 37, length: 11, rect: [10,331 468.75x80] baseline: 63.984375
+ frag 4 from TextNode start: 37, length: 11, rect: [11,331 468.75x80] baseline: 63.984375
"background."
TextNode <#text> (not painted)
BlockContainer <(anonymous)> (not painted) [BFC] children: inline
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-sizing/keyword-sizes-on-abspos.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-sizing/keyword-sizes-on-abspos.txt
index 49843cc5d9d..8cd27058889 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-sizing/keyword-sizes-on-abspos.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-sizing/keyword-sizes-on-abspos.txt
@@ -2,21 +2,21 @@ Harness status: OK
Found 60 tests
-51 Pass
-9 Fail
+54 Pass
+6 Fail
Pass .test 1
Pass .test 2
-Fail .test 3
+Pass .test 3
Pass .test 4
Pass .test 5
Pass .test 6
Pass .test 7
-Fail .test 8
+Pass .test 8
Pass .test 9
Pass .test 10
Pass .test 11
Pass .test 12
-Fail .test 13
+Pass .test 13
Pass .test 14
Pass .test 15
Pass .test 16
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-sizing/keyword-sizes-on-flex-item-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-sizing/keyword-sizes-on-flex-item-001.txt
index b2157647b9c..2d36fb165e5 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-sizing/keyword-sizes-on-flex-item-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-sizing/keyword-sizes-on-flex-item-001.txt
@@ -2,13 +2,13 @@ Harness status: OK
Found 74 tests
-65 Pass
-9 Fail
+68 Pass
+6 Fail
Pass .test 1
Pass .test 2
Pass .test 3
Pass .test 4
-Fail .test 5
+Pass .test 5
Pass .test 6
Pass .test 7
Pass .test 8
@@ -17,7 +17,7 @@ Pass .test 10
Pass .test 11
Pass .test 12
Pass .test 13
-Fail .test 14
+Pass .test 14
Pass .test 15
Pass .test 16
Pass .test 17
@@ -26,7 +26,7 @@ Pass .test 19
Pass .test 20
Pass .test 21
Pass .test 22
-Fail .test 23
+Pass .test 23
Pass .test 24
Pass .test 25
Pass .test 26