From d94b33e2056fe21ef03c2cf47612d2ecb53a6758 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 19 Aug 2025 01:23:00 +0200 Subject: [PATCH] LibWeb: Handle correctly case when abspos and relpos GFC is interleaved ...by another GFC. When searching for grid item that contains an abspos box positioned relative to GFC, it's incorrect to assume that the closest ancestor box whose parent establishes GFC is always the one we are looking for, because there may be non-positioned GFC in between. Fixes regression introduced in 80c8e78. --- .../LibWeb/Layout/GridFormattingContext.cpp | 2 +- .../gfc-between-relpos-gfc-and-abspos-item.txt | 18 ++++++++++++++++++ ...gfc-between-relpos-gfc-and-abspos-item.html | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/grid/gfc-between-relpos-gfc-and-abspos-item.txt create mode 100644 Tests/LibWeb/Layout/input/grid/gfc-between-relpos-gfc-and-abspos-item.html diff --git a/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Libraries/LibWeb/Layout/GridFormattingContext.cpp index 4899f56807b..78bd751b129 100644 --- a/Libraries/LibWeb/Layout/GridFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/GridFormattingContext.cpp @@ -2120,7 +2120,7 @@ void GridFormattingContext::layout_absolutely_positioned_element(Box const& box) // `Node::containing_block()` is not aware of that. Therefore, we need to // find the closest grid item ancestor in order to identify grid area it belongs to. NodeWithStyle const* containing_grid_item = &box; - while (containing_grid_item->parent() && !containing_grid_item->parent()->display().is_grid_inside()) + while (containing_grid_item->parent() && containing_grid_item->parent() != &grid_container()) containing_grid_item = containing_grid_item->parent(); auto const& computed_values = containing_grid_item->computed_values(); diff --git a/Tests/LibWeb/Layout/expected/grid/gfc-between-relpos-gfc-and-abspos-item.txt b/Tests/LibWeb/Layout/expected/grid/gfc-between-relpos-gfc-and-abspos-item.txt new file mode 100644 index 00000000000..4c516da78c3 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/grid/gfc-between-relpos-gfc-and-abspos-item.txt @@ -0,0 +1,18 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x16 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x0 children: not-inline + Box at (8,8) content-size 784x0 positioned [GFC] children: not-inline + Box at (8,8) content-size 784x0 [GFC] children: not-inline + BlockContainer
at (8,8) content-size 784x0 [BFC] children: not-inline + BlockContainer at (8,8) content-size 0x0 positioned [BFC] children: not-inline + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x16] + PaintableWithLines (BlockContainer) [8,8 784x0] + PaintableBox (Box
.outer) [8,8 784x0] + PaintableBox (Box
.middle) [8,8 784x0] + PaintableWithLines (BlockContainer
) [8,8 784x0] + PaintableWithLines (BlockContainer
.abs) [8,8 0x0] + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [0,0 800x16] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/input/grid/gfc-between-relpos-gfc-and-abspos-item.html b/Tests/LibWeb/Layout/input/grid/gfc-between-relpos-gfc-and-abspos-item.html new file mode 100644 index 00000000000..327b92807c5 --- /dev/null +++ b/Tests/LibWeb/Layout/input/grid/gfc-between-relpos-gfc-and-abspos-item.html @@ -0,0 +1,5 @@ +
\ No newline at end of file