From 3476cf0fcb94dd3df8be9a76477c82838110d7fd Mon Sep 17 00:00:00 2001 From: Andi Gallo Date: Sun, 9 Jul 2023 23:04:24 +0000 Subject: [PATCH] LibWeb: Add border conflict resolution with rowgroup --- ...rder-conflict-resolution-with-rowgroup.txt | 70 +++++++++++++++++++ ...der-conflict-resolution-with-rowgroup.html | 32 +++++++++ .../LibWeb/Layout/TableFormattingContext.cpp | 49 ++++++++++++- .../LibWeb/Layout/TableFormattingContext.h | 8 +++ 4 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/table/border-conflict-resolution-with-rowgroup.txt create mode 100644 Tests/LibWeb/Layout/input/table/border-conflict-resolution-with-rowgroup.html diff --git a/Tests/LibWeb/Layout/expected/table/border-conflict-resolution-with-rowgroup.txt b/Tests/LibWeb/Layout/expected/table/border-conflict-resolution-with-rowgroup.txt new file mode 100644 index 0000000000..e716544177 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/table/border-conflict-resolution-with-rowgroup.txt @@ -0,0 +1,70 @@ +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 784x124.40625 children: not-inline + TableWrapper <(anonymous)> at (8,8) content-size 113.40625x124.40625 [BFC] children: not-inline + Box at (8,8) content-size 113.40625x124.40625 table-box [TFC] children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + Box at (8,8) content-size 113.40625x41.46875 table-header-group children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + Box at (8,8) content-size 113.40625x41.46875 table-row children: not-inline + BlockContainer at (8,49.46875) content-size 113.40625x41.46875 table-row children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer at (8,90.9375) content-size 113.40625x41.46875 table-row children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer
at (29,19) content-size 16.265625x17.46875 table-cell [BFC] children: inline + line 0 width: 9.59375, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 1, rect: [29,19 9.59375x17.46875] + "0" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer at (87.265625,19) content-size 13.140625x17.46875 table-cell [BFC] children: inline + line 0 width: 6.34375, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 1, rect: [87.265625,19 6.34375x17.46875] + "1" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + Box at (8,49.46875) content-size 113.40625x82.9375 table-row-group children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + Box
at (31,62.46875) content-size 14.265625x17.46875 table-cell [BFC] children: inline + line 0 width: 14.265625, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 1, rect: [31,62.46875 14.265625x17.46875] + "A" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer at (87.265625,62.46875) content-size 11.140625x17.46875 table-cell [BFC] children: inline + line 0 width: 9.34375, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 1, rect: [87.265625,62.46875 9.34375x17.46875] + "B" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + Box
at (31,101.9375) content-size 14.265625x17.46875 table-cell [BFC] children: inline + line 0 width: 10.3125, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 1, rect: [31,101.9375 10.3125x17.46875] + "C" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer at (87.265625,101.9375) content-size 11.140625x17.46875 table-cell [BFC] children: inline + line 0 width: 11.140625, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 1, rect: [87.265625,101.9375 11.140625x17.46875] + "D" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> diff --git a/Tests/LibWeb/Layout/input/table/border-conflict-resolution-with-rowgroup.html b/Tests/LibWeb/Layout/input/table/border-conflict-resolution-with-rowgroup.html new file mode 100644 index 0000000000..c99ceb6c2e --- /dev/null +++ b/Tests/LibWeb/Layout/input/table/border-conflict-resolution-with-rowgroup.html @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + +
01
AB
CD
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp index be5ccc384c..adc9fa6827 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -1025,6 +1026,7 @@ TableFormattingContext::BorderConflictFinder::BorderConflictFinder(TableFormatti : m_context(context) { collect_conflicting_col_elements(); + collect_conflicting_row_group_elements(); } void TableFormattingContext::BorderConflictFinder::collect_conflicting_col_elements() @@ -1047,11 +1049,29 @@ void TableFormattingContext::BorderConflictFinder::collect_conflicting_col_eleme } } +void TableFormattingContext::BorderConflictFinder::collect_conflicting_row_group_elements() +{ + m_row_group_elements_by_index.resize(m_context->m_rows.size()); + size_t current_row_index = 0; + for_each_child_box_matching(m_context->table_box(), is_table_row_group, [&](auto& row_group_box) { + auto start_row_index = current_row_index; + size_t row_count = 0; + for_each_child_box_matching(row_group_box, is_table_row, [&](auto&) { + ++row_count; + }); + for_each_child_box_matching(row_group_box, is_table_row, [&](auto&) { + m_row_group_elements_by_index[current_row_index] = RowGroupInfo { + .row_group = &row_group_box, .start_index = start_row_index, .row_count = row_count + }; + ++current_row_index; + return IterationDecision::Continue; + }); + }); +} + Vector TableFormattingContext::BorderConflictFinder::conflicting_edges( Cell const& cell, TableFormattingContext::ConflictingSide edge) const { - // FIXME: Conflicting elements can be cells, rows, row groups, columns, column groups, and the table itself, - // but we only consider cells, rows, 'col' elements in a 'colgroup' and the table itself for now. Vector result = {}; if (cell.column_index >= cell.column_span && edge == ConflictingSide::Left) { auto maybe_cell_to_left = m_context->m_cells_by_coordinate[cell.row_index][cell.column_index - cell.column_span]; @@ -1089,6 +1109,25 @@ Vector TableFormattingContext::BorderCo if (cell.row_index + cell.row_span < m_context->m_rows.size() && edge == ConflictingSide::Bottom) { result.append({ m_context->m_rows[cell.row_index + cell.row_span].box, ConflictingSide::Top }); } + auto const& maybe_row_group = m_row_group_elements_by_index[cell.row_index]; + if (maybe_row_group.has_value() && cell.row_index == maybe_row_group->start_index && edge == ConflictingSide::Top) { + result.append({ maybe_row_group->row_group, ConflictingSide::Top }); + } + if (cell.row_index >= cell.row_span) { + auto const& maybe_row_group_above = m_row_group_elements_by_index[cell.row_index - cell.row_span]; + if (maybe_row_group_above.has_value() && cell.row_index == maybe_row_group_above->start_index + maybe_row_group_above->row_count && edge == ConflictingSide::Top) { + result.append({ maybe_row_group_above->row_group, ConflictingSide::Bottom }); + } + } + if (maybe_row_group.has_value() && cell.row_index == maybe_row_group->start_index + maybe_row_group->row_count - 1 && edge == ConflictingSide::Bottom) { + result.append({ maybe_row_group->row_group, ConflictingSide::Bottom }); + } + if (cell.row_index + cell.row_span < m_row_group_elements_by_index.size()) { + auto const& maybe_row_group_below = m_row_group_elements_by_index[cell.row_index + cell.row_span]; + if (maybe_row_group_below.has_value() && cell.row_index + cell.row_span == maybe_row_group_below->start_index && edge == ConflictingSide::Bottom) { + result.append({ maybe_row_group_below->row_group, ConflictingSide::Top }); + } + } if (m_col_elements_by_index[cell.column_index] && edge == ConflictingSide::Left) { result.append({ m_col_elements_by_index[cell.column_index], ConflictingSide::Left }); } @@ -1115,10 +1154,16 @@ Vector TableFormattingContext::BorderCo } if (cell.column_index == 0 && edge == ConflictingSide::Left) { result.append({ m_context->m_rows[cell.row_index].box, ConflictingSide::Left }); + if (m_row_group_elements_by_index[cell.row_index].has_value()) { + result.append({ m_row_group_elements_by_index[cell.row_index]->row_group, ConflictingSide::Left }); + } result.append({ &m_context->table_box(), ConflictingSide::Left }); } if (cell.column_index == m_context->m_columns.size() - 1 && edge == ConflictingSide::Right) { result.append({ m_context->m_rows[cell.row_index].box, ConflictingSide::Right }); + if (m_row_group_elements_by_index[cell.row_index].has_value()) { + result.append({ m_row_group_elements_by_index[cell.row_index]->row_group, ConflictingSide::Right }); + } result.append({ &m_context->table_box(), ConflictingSide::Right }); } return result; diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h index 1a20a1ab7c..87dceadcbd 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h @@ -143,8 +143,16 @@ private: private: void collect_conflicting_col_elements(); + void collect_conflicting_row_group_elements(); + + struct RowGroupInfo { + Node const* row_group; + size_t start_index; + size_t row_count; + }; Vector m_col_elements_by_index; + Vector> m_row_group_elements_by_index; TableFormattingContext const* m_context; };