From de71eb9b1323aa4552e3df800e9177ed9bffa7c7 Mon Sep 17 00:00:00 2001 From: InvalidUsernameException Date: Sun, 19 Jan 2025 14:35:25 +0100 Subject: [PATCH] LibWeb: Accept TableWrapper as containing block for abspos items When an element is displayed as table, an anonymous table wrapper box needs to be created for it. Among others, the position property of the table element is then applied to the anonymous table wrapper box instead. If the table happens to be positioned absolutely, the table wrapper box may become the containing block for absolutely positioned elements inside the table. In the original code however, anonymous layout nodes were excluded from becoming the containing block for an absolutely positioned element. Because of this, the containing block was calculated to be the first suitable parent block of the table wrapper box. This incorrect containing block would result in a crash later on when trying to size the absolutely positioned element inside the table. To prevent this crash, the anonymous table wrapper box is now allowed to become the containing block for absolutely positioned elements inside a table. The definition of containing block for an absolutely positioned element in the spec does not mention anything about skipping anonymous boxes. Additionally the rules for absolute positioning of tables (https://www.w3.org/TR/css-tables-3/#abspos-boxes-in-table-root) imply that a table wrapper box is indeed able to be the containing block for absolutely positioned elements. --- Libraries/LibWeb/Layout/Node.cpp | 2 -- .../css/css-tables/absolute-tables-006.html | 35 +++++++++++++++++++ .../abspos-child-inside-abspos-table.txt | 1 + .../abspos-child-inside-abspos-table.html | 12 +++++++ 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Ref/input/wpt-import/css/css-tables/absolute-tables-006.html create mode 100644 Tests/LibWeb/Text/expected/abspos-child-inside-abspos-table.txt create mode 100644 Tests/LibWeb/Text/input/abspos-child-inside-abspos-table.html diff --git a/Libraries/LibWeb/Layout/Node.cpp b/Libraries/LibWeb/Layout/Node.cpp index d513d84db76..2fb0063f79d 100644 --- a/Libraries/LibWeb/Layout/Node.cpp +++ b/Libraries/LibWeb/Layout/Node.cpp @@ -118,8 +118,6 @@ Box const* Node::containing_block() const auto const* ancestor = parent(); while (ancestor && !ancestor->can_contain_boxes_with_position_absolute()) ancestor = ancestor->parent(); - while (ancestor && ancestor->is_anonymous()) - ancestor = nearest_ancestor_capable_of_forming_a_containing_block(*ancestor); return static_cast(ancestor); } diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-tables/absolute-tables-006.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-tables/absolute-tables-006.html new file mode 100644 index 00000000000..3b89d4fc1c3 --- /dev/null +++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-tables/absolute-tables-006.html @@ -0,0 +1,35 @@ + + + + + + + + +

Test passes if there is a filled green square.

+ + +
+ diff --git a/Tests/LibWeb/Text/expected/abspos-child-inside-abspos-table.txt b/Tests/LibWeb/Text/expected/abspos-child-inside-abspos-table.txt new file mode 100644 index 00000000000..ce5a342f77b --- /dev/null +++ b/Tests/LibWeb/Text/expected/abspos-child-inside-abspos-table.txt @@ -0,0 +1 @@ +PASS (did not crash) diff --git a/Tests/LibWeb/Text/input/abspos-child-inside-abspos-table.html b/Tests/LibWeb/Text/input/abspos-child-inside-abspos-table.html new file mode 100644 index 00000000000..66ef73006b1 --- /dev/null +++ b/Tests/LibWeb/Text/input/abspos-child-inside-abspos-table.html @@ -0,0 +1,12 @@ + + +
+