Truly independent web browser
LibWeb: Size flex rows from items with percentage height and ratio
Jelle Raaijmakersfd4a060c799e
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rsindex 5ffd5417376..c92f3424223 100644--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs@@ -2778,6 +2778,20 @@ impl<'pass> FlexFormattingContext<'pass> {Some(self.cross_size_from_main_size_and_aspect_ratio(node, main_size))}+ // https://drafts.csswg.org/css-sizing-3/#cyclic-percentage-contribution+ fn cross_size_is_cyclic_percentage_of_aspect_ratio_item(&self, index: usize) -> bool {+ let node = self.flex_items[index].box_;+ // If the box is non-replaced, then the entire value of any max size property or preferred size property+ // ('width'/'max-width'/'height'/'max-height') specified as an expression containing a percentage (such as+ // '10%' or 'calc(10px + 0%)') that is cyclic is treated for the purpose of calculating the box's intrinsic+ // size contributions only as that property's initial value.+ !self.cross_axis_is_horizontal()+ && self.computed_cross_size(node).0.contains_percentage()+ && self+ .sizing()+ .block_size_transfers_through_aspect_ratio(node, self.item_containing_block_constraints())+ }+fn calculate_cross_content_contribution(&self,index: usize,@@ -2785,7 +2799,8 @@ impl<'pass> FlexFormattingContext<'pass> {max_content: bool,) -> CssPixels {let node = self.flex_items[index].box_;- let cross_size_auto = self.should_treat_cross_size_as_auto(node);+ let cross_size_auto = self.should_treat_cross_size_as_auto(node)+ || self.cross_size_is_cyclic_percentage_of_aspect_ratio_item(index);let mut size = if cross_size_auto {self.cross_size_transferred_from_definite_main_size(index).unwrap_or_else(|| {diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rsindex c0dc39d6b70..7f9bba525e1 100644--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs@@ -1108,6 +1108,19 @@ impl<'pass> SizingContext<'pass> {size}+ // NB: Like auto, a definite inline size transfers through the aspect ratio of a non-replaced box.+ pub(crate) fn block_size_transfers_through_aspect_ratio(+ &self,+ node: Node,+ constraints: ContainingBlockConstraints,+ ) -> bool {+ let facts = self.facts(node);+ self.used(node).has_definite_inline_size()+ && !facts.is_replaced_box()+ && facts.has_preferred_aspect_ratio()+ && self.preferred_block_size(node, constraints).is_auto()+ }+pub(crate) fn should_treat_block_size_as_auto(&self,node: Node,@@ -1129,11 +1142,7 @@ impl<'pass> SizingContext<'pass> {return false;}formatting_context::CyclicPercentageIntrinsicContribution::TreatAsInitialValue => {- // NB: Like auto, a definite inline size transfers through the aspect ratio of a non-replaced box.- return !(self.used(node).has_definite_inline_size()- && !facts.is_replaced_box()- && facts.has_preferred_aspect_ratio()- && self.preferred_block_size(node, constraints).is_auto());+ return !self.block_size_transfers_through_aspect_ratio(node, constraints);}formatting_context::CyclicPercentageIntrinsicContribution::NotCyclic => {}}diff --git a/Tests/LibWeb/Layout/expected/grid/row-sized-by-flex-item-with-percentage-height-and-aspect-ratio.txt b/Tests/LibWeb/Layout/expected/grid/row-sized-by-flex-item-with-percentage-height-and-aspect-ratio.txtnew file mode 100644index 00000000000..b7dcb935fe8--- /dev/null+++ b/Tests/LibWeb/Layout/expected/grid/row-sized-by-flex-item-with-percentage-height-and-aspect-ratio.txt@@ -0,0 +1,27 @@+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 128.5 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [0,0] [0+0+0 800 0+0+0] [0+0+0 128.5 0+0+0] children: not-inline+ Box <ul> at [0,0] [0+0+0 300 0+0+500] [0+0+0 112.5 0+0+0] [GFC] children: not-inline+ BlockContainer <(anonymous)> (not painted) [BFC] children: inline+ TextNode <#text> (not painted)+ ListItemBox <li> at [0,0] [0+0+0 150 0+0+0] [0+0+0 112.5 0+0+0] [BFC] children: not-inline+ Box <a> at [0,0] flex-container(row) [0+0+0 150 0+0+0] [0+0+0 112.5 0+0+0] [FFC] children: not-inline+ BlockContainer <div> at [0,0] flex-item [0+0+0 150 0+0+0] [0+0+0 112.5 0+0+0] [BFC] children: not-inline+ BlockContainer <(anonymous)> (not painted) [BFC] children: inline+ TextNode <#text> (not painted)+ ListItemBox <li> at [150,0] [0+0+0 150 0+0+0] [0+0+0 112.5 0+0+0] [BFC] children: not-inline+ Box <a> at [150,0] flex-container(row) [0+0+0 150 0+0+0] [0+0+0 112.5 0+0+0] [FFC] children: not-inline+ BlockContainer <div> at [150,0] flex-item [0+0+0 150 0+0+0] [0+0+0 112.5 0+0+0] [BFC] children: not-inline+ BlockContainer <(anonymous)> (not painted) [BFC] children: inline+ TextNode <#text> (not painted)+ BlockContainer <(anonymous)> at [0,112.5] [0+0+0 800 0+0+0] [0+0+0 0 0+0+0] children: inline+ TextNode <#text> (not painted)+ BlockContainer <p> at [0,112.5] [0+0+0 800 0+0+0] [0+0+0 16 0+0+0] children: inline+ frag 0 from TextNode start: 0, length: 40, rect: [0,112.5 341.84375x16] baseline: 12.796875+ "The paragraph must not overlap the grid."+ TextNode <#text> (not painted)+ BlockContainer <(anonymous)> at [0,128.5] [0+0+0 800 0+0+0] [0+0+0 0 0+0+0] children: inline+ TextNode <#text> (not painted)++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x128.5] (z-index: auto)diff --git a/Tests/LibWeb/Layout/input/grid/row-sized-by-flex-item-with-percentage-height-and-aspect-ratio.html b/Tests/LibWeb/Layout/input/grid/row-sized-by-flex-item-with-percentage-height-and-aspect-ratio.htmlnew file mode 100644index 00000000000..4deb96cae68--- /dev/null+++ b/Tests/LibWeb/Layout/input/grid/row-sized-by-flex-item-with-percentage-height-and-aspect-ratio.html@@ -0,0 +1,24 @@+<!DOCTYPE html>+<style>+ * { margin: 0; padding: 0; }+ ul {+ display: grid;+ grid-template-columns: 1fr 1fr;+ width: 300px;+ list-style: none;+ }+ a {+ display: flex;+ }+ div {+ width: 100%;+ height: 100%;+ aspect-ratio: 4 / 3;+ background: teal;+ }+</style>+<ul>+ <li><a><div></div></a></li>+ <li><a><div></div></a></li>+</ul>+<p>The paragraph must not overlap the grid.</p>