@@ -1443,111 +1443,156 @@ void TableFormattingContext::BorderConflictFinder::collect_conflicting_row_group
1443
1443
});
1444
1444
}
1445
1445
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
1448
1447
{
1449
- Vector<ConflictingEdge> result = {};
1448
+ // Right edge of the cell to the left.
1450
1449
if (cell.column_index >= cell.column_span && edge == ConflictingSide::Left) {
1451
1450
auto left_cell_column_index = cell.column_index - cell.column_span ;
1452
1451
auto maybe_cell_to_left = m_context->m_cells_by_coordinate [cell.row_index ][left_cell_column_index];
1453
1452
if (maybe_cell_to_left.has_value ()) {
1454
1453
result.append ({ maybe_cell_to_left->box , Painting::PaintableBox::ConflictingElementKind::Cell, ConflictingSide::Right, cell.row_index , left_cell_column_index });
1455
1454
}
1456
1455
}
1456
+ // Left edge of the cell to the right.
1457
1457
if (cell.column_index + cell.column_span < m_context->m_cells_by_coordinate [cell.row_index ].size () && edge == ConflictingSide::Right) {
1458
1458
auto right_cell_column_index = cell.column_index + cell.column_span ;
1459
1459
auto maybe_cell_to_right = m_context->m_cells_by_coordinate [cell.row_index ][right_cell_column_index];
1460
1460
if (maybe_cell_to_right.has_value ()) {
1461
1461
result.append ({ maybe_cell_to_right->box , Painting::PaintableBox::ConflictingElementKind::Cell, ConflictingSide::Left, cell.row_index , right_cell_column_index });
1462
1462
}
1463
1463
}
1464
+ // Bottom edge of the cell above.
1464
1465
if (cell.row_index >= cell.row_span && edge == ConflictingSide::Top) {
1465
1466
auto above_cell_row_index = cell.row_index - cell.row_span ;
1466
1467
auto maybe_cell_above = m_context->m_cells_by_coordinate [above_cell_row_index][cell.column_index ];
1467
1468
if (maybe_cell_above.has_value ()) {
1468
1469
result.append ({ maybe_cell_above->box , Painting::PaintableBox::ConflictingElementKind::Cell, ConflictingSide::Bottom, above_cell_row_index, cell.column_index });
1469
1470
}
1470
1471
}
1472
+ // Top edge of the cell below.
1471
1473
if (cell.row_index + cell.row_span < m_context->m_cells_by_coordinate .size () && edge == ConflictingSide::Bottom) {
1472
1474
auto below_cell_row_index = cell.row_index + cell.row_span ;
1473
1475
auto maybe_cell_below = m_context->m_cells_by_coordinate [below_cell_row_index][cell.column_index ];
1474
1476
if (maybe_cell_below.has_value ()) {
1475
1477
result.append ({ maybe_cell_below->box , Painting::PaintableBox::ConflictingElementKind::Cell, ConflictingSide::Top, below_cell_row_index, cell.column_index });
1476
1478
}
1477
1479
}
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.
1478
1485
if (edge == ConflictingSide::Top) {
1479
1486
result.append ({ m_context->m_rows [cell.row_index ].box , Painting::PaintableBox::ConflictingElementKind::Row, ConflictingSide::Top, cell.row_index , {} });
1480
1487
}
1488
+ // Bottom edge of the row.
1481
1489
if (edge == ConflictingSide::Bottom) {
1482
1490
result.append ({ m_context->m_rows [cell.row_index ].box , Painting::PaintableBox::ConflictingElementKind::Row, ConflictingSide::Bottom, cell.row_index , {} });
1483
1491
}
1492
+ // Bottom edge of the row above.
1484
1493
if (cell.row_index >= cell.row_span && edge == ConflictingSide::Top) {
1485
1494
auto above_row_index = cell.row_index - cell.row_span ;
1486
1495
result.append ({ m_context->m_rows [above_row_index].box , Painting::PaintableBox::ConflictingElementKind::Row, ConflictingSide::Bottom, above_row_index, {} });
1487
1496
}
1497
+ // Top edge of the row below.
1488
1498
if (cell.row_index + cell.row_span < m_context->m_rows .size () && edge == ConflictingSide::Bottom) {
1489
1499
auto below_row_index = cell.row_index + cell.row_span ;
1490
1500
result.append ({ m_context->m_rows [below_row_index].box , Painting::PaintableBox::ConflictingElementKind::Row, ConflictingSide::Top, below_row_index, {} });
1491
1501
}
1502
+ }
1503
+
1504
+ void TableFormattingContext::BorderConflictFinder::collect_row_group_conflicting_edges (Vector<ConflictingEdge>& result, Cell const & cell, TableFormattingContext::ConflictingSide edge) const
1505
+ {
1492
1506
auto const & maybe_row_group = m_row_group_elements_by_index[cell.row_index ];
1507
+ // Top edge of the row group.
1493
1508
if (maybe_row_group.has_value () && cell.row_index == maybe_row_group->start_index && edge == ConflictingSide::Top) {
1494
1509
result.append ({ maybe_row_group->row_group , Painting::PaintableBox::ConflictingElementKind::RowGroup, ConflictingSide::Top, maybe_row_group->start_index , {} });
1495
1510
}
1511
+ // Bottom edge of the row group above.
1496
1512
if (cell.row_index >= cell.row_span ) {
1497
1513
auto const & maybe_row_group_above = m_row_group_elements_by_index[cell.row_index - cell.row_span ];
1498
1514
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) {
1499
1515
result.append ({ maybe_row_group_above->row_group , Painting::PaintableBox::ConflictingElementKind::RowGroup, ConflictingSide::Bottom, maybe_row_group_above->start_index , {} });
1500
1516
}
1501
1517
}
1518
+ // Bottom edge of the row group.
1502
1519
if (maybe_row_group.has_value () && cell.row_index == maybe_row_group->start_index + maybe_row_group->row_count - 1 && edge == ConflictingSide::Bottom) {
1503
1520
result.append ({ maybe_row_group->row_group , Painting::PaintableBox::ConflictingElementKind::RowGroup, ConflictingSide::Bottom, maybe_row_group->start_index , {} });
1504
1521
}
1522
+ // Top edge of the row group below.
1505
1523
if (cell.row_index + cell.row_span < m_row_group_elements_by_index.size ()) {
1506
1524
auto const & maybe_row_group_below = m_row_group_elements_by_index[cell.row_index + cell.row_span ];
1507
1525
if (maybe_row_group_below.has_value () && cell.row_index + cell.row_span == maybe_row_group_below->start_index && edge == ConflictingSide::Bottom) {
1508
1526
result.append ({ maybe_row_group_below->row_group , Painting::PaintableBox::ConflictingElementKind::RowGroup, ConflictingSide::Top, maybe_row_group_below->start_index , {} });
1509
1527
}
1510
1528
}
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.
1511
1534
if (m_col_elements_by_index[cell.column_index ] && edge == ConflictingSide::Left) {
1512
1535
result.append ({ m_col_elements_by_index[cell.column_index ], Painting::PaintableBox::ConflictingElementKind::ColumnGroup, ConflictingSide::Left, {}, cell.column_index });
1513
1536
}
1537
+ // Right edge of the column group to the left.
1514
1538
if (cell.column_index >= cell.column_span && m_col_elements_by_index[cell.column_index - cell.column_span ] && edge == ConflictingSide::Left) {
1515
1539
auto left_column_index = cell.column_index - cell.column_span ;
1516
1540
result.append ({ m_col_elements_by_index[left_column_index], Painting::PaintableBox::ConflictingElementKind::ColumnGroup, ConflictingSide::Right, {}, left_column_index });
1517
1541
}
1542
+ // Right edge of the column group.
1518
1543
if (m_col_elements_by_index[cell.column_index ] && edge == ConflictingSide::Right) {
1519
1544
result.append ({ m_col_elements_by_index[cell.column_index ], Painting::PaintableBox::ConflictingElementKind::ColumnGroup, ConflictingSide::Right, {}, cell.column_index });
1520
1545
}
1546
+ // Left edge of the column group to the right.
1521
1547
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) {
1522
1548
auto right_column_index = cell.column_index + cell.column_span ;
1523
1549
result.append ({ m_col_elements_by_index[right_column_index], Painting::PaintableBox::ConflictingElementKind::ColumnGroup, ConflictingSide::Left, {}, right_column_index });
1524
1550
}
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.
1525
1556
if (cell.row_index == 0 && edge == ConflictingSide::Top) {
1526
1557
if (m_col_elements_by_index[cell.column_index ]) {
1527
1558
result.append ({ m_col_elements_by_index[cell.column_index ], Painting::PaintableBox::ConflictingElementKind::ColumnGroup, ConflictingSide::Top, {}, cell.column_index });
1528
1559
}
1529
1560
result.append ({ &m_context->table_box (), Painting::PaintableBox::ConflictingElementKind::Table, ConflictingSide::Top, {}, {} });
1530
1561
}
1562
+ // Bottom edge from column group or table. Left and right edges of the column group are handled in collect_column_group_conflicting_edges.
1531
1563
if (cell.row_index == m_context->m_rows .size () - 1 && edge == ConflictingSide::Bottom) {
1532
1564
if (m_col_elements_by_index[cell.column_index ]) {
1533
1565
result.append ({ m_col_elements_by_index[cell.column_index ], Painting::PaintableBox::ConflictingElementKind::ColumnGroup, ConflictingSide::Bottom, {}, cell.column_index });
1534
1566
}
1535
1567
result.append ({ &m_context->table_box (), Painting::PaintableBox::ConflictingElementKind::Table, ConflictingSide::Bottom, {}, {} });
1536
1568
}
1569
+ // Left edge from row group or table. Top and bottom edges of the row group are handled in collect_row_group_conflicting_edges.
1537
1570
if (cell.column_index == 0 && edge == ConflictingSide::Left) {
1538
1571
result.append ({ m_context->m_rows [cell.row_index ].box , Painting::PaintableBox::ConflictingElementKind::Row, ConflictingSide::Left, cell.row_index , {} });
1539
1572
if (m_row_group_elements_by_index[cell.row_index ].has_value ()) {
1540
1573
result.append ({ m_row_group_elements_by_index[cell.row_index ]->row_group , Painting::PaintableBox::ConflictingElementKind::RowGroup, ConflictingSide::Left, cell.row_index , {} });
1541
1574
}
1542
1575
result.append ({ &m_context->table_box (), Painting::PaintableBox::ConflictingElementKind::Table, ConflictingSide::Left, {}, {} });
1543
1576
}
1577
+ // Right edge from row group or table. Top and bottom edges of the row group are handled in collect_row_group_conflicting_edges.
1544
1578
if (cell.column_index == m_context->m_columns .size () - 1 && edge == ConflictingSide::Right) {
1545
1579
result.append ({ m_context->m_rows [cell.row_index ].box , Painting::PaintableBox::ConflictingElementKind::Row, ConflictingSide::Right, cell.row_index , {} });
1546
1580
if (m_row_group_elements_by_index[cell.row_index ].has_value ()) {
1547
1581
result.append ({ m_row_group_elements_by_index[cell.row_index ]->row_group , Painting::PaintableBox::ConflictingElementKind::RowGroup, ConflictingSide::Right, cell.row_index , {} });
1548
1582
}
1549
1583
result.append ({ &m_context->table_box (), Painting::PaintableBox::ConflictingElementKind::Table, ConflictingSide::Right, {}, {} });
1550
1584
}
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);
1551
1596
return result;
1552
1597
}
1553
1598
0 commit comments