From 25a94efcdf4affd6d8ad648aa35e3c9b5df7b073 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Fri, 10 Jan 2025 15:22:32 -0800 Subject: [PATCH] layout: Improve sizing of tables in collapsed-borders mode (#34932) Signed-off-by: Oriol Brufau --- components/layout_2020/style_ext.rs | 17 ++++++++++++ components/layout_2020/table/layout.rs | 27 ++++++++++++++----- .../table-backgrounds-bc-cell-001.xht.ini | 2 -- .../table-backgrounds-bc-colgroup-001.xht.ini | 2 -- .../table-backgrounds-bc-column-001.xht.ini | 2 -- .../table-backgrounds-bc-row-001.xht.ini | 2 -- .../table-backgrounds-bc-rowgroup-001.xht.ini | 2 -- .../table-backgrounds-bc-table-001.xht.ini | 2 -- .../border-collapse-double-border.html.ini | 2 ++ .../border-collapse-dynamic-oof.html.ini | 2 ++ .../row-group-margin-border-padding.html.ini | 2 -- .../row-margin-border-padding.html.ini | 2 -- .../subpixel-collapsed-borders-001.html.ini | 2 -- .../subpixel-collapsed-borders-002.html.ini | 2 -- ...background-image-column-collapsed.html.ini | 2 -- .../background-image-row-collapsed.html.ini | 2 -- .../tentative/td-box-sizing-002.html.ini | 6 ----- .../cssom-view/table-offset-props.html.ini | 3 --- .../cssom-view/table-scroll-props.html.ini | 3 --- .../meta/gfx-rs-gecko/356774-1.html.ini | 2 ++ 20 files changed, 44 insertions(+), 42 deletions(-) delete mode 100644 tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-cell-001.xht.ini delete mode 100644 tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-colgroup-001.xht.ini delete mode 100644 tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-column-001.xht.ini delete mode 100644 tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-row-001.xht.ini delete mode 100644 tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-rowgroup-001.xht.ini delete mode 100644 tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-table-001.xht.ini create mode 100644 tests/wpt/meta/css/css-tables/border-collapse-double-border.html.ini create mode 100644 tests/wpt/meta/css/css-tables/border-collapse-dynamic-oof.html.ini delete mode 100644 tests/wpt/meta/css/css-tables/row-group-margin-border-padding.html.ini delete mode 100644 tests/wpt/meta/css/css-tables/row-margin-border-padding.html.ini delete mode 100644 tests/wpt/meta/css/css-tables/subpixel-collapsed-borders-001.html.ini delete mode 100644 tests/wpt/meta/css/css-tables/subpixel-collapsed-borders-002.html.ini delete mode 100644 tests/wpt/meta/css/css-tables/tentative/paint/background-image-column-collapsed.html.ini delete mode 100644 tests/wpt/meta/css/css-tables/tentative/paint/background-image-row-collapsed.html.ini delete mode 100644 tests/wpt/meta/css/css-tables/tentative/td-box-sizing-002.html.ini delete mode 100644 tests/wpt/meta/css/cssom-view/table-offset-props.html.ini delete mode 100644 tests/wpt/meta/css/cssom-view/table-scroll-props.html.ini create mode 100644 tests/wpt/mozilla/meta/gfx-rs-gecko/356774-1.html.ini diff --git a/components/layout_2020/style_ext.rs b/components/layout_2020/style_ext.rs index 7df170f227c..feb30e6c714 100644 --- a/components/layout_2020/style_ext.rs +++ b/components/layout_2020/style_ext.rs @@ -616,6 +616,23 @@ impl ComputedValuesExt for ComputedValues { fn border_width(&self, containing_block_writing_mode: WritingMode) -> LogicalSides { let border = self.get_border(); + if self.get_box().display.inside() == stylo::DisplayInside::Table && + !matches!(self.pseudo(), Some(PseudoElement::ServoTableGrid)) && + self.get_inherited_table().border_collapse == BorderCollapse::Collapse + { + // For tables in collapsed-borders mode we halve the border widths, because + // > in this model, the width of the table includes half the table border. + // https://www.w3.org/TR/CSS22/tables.html#collapsing-borders + return LogicalSides::from_physical( + &PhysicalSides::new( + border.border_top_width / 2, + border.border_right_width / 2, + border.border_bottom_width / 2, + border.border_left_width / 2, + ), + containing_block_writing_mode, + ); + } LogicalSides::from_physical( &PhysicalSides::new( border.border_top_width, diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs index 63afbdb9b61..226f6020656 100644 --- a/components/layout_2020/table/layout.rs +++ b/components/layout_2020/table/layout.rs @@ -1626,8 +1626,6 @@ impl<'a> TableLayout<'a> { containing_block_for_table: &ContainingBlock, ) -> IndependentLayout { let table_writing_mode = containing_block_for_children.style.writing_mode; - let grid_min_max = self.compute_grid_min_max(layout_context, table_writing_mode); - let caption_minimum_inline_size = self.compute_caption_minimum_inline_size(layout_context); self.pbm = self .table .style @@ -1635,6 +1633,8 @@ impl<'a> TableLayout<'a> { table_writing_mode, containing_block_for_table.size.inline, ); + let grid_min_max = self.compute_grid_min_max(layout_context, table_writing_mode); + let caption_minimum_inline_size = self.compute_caption_minimum_inline_size(layout_context); self.compute_table_width( containing_block_for_children, grid_min_max, @@ -2197,6 +2197,7 @@ impl<'a> TableLayout<'a> { }; let all_rows = 0..self.table.size.height; let all_columns = 0..self.table.size.width; + apply_border(&self.table.grid_style, &all_rows, &all_columns); for column_group in &self.table.column_groups { apply_border(&column_group.style, &all_rows, &column_group.track_range); } @@ -2242,16 +2243,24 @@ impl<'a> TableLayout<'a> { block_end: collapsed_borders.block[end_y].width, }; - if coordinates.x != 0 { + if coordinates.x == 0 { + result.inline_start -= self.pbm.border.inline_start; + } else { result.inline_start /= 2; } - if coordinates.y != 0 { + if coordinates.y == 0 { + result.block_start -= self.pbm.border.block_start; + } else { result.block_start /= 2; } - if end_x != self.table.size.width { + if end_x == self.table.size.width { + result.inline_end -= self.pbm.border.inline_end; + } else { result.inline_end /= 2; } - if end_y != self.table.size.height { + if end_y == self.table.size.height { + result.block_end -= self.pbm.border.block_end; + } else { result.block_end /= 2; } @@ -2680,6 +2689,12 @@ impl ComputeInlineContentSizes for Table { ) -> InlineContentSizesResult { let writing_mode = constraint_space.writing_mode; let mut layout = TableLayout::new(self); + layout.pbm = self + .style + .padding_border_margin_with_writing_mode_and_containing_block_inline_size( + writing_mode, + Au::zero(), + ); let mut table_content_sizes = layout.compute_grid_min_max(layout_context, writing_mode); let mut caption_minimum_inline_size = diff --git a/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-cell-001.xht.ini b/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-cell-001.xht.ini deleted file mode 100644 index f736c1c3588..00000000000 --- a/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-cell-001.xht.ini +++ /dev/null @@ -1,2 +0,0 @@ -[table-backgrounds-bc-cell-001.xht] - expected: FAIL diff --git a/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-colgroup-001.xht.ini b/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-colgroup-001.xht.ini deleted file mode 100644 index 223ea972b27..00000000000 --- a/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-colgroup-001.xht.ini +++ /dev/null @@ -1,2 +0,0 @@ -[table-backgrounds-bc-colgroup-001.xht] - expected: FAIL diff --git a/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-column-001.xht.ini b/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-column-001.xht.ini deleted file mode 100644 index 33bc44435e6..00000000000 --- a/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-column-001.xht.ini +++ /dev/null @@ -1,2 +0,0 @@ -[table-backgrounds-bc-column-001.xht] - expected: FAIL diff --git a/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-row-001.xht.ini b/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-row-001.xht.ini deleted file mode 100644 index 2023cc4c99e..00000000000 --- a/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-row-001.xht.ini +++ /dev/null @@ -1,2 +0,0 @@ -[table-backgrounds-bc-row-001.xht] - expected: FAIL diff --git a/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-rowgroup-001.xht.ini b/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-rowgroup-001.xht.ini deleted file mode 100644 index 8a4e4b202e1..00000000000 --- a/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-rowgroup-001.xht.ini +++ /dev/null @@ -1,2 +0,0 @@ -[table-backgrounds-bc-rowgroup-001.xht] - expected: FAIL diff --git a/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-table-001.xht.ini b/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-table-001.xht.ini deleted file mode 100644 index d89f8c626b1..00000000000 --- a/tests/wpt/meta/css/CSS2/tables/table-backgrounds-bc-table-001.xht.ini +++ /dev/null @@ -1,2 +0,0 @@ -[table-backgrounds-bc-table-001.xht] - expected: FAIL diff --git a/tests/wpt/meta/css/css-tables/border-collapse-double-border.html.ini b/tests/wpt/meta/css/css-tables/border-collapse-double-border.html.ini new file mode 100644 index 00000000000..4baa99cad80 --- /dev/null +++ b/tests/wpt/meta/css/css-tables/border-collapse-double-border.html.ini @@ -0,0 +1,2 @@ +[border-collapse-double-border.html] + expected: FAIL diff --git a/tests/wpt/meta/css/css-tables/border-collapse-dynamic-oof.html.ini b/tests/wpt/meta/css/css-tables/border-collapse-dynamic-oof.html.ini new file mode 100644 index 00000000000..b83f8101056 --- /dev/null +++ b/tests/wpt/meta/css/css-tables/border-collapse-dynamic-oof.html.ini @@ -0,0 +1,2 @@ +[border-collapse-dynamic-oof.html] + expected: FAIL diff --git a/tests/wpt/meta/css/css-tables/row-group-margin-border-padding.html.ini b/tests/wpt/meta/css/css-tables/row-group-margin-border-padding.html.ini deleted file mode 100644 index e5b3dd0420d..00000000000 --- a/tests/wpt/meta/css/css-tables/row-group-margin-border-padding.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[row-group-margin-border-padding.html] - expected: FAIL diff --git a/tests/wpt/meta/css/css-tables/row-margin-border-padding.html.ini b/tests/wpt/meta/css/css-tables/row-margin-border-padding.html.ini deleted file mode 100644 index 360b9c1d5bf..00000000000 --- a/tests/wpt/meta/css/css-tables/row-margin-border-padding.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[row-margin-border-padding.html] - expected: FAIL diff --git a/tests/wpt/meta/css/css-tables/subpixel-collapsed-borders-001.html.ini b/tests/wpt/meta/css/css-tables/subpixel-collapsed-borders-001.html.ini deleted file mode 100644 index 70bf4b0238b..00000000000 --- a/tests/wpt/meta/css/css-tables/subpixel-collapsed-borders-001.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[subpixel-collapsed-borders-001.html] - expected: FAIL diff --git a/tests/wpt/meta/css/css-tables/subpixel-collapsed-borders-002.html.ini b/tests/wpt/meta/css/css-tables/subpixel-collapsed-borders-002.html.ini deleted file mode 100644 index 21adf2a8c87..00000000000 --- a/tests/wpt/meta/css/css-tables/subpixel-collapsed-borders-002.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[subpixel-collapsed-borders-002.html] - expected: FAIL diff --git a/tests/wpt/meta/css/css-tables/tentative/paint/background-image-column-collapsed.html.ini b/tests/wpt/meta/css/css-tables/tentative/paint/background-image-column-collapsed.html.ini deleted file mode 100644 index ca754041021..00000000000 --- a/tests/wpt/meta/css/css-tables/tentative/paint/background-image-column-collapsed.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[background-image-column-collapsed.html] - expected: FAIL diff --git a/tests/wpt/meta/css/css-tables/tentative/paint/background-image-row-collapsed.html.ini b/tests/wpt/meta/css/css-tables/tentative/paint/background-image-row-collapsed.html.ini deleted file mode 100644 index ba0303e4ff1..00000000000 --- a/tests/wpt/meta/css/css-tables/tentative/paint/background-image-row-collapsed.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[background-image-row-collapsed.html] - expected: FAIL diff --git a/tests/wpt/meta/css/css-tables/tentative/td-box-sizing-002.html.ini b/tests/wpt/meta/css/css-tables/tentative/td-box-sizing-002.html.ini deleted file mode 100644 index bfd934805f6..00000000000 --- a/tests/wpt/meta/css/css-tables/tentative/td-box-sizing-002.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[td-box-sizing-002.html] - [.t 6] - expected: FAIL - - [.t 13] - expected: FAIL diff --git a/tests/wpt/meta/css/cssom-view/table-offset-props.html.ini b/tests/wpt/meta/css/cssom-view/table-offset-props.html.ini deleted file mode 100644 index 1e18b63a4ac..00000000000 --- a/tests/wpt/meta/css/cssom-view/table-offset-props.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[table-offset-props.html] - [Table with collapsed border] - expected: FAIL diff --git a/tests/wpt/meta/css/cssom-view/table-scroll-props.html.ini b/tests/wpt/meta/css/cssom-view/table-scroll-props.html.ini deleted file mode 100644 index e5bdcf01844..00000000000 --- a/tests/wpt/meta/css/cssom-view/table-scroll-props.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[table-scroll-props.html] - [Table with collapsed border] - expected: FAIL diff --git a/tests/wpt/mozilla/meta/gfx-rs-gecko/356774-1.html.ini b/tests/wpt/mozilla/meta/gfx-rs-gecko/356774-1.html.ini new file mode 100644 index 00000000000..b958c0e4b07 --- /dev/null +++ b/tests/wpt/mozilla/meta/gfx-rs-gecko/356774-1.html.ini @@ -0,0 +1,2 @@ +[356774-1.html] + expected: FAIL