Truly independent web browser
LibWeb: Measure a box’s intrinsic height at its own width
sideshowbarker2d6afbdb69a8
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex b961c8daf62..ca7bd912710 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -3989,6 +3989,17 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {}}+ /// The inline size at which to measure the intrinsic block sizes of `sized`: its own content inline size once+ /// that's resolved, since its contents are laid out in it, and otherwise the available inline size.+ fn inline_size_for_intrinsic_block_size(&self, sized: SizedBox<'_>, available_space: AvailableSpace) -> CssPixels {+ let metrics = sized.metrics();+ if metrics.has_definite_inline_size() {+ metrics.content_inline_size()+ } else {+ available_space.inline_size.to_px_or_zero()+ }+ }+pub(crate) fn calculate_fit_content_size(&self,sized: SizedBox<'_>,@@ -4017,7 +4028,7 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {self.calculate_max_content_inline_size(sized, constraints)}SizingAxis::Block => {- let inline_size = available_space.inline_size.to_px_or_zero();+ let inline_size = self.inline_size_for_intrinsic_block_size(sized, available_space);// https://drafts.csswg.org/css-sizing-3/#fit-content-size// If the available space in a given axis is definite,// equal to clamp(min-content size, stretch-fit size, max-content size)@@ -4389,9 +4400,11 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {} else if preferred_size.is_fit_content() {Some(self.calculate_fit_content_size(sized, SizingAxis::Block, available_space, constraints))} else if preferred_size.is_max_content() {- Some(self.calculate_max_content_block_size(sized, available_space.inline_size.to_px_or_zero(), constraints))+ let inline_size = self.inline_size_for_intrinsic_block_size(sized, available_space);+ Some(self.calculate_max_content_block_size(sized, inline_size, constraints))} else if preferred_size.is_min_content() {- Some(self.calculate_min_content_block_size(sized, available_space.inline_size.to_px_or_zero(), constraints))+ let inline_size = self.inline_size_for_intrinsic_block_size(sized, available_space);+ Some(self.calculate_min_content_block_size(sized, inline_size, constraints))} else {None};diff --git a/Tests/LibWeb/Layout/expected/fit-content-height-uses-used-width.txt b/Tests/LibWeb/Layout/expected/fit-content-height-uses-used-width.txtnew file mode 100644index 00000000000..358592df034--- /dev/null+++ b/Tests/LibWeb/Layout/expected/fit-content-height-uses-used-width.txt@@ -0,0 +1,10 @@+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 303.203125 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [20,20] [20+0+0 760 0+0+20] [20+0+0 263.203125 0+0+20] children: inline+ frag 0 from BlockContainer start: 0, length: 0, rect: [24,24 448x252] baseline: 260+ BlockContainer <div.wrapper> at [24,24] inline-block [0+0+4 448 4+0+0] [0+0+4 252 4+0+0] [BFC] children: not-inline+ CanvasBox <canvas> at [24,24] [0+0+0 448 0+0+0] [0+0+0 252 0+0+0] children: not-inline+ TextNode <#text> (not painted)++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x303.203125] (z-index: auto)diff --git a/Tests/LibWeb/Layout/input/fit-content-height-uses-used-width.html b/Tests/LibWeb/Layout/input/fit-content-height-uses-used-width.htmlnew file mode 100644index 00000000000..cec23abff04--- /dev/null+++ b/Tests/LibWeb/Layout/input/fit-content-height-uses-used-width.html@@ -0,0 +1,5 @@+<!DOCTYPE html><style>+ body { margin: 20px; }+ .wrapper { display: inline-block; width: 100%; max-width: 448px; height: fit-content; padding: 4px; line-height: 0; background: red; }+ canvas { display: block; width: 100%; height: auto; background: green; }+</style><div class="wrapper"><canvas width="448" height="252"></canvas></div>