From 28c1dd551bc198fcefe6f398a0ed2f845cd0ade0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 5 Aug 2025 18:03:22 +0200 Subject: [PATCH] LibWeb: Don't let aspect-ratio influence size definiteness As it turns out, we still have to let the formatting contexts do a bit of layout work in order to correctly apply the aspect-ratio. Hence we can't just implicitly transfer definiteness from one size to the other. This is a revert of 1cfd8b3ac035aaf7d24ad22991f2482de03ea5e9. --- Libraries/LibWeb/Layout/LayoutState.cpp | 17 --------- ...ratio-with-percentage-width-and-height.txt | 36 +++++++++++++++++++ ...atio-with-percentage-width-and-height.html | 19 ++++++++++ 3 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/flex/aspect-ratio-with-percentage-width-and-height.txt create mode 100644 Tests/LibWeb/Layout/input/flex/aspect-ratio-with-percentage-width-and-height.html diff --git a/Libraries/LibWeb/Layout/LayoutState.cpp b/Libraries/LibWeb/Layout/LayoutState.cpp index 8b035b885df..b412e44ce55 100644 --- a/Libraries/LibWeb/Layout/LayoutState.cpp +++ b/Libraries/LibWeb/Layout/LayoutState.cpp @@ -605,23 +605,6 @@ void LayoutState::UsedValues::set_node(NodeWithStyle& node, UsedValues const* co m_has_definite_width = is_definite_size(computed_values.width(), m_content_width, true); m_has_definite_height = is_definite_size(computed_values.height(), m_content_height, false); - // For boxes with a preferred aspect ratio and one definite size, we can infer the other size - // and consider it definite since this did not require performing layout. - if (is(node)) { - auto const& box = static_cast(node); - if (auto aspect_ratio = box.preferred_aspect_ratio(); aspect_ratio.has_value()) { - if (m_has_definite_width && m_has_definite_height) { - // Both width and height are definite. - } else if (m_has_definite_width) { - m_content_height = *aspect_ratio == 0 ? 0 : clamp_to_max_dimension_value(m_content_width / *aspect_ratio); - m_has_definite_height = true; - } else if (m_has_definite_height) { - m_content_width = clamp_to_max_dimension_value(m_content_height * *aspect_ratio); - m_has_definite_width = true; - } - } - } - if (m_has_definite_width) { if (has_definite_min_width) m_content_width = clamp_to_max_dimension_value(max(min_width, m_content_width)); diff --git a/Tests/LibWeb/Layout/expected/flex/aspect-ratio-with-percentage-width-and-height.txt b/Tests/LibWeb/Layout/expected/flex/aspect-ratio-with-percentage-width-and-height.txt new file mode 100644 index 00000000000..03d424ac188 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/flex/aspect-ratio-with-percentage-width-and-height.txt @@ -0,0 +1,36 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x92.671875 [BFC] children: not-inline + Box at (13,13) content-size 200x66.671875 flex-container(row) [FFC] children: not-inline + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer
at (18,18) content-size 56.671875x56.671875 flex-item [BFC] children: inline + frag 0 from TextNode start: 0, length: 3, rect: [18,18 27.15625x18] baseline: 13.796875 + "foo" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer
at (84.671875,18) content-size 56.671875x56.671875 flex-item [BFC] children: inline + frag 0 from TextNode start: 0, length: 3, rect: [84.671875,18 27.640625x18] baseline: 13.796875 + "bar" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + BlockContainer
at (151.34375,18) content-size 56.671875x56.671875 flex-item [BFC] children: inline + frag 0 from TextNode start: 0, length: 3, rect: [151.34375,18 27.203125x18] baseline: 13.796875 + "baz" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) [BFC] children: inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x92.671875] + PaintableBox (Box) [8,8 210x76.671875] overflow: [13,13 200.015625x66.671875] + PaintableWithLines (BlockContainer
) [13,13 66.671875x66.671875] + TextPaintable (TextNode<#text>) + PaintableWithLines (BlockContainer
) [79.671875,13 66.671875x66.671875] + TextPaintable (TextNode<#text>) + PaintableWithLines (BlockContainer
) [146.34375,13 66.671875x66.671875] + TextPaintable (TextNode<#text>) + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [0,0 800x92.671875] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/input/flex/aspect-ratio-with-percentage-width-and-height.html b/Tests/LibWeb/Layout/input/flex/aspect-ratio-with-percentage-width-and-height.html new file mode 100644 index 00000000000..1496376b2db --- /dev/null +++ b/Tests/LibWeb/Layout/input/flex/aspect-ratio-with-percentage-width-and-height.html @@ -0,0 +1,19 @@ + + +
foo
+
bar
+
baz