Truly independent web browser
LibWeb: Transfer main size to a replaced item with only a ratio
sideshowbarker35904b3a3dad
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rsindex f04c8854603..d2491d9cdb8 100644--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs@@ -2435,24 +2435,6 @@ impl<'pass> FlexFormattingContext<'pass> {}if self.flex_item_details[index].inputs.preferred_aspect_ratio.is_some() {- let inputs = self.flex_item_details[index].inputs;- // AD-HOC: For a replaced box whose only sizing information is a natural aspect ratio (e.g an SVG with a- // viewBox but no natural width or height) and an indefinite flex basis, we stretch-fit the cross size- // to the flex container instead of transferring the used main size through the aspect ratio.- let replaced_with_only_natural_ratio = inputs.is_replaced_box- && !(inputs.auto_content_size.width.is_some() && inputs.auto_content_size.height.is_some());- if replaced_with_only_natural_ratio- && !self.flex_items[index].used_flex_basis_is_definite- && self.has_definite_cross_size_used(&self.container_cells)- {- self.set_hypothetical_cross_size(- index,- self.inner_cross_size_used(&self.container_cells),- clamp_min,- clamp_max,- );- return;- }// https://drafts.csswg.org/css-sizing-4/#aspect-ratio-automatic// When a box has a preferred aspect ratio, its automatic sizes are calculated the same as for a// replaced element with a natural aspect ratio and no natural size in that axis, see e.g. CSS2 § 10diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-flexbox/flex-aspect-ratio-img-column-013.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-flexbox/flex-aspect-ratio-img-column-013.htmlnew file mode 100644index 00000000000..7abfb2559e3--- /dev/null+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-flexbox/flex-aspect-ratio-img-column-013.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<title>SVG img as flex item</title>+<link rel="author" title="David Grogan" href="mailto:[email protected]">+<link rel="help" href="https://drafts.csswg.org/css-flexbox/#algo-main-item" title="Part E">+<link rel="match" href="../../../../expected/wpt-import/css/css-flexbox/../reference/ref-filled-green-100px-square-only.html">+<meta name="assert" content="SVG's specified intrinsic height is honored when used as a flex base size and no intrinsic width is specified." />++<p>Test passes if there is a filled green square.</p>++<div style="display: flex; width: 100px; height: 100px; align-items: flex-start;">+ <img src="data:image/svg+xml,%3Csvg viewBox='0 0 400 200' height='50px' xmlns='http://www.w3.org/2000/svg' %3E%3Crect width='100%' height='100%' fill='green' /%3E%3C/svg%3E" style="border-top: 50px solid green; min-height: 0px;">+</div>diff --git a/Tests/LibWeb/Text/expected/Layout/flex-replaced-item-with-only-natural-ratio-transfers-main-size.txt b/Tests/LibWeb/Text/expected/Layout/flex-replaced-item-with-only-natural-ratio-transfers-main-size.txtnew file mode 100644index 00000000000..4df96162cb8--- /dev/null+++ b/Tests/LibWeb/Text/expected/Layout/flex-replaced-item-with-only-natural-ratio-transfers-main-size.txt@@ -0,0 +1,12 @@+square: 40x40+wide: 40x20+tall: 40x80+natural-size: 40x40+square-without-max-width: 100x100+wide-without-max-width: 100x50+square-stretched: 40x100+square-max-height: 40x40+column-square-max-height: 40x40+column-square-max-width: 40x40+square-min-width: 120x120+square-auto-height-container: 40x40diff --git a/Tests/LibWeb/Text/input/Layout/flex-replaced-item-with-only-natural-ratio-transfers-main-size.html b/Tests/LibWeb/Text/input/Layout/flex-replaced-item-with-only-natural-ratio-transfers-main-size.htmlnew file mode 100644index 00000000000..d9d99cb7b95--- /dev/null+++ b/Tests/LibWeb/Text/input/Layout/flex-replaced-item-with-only-natural-ratio-transfers-main-size.html@@ -0,0 +1,35 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body { margin: 0; }+ .flex { display: flex; align-items: center; width: 100px; height: 100px; margin-bottom: 4px; }+ img { display: block; }+</style>+<!-- A replaced flex item with a natural aspect ratio but no natural size takes its cross size from its used main size+ through that ratio, like any other item with an aspect ratio, rather than from the flex container. -->+<div class="flex"><img id="square" style="max-width: 40px" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'/%3E"></div>+<div class="flex"><img id="wide" style="max-width: 40px" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 100'/%3E"></div>+<div class="flex"><img id="tall" style="max-width: 40px" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 200'/%3E"></div>+<div class="flex"><img id="natural-size" style="max-width: 40px" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'/%3E"></div>+<div class="flex"><img id="square-without-max-width" style="" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'/%3E"></div>+<div class="flex"><img id="wide-without-max-width" style="" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 100'/%3E"></div>+<div class="flex" style="align-items: stretch"><img id="square-stretched" style="max-width: 40px" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'/%3E"></div>+<div class="flex"><img id="square-max-height" style="max-height: 40px" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'/%3E"></div>+<div class="flex" style="flex-direction: column"><img id="column-square-max-height" style="max-height: 40px" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'/%3E"></div>+<div class="flex" style="flex-direction: column"><img id="column-square-max-width" style="max-width: 40px" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'/%3E"></div>+<div class="flex"><img id="square-min-width" style="min-width: 120px" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'/%3E"></div>+<div class="flex" style="height: auto"><img id="square-auto-height-container" style="max-width: 40px" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'/%3E"></div>+<script>+ function run(report) {+ for (const element of document.querySelectorAll("[id]:not(#out)")) {+ const rect = element.getBoundingClientRect();+ report(`${element.id}: ${rect.width}x${rect.height}`);+ }+ }+</script>+<script>+ if (window.asyncTest)+ asyncTest(done => addEventListener("load", () => { run(println); done(); }));+ else+ addEventListener("load", () => { run(line => console.log(line)); window.engineCompareDone = true; });+</script>