From 8afe5ce7181b9afc5aebb9ca3382a111c15f04ba Mon Sep 17 00:00:00 2001 From: Andi Gallo Date: Mon, 26 Jun 2023 02:48:09 +0000 Subject: [PATCH] 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. --- .../row-outer-size-with-computed-size.txt | 34 +++++++++++++++ .../row-outer-size-with-computed-size.html | 11 +++++ .../LibWeb/Layout/TableFormattingContext.cpp | 42 +++++++++++++++---- .../LibWeb/Layout/TableFormattingContext.h | 2 + 4 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/table/row-outer-size-with-computed-size.txt create mode 100644 Tests/LibWeb/Layout/input/table/row-outer-size-with-computed-size.html diff --git a/Tests/LibWeb/Layout/expected/table/row-outer-size-with-computed-size.txt b/Tests/LibWeb/Layout/expected/table/row-outer-size-with-computed-size.txt new file mode 100644 index 0000000000..b2ecf03c30 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/table/row-outer-size-with-computed-size.txt @@ -0,0 +1,34 @@ +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 784x21.46875 children: not-inline + TableWrapper <(anonymous)> at (8,8) content-size 49.21875x21.46875 [BFC] children: not-inline + Box at (8,8) content-size 49.21875x21.46875 table-box [TFC] children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + Box at (8,8) content-size 43.21875x15.46875 table-row-group children: not-inline + Box at (10,10) content-size 43.21875x7.734375 table-row children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer at (10,17.734375) content-size 43.21875x7.734375 table-row children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer
at (11,13.867187) content-size 0x0 table-cell [BFC] children: not-inline + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer 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 + TextNode <#text> + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + BlockContainer <(anonymous)> (not painted) children: inline + TextNode <#text> + Box
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> diff --git a/Tests/LibWeb/Layout/input/table/row-outer-size-with-computed-size.html b/Tests/LibWeb/Layout/input/table/row-outer-size-with-computed-size.html new file mode 100644 index 0000000000..d819e4c366 --- /dev/null +++ b/Tests/LibWeb/Layout/input/table/row-outer-size-with-computed-size.html @@ -0,0 +1,11 @@ + + + + + + + + +
+ Test +
\ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp index faeac19786..992fb1c9bc 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -223,17 +223,45 @@ void TableFormattingContext::compute_cell_measures(AvailableSpace const& availab } } +template<> +void TableFormattingContext::initialize_table_measures() +{ + 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() +{ + 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 void TableFormattingContext::compute_table_measures() { + initialize_table_measures(); + auto& rows_or_columns = table_rows_or_columns(); - for (auto& cell : m_cells) { - if (cell_span(cell) == 1) { - auto rc_index = cell_index(cell); - rows_or_columns[rc_index].min_size = max(rows_or_columns[rc_index].min_size, cell_min_size(cell)); - rows_or_columns[rc_index].max_size = max(rows_or_columns[rc_index].max_size, cell_max_size(cell)); - } - } size_t max_cell_span = 1; for (auto& cell : m_cells) { diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h index 6d998e874c..58ffbff19f 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h @@ -38,6 +38,8 @@ private: void calculate_row_column_grid(Box const&); void compute_cell_measures(AvailableSpace const& available_space); template + void initialize_table_measures(); + template void compute_table_measures(); void compute_table_width(); void distribute_width_to_columns();