Truly independent web browser
LibWeb: Transfer intrinsic min and max widths of replaced elements
Andreas Kling082c4a193964
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex 86b332e0da9..0356b446b5e 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -661,34 +661,54 @@ impl<'pass> SizingContext<'pass> {&& size.is_intrinsic_sizing_constraint()&& self.intrinsic_inline_sizes_are_transferred(node, constraints)};+ // NB: The min-content and max-content inline sizes of a replaced element follow a non-automatic block size+ // through the aspect ratio.+ let transferred_intrinsic_limit = |size: &ComputedSize| {+ (size.is_intrinsic_sizing_constraint()+ && self.facts(node).has_preferred_aspect_ratio()+ && !self.preferred_block_size(node, constraints).is_auto()+ && !self.should_treat_block_size_as_auto(node, available_space, constraints))+ .then(|| {+ let block_size = self.compute_block_size_for_replaced_element(node, available_space, constraints);+ self.content_inline_size_from_aspect_ratio(node, block_size)+ })+ };// 2. If the tentative used width is greater than 'max-width', the rules above are applied again,// but this time using the computed value of 'max-width' as the computed value for 'width'.if !self.should_treat_max_inline_size_as_none(node, available_space.inline_size, constraints)&& !is_transferred_intrinsic_limit(style.max_width()){- let max =- self.calculate_inner_inline_size(node, available_space.inline_size, style.max_width(), constraints);- if used > max {- used = self.tentative_inline_size_for_replaced_element(- node,- style.max_width(),- available_space,- constraints,- );+ if let Some(max) = transferred_intrinsic_limit(style.max_width()) {+ used = used.min(max);+ } else {+ let max =+ self.calculate_inner_inline_size(node, available_space.inline_size, style.max_width(), constraints);+ if used > max {+ used = self.tentative_inline_size_for_replaced_element(+ node,+ style.max_width(),+ available_space,+ constraints,+ );+ }}}// 3. If the resulting width is smaller than 'min-width', the rules above are applied again,// but this time using the value of 'min-width' as the computed value for 'width'.if !style.min_width().is_auto() && !is_transferred_intrinsic_limit(style.min_width()) {- let min =- self.calculate_inner_inline_size(node, available_space.inline_size, style.min_width(), constraints);- if used < min {- used = self.tentative_inline_size_for_replaced_element(- node,- style.min_width(),- available_space,- constraints,- );+ if let Some(min) = transferred_intrinsic_limit(style.min_width()) {+ used = used.max(min);+ } else {+ let min =+ self.calculate_inner_inline_size(node, available_space.inline_size, style.min_width(), constraints);+ if used < min {+ used = self.tentative_inline_size_for_replaced_element(+ node,+ style.min_width(),+ available_space,+ constraints,+ );+ }}}useddiff --git a/Tests/LibWeb/Text/expected/replaced-intrinsic-min-max-width-follow-height-through-ratio.txt b/Tests/LibWeb/Text/expected/replaced-intrinsic-min-max-width-follow-height-through-ratio.txtnew file mode 100644index 00000000000..2afd3a211fe--- /dev/null+++ b/Tests/LibWeb/Text/expected/replaced-intrinsic-min-max-width-follow-height-through-ratio.txt@@ -0,0 +1,4 @@+height: 20px; width: 1px; min-width: fit-content: 10x20+height: 20px; width: 100px; max-width: min-content: 10x20+height: 20px; width: 1px; min-width: max-content: 10x20+width: 1px; min-width: fit-content: 30x60diff --git a/Tests/LibWeb/Text/input/replaced-intrinsic-min-max-width-follow-height-through-ratio.html b/Tests/LibWeb/Text/input/replaced-intrinsic-min-max-width-follow-height-through-ratio.htmlnew file mode 100644index 00000000000..6efc4256837--- /dev/null+++ b/Tests/LibWeb/Text/input/replaced-intrinsic-min-max-width-follow-height-through-ratio.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<canvas width="30" height="60" style="height: 20px; width: 1px; min-width: fit-content"></canvas>+<canvas width="30" height="60" style="height: 20px; width: 100px; max-width: min-content"></canvas>+<canvas width="30" height="60" style="height: 20px; width: 1px; min-width: max-content"></canvas>+<canvas width="30" height="60" style="width: 1px; min-width: fit-content"></canvas>+<script src="include.js"></script>+<script>+ test(() => {+ for (const canvas of document.querySelectorAll("canvas"))+ println(`${canvas.getAttribute("style")}: ${canvas.offsetWidth}x${canvas.offsetHeight}`);+ });+</script>