1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 19:47:42 +00:00

LibWeb: Resolve table border conflicts with rows

This commit is contained in:
Andi Gallo 2023-07-09 04:57:03 +00:00 committed by Andreas Kling
parent e30662a8a0
commit cf40b95be8
3 changed files with 115 additions and 1 deletions

View file

@ -0,0 +1,69 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
BlockContainer <body> at (8,8) content-size 784x130.40625 children: not-inline
TableWrapper <(anonymous)> at (8,8) content-size 114.8125x130.40625 [BFC] children: not-inline
Box <table> at (8,8) content-size 114.8125x130.40625 table-box [TFC] children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
Box <tbody> at (8,8) content-size 114.8125x130.40625 table-row-group children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
Box <tr.td-thick-border> at (8,8) content-size 114.8125x43.46875 table-row children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <td> at (31,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: [31,21 14.265625x17.46875]
"A"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <td> at (87.265625,21) content-size 12.546875x17.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,21 9.34375x17.46875]
"B"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
Box <tr> at (8,51.46875) content-size 114.8125x43.46875 table-row children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <td> at (29,64.46875) content-size 16.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: [29,64.46875 10.3125x17.46875]
"C"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <td> at (87.265625,64.46875) content-size 14.546875x17.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,64.46875 11.140625x17.46875]
"D"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
Box <tr.td-thick-border> at (8,94.9375) content-size 114.8125x43.46875 table-row children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <td> at (31,107.9375) content-size 14.265625x17.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: [31,107.9375 11.859375x17.46875]
"E"
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <td> at (87.265625,107.9375) 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: [87.265625,107.9375 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>

View file

@ -0,0 +1,31 @@
<style>
table {
border-collapse: collapse;
}
td {
border: 1px solid black;
padding: 10px 20px;
}
.td-thick-border {
border: 5px solid black;
}
</style>
<table>
<tbody>
<tr class="td-thick-border">
<td>A</td>
<td>B</td>
</tr>
<tr>
<td>C</td>
<td>D</td>
</tr>
<tr class="td-thick-border">
<td>E</td>
<td>F</td>
</tr>
</tbody>
</table>

View file

@ -1051,7 +1051,7 @@ Vector<TableFormattingContext::ConflictingEdge> 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 cells, 'col' elements in a 'colgroup' and the table itself for now.
// but we only consider cells, rows, 'col' elements in a 'colgroup' and the table itself for now.
Vector<ConflictingEdge> 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];
@ -1077,6 +1077,18 @@ Vector<TableFormattingContext::ConflictingEdge> TableFormattingContext::BorderCo
result.append({ maybe_cell_below->box, ConflictingSide::Top });
}
}
if (edge == ConflictingSide::Top) {
result.append({ m_context->m_rows[cell.row_index].box, ConflictingSide::Top });
}
if (edge == ConflictingSide::Bottom) {
result.append({ m_context->m_rows[cell.row_index].box, ConflictingSide::Bottom });
}
if (cell.row_index >= cell.row_span && edge == ConflictingSide::Top) {
result.append({ m_context->m_rows[cell.row_index - cell.row_span].box, ConflictingSide::Bottom });
}
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 });
}
if (m_col_elements_by_index[cell.column_index] && edge == ConflictingSide::Left) {
result.append({ m_col_elements_by_index[cell.column_index], ConflictingSide::Left });
}
@ -1102,9 +1114,11 @@ Vector<TableFormattingContext::ConflictingEdge> TableFormattingContext::BorderCo
result.append({ &m_context->table_box(), ConflictingSide::Bottom });
}
if (cell.column_index == 0 && edge == ConflictingSide::Left) {
result.append({ m_context->m_rows[cell.row_index].box, 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 });
result.append({ &m_context->table_box(), ConflictingSide::Right });
}
return result;