From dbe3cb8a3c169020ba6e61390c9ae6d4725aa0ae Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Mon, 25 Mar 2024 10:39:02 +0100 Subject: [PATCH] Don't update row baseline if cell is empty (#31831) Gecko, Blink and WebKit agree that the if a row only has empty cells, its baseline should be at the bottom, not at the top. There isn't interoperability when the cells are just empty-ish, so this patch takes the simplest approach, aligning with Blink: any out-of-flow or in-flow content other than collapsed whitespace counts as not empty. --- components/layout_2020/table/layout.rs | 8 +++++- .../table-vertical-align-baseline-008.xht.ini | 2 ++ tests/wpt/meta/MANIFEST.json | 13 ++++++++++ .../max-width-applies-to-014.xht.ini | 2 -- .../min-height-applies-to-014.xht.ini | 2 -- .../min-width-applies-to-014.xht.ini | 2 -- .../table-vertical-align-baseline-008.xht | 25 +++++++++++++++++++ 7 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 tests/wpt/meta-legacy-layout/css/CSS2/tables/table-vertical-align-baseline-008.xht.ini delete mode 100644 tests/wpt/meta/css/CSS2/normal-flow/max-width-applies-to-014.xht.ini delete mode 100644 tests/wpt/meta/css/CSS2/normal-flow/min-height-applies-to-014.xht.ini delete mode 100644 tests/wpt/meta/css/CSS2/normal-flow/min-width-applies-to-014.xht.ini create mode 100644 tests/wpt/tests/css/CSS2/tables/table-vertical-align-baseline-008.xht diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs index 93a9d09dab1..652f7a3b2f3 100644 --- a/components/layout_2020/table/layout.rs +++ b/components/layout_2020/table/layout.rs @@ -54,6 +54,12 @@ impl CellLayout { fn outer_block_size(&self) -> Au { self.layout.content_block_size + (self.border.block_sum() + self.padding.block_sum()).into() } + + /// Whether the cell has no in-flow or out-of-flow contents, other than collapsed whitespace. + /// Note this logic differs from 'empty-cells', which counts abspos contents as empty. + fn is_empty(&self) -> bool { + self.layout.fragments.is_empty() + } } /// Information stored during the layout of rows. @@ -1560,7 +1566,7 @@ impl<'a> TableLayout<'a> { let row_block_offset = row_rect.start_corner.block; let row_baseline = self.row_baselines[row_index]; - if cell.effective_vertical_align() == VerticalAlignKeyword::Baseline { + if cell.effective_vertical_align() == VerticalAlignKeyword::Baseline && !layout.is_empty() { let baseline = row_block_offset + row_baseline; if row_index == 0 { baselines.first = Some(baseline); diff --git a/tests/wpt/meta-legacy-layout/css/CSS2/tables/table-vertical-align-baseline-008.xht.ini b/tests/wpt/meta-legacy-layout/css/CSS2/tables/table-vertical-align-baseline-008.xht.ini new file mode 100644 index 00000000000..f52aa88efc6 --- /dev/null +++ b/tests/wpt/meta-legacy-layout/css/CSS2/tables/table-vertical-align-baseline-008.xht.ini @@ -0,0 +1,2 @@ +[table-vertical-align-baseline-008.xht] + expected: FAIL diff --git a/tests/wpt/meta/MANIFEST.json b/tests/wpt/meta/MANIFEST.json index 654c9f2bc16..034edff4a33 100644 --- a/tests/wpt/meta/MANIFEST.json +++ b/tests/wpt/meta/MANIFEST.json @@ -106867,6 +106867,19 @@ {} ] ], + "table-vertical-align-baseline-008.xht": [ + "60079c7ce26491a0d91c8e818a1a7ead406c3a20", + [ + null, + [ + [ + "/css/CSS2/reference/ref-filled-green-100px-square.xht", + "==" + ] + ], + {} + ] + ], "table-visual-layout-017.xht": [ "25067cb68385a520a10a31949d742b520c7e9cd6", [ diff --git a/tests/wpt/meta/css/CSS2/normal-flow/max-width-applies-to-014.xht.ini b/tests/wpt/meta/css/CSS2/normal-flow/max-width-applies-to-014.xht.ini deleted file mode 100644 index 321f284c7b6..00000000000 --- a/tests/wpt/meta/css/CSS2/normal-flow/max-width-applies-to-014.xht.ini +++ /dev/null @@ -1,2 +0,0 @@ -[max-width-applies-to-014.xht] - expected: FAIL diff --git a/tests/wpt/meta/css/CSS2/normal-flow/min-height-applies-to-014.xht.ini b/tests/wpt/meta/css/CSS2/normal-flow/min-height-applies-to-014.xht.ini deleted file mode 100644 index f6e7c61b425..00000000000 --- a/tests/wpt/meta/css/CSS2/normal-flow/min-height-applies-to-014.xht.ini +++ /dev/null @@ -1,2 +0,0 @@ -[min-height-applies-to-014.xht] - expected: FAIL diff --git a/tests/wpt/meta/css/CSS2/normal-flow/min-width-applies-to-014.xht.ini b/tests/wpt/meta/css/CSS2/normal-flow/min-width-applies-to-014.xht.ini deleted file mode 100644 index b6d42d4e024..00000000000 --- a/tests/wpt/meta/css/CSS2/normal-flow/min-width-applies-to-014.xht.ini +++ /dev/null @@ -1,2 +0,0 @@ -[min-width-applies-to-014.xht] - expected: FAIL diff --git a/tests/wpt/tests/css/CSS2/tables/table-vertical-align-baseline-008.xht b/tests/wpt/tests/css/CSS2/tables/table-vertical-align-baseline-008.xht new file mode 100644 index 00000000000..1200ac1ae87 --- /dev/null +++ b/tests/wpt/tests/css/CSS2/tables/table-vertical-align-baseline-008.xht @@ -0,0 +1,25 @@ + + + + CSS Test: Test for baseline alignment of table cells + + + + + + + + +

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

+
+
+ + +
+
+ +