Truly independent web browser
LibWeb: Size a flex item from an image’s percentage height
sideshowbarker6e7edb068ee0
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex 3490b748fd5..58e99adf6c6 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -2749,23 +2749,15 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {sized: SizedBox<'_>,constraints: ContainingBlockConstraints,) -> Option<CssPixels> {- let node = sized.node;if !self.intrinsic_inline_sizes_are_transferred(sized, constraints) {return None;}- let facts = self.facts(node);let available_space = self.transferred_intrinsic_inline_sizing_space(sized);- // NB: Replaced elements resolve their sizes here without a percentage basis.- let sizing_constraints = if facts.is_replaced_box() {- ContainingBlockConstraints::default()- } else {- constraints- };// https://drafts.csswg.org/css2/#inline-replaced-width// "(used height) * (intrinsic ratio)"- let inline_size = self.compute_inline_size_for_replaced_element(sized, available_space, sizing_constraints);+ let inline_size = self.compute_inline_size_for_replaced_element(sized, available_space, constraints);// https://drafts.csswg.org/css-sizing-4/#aspect-ratio-minimum- let block_size = self.compute_block_size_for_replaced_element(sized, available_space, sizing_constraints);+ let block_size = self.compute_block_size_for_replaced_element(sized, available_space, constraints);let minimum = self.automatic_minimum_size_from_aspect_ratio(sized,SizingAxis::Inline,diff --git a/Tests/LibWeb/Text/expected/flex/flex-item-minimum-width-from-image-with-percentage-height.txt b/Tests/LibWeb/Text/expected/flex/flex-item-minimum-width-from-image-with-percentage-height.txtnew file mode 100644index 00000000000..e4a3f3b1522--- /dev/null+++ b/Tests/LibWeb/Text/expected/flex/flex-item-minimum-width-from-image-with-percentage-height.txt@@ -0,0 +1,2 @@+image: 200x100+second item starts at x=308diff --git a/Tests/LibWeb/Text/input/flex/flex-item-minimum-width-from-image-with-percentage-height.html b/Tests/LibWeb/Text/input/flex/flex-item-minimum-width-from-image-with-percentage-height.htmlnew file mode 100644index 00000000000..a4342edac30--- /dev/null+++ b/Tests/LibWeb/Text/input/flex/flex-item-minimum-width-from-image-with-percentage-height.html@@ -0,0 +1,36 @@+<!DOCTYPE html>+<style>+ .row {+ display: flex;+ width: 600px;+ }+ .item {+ flex: 0 1 50%;+ }+ .frame {+ display: flex;+ height: 100px;+ overflow: hidden;+ }+ .frame img {+ height: 100%;+ }+</style>+<div class="row">+ <div class="item"><div class="frame"><img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='2000' height='1000'%3E%3Crect width='2000' height='1000' fill='teal'/%3E%3C/svg%3E"></div></div>+ <div class="item" id="second">second item</div>+</div>+<script src="../include.js"></script>+<script>+ // The image's height: 100% resolves against the frame's definite height, so its width comes through its aspect+ // ratio, and the item holding it can shrink to half the row.+ asyncTest(done => {+ window.addEventListener("load", () => {+ const image = document.querySelector("img").getBoundingClientRect();+ const second = document.getElementById("second").getBoundingClientRect();+ println(`image: ${image.width}x${image.height}`);+ println(`second item starts at x=${second.left}`);+ done();+ });+ });+</script>