From 97edca4e4e60fb32f72f1a59dde4c78747e9b548 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 23 Jun 2024 15:52:14 +0200 Subject: [PATCH] LibWeb: Fix overeager fallback to stretch-fit width for some flex items If a flex item has a preferred aspect ratio and the flex basis is not definite, we were falling back to using stretch-fit for the main size, since that appeared to match other browsers. However, we missed the case where we actually have a definite cross size through which the preferred aspect ratio can be naturally resolved. (cherry picked from commit db1faef786dbd1722bbe6a1f4a5616f3069bdb6a) --- ...an-resolve-aspect-ratio-through-height.txt | 14 ++++++++++++++ ...n-resolve-aspect-ratio-through-height.html | 19 +++++++++++++++++++ .../LibWeb/Layout/FlexFormattingContext.cpp | 6 +++--- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/flex/no-stretch-fit-width-for-item-that-can-resolve-aspect-ratio-through-height.txt create mode 100644 Tests/LibWeb/Layout/input/flex/no-stretch-fit-width-for-item-that-can-resolve-aspect-ratio-through-height.html diff --git a/Tests/LibWeb/Layout/expected/flex/no-stretch-fit-width-for-item-that-can-resolve-aspect-ratio-through-height.txt b/Tests/LibWeb/Layout/expected/flex/no-stretch-fit-width-for-item-that-can-resolve-aspect-ratio-through-height.txt new file mode 100644 index 0000000000..101bb4798f --- /dev/null +++ b/Tests/LibWeb/Layout/expected/flex/no-stretch-fit-width-for-item-that-can-resolve-aspect-ratio-through-height.txt @@ -0,0 +1,14 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x36 [BFC] children: not-inline + Box at (8,8) content-size 200x20 flex-container(row) [FFC] children: not-inline + SVGSVGBox at (8,8) content-size 20x20 flex-item [SVG] children: not-inline + SVGGeometryBox at (8,8) content-size 10x10 children: not-inline + BlockContainer
at (28,8) content-size 100x20 flex-item [BFC] children: inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x36] + PaintableBox (Box) [8,8 200x20] + SVGSVGPaintable (SVGSVGBox) [8,8 20x20] + SVGPathPaintable (SVGGeometryBox) [8,8 10x10] + PaintableWithLines (BlockContainer
) [28,8 100x20] diff --git a/Tests/LibWeb/Layout/input/flex/no-stretch-fit-width-for-item-that-can-resolve-aspect-ratio-through-height.html b/Tests/LibWeb/Layout/input/flex/no-stretch-fit-width-for-item-that-can-resolve-aspect-ratio-through-height.html new file mode 100644 index 0000000000..3d76c48e04 --- /dev/null +++ b/Tests/LibWeb/Layout/input/flex/no-stretch-fit-width-for-item-that-can-resolve-aspect-ratio-through-height.html @@ -0,0 +1,19 @@ +
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index b9d92a0987..aab22b5668 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -639,10 +639,10 @@ void FlexFormattingContext::determine_flex_base_size_and_hypothetical_main_size( // AD-HOC: This is not mentioned in the spec, but if the item has an aspect ratio, // we may need to adjust the main size in these ways: - // - using stretch-fit main size if the flex basis is indefinite. + // - using stretch-fit main size if the flex basis is indefinite and there is no cross size to resolve the ratio against. // - in response to cross size min/max constraints. - if (item.box->has_preferred_aspect_ratio()) { - if (!item.used_flex_basis_is_definite) { + if (item.box->has_natural_aspect_ratio()) { + if (!item.used_flex_basis_is_definite && !has_definite_cross_size(item)) { item.flex_base_size = inner_main_size(m_flex_container_state); } item.flex_base_size = adjust_main_size_through_aspect_ratio_for_cross_size_min_max_constraints(child_box, item.flex_base_size, computed_cross_min_size(child_box), computed_cross_max_size(child_box));