mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:27:35 +00:00
LibWeb: Add border conflict resolution with rowgroup
This commit is contained in:
parent
cf40b95be8
commit
3476cf0fcb
4 changed files with 157 additions and 2 deletions
|
@ -0,0 +1,70 @@
|
|||
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 784x124.40625 children: not-inline
|
||||
TableWrapper <(anonymous)> at (8,8) content-size 113.40625x124.40625 [BFC] children: not-inline
|
||||
Box <table> at (8,8) content-size 113.40625x124.40625 table-box [TFC] children: not-inline
|
||||
BlockContainer <(anonymous)> (not painted) children: inline
|
||||
TextNode <#text>
|
||||
Box <thead> at (8,8) content-size 113.40625x41.46875 table-header-group children: not-inline
|
||||
BlockContainer <(anonymous)> (not painted) children: inline
|
||||
TextNode <#text>
|
||||
Box <tr> at (8,8) content-size 113.40625x41.46875 table-row children: not-inline
|
||||
BlockContainer <td> 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 <td> 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 <tbody.thick-border> at (8,49.46875) content-size 113.40625x82.9375 table-row-group children: not-inline
|
||||
BlockContainer <(anonymous)> (not painted) children: inline
|
||||
TextNode <#text>
|
||||
Box <tr> at (8,49.46875) content-size 113.40625x41.46875 table-row children: not-inline
|
||||
BlockContainer <(anonymous)> (not painted) children: inline
|
||||
TextNode <#text>
|
||||
BlockContainer <td> 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 <td> 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 <tr> at (8,90.9375) content-size 113.40625x41.46875 table-row children: not-inline
|
||||
BlockContainer <(anonymous)> (not painted) children: inline
|
||||
TextNode <#text>
|
||||
BlockContainer <td> 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 <td> 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>
|
|
@ -0,0 +1,32 @@
|
|||
<style>
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
td,
|
||||
th {
|
||||
border: 1px solid black;
|
||||
padding: 10px 20px;
|
||||
}
|
||||
|
||||
.thick-border {
|
||||
border: 5px solid black;
|
||||
}
|
||||
</style>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<td>0</td>
|
||||
<td>1</td>
|
||||
</thead>
|
||||
<tbody class="thick-border">
|
||||
<tr>
|
||||
<td>A</td>
|
||||
<td>B</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>C</td>
|
||||
<td>D</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
|
@ -8,6 +8,7 @@
|
|||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/HTML/HTMLTableCellElement.h>
|
||||
#include <LibWeb/HTML/HTMLTableColElement.h>
|
||||
#include <LibWeb/HTML/HTMLTableRowElement.h>
|
||||
#include <LibWeb/Layout/BlockFormattingContext.h>
|
||||
#include <LibWeb/Layout/Box.h>
|
||||
#include <LibWeb/Layout/InlineFormattingContext.h>
|
||||
|
@ -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::ConflictingEdge> 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<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];
|
||||
|
@ -1089,6 +1109,25 @@ Vector<TableFormattingContext::ConflictingEdge> 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::ConflictingEdge> 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;
|
||||
|
|
|
@ -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<Node const*> m_col_elements_by_index;
|
||||
Vector<Optional<RowGroupInfo>> m_row_group_elements_by_index;
|
||||
TableFormattingContext const* m_context;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue