From 549dee4db171a94317d49bfb2e6beb7490b29766 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 31 Oct 2023 06:38:07 +0100 Subject: [PATCH] LibWeb: Call prepare_for_replaced_layout() on replaced boxes in GFC We need to call prepare_for_replaced_layout() on grid items to populate their natural sizes and aspect ration. --- Tests/LibWeb/Layout/expected/grid/replaced-item-1.txt | 11 +++++++++++ Tests/LibWeb/Layout/input/grid/replaced-item-1.html | 10 ++++++++++ .../Libraries/LibWeb/Layout/GridFormattingContext.cpp | 7 +++++++ 3 files changed, 28 insertions(+) create mode 100644 Tests/LibWeb/Layout/expected/grid/replaced-item-1.txt create mode 100644 Tests/LibWeb/Layout/input/grid/replaced-item-1.html diff --git a/Tests/LibWeb/Layout/expected/grid/replaced-item-1.txt b/Tests/LibWeb/Layout/expected/grid/replaced-item-1.txt new file mode 100644 index 0000000000..6153c3749b --- /dev/null +++ b/Tests/LibWeb/Layout/expected/grid/replaced-item-1.txt @@ -0,0 +1,11 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x516 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x500 children: not-inline + Box at (8,8) content-size 100x500 [GFC] children: not-inline + ImageBox at (8,8) content-size 500x500 children: not-inline + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x516] + PaintableWithLines (BlockContainer) [8,8 784x500] + PaintableBox (Box
.grid) [8,8 100x500] overflow: [8,8 500x500] + ImagePaintable (ImageBox) [8,8 500x500] diff --git a/Tests/LibWeb/Layout/input/grid/replaced-item-1.html b/Tests/LibWeb/Layout/input/grid/replaced-item-1.html new file mode 100644 index 0000000000..986b282d3d --- /dev/null +++ b/Tests/LibWeb/Layout/input/grid/replaced-item-1.html @@ -0,0 +1,10 @@ +
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp index 6ee6105ad1..9003c925d0 100644 --- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace Web::Layout { @@ -1845,6 +1846,12 @@ void GridFormattingContext::run(Box const& box, LayoutMode, AvailableSpace const box_state.set_indefinite_content_width(); if (!computed_values.height().is_length()) box_state.set_indefinite_content_height(); + + if (item.box->is_replaced_box()) { + auto& replaced_box = static_cast(*item.box); + // FIXME: This const_cast is gross. + const_cast(replaced_box).prepare_for_replaced_layout(); + } } // Do the first pass of resolving grid items box metrics to compute values that are independent of a track width