LibWeb: Fix min-content initialization for row measures

This ensures that min-content contributions from cells with no content
are computed using their calculated values, which are never considered
for min-content before then. The specification diverges from column
measures algorithm, which doesn't use specified width of cells anywhere.
This commit is contained in:
Andi Gallo 2023-06-26 02:48:09 +00:00 committed by Andreas Kling
parent 5aef8f280f
commit 8afe5ce718
Notes: sideshowbarker 2024-07-17 06:51:40 +09:00
4 changed files with 82 additions and 7 deletions

View file

@ -0,0 +1,34 @@
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 784x21.46875 children: not-inline
TableWrapper <(anonymous)> at (8,8) content-size 49.21875x21.46875 [BFC] children: not-inline
Box <table> at (8,8) content-size 49.21875x21.46875 table-box [TFC] children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
Box <tbody> at (8,8) content-size 43.21875x15.46875 table-row-group children: not-inline
Box <tr> at (10,10) content-size 43.21875x7.734375 table-row children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <td> at (11,13.867187) content-size 0x0 table-cell [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <td> at (16,10) content-size 37.21875x17.46875 table-cell [BFC] children: inline
line 0 width: 37.21875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
frag 0 from TextNode start: 0, length: 4, rect: [16,10 37.21875x17.46875]
"Test"
TextNode <#text>
InlineNode <a>
TextNode <#text>
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
Box <tr> at (10,17.734375) content-size 43.21875x7.734375 table-row children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <td> at (11,23.601562) content-size 0x0 table-cell [BFC] children: not-inline
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>
BlockContainer <(anonymous)> (not painted) children: inline
TextNode <#text>

View file

@ -0,0 +1,11 @@
<table style="border-collapse:separate;">
<tr>
<td style="height:6px"></td>
<td rowspan="2" style="border:1px solid black">
<a href="">Test</a>
</td>
</tr>
<tr>
<td style="height:6px"></td>
</tr>
</table>

View file

@ -223,17 +223,45 @@ void TableFormattingContext::compute_cell_measures(AvailableSpace const& availab
}
}
template<>
void TableFormattingContext::initialize_table_measures<TableFormattingContext::Row>()
{
auto const& containing_block = m_state.get(*table_wrapper().containing_block());
for (auto& cell : m_cells) {
auto const& computed_values = cell.box->computed_values();
if (cell.row_span == 1) {
// FIXME: Implement intrinsic percentage width of a column based on cells of span up to 1.
auto specified_height = m_rows[cell.row_index].type == SizeType::Pixel
? computed_values.height().to_px(cell.box, containing_block.content_height())
: 0;
// https://www.w3.org/TR/css-tables-3/#row-layout makes specified cell height part of the initialization formula for row table measures:
// This is done by running the same algorithm as the column measurement, with the span=1 value being initialized (for min-content) with
// the largest of the resulting height of the previous row layout, the height specified on the corresponding table-row (if any), and
// the largest height specified on cells that span this row only (the algorithm starts by considering cells of span 2 on top of that assignment).
m_rows[cell.row_index].min_size = max(m_rows[cell.row_index].min_size, max(cell.min_height, specified_height));
m_rows[cell.row_index].max_size = max(m_rows[cell.row_index].max_size, cell.max_height);
}
}
}
template<>
void TableFormattingContext::initialize_table_measures<TableFormattingContext::Column>()
{
for (auto& cell : m_cells) {
if (cell.column_span == 1) {
m_columns[cell.column_index].min_size = max(m_columns[cell.column_index].min_size, cell.min_width);
m_columns[cell.column_index].max_size = max(m_columns[cell.column_index].max_size, cell.max_width);
}
}
}
template<class RowOrColumn>
void TableFormattingContext::compute_table_measures()
{
initialize_table_measures<RowOrColumn>();
auto& rows_or_columns = table_rows_or_columns<RowOrColumn>();
for (auto& cell : m_cells) {
if (cell_span<RowOrColumn>(cell) == 1) {
auto rc_index = cell_index<RowOrColumn>(cell);
rows_or_columns[rc_index].min_size = max(rows_or_columns[rc_index].min_size, cell_min_size<RowOrColumn>(cell));
rows_or_columns[rc_index].max_size = max(rows_or_columns[rc_index].max_size, cell_max_size<RowOrColumn>(cell));
}
}
size_t max_cell_span = 1;
for (auto& cell : m_cells) {

View file

@ -38,6 +38,8 @@ private:
void calculate_row_column_grid(Box const&);
void compute_cell_measures(AvailableSpace const& available_space);
template<class RowOrColumn>
void initialize_table_measures();
template<class RowOrColumn>
void compute_table_measures();
void compute_table_width();
void distribute_width_to_columns();