Skip to content

Commit 26c20e3

Browse files
axgalloawesomekling
authored andcommitted
LibWeb: Split BorderConflictFinder::conflicting_edges method
Make it clearer which edges and elements are considered at each step.
1 parent a7166eb commit 26c20e3

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,111 +1443,156 @@ void TableFormattingContext::BorderConflictFinder::collect_conflicting_row_group
14431443
});
14441444
}
14451445

1446-
Vector<TableFormattingContext::ConflictingEdge> TableFormattingContext::BorderConflictFinder::conflicting_edges(
1447-
Cell const& cell, TableFormattingContext::ConflictingSide edge) const
1446+
void TableFormattingContext::BorderConflictFinder::collect_cell_conflicting_edges(Vector<ConflictingEdge>& result, Cell const& cell, TableFormattingContext::ConflictingSide edge) const
14481447
{
1449-
Vector<ConflictingEdge> result = {};
1448+
// Right edge of the cell to the left.
14501449
if (cell.column_index >= cell.column_span && edge == ConflictingSide::Left) {
14511450
auto left_cell_column_index = cell.column_index - cell.column_span;
14521451
auto maybe_cell_to_left = m_context->m_cells_by_coordinate[cell.row_index][left_cell_column_index];
14531452
if (maybe_cell_to_left.has_value()) {
14541453
result.append({ maybe_cell_to_left->box, Painting::PaintableBox::ConflictingElementKind::Cell, ConflictingSide::Right, cell.row_index, left_cell_column_index });
14551454
}
14561455
}
1456+
// Left edge of the cell to the right.
14571457
if (cell.column_index + cell.column_span < m_context->m_cells_by_coordinate[cell.row_index].size() && edge == ConflictingSide::Right) {
14581458
auto right_cell_column_index = cell.column_index + cell.column_span;
14591459
auto maybe_cell_to_right = m_context->m_cells_by_coordinate[cell.row_index][right_cell_column_index];
14601460
if (maybe_cell_to_right.has_value()) {
14611461
result.append({ maybe_cell_to_right->box, Painting::PaintableBox::ConflictingElementKind::Cell, ConflictingSide::Left, cell.row_index, right_cell_column_index });
14621462
}
14631463
}
1464+
// Bottom edge of the cell above.
14641465
if (cell.row_index >= cell.row_span && edge == ConflictingSide::Top) {
14651466
auto above_cell_row_index = cell.row_index - cell.row_span;
14661467
auto maybe_cell_above = m_context->m_cells_by_coordinate[above_cell_row_index][cell.column_index];
14671468
if (maybe_cell_above.has_value()) {
14681469
result.append({ maybe_cell_above->box, Painting::PaintableBox::ConflictingElementKind::Cell, ConflictingSide::Bottom, above_cell_row_index, cell.column_index });
14691470
}
14701471
}
1472+
// Top edge of the cell below.
14711473
if (cell.row_index + cell.row_span < m_context->m_cells_by_coordinate.size() && edge == ConflictingSide::Bottom) {
14721474
auto below_cell_row_index = cell.row_index + cell.row_span;
14731475
auto maybe_cell_below = m_context->m_cells_by_coordinate[below_cell_row_index][cell.column_index];
14741476
if (maybe_cell_below.has_value()) {
14751477
result.append({ maybe_cell_below->box, Painting::PaintableBox::ConflictingElementKind::Cell, ConflictingSide::Top, below_cell_row_index, cell.column_index });
14761478
}
14771479
}
1480+
}
1481+
1482+
void TableFormattingContext::BorderConflictFinder::collect_row_conflicting_edges(Vector<ConflictingEdge>& result, Cell const& cell, TableFormattingContext::ConflictingSide edge) const
1483+
{
1484+
// Top edge of the row.
14781485
if (edge == ConflictingSide::Top) {
14791486
result.append({ m_context->m_rows[cell.row_index].box, Painting::PaintableBox::ConflictingElementKind::Row, ConflictingSide::Top, cell.row_index, {} });
14801487
}
1488+
// Bottom edge of the row.
14811489
if (edge == ConflictingSide::Bottom) {
14821490
result.append({ m_context->m_rows[cell.row_index].box, Painting::PaintableBox::ConflictingElementKind::Row, ConflictingSide::Bottom, cell.row_index, {} });
14831491
}
1492+
// Bottom edge of the row above.
14841493
if (cell.row_index >= cell.row_span && edge == ConflictingSide::Top) {
14851494
auto above_row_index = cell.row_index - cell.row_span;
14861495
result.append({ m_context->m_rows[above_row_index].box, Painting::PaintableBox::ConflictingElementKind::Row, ConflictingSide::Bottom, above_row_index, {} });
14871496
}
1497+
// Top edge of the row below.
14881498
if (cell.row_index + cell.row_span < m_context->m_rows.size() && edge == ConflictingSide::Bottom) {
14891499
auto below_row_index = cell.row_index + cell.row_span;
14901500
result.append({ m_context->m_rows[below_row_index].box, Painting::PaintableBox::ConflictingElementKind::Row, ConflictingSide::Top, below_row_index, {} });
14911501
}
1502+
}
1503+
1504+
void TableFormattingContext::BorderConflictFinder::collect_row_group_conflicting_edges(Vector<ConflictingEdge>& result, Cell const& cell, TableFormattingContext::ConflictingSide edge) const
1505+
{
14921506
auto const& maybe_row_group = m_row_group_elements_by_index[cell.row_index];
1507+
// Top edge of the row group.
14931508
if (maybe_row_group.has_value() && cell.row_index == maybe_row_group->start_index && edge == ConflictingSide::Top) {
14941509
result.append({ maybe_row_group->row_group, Painting::PaintableBox::ConflictingElementKind::RowGroup, ConflictingSide::Top, maybe_row_group->start_index, {} });
14951510
}
1511+
// Bottom edge of the row group above.
14961512
if (cell.row_index >= cell.row_span) {
14971513
auto const& maybe_row_group_above = m_row_group_elements_by_index[cell.row_index - cell.row_span];
14981514
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) {
14991515
result.append({ maybe_row_group_above->row_group, Painting::PaintableBox::ConflictingElementKind::RowGroup, ConflictingSide::Bottom, maybe_row_group_above->start_index, {} });
15001516
}
15011517
}
1518+
// Bottom edge of the row group.
15021519
if (maybe_row_group.has_value() && cell.row_index == maybe_row_group->start_index + maybe_row_group->row_count - 1 && edge == ConflictingSide::Bottom) {
15031520
result.append({ maybe_row_group->row_group, Painting::PaintableBox::ConflictingElementKind::RowGroup, ConflictingSide::Bottom, maybe_row_group->start_index, {} });
15041521
}
1522+
// Top edge of the row group below.
15051523
if (cell.row_index + cell.row_span < m_row_group_elements_by_index.size()) {
15061524
auto const& maybe_row_group_below = m_row_group_elements_by_index[cell.row_index + cell.row_span];
15071525
if (maybe_row_group_below.has_value() && cell.row_index + cell.row_span == maybe_row_group_below->start_index && edge == ConflictingSide::Bottom) {
15081526
result.append({ maybe_row_group_below->row_group, Painting::PaintableBox::ConflictingElementKind::RowGroup, ConflictingSide::Top, maybe_row_group_below->start_index, {} });
15091527
}
15101528
}
1529+
}
1530+
1531+
void TableFormattingContext::BorderConflictFinder::collect_column_group_conflicting_edges(Vector<ConflictingEdge>& result, Cell const& cell, TableFormattingContext::ConflictingSide edge) const
1532+
{
1533+
// Left edge of the column group.
15111534
if (m_col_elements_by_index[cell.column_index] && edge == ConflictingSide::Left) {
15121535
result.append({ m_col_elements_by_index[cell.column_index], Painting::PaintableBox::ConflictingElementKind::ColumnGroup, ConflictingSide::Left, {}, cell.column_index });
15131536
}
1537+
// Right edge of the column group to the left.
15141538
if (cell.column_index >= cell.column_span && m_col_elements_by_index[cell.column_index - cell.column_span] && edge == ConflictingSide::Left) {
15151539
auto left_column_index = cell.column_index - cell.column_span;
15161540
result.append({ m_col_elements_by_index[left_column_index], Painting::PaintableBox::ConflictingElementKind::ColumnGroup, ConflictingSide::Right, {}, left_column_index });
15171541
}
1542+
// Right edge of the column group.
15181543
if (m_col_elements_by_index[cell.column_index] && edge == ConflictingSide::Right) {
15191544
result.append({ m_col_elements_by_index[cell.column_index], Painting::PaintableBox::ConflictingElementKind::ColumnGroup, ConflictingSide::Right, {}, cell.column_index });
15201545
}
1546+
// Left edge of the column group to the right.
15211547
if (cell.column_index + cell.column_span < m_col_elements_by_index.size() && m_col_elements_by_index[cell.column_index + cell.column_span] && edge == ConflictingSide::Right) {
15221548
auto right_column_index = cell.column_index + cell.column_span;
15231549
result.append({ m_col_elements_by_index[right_column_index], Painting::PaintableBox::ConflictingElementKind::ColumnGroup, ConflictingSide::Left, {}, right_column_index });
15241550
}
1551+
}
1552+
1553+
void TableFormattingContext::BorderConflictFinder::collect_table_box_conflicting_edges(Vector<ConflictingEdge>& result, Cell const& cell, TableFormattingContext::ConflictingSide edge) const
1554+
{
1555+
// Top edge from column group or table. Left and right edges of the column group are handled in collect_column_group_conflicting_edges.
15251556
if (cell.row_index == 0 && edge == ConflictingSide::Top) {
15261557
if (m_col_elements_by_index[cell.column_index]) {
15271558
result.append({ m_col_elements_by_index[cell.column_index], Painting::PaintableBox::ConflictingElementKind::ColumnGroup, ConflictingSide::Top, {}, cell.column_index });
15281559
}
15291560
result.append({ &m_context->table_box(), Painting::PaintableBox::ConflictingElementKind::Table, ConflictingSide::Top, {}, {} });
15301561
}
1562+
// Bottom edge from column group or table. Left and right edges of the column group are handled in collect_column_group_conflicting_edges.
15311563
if (cell.row_index == m_context->m_rows.size() - 1 && edge == ConflictingSide::Bottom) {
15321564
if (m_col_elements_by_index[cell.column_index]) {
15331565
result.append({ m_col_elements_by_index[cell.column_index], Painting::PaintableBox::ConflictingElementKind::ColumnGroup, ConflictingSide::Bottom, {}, cell.column_index });
15341566
}
15351567
result.append({ &m_context->table_box(), Painting::PaintableBox::ConflictingElementKind::Table, ConflictingSide::Bottom, {}, {} });
15361568
}
1569+
// Left edge from row group or table. Top and bottom edges of the row group are handled in collect_row_group_conflicting_edges.
15371570
if (cell.column_index == 0 && edge == ConflictingSide::Left) {
15381571
result.append({ m_context->m_rows[cell.row_index].box, Painting::PaintableBox::ConflictingElementKind::Row, ConflictingSide::Left, cell.row_index, {} });
15391572
if (m_row_group_elements_by_index[cell.row_index].has_value()) {
15401573
result.append({ m_row_group_elements_by_index[cell.row_index]->row_group, Painting::PaintableBox::ConflictingElementKind::RowGroup, ConflictingSide::Left, cell.row_index, {} });
15411574
}
15421575
result.append({ &m_context->table_box(), Painting::PaintableBox::ConflictingElementKind::Table, ConflictingSide::Left, {}, {} });
15431576
}
1577+
// Right edge from row group or table. Top and bottom edges of the row group are handled in collect_row_group_conflicting_edges.
15441578
if (cell.column_index == m_context->m_columns.size() - 1 && edge == ConflictingSide::Right) {
15451579
result.append({ m_context->m_rows[cell.row_index].box, Painting::PaintableBox::ConflictingElementKind::Row, ConflictingSide::Right, cell.row_index, {} });
15461580
if (m_row_group_elements_by_index[cell.row_index].has_value()) {
15471581
result.append({ m_row_group_elements_by_index[cell.row_index]->row_group, Painting::PaintableBox::ConflictingElementKind::RowGroup, ConflictingSide::Right, cell.row_index, {} });
15481582
}
15491583
result.append({ &m_context->table_box(), Painting::PaintableBox::ConflictingElementKind::Table, ConflictingSide::Right, {}, {} });
15501584
}
1585+
}
1586+
1587+
Vector<TableFormattingContext::ConflictingEdge> TableFormattingContext::BorderConflictFinder::conflicting_edges(
1588+
Cell const& cell, TableFormattingContext::ConflictingSide edge) const
1589+
{
1590+
Vector<ConflictingEdge> result = {};
1591+
collect_cell_conflicting_edges(result, cell, edge);
1592+
collect_row_conflicting_edges(result, cell, edge);
1593+
collect_row_group_conflicting_edges(result, cell, edge);
1594+
collect_column_group_conflicting_edges(result, cell, edge);
1595+
collect_table_box_conflicting_edges(result, cell, edge);
15511596
return result;
15521597
}
15531598

Userland/Libraries/LibWeb/Layout/TableFormattingContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ class TableFormattingContext final : public FormattingContext {
177177
void collect_conflicting_col_elements();
178178
void collect_conflicting_row_group_elements();
179179

180+
void collect_cell_conflicting_edges(Vector<ConflictingEdge>&, Cell const&, ConflictingSide) const;
181+
void collect_row_conflicting_edges(Vector<ConflictingEdge>&, Cell const&, ConflictingSide) const;
182+
void collect_row_group_conflicting_edges(Vector<ConflictingEdge>&, Cell const&, ConflictingSide) const;
183+
void collect_column_group_conflicting_edges(Vector<ConflictingEdge>&, Cell const&, ConflictingSide) const;
184+
void collect_table_box_conflicting_edges(Vector<ConflictingEdge>&, Cell const&, ConflictingSide) const;
185+
180186
struct RowGroupInfo {
181187
Node const* row_group;
182188
size_t start_index;

0 commit comments

Comments
 (0)