From e3f693ca7c84e51d84174d0d6b840e645ceccc3b Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Sun, 3 Sep 2023 19:20:50 -0500 Subject: [PATCH] LibWeb: Resolve replaced element size constraints using aspect ratios Some replaced elements can have intrinsic aspect ratios but no intrinsic size. In these cases, the tentative sizes are undefined, and can therefore sometimes be zero. However, when resolving the size constraints, we are already guaranteed to have an intrinsic aspect ratio, so let's use that instead to calculate the resolved sizes. --- .../expected/replaced-within-max-content.txt | 21 +++++++++++++++++++ .../input/replaced-within-max-content.html | 15 +++++++++++++ .../LibWeb/Layout/FormattingContext.cpp | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/replaced-within-max-content.txt create mode 100644 Tests/LibWeb/Layout/input/replaced-within-max-content.html diff --git a/Tests/LibWeb/Layout/expected/replaced-within-max-content.txt b/Tests/LibWeb/Layout/expected/replaced-within-max-content.txt new file mode 100644 index 0000000000..18829a016a --- /dev/null +++ b/Tests/LibWeb/Layout/expected/replaced-within-max-content.txt @@ -0,0 +1,21 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x166 [BFC] children: not-inline + BlockContainer <(anonymous)> at (0,0) content-size 800x0 children: inline + TextNode <#text> + BlockContainer at (8,8) content-size 784x150 children: not-inline + BlockContainer at (8,8) content-size 150x150 children: inline + line 0 width: 150, height: 150, bottom: 150, baseline: 150 + frag 0 from ImageBox start: 0, length: 0, rect: [8,8 150x150] + ImageBox at (8,8) content-size 150x150 children: not-inline + (SVG-as-image isolated context) + Viewport <#document> at (0,0) content-size 150x150 children: inline + SVGSVGBox at (0,0) content-size 150x150 [SVG] children: not-inline + SVGGeometryBox at (0,0) content-size 150x150 children: not-inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x166] + PaintableWithLines (BlockContainer(anonymous)) [0,0 800x0] + PaintableWithLines (BlockContainer) [8,8 784x150] + PaintableWithLines (BlockContainer
.container) [8,8 150x150] + ImagePaintable (ImageBox.replaced) [8,8 150x150] diff --git a/Tests/LibWeb/Layout/input/replaced-within-max-content.html b/Tests/LibWeb/Layout/input/replaced-within-max-content.html new file mode 100644 index 0000000000..80536c32dd --- /dev/null +++ b/Tests/LibWeb/Layout/input/replaced-within-max-content.html @@ -0,0 +1,15 @@ + + + + + +
diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 6fcb9a1474..168c0bf4b4 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -274,7 +274,7 @@ CSSPixelSize FormattingContext::solve_replaced_size_constraint(CSSPixels input_w auto specified_max_height = should_treat_max_height_as_none(box, available_space.height) ? input_height : box.computed_values().max_height().to_px(box, height_of_containing_block); auto max_height = max(min_height, specified_max_height); - auto aspect_ratio = input_width / input_height; + CSSPixelFraction aspect_ratio = *box.preferred_aspect_ratio(); // These are from the "Constraint Violation" table in spec, but reordered so that each condition is // interpreted as mutually exclusive to any other.