From 63e72feee1a59fd63e2ed098c54068b6304bd79e Mon Sep 17 00:00:00 2001 From: Andi Gallo Date: Sun, 16 Jul 2023 22:00:30 +0000 Subject: [PATCH] LibWeb: Add additional term to the table cell min contribution Align with specification. --- .../row-outer-size-with-computed-size.txt | 20 ++++++++-------- .../LibWeb/Layout/TableFormattingContext.cpp | 23 +++++++++++++++++-- 2 files changed, 31 insertions(+), 12 deletions(-) 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 index 144fca97f5..20e31618ed 100644 --- 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 @@ -1,20 +1,20 @@ 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 at (8,8) content-size 784x25.46875 children: not-inline + TableWrapper <(anonymous)> at (8,8) content-size 49.21875x25.46875 [BFC] children: not-inline + Box
at (8,8) content-size 49.21875x25.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 + Box at (8,8) content-size 43.21875x19.46875 table-row-group children: not-inline + Box at (10,10) content-size 43.21875x9.734375 table-row children: not-inline BlockContainer <(anonymous)> (not painted) children: inline TextNode <#text> - BlockContainer at (10,19.734375) content-size 43.21875x7.734375 table-row children: not-inline + Box at (10,21.734375) content-size 43.21875x9.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 at (11,14.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 + BlockContainer at (16,12) 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] + frag 0 from TextNode start: 0, length: 4, rect: [16,12 37.21875x17.46875] "Test" TextNode <#text> InlineNode @@ -24,10 +24,10 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-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 at (11,26.601562) content-size 0x0 table-cell [BFC] children: not-inline BlockContainer <(anonymous)> (not painted) children: inline TextNode <#text> BlockContainer <(anonymous)> (not painted) children: inline diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp index 59b1fddc17..3542634bdc 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -387,12 +387,16 @@ void TableFormattingContext::compute_table_measures() auto cell_span_value = cell_span(cell); if (cell_span_value == current_span) { // Define the baseline max-content size as the sum of the max-content sizes based on cells of span up to N-1 of all columns that the cell spans. - CSSPixels baseline_max_content_size = 0; auto cell_start_rc_index = cell_index(cell); auto cell_end_rc_index = cell_start_rc_index + cell_span_value; + CSSPixels baseline_max_content_size = 0; for (auto rc_index = cell_start_rc_index; rc_index < cell_end_rc_index; rc_index++) { baseline_max_content_size += rows_or_columns[rc_index].max_size; } + CSSPixels baseline_min_content_size = 0; + for (auto rc_index = cell_start_rc_index; rc_index < cell_end_rc_index; rc_index++) { + baseline_min_content_size += rows_or_columns[rc_index].min_size; + } // Define the baseline border spacing as the sum of the horizontal border-spacing for any columns spanned by the cell, other than the one in which the cell originates. auto baseline_border_spacing = border_spacing() * (cell_span_value - 1); @@ -403,7 +407,22 @@ void TableFormattingContext::compute_table_measures() // The contribution of the cell is the sum of: // the min-content size of the column based on cells of span up to N-1 auto cell_min_contribution = rows_or_columns[rc_index].min_size; - // and the product of: + // the product of: + // - the ratio of: + // - the max-content size of the row / column based on cells of span up to N-1 of the row / column minus the + // min-content size of the row / column based on cells of span up to N-1 of the row / column, to + // - the baseline max-content size minus the baseline min-content size + // or zero if this ratio is undefined, and + // - the outer min-content size of the cell minus the baseline min-content size and the baseline border spacing, clamped + // to be at least 0 and at most the difference between the baseline max-content size and the baseline min-content size + auto normalized_max_min_diff = baseline_max_content_size != baseline_min_content_size + ? (rows_or_columns[rc_index].max_size - rows_or_columns[rc_index].min_size) / (baseline_max_content_size - baseline_min_content_size) + : 0; + auto clamped_diff_to_baseline_min = min( + max(cell_min_size(cell) - baseline_min_content_size - baseline_border_spacing, 0), + baseline_max_content_size - baseline_min_content_size); + cell_min_contribution += normalized_max_min_diff * clamped_diff_to_baseline_min; + // the product of: // - the ratio of the max-content size based on cells of span up to N-1 of the column to the baseline max-content size // - the outer min-content size of the cell minus the baseline max-content size and baseline border spacing, or 0 if this is negative cell_min_contribution += (rows_or_columns[rc_index].max_size / baseline_max_content_size)