From 2660bbb94fbd2764e785e829c80d07a67102aab7 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sat, 4 Nov 2023 04:08:59 +0100 Subject: [PATCH] LibWeb: Consider colgroups while calculating table grid size We should take in account elements in column groups while finding number of columns in a table. --- .../expected/table/colgroup-with-two-cols.txt | 16 ++++++++++++++++ .../input/table/colgroup-with-two-cols.html | 1 + Userland/Libraries/LibWeb/Layout/TableGrid.cpp | 13 +++++++++++++ Userland/Libraries/LibWeb/Layout/TableGrid.h | 5 +++++ 4 files changed, 35 insertions(+) create mode 100644 Tests/LibWeb/Layout/expected/table/colgroup-with-two-cols.txt create mode 100644 Tests/LibWeb/Layout/input/table/colgroup-with-two-cols.html diff --git a/Tests/LibWeb/Layout/expected/table/colgroup-with-two-cols.txt b/Tests/LibWeb/Layout/expected/table/colgroup-with-two-cols.txt new file mode 100644 index 0000000000..d4e8504c6c --- /dev/null +++ b/Tests/LibWeb/Layout/expected/table/colgroup-with-two-cols.txt @@ -0,0 +1,16 @@ +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 784x2 children: not-inline + TableWrapper <(anonymous)> at (8,8) content-size 6x2 [BFC] children: not-inline + Box at (8,8) content-size 6x2 table-box [TFC] children: not-inline + BlockContainer (not painted) table-column-group children: not-inline + BlockContainer (not painted) children: not-inline + BlockContainer (not painted) children: not-inline + Box at (8,8) content-size 0x0 table-row-group children: not-inline + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x600] + PaintableWithLines (BlockContainer) [8,8 784x2] + PaintableWithLines (TableWrapper(anonymous)) [8,8 6x2] + PaintableBox (Box
) [8,8 6x2] + PaintableBox (Box) [8,8 0x0] diff --git a/Tests/LibWeb/Layout/input/table/colgroup-with-two-cols.html b/Tests/LibWeb/Layout/input/table/colgroup-with-two-cols.html new file mode 100644 index 0000000000..59d6634d3c --- /dev/null +++ b/Tests/LibWeb/Layout/input/table/colgroup-with-two-cols.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/TableGrid.cpp b/Userland/Libraries/LibWeb/Layout/TableGrid.cpp index 2338daa926..403ebaca38 100644 --- a/Userland/Libraries/LibWeb/Layout/TableGrid.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableGrid.cpp @@ -5,6 +5,7 @@ */ #include +#include #include namespace Web::Layout { @@ -62,6 +63,18 @@ TableGrid TableGrid::calculate_row_column_grid(Box const& box, Vector& cel y_current++; }; + auto process_col_group = [&](auto& col_group) { + auto dom_node = col_group.dom_node(); + dom_node->template for_each_in_subtree_of_type([&](auto&) { + x_width += 1; + return IterationDecision::Continue; + }); + }; + + for_each_child_box_matching(box, is_table_column_group, [&](auto& column_group_box) { + process_col_group(column_group_box); + }); + for_each_child_box_matching(box, is_table_row_group, [&](auto& row_group_box) { for_each_child_box_matching(row_group_box, is_table_row, [&](auto& row_box) { process_row(row_box); diff --git a/Userland/Libraries/LibWeb/Layout/TableGrid.h b/Userland/Libraries/LibWeb/Layout/TableGrid.h index 1e414d0615..5445b6261f 100644 --- a/Userland/Libraries/LibWeb/Layout/TableGrid.h +++ b/Userland/Libraries/LibWeb/Layout/TableGrid.h @@ -65,6 +65,11 @@ public: return box.display().is_table_row(); } + static bool is_table_column_group(Box const& box) + { + return box.display().is_table_column_group(); + } + template static void for_each_child_box_matching(Box const& parent, Matcher matcher, Callback callback) {