From 7977357a576c75c077ca8be5164980ab632087c9 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Mon, 27 Jan 2025 12:40:26 -0800 Subject: [PATCH] layout: Zero out collapsed track sizes when painting collapsed borders (#35165) We were painting collapsed borders without taking into account that some tracks might have been "removed" by `visibility: collapse`. This just sets the sizes of these tracks to zero. Note this implies that collapsed borders may overlap each other, or overlap cell contents, but this seems to match Blink. Signed-off-by: Oriol Brufau --- components/layout_2020/table/layout.rs | 14 +++++++- tests/wpt/meta/MANIFEST.json | 26 +++++++++++++++ ...pse-visibility-collapse-001.tentative.html | 21 ++++++++++++ ...pse-visibility-collapse-002.tentative.html | 32 +++++++++++++++++++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tests/wpt/tests/css/CSS2/tables/border-collapse-visibility-collapse-001.tentative.html create mode 100644 tests/wpt/tests/css/CSS2/tables/border-collapse-visibility-collapse-002.tentative.html diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs index 062e5c118bb..ed54370abd8 100644 --- a/components/layout_2020/table/layout.rs +++ b/components/layout_2020/table/layout.rs @@ -1931,11 +1931,23 @@ impl<'a> TableLayout<'a> { fn specific_layout_info_for_grid(&mut self) -> Option { mem::take(&mut self.collapsed_borders).map(|mut collapsed_borders| { - let writing_mode = self.table.style.writing_mode; + // TODO: It would probably be better to use `TableAndTrackDimensions`, since that + // has already taken care of collapsed tracks and knows the final track positions. let mut track_sizes = LogicalVec2 { inline: mem::take(&mut self.distributed_column_widths), block: mem::take(&mut self.row_sizes), }; + for (column_index, column_size) in track_sizes.inline.iter_mut().enumerate() { + if self.is_column_collapsed(column_index) { + mem::take(column_size); + } + } + for (row_index, row_size) in track_sizes.block.iter_mut().enumerate() { + if self.is_row_collapsed(row_index) { + mem::take(row_size); + } + } + let writing_mode = self.table.style.writing_mode; if !writing_mode.is_bidi_ltr() { track_sizes.inline.reverse(); collapsed_borders.inline.reverse(); diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json index 9e23b6caa8a..e5bfc980545 100644 --- a/tests/wpt/meta/MANIFEST.json +++ b/tests/wpt/meta/MANIFEST.json @@ -105658,6 +105658,32 @@ {} ] ], + "border-collapse-visibility-collapse-001.tentative.html": [ + "d2d6e9242b98eb82e41a90b865b3e0f4204d4464", + [ + null, + [ + [ + "/css/CSS2/reference/ref-filled-green-100px-square.xht", + "==" + ] + ], + {} + ] + ], + "border-collapse-visibility-collapse-002.tentative.html": [ + "582934960946f65b2aa4f076e1ad4c3320e2352f", + [ + null, + [ + [ + "/css/CSS2/reference/ref-filled-green-100px-square.xht", + "==" + ] + ], + {} + ] + ], "border-conflict-element-001a.xht": [ "585957f13b22ec2d0208f07deb127698d15ddea5", [ diff --git a/tests/wpt/tests/css/CSS2/tables/border-collapse-visibility-collapse-001.tentative.html b/tests/wpt/tests/css/CSS2/tables/border-collapse-visibility-collapse-001.tentative.html new file mode 100644 index 00000000000..d2d6e9242b9 --- /dev/null +++ b/tests/wpt/tests/css/CSS2/tables/border-collapse-visibility-collapse-001.tentative.html @@ -0,0 +1,21 @@ + +CSS Test: Table with collapsed borders and collapsed tracks + + + + + +

Test passes if there is a filled green square and no red.

+ + + + + + + + + + +
diff --git a/tests/wpt/tests/css/CSS2/tables/border-collapse-visibility-collapse-002.tentative.html b/tests/wpt/tests/css/CSS2/tables/border-collapse-visibility-collapse-002.tentative.html new file mode 100644 index 00000000000..58293496094 --- /dev/null +++ b/tests/wpt/tests/css/CSS2/tables/border-collapse-visibility-collapse-002.tentative.html @@ -0,0 +1,32 @@ + +CSS Test: Table with collapsed borders and collapsed tracks + + + + + +

Test passes if there is a filled green square and no red.

+ + + + + + + + + + + + + + + + + + + + + +