Truly independent web browser
LibWeb: Size an aspect-ratio box's height from its used width
Andreas Klingd0bb6a747068
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex 418b000d016..f93f21028d1 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -694,7 +694,16 @@ impl<'pass> SizingContext<'pass> {// 1. The tentative used height is calculated (without 'min-height' and 'max-height')let mut used =self.tentative_block_size_for_replaced_element(node, computed_block, available_space, constraints);- if computed_inline.is_auto() && computed_block.is_auto() && self.facts(node).has_preferred_aspect_ratio() {+ let facts = self.facts(node);+ // NB: A non-replaced box sized through its aspect ratio already has its used inline size, which transfers+ // through the ratio before its min/max block sizes apply on their own.+ // https://drafts.csswg.org/css-sizing-4/#aspect-ratio-automatic+ let inline_size_is_already_used = !facts.is_replaced_box() && self.used(node).has_definite_inline_size();+ if computed_inline.is_auto()+ && computed_block.is_auto()+ && facts.has_preferred_aspect_ratio()+ && !inline_size_is_already_used+ {// However, for replaced elements with both 'width' and 'height' computed as 'auto',// use the algorithm under 'Minimum and maximum widths'// https://www.w3.org/TR/CSS22/visudet.html#min-max-widthsdiff --git a/Tests/LibWeb/Text/expected/css/aspect-ratio-min-max-transfer-matrix.txt b/Tests/LibWeb/Text/expected/css/aspect-ratio-min-max-transfer-matrix.txtindex 796a21693f9..61c2486205a 100644--- a/Tests/LibWeb/Text/expected/css/aspect-ratio-min-max-transfer-matrix.txt+++ b/Tests/LibWeb/Text/expected/css/aspect-ratio-min-max-transfer-matrix.txt@@ -974,11 +974,11 @@ block abspos width=auto height=auto empty min-height: 120x60 child=0block abspos width=auto height=auto empty min-height-large: 300x150 child=0block abspos width=auto height=auto empty max-height: 0x0 child=0block abspos width=auto height=auto empty min-width: 150x75 child=0-block abspos width=auto height=auto empty max-width: 0x20 child=0+block abspos width=auto height=auto empty max-width: 0x0 child=0block abspos width=auto height=auto empty min-width-max-height: 150x30 child=0block abspos width=auto height=auto empty max-width-min-height: 40x60 child=0block abspos width=auto height=auto empty border-box-min-height: 120x60 child=0-block abspos width=auto height=auto empty border-box-max-width: 20x20 child=0+block abspos width=auto height=auto empty border-box-max-width: 20x10 child=0block abspos width=auto height=auto tall min-height: 120x60 child=0block abspos width=auto height=auto tall min-height-large: 300x150 child=0block abspos width=auto height=auto tall max-height: 10x30 child=0@@ -2108,11 +2108,11 @@ block-definite abspos width=auto height=auto empty min-height: 120x60 child=0block-definite abspos width=auto height=auto empty min-height-large: 300x150 child=0block-definite abspos width=auto height=auto empty max-height: 0x0 child=0block-definite abspos width=auto height=auto empty min-width: 150x75 child=0-block-definite abspos width=auto height=auto empty max-width: 0x20 child=0+block-definite abspos width=auto height=auto empty max-width: 0x0 child=0block-definite abspos width=auto height=auto empty min-width-max-height: 150x30 child=0block-definite abspos width=auto height=auto empty max-width-min-height: 40x60 child=0block-definite abspos width=auto height=auto empty border-box-min-height: 120x60 child=0-block-definite abspos width=auto height=auto empty border-box-max-width: 20x20 child=0+block-definite abspos width=auto height=auto empty border-box-max-width: 20x10 child=0block-definite abspos width=auto height=auto tall min-height: 120x60 child=0block-definite abspos width=auto height=auto tall min-height-large: 300x150 child=0block-definite abspos width=auto height=auto tall max-height: 10x30 child=0@@ -3242,11 +3242,11 @@ flex-row abspos width=auto height=auto empty min-height: 120x60 child=0flex-row abspos width=auto height=auto empty min-height-large: 300x150 child=0flex-row abspos width=auto height=auto empty max-height: 0x0 child=0flex-row abspos width=auto height=auto empty min-width: 150x75 child=0-flex-row abspos width=auto height=auto empty max-width: 0x20 child=0+flex-row abspos width=auto height=auto empty max-width: 0x0 child=0flex-row abspos width=auto height=auto empty min-width-max-height: 150x30 child=0flex-row abspos width=auto height=auto empty max-width-min-height: 40x60 child=0flex-row abspos width=auto height=auto empty border-box-min-height: 120x60 child=0-flex-row abspos width=auto height=auto empty border-box-max-width: 20x20 child=0+flex-row abspos width=auto height=auto empty border-box-max-width: 20x10 child=0flex-row abspos width=auto height=auto tall min-height: 120x60 child=0flex-row abspos width=auto height=auto tall min-height-large: 300x150 child=0flex-row abspos width=auto height=auto tall max-height: 10x30 child=0@@ -4376,11 +4376,11 @@ flex-row-stretch abspos width=auto height=auto empty min-height: 120x60 child=0flex-row-stretch abspos width=auto height=auto empty min-height-large: 300x150 child=0flex-row-stretch abspos width=auto height=auto empty max-height: 0x0 child=0flex-row-stretch abspos width=auto height=auto empty min-width: 150x75 child=0-flex-row-stretch abspos width=auto height=auto empty max-width: 0x20 child=0+flex-row-stretch abspos width=auto height=auto empty max-width: 0x0 child=0flex-row-stretch abspos width=auto height=auto empty min-width-max-height: 150x30 child=0flex-row-stretch abspos width=auto height=auto empty max-width-min-height: 40x60 child=0flex-row-stretch abspos width=auto height=auto empty border-box-min-height: 120x60 child=0-flex-row-stretch abspos width=auto height=auto empty border-box-max-width: 20x20 child=0+flex-row-stretch abspos width=auto height=auto empty border-box-max-width: 20x10 child=0flex-row-stretch abspos width=auto height=auto tall min-height: 120x60 child=0flex-row-stretch abspos width=auto height=auto tall min-height-large: 300x150 child=0flex-row-stretch abspos width=auto height=auto tall max-height: 10x30 child=0@@ -5510,11 +5510,11 @@ flex-column abspos width=auto height=auto empty min-height: 120x60 child=0flex-column abspos width=auto height=auto empty min-height-large: 300x150 child=0flex-column abspos width=auto height=auto empty max-height: 0x0 child=0flex-column abspos width=auto height=auto empty min-width: 150x75 child=0-flex-column abspos width=auto height=auto empty max-width: 0x20 child=0+flex-column abspos width=auto height=auto empty max-width: 0x0 child=0flex-column abspos width=auto height=auto empty min-width-max-height: 150x30 child=0flex-column abspos width=auto height=auto empty max-width-min-height: 40x60 child=0flex-column abspos width=auto height=auto empty border-box-min-height: 120x60 child=0-flex-column abspos width=auto height=auto empty border-box-max-width: 20x20 child=0+flex-column abspos width=auto height=auto empty border-box-max-width: 20x10 child=0flex-column abspos width=auto height=auto tall min-height: 120x60 child=0flex-column abspos width=auto height=auto tall min-height-large: 300x150 child=0flex-column abspos width=auto height=auto tall max-height: 10x30 child=0@@ -6644,11 +6644,11 @@ grid abspos width=auto height=auto empty min-height: 120x60 child=0grid abspos width=auto height=auto empty min-height-large: 300x150 child=0grid abspos width=auto height=auto empty max-height: 0x0 child=0grid abspos width=auto height=auto empty min-width: 150x75 child=0-grid abspos width=auto height=auto empty max-width: 0x20 child=0+grid abspos width=auto height=auto empty max-width: 0x0 child=0grid abspos width=auto height=auto empty min-width-max-height: 150x30 child=0grid abspos width=auto height=auto empty max-width-min-height: 40x60 child=0grid abspos width=auto height=auto empty border-box-min-height: 120x60 child=0-grid abspos width=auto height=auto empty border-box-max-width: 20x20 child=0+grid abspos width=auto height=auto empty border-box-max-width: 20x10 child=0grid abspos width=auto height=auto tall min-height: 120x60 child=0grid abspos width=auto height=auto tall min-height-large: 300x150 child=0grid abspos width=auto height=auto tall max-height: 10x30 child=0@@ -7778,11 +7778,11 @@ grid-definite-row abspos width=auto height=auto empty min-height: 120x60 child=0grid-definite-row abspos width=auto height=auto empty min-height-large: 300x150 child=0grid-definite-row abspos width=auto height=auto empty max-height: 0x0 child=0grid-definite-row abspos width=auto height=auto empty min-width: 150x75 child=0-grid-definite-row abspos width=auto height=auto empty max-width: 0x20 child=0+grid-definite-row abspos width=auto height=auto empty max-width: 0x0 child=0grid-definite-row abspos width=auto height=auto empty min-width-max-height: 150x30 child=0grid-definite-row abspos width=auto height=auto empty max-width-min-height: 40x60 child=0grid-definite-row abspos width=auto height=auto empty border-box-min-height: 120x60 child=0-grid-definite-row abspos width=auto height=auto empty border-box-max-width: 20x20 child=0+grid-definite-row abspos width=auto height=auto empty border-box-max-width: 20x10 child=0grid-definite-row abspos width=auto height=auto tall min-height: 120x60 child=0grid-definite-row abspos width=auto height=auto tall min-height-large: 300x150 child=0grid-definite-row abspos width=auto height=auto tall max-height: 10x30 child=0@@ -8912,11 +8912,11 @@ inline-block abspos width=auto height=auto empty min-height: 120x60 child=0inline-block abspos width=auto height=auto empty min-height-large: 300x150 child=0inline-block abspos width=auto height=auto empty max-height: 0x0 child=0inline-block abspos width=auto height=auto empty min-width: 150x75 child=0-inline-block abspos width=auto height=auto empty max-width: 0x20 child=0+inline-block abspos width=auto height=auto empty max-width: 0x0 child=0inline-block abspos width=auto height=auto empty min-width-max-height: 150x30 child=0inline-block abspos width=auto height=auto empty max-width-min-height: 40x60 child=0inline-block abspos width=auto height=auto empty border-box-min-height: 120x60 child=0-inline-block abspos width=auto height=auto empty border-box-max-width: 20x20 child=0+inline-block abspos width=auto height=auto empty border-box-max-width: 20x10 child=0inline-block abspos width=auto height=auto tall min-height: 120x60 child=0inline-block abspos width=auto height=auto tall min-height-large: 300x150 child=0inline-block abspos width=auto height=auto tall max-height: 10x30 child=0@@ -10046,11 +10046,11 @@ float abspos width=auto height=auto empty min-height: 120x60 child=0float abspos width=auto height=auto empty min-height-large: 300x150 child=0float abspos width=auto height=auto empty max-height: 0x0 child=0float abspos width=auto height=auto empty min-width: 150x75 child=0-float abspos width=auto height=auto empty max-width: 0x20 child=0+float abspos width=auto height=auto empty max-width: 0x0 child=0float abspos width=auto height=auto empty min-width-max-height: 150x30 child=0float abspos width=auto height=auto empty max-width-min-height: 40x60 child=0float abspos width=auto height=auto empty border-box-min-height: 120x60 child=0-float abspos width=auto height=auto empty border-box-max-width: 20x20 child=0+float abspos width=auto height=auto empty border-box-max-width: 20x10 child=0float abspos width=auto height=auto tall min-height: 120x60 child=0float abspos width=auto height=auto tall min-height-large: 300x150 child=0float abspos width=auto height=auto tall max-height: 10x30 child=0@@ -12314,11 +12314,11 @@ table-cell abspos width=auto height=auto empty min-height: 120x60 child=0table-cell abspos width=auto height=auto empty min-height-large: 300x150 child=0table-cell abspos width=auto height=auto empty max-height: 0x0 child=0table-cell abspos width=auto height=auto empty min-width: 150x75 child=0-table-cell abspos width=auto height=auto empty max-width: 0x20 child=0+table-cell abspos width=auto height=auto empty max-width: 0x0 child=0table-cell abspos width=auto height=auto empty min-width-max-height: 150x30 child=0table-cell abspos width=auto height=auto empty max-width-min-height: 40x60 child=0table-cell abspos width=auto height=auto empty border-box-min-height: 120x60 child=0-table-cell abspos width=auto height=auto empty border-box-max-width: 20x20 child=0+table-cell abspos width=auto height=auto empty border-box-max-width: 20x10 child=0table-cell abspos width=auto height=auto tall min-height: 120x60 child=0table-cell abspos width=auto height=auto tall min-height-large: 300x150 child=0table-cell abspos width=auto height=auto tall max-height: 10x30 child=0