From 6175fcdaeb64e27d3dedfc1984867d8fd3739205 Mon Sep 17 00:00:00 2001 From: Andi Gallo Date: Thu, 24 Aug 2023 03:40:01 +0000 Subject: [PATCH] LibWeb: Add a table row to the layout tree for buttons We were relying on the table fixup algorithm to insert the missing table row, which fails to do so when we only have an image in the button. While that might be a problem with the table fixup algorithm, we should build a correct layout tree explicitly anyway. Fixes crashes on GitHub. --- .../block-and-inline/button-image-only.txt | 28 +++++++++++++++++++ .../block-and-inline/button-image-only.html | 5 ++++ .../Libraries/LibWeb/Layout/TreeBuilder.cpp | 8 +++++- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/block-and-inline/button-image-only.txt create mode 100644 Tests/LibWeb/Layout/input/block-and-inline/button-image-only.html diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/button-image-only.txt b/Tests/LibWeb/Layout/expected/block-and-inline/button-image-only.txt new file mode 100644 index 0000000000..b8e0ecd662 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/block-and-inline/button-image-only.txt @@ -0,0 +1,28 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x600 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x419.203125 children: inline + line 0 width: 430, height: 419.203125, bottom: 419.203125, baseline: 422 + frag 0 from BlockContainer start: 0, length: 0, rect: [13,10 420x415.203125] + BlockContainer \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp index aca6b2caa3..c52bbfe49c 100644 --- a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp @@ -389,12 +389,17 @@ ErrorOr TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder:: static_cast(cell_computed_values).set_display(CSS::Display { CSS::Display::Internal::TableCell }); static_cast(cell_computed_values).set_vertical_align(CSS::VerticalAlign::Middle); + auto row_computed_values = parent.computed_values().clone_inherited_values(); + static_cast(row_computed_values).set_display(CSS::Display { CSS::Display::Internal::TableRow }); + auto table_wrapper = parent.heap().template allocate_without_realm(parent.document(), nullptr, move(table_computed_values)); auto cell_wrapper = parent.heap().template allocate_without_realm(parent.document(), nullptr, move(cell_computed_values)); + auto row_wrapper = parent.heap().template allocate_without_realm(parent.document(), nullptr, move(row_computed_values)); cell_wrapper->set_line_height(parent.line_height()); cell_wrapper->set_font(parent.font()); cell_wrapper->set_children_are_inline(parent.children_are_inline()); + row_wrapper->set_children_are_inline(false); Vector> sequence; for (auto child = parent.first_child(); child; child = child->next_sibling()) { @@ -406,7 +411,8 @@ ErrorOr TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder:: cell_wrapper->append_child(*node); } - table_wrapper->append_child(*cell_wrapper); + row_wrapper->append_child(*cell_wrapper); + table_wrapper->append_child(*row_wrapper); parent.append_child(*table_wrapper); }