diff --git a/Tests/LibWeb/Layout/expected/table/border-conflict-resolution-with-cell.txt b/Tests/LibWeb/Layout/expected/table/border-conflict-resolution-with-cell.txt new file mode 100644 index 0000000000..4900b2343f --- /dev/null +++ b/Tests/LibWeb/Layout/expected/table/border-conflict-resolution-with-cell.txt @@ -0,0 +1,64 @@ +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 784x86.9375 children: not-inline + TableWrapper <(anonymous)> at (8,8) content-size 172.671875x86.9375 [BFC] children: not-inline + Box at (8,8) content-size 172.671875x86.9375 table-box [TFC] children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + Box at (8,8) content-size 172.671875x86.9375 table-row-group children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + Box at (8,8) content-size 172.671875x43.46875 table-row children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer at (8,51.46875) content-size 172.671875x43.46875 table-row children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer
at (29,21) 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: [29,21 14.265625x17.46875] + "A" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer at (89.265625,21) content-size 9.859375x17.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: [89.265625,21 9.34375x17.46875] + "B" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer at (145.125,20) content-size 14.546875x17.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: [145.125,20 10.3125x17.46875] + "C" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + Box
at (29,64.46875) content-size 16.265625x17.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: [29,64.46875 11.140625x17.46875] + "D" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer at (87.265625,65.46875) content-size 11.859375x17.46875 table-cell [BFC] children: inline + line 0 width: 11.859375, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 1, rect: [87.265625,65.46875 11.859375x17.46875] + "E" + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer at (145.125,64.46875) content-size 12.546875x17.46875 table-cell [BFC] children: inline + line 0 width: 12.546875, height: 17.46875, bottom: 17.46875, baseline: 13.53125 + frag 0 from TextNode start: 0, length: 1, rect: [145.125,64.46875 12.546875x17.46875] + "F" + 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-cell.html b/Tests/LibWeb/Layout/input/table/border-conflict-resolution-with-cell.html new file mode 100644 index 0000000000..2c3fbfd5a2 --- /dev/null +++ b/Tests/LibWeb/Layout/input/table/border-conflict-resolution-with-cell.html @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + +
ABC
DEF
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp index f0519d41e8..9d25cb0276 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -97,6 +97,7 @@ void TableFormattingContext::calculate_row_column_grid(Box const& box) size_t x_width = 0, y_height = 0; size_t x_current = 0, y_current = 0; + size_t max_cell_x = 0, max_cell_y = 0; // Implements https://html.spec.whatwg.org/multipage/tables.html#algorithm-for-processing-rows auto process_row = [&](auto& row) { @@ -131,6 +132,8 @@ void TableFormattingContext::calculate_row_column_grid(Box const& box) for (size_t x = x_current; x < x_current + colspan; x++) grid.set(GridPosition { x, y }, true); m_cells.append(Cell { *box, x_current, y_current, colspan, rowspan }); + max_cell_x = max(x_current, max_cell_x); + max_cell_y = max(y_current, max_cell_y); x_current += colspan; } @@ -159,6 +162,14 @@ void TableFormattingContext::calculate_row_column_grid(Box const& box) cell.row_span = min(cell.row_span, m_rows.size() - cell.row_index); cell.column_span = min(cell.column_span, m_columns.size() - cell.column_index); } + + m_cells_by_coordinate.resize(max_cell_y + 1); + for (auto& position_to_cell_row : m_cells_by_coordinate) { + position_to_cell_row.resize(max_cell_x + 1); + } + for (auto const& cell : m_cells) { + m_cells_by_coordinate[cell.row_index][cell.column_index] = cell; + } } void TableFormattingContext::compute_cell_measures(AvailableSpace const& available_space) @@ -1040,8 +1051,32 @@ Vector TableFormattingContext::BorderCo 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 'col' elements in a 'colgroup' and the table itself for now. + // but we only consider cells, '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]; + if (maybe_cell_to_left.has_value()) { + result.append({ maybe_cell_to_left->box, ConflictingSide::Right }); + } + } + if (cell.column_index + cell.column_span < m_context->m_cells_by_coordinate[cell.row_index].size() && edge == ConflictingSide::Right) { + auto maybe_cell_to_right = m_context->m_cells_by_coordinate[cell.row_index][cell.column_index + cell.column_span]; + if (maybe_cell_to_right.has_value()) { + result.append({ maybe_cell_to_right->box, ConflictingSide::Left }); + } + } + if (cell.row_index >= cell.row_span && edge == ConflictingSide::Top) { + auto maybe_cell_above = m_context->m_cells_by_coordinate[cell.row_index - cell.row_span][cell.column_index]; + if (maybe_cell_above.has_value()) { + result.append({ maybe_cell_above->box, ConflictingSide::Bottom }); + } + } + if (cell.row_index + cell.row_span < m_context->m_cells_by_coordinate.size() && edge == ConflictingSide::Bottom) { + auto maybe_cell_below = m_context->m_cells_by_coordinate[cell.row_index + cell.row_span][cell.column_index]; + if (maybe_cell_below.has_value()) { + result.append({ maybe_cell_below->box, 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 }); } diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h index 7802d22040..1a20a1ab7c 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h @@ -134,7 +134,7 @@ private: ConflictingSide side; }; - const CSS::BorderData& border_data_conflicting_edge(ConflictingEdge const& conflicting_edge); + static const CSS::BorderData& border_data_conflicting_edge(ConflictingEdge const& conflicting_edge); class BorderConflictFinder { public: @@ -149,6 +149,7 @@ private: }; Vector m_cells; + Vector>> m_cells_by_coordinate; Vector m_columns; Vector m_rows; };