From 0cefee48e125c3f392e44bd1ae161d41d7246808 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Thu, 26 Sep 2024 07:06:33 -0700 Subject: [PATCH] Fix table track constrainedness (#33550) * Fix table track constraindness Only as size that isn't `auto` and doesn't contain percentages can constrain a table track (https://drafts.csswg.org/css-tables/#constrainedness). However, in a bunch of cases we were only checking for `auto`. Also, we were allowing the inline-size of a cell to constrain both its column and row. Using the block-size of the row makes more sense. The spec doesn't define constrainedness for rows, though. Signed-off-by: Oriol Brufau * Apply suggestions from code review Co-authored-by: Martin Robinson Signed-off-by: Oriol Brufau --------- Signed-off-by: Oriol Brufau Co-authored-by: Martin Robinson --- components/layout_2020/geom.rs | 9 ++++++ components/layout_2020/table/layout.rs | 30 +++++++++---------- .../auto-layout-calc-width-001.html.ini | 3 -- .../fixed-layout-calc-width-001.html.ini | 3 -- .../rowspan-height-redistribution.html.ini | 2 +- .../table-height-redistribution.html.ini | 15 ---------- .../visibility-collapse-row-004.html.ini | 3 -- .../tables/table-attribute.html.ini | 9 ++---- 8 files changed, 27 insertions(+), 47 deletions(-) delete mode 100644 tests/wpt/meta/css/css-tables/auto-layout-calc-width-001.html.ini delete mode 100644 tests/wpt/meta/css/css-tables/fixed-layout-calc-width-001.html.ini delete mode 100644 tests/wpt/meta/css/css-tables/visibility-collapse-row-004.html.ini diff --git a/components/layout_2020/geom.rs b/components/layout_2020/geom.rs index d117bf15edb..906a9808154 100644 --- a/components/layout_2020/geom.rs +++ b/components/layout_2020/geom.rs @@ -55,6 +55,15 @@ impl fmt::Debug for LogicalVec2 { } } +impl Default for LogicalVec2 { + fn default() -> Self { + Self { + inline: T::default(), + block: T::default(), + } + } +} + impl LogicalVec2 { pub fn from_physical_size(physical_size: &PhysicalSize, mode: WritingMode) -> Self { // https://drafts.csswg.org/css-writing-modes/#logical-to-physical diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs index 2a45e01bd28..14b6d5f54b6 100644 --- a/components/layout_2020/table/layout.rs +++ b/components/layout_2020/table/layout.rs @@ -369,52 +369,50 @@ impl<'a> TableLayout<'a> { self.rows = vec![RowLayout::default(); self.table.size.height]; self.columns = vec![ColumnLayout::default(); self.table.size.width]; + let is_length = |size: &LengthPercentageOrAuto| { + size.non_auto().is_some_and(|size| !size.has_percentage()) + }; + for column_index in 0..self.table.size.width { if let Some(column) = self.table.columns.get(column_index) { - if !column.style.box_size(writing_mode).inline.is_auto() { + if is_length(&column.style.box_size(writing_mode).inline) { self.columns[column_index].constrained = true; continue; } if let Some(column_group_index) = column.group_index { let column_group = &self.table.column_groups[column_group_index]; - if !column_group.style.box_size(writing_mode).inline.is_auto() { + if is_length(&column_group.style.box_size(writing_mode).inline) { self.columns[column_index].constrained = true; continue; } } - self.columns[column_index].constrained = false; } } for row_index in 0..self.table.size.height { if let Some(row) = self.table.rows.get(row_index) { - if !row.style.box_size(writing_mode).block.is_auto() { + if is_length(&row.style.box_size(writing_mode).block) { self.rows[row_index].constrained = true; continue; } if let Some(row_group_index) = row.group_index { let row_group = &self.table.row_groups[row_group_index]; - if !row_group.style.box_size(writing_mode).block.is_auto() { + if is_length(&row_group.style.box_size(writing_mode).block) { self.rows[row_index].constrained = true; continue; } } } - self.rows[row_index].constrained = false; } for column_index in 0..self.table.size.width { for row_index in 0..self.table.size.height { let coords = TableSlotCoordinates::new(column_index, row_index); let cell_constrained = match self.table.resolve_first_cell(coords) { - Some(cell) if cell.colspan == 1 => cell - .style - .box_size(writing_mode) - .inline - .non_auto() - .and_then(|length_percentage| length_percentage.to_length()) - .is_some(), - _ => false, + Some(cell) if cell.colspan == 1 => { + cell.style.box_size(writing_mode).map(is_length) + }, + _ => LogicalVec2::default(), }; let rowspan_greater_than_1 = match self.table.slots[row_index][column_index] { @@ -423,12 +421,12 @@ impl<'a> TableLayout<'a> { }; self.rows[row_index].has_cell_with_span_greater_than_one |= rowspan_greater_than_1; - self.rows[row_index].constrained |= cell_constrained; + self.rows[row_index].constrained |= cell_constrained.block; let has_originating_cell = matches!(self.table.get_slot(coords), Some(TableSlot::Cell(_))); self.columns[column_index].has_originating_cells |= has_originating_cell; - self.columns[column_index].constrained |= cell_constrained; + self.columns[column_index].constrained |= cell_constrained.inline; } } } diff --git a/tests/wpt/meta/css/css-tables/auto-layout-calc-width-001.html.ini b/tests/wpt/meta/css/css-tables/auto-layout-calc-width-001.html.ini deleted file mode 100644 index fed12f24824..00000000000 --- a/tests/wpt/meta/css/css-tables/auto-layout-calc-width-001.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[auto-layout-calc-width-001.html] - [#theTable 1] - expected: FAIL diff --git a/tests/wpt/meta/css/css-tables/fixed-layout-calc-width-001.html.ini b/tests/wpt/meta/css/css-tables/fixed-layout-calc-width-001.html.ini deleted file mode 100644 index 6e16210b7cf..00000000000 --- a/tests/wpt/meta/css/css-tables/fixed-layout-calc-width-001.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[fixed-layout-calc-width-001.html] - [#theTable 1] - expected: FAIL diff --git a/tests/wpt/meta/css/css-tables/tentative/rowspan-height-redistribution.html.ini b/tests/wpt/meta/css/css-tables/tentative/rowspan-height-redistribution.html.ini index 44ecb21129b..ee78d79ebb7 100644 --- a/tests/wpt/meta/css/css-tables/tentative/rowspan-height-redistribution.html.ini +++ b/tests/wpt/meta/css/css-tables/tentative/rowspan-height-redistribution.html.ini @@ -1,5 +1,5 @@ [rowspan-height-redistribution.html] - [table 8] + [table 17] expected: FAIL [table 22] diff --git a/tests/wpt/meta/css/css-tables/tentative/table-height-redistribution.html.ini b/tests/wpt/meta/css/css-tables/tentative/table-height-redistribution.html.ini index 54c6daef5c1..4ee70f87306 100644 --- a/tests/wpt/meta/css/css-tables/tentative/table-height-redistribution.html.ini +++ b/tests/wpt/meta/css/css-tables/tentative/table-height-redistribution.html.ini @@ -8,21 +8,6 @@ [table 17] expected: FAIL - [table 18] - expected: FAIL - - [table 19] - expected: FAIL - - [table 20] - expected: FAIL - - [table 21] - expected: FAIL - - [table 22] - expected: FAIL - [table 25] expected: FAIL diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-row-004.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-row-004.html.ini deleted file mode 100644 index 667374037ab..00000000000 --- a/tests/wpt/meta/css/css-tables/visibility-collapse-row-004.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[visibility-collapse-row-004.html] - [collapsed row shrinks table height] - expected: FAIL diff --git a/tests/wpt/meta/html/rendering/non-replaced-elements/tables/table-attribute.html.ini b/tests/wpt/meta/html/rendering/non-replaced-elements/tables/table-attribute.html.ini index 85eb50a84b9..3f4988af40e 100644 --- a/tests/wpt/meta/html/rendering/non-replaced-elements/tables/table-attribute.html.ini +++ b/tests/wpt/meta/html/rendering/non-replaced-elements/tables/table-attribute.html.ini @@ -122,12 +122,6 @@ [table th align attribute justify is correct] expected: FAIL - [td height attribute pixel is correct] - expected: FAIL - - [th height attribute pixel is correct] - expected: FAIL - [table_td height attribute percentage is correct] expected: FAIL @@ -139,3 +133,6 @@ [table cellpadding attribute is correct] expected: FAIL + + [table_tr height attribute percentage is correct] + expected: FAIL