Truly independent web browser
LibWeb: Preserve an SVG image’s ratio under a height limit
sideshowbarkera3257c0e72f8
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex 062c30c41bb..f97c4e0841d 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -1071,8 +1071,11 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {&& is_plain_auto(computed_block)&& self.facts(node).has_preferred_aspect_ratio(){- let block =- self.tentative_block_size_for_replaced_element(sized, computed_block, available_space, constraints);+ let block = if self.facts(node).is_replaced_box() && self.auto_content_size(node).height.is_none() {+ self.content_block_size_from_aspect_ratio(sized, used)+ } else {+ self.tentative_block_size_for_replaced_element(sized, computed_block, available_space, constraints)+ };used = self.solve_replaced_size_constraint(sized, used, block, available_space, constraints).0;diff --git a/Tests/LibWeb/Text/expected/replaced/image-with-ratio-only-min-max-size.txt b/Tests/LibWeb/Text/expected/replaced/image-with-ratio-only-min-max-size.txtnew file mode 100644index 00000000000..ac1d9171583--- /dev/null+++ b/Tests/LibWeb/Text/expected/replaced/image-with-ratio-only-min-max-size.txt@@ -0,0 +1,12 @@+auto: 600x300+height limit: 60x30+block: 60x30+width limit: 120x60+both limits: 40x20+fixed width: 200x30+fixed height: 60x30+width minimum: 120x30+zero maximum: 0x0+natural size: 60x30+border box: 50x30+vertical writing mode: 60x30diff --git a/Tests/LibWeb/Text/input/replaced/image-with-ratio-only-min-max-size.html b/Tests/LibWeb/Text/input/replaced/image-with-ratio-only-min-max-size.htmlnew file mode 100644index 00000000000..42b7ccc8eda--- /dev/null+++ b/Tests/LibWeb/Text/input/replaced/image-with-ratio-only-min-max-size.html@@ -0,0 +1,31 @@+<!doctype html>+<body>+<script src="../include.js"></script>+<script>+ promiseTest(async () => {+ const outer = document.createElement("div");+ outer.style.width = "600px";+ document.body.append(outer);+ for (const [label, css, dimensions = ""] of [+ ["auto", ""],+ ["height limit", "max-height: 30px"],+ ["block", "display: block; max-height: 30px"],+ ["width limit", "max-width: 120px"],+ ["both limits", "max-width: 40px; max-height: 30px"],+ ["fixed width", "width: 200px; max-height: 30px"],+ ["fixed height", "height: 100px; max-height: 30px"],+ ["width minimum", "min-width: 120px; max-height: 30px"],+ ["zero maximum", "max-height: 0"],+ ["natural size", "max-height: 30px", "width='200' height='100'"],+ ["border box", "max-height: 30px; padding: 5px; box-sizing: border-box"],+ ["vertical writing mode", "max-height: 30px; writing-mode: vertical-rl"],+ ]) {+ const img = new Image();+ img.src = `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 1' ${dimensions}/%3E`;+ await img.decode();+ img.style.cssText = css;+ outer.replaceChildren(img);+ println(`${label}: ${img.offsetWidth}x${img.offsetHeight}`);+ }+ });+</script>