diff --git a/components/layout_2020/table/construct.rs b/components/layout_2020/table/construct.rs
index 61f939e9300..461267bdad0 100644
--- a/components/layout_2020/table/construct.rs
+++ b/components/layout_2020/table/construct.rs
@@ -271,8 +271,8 @@ impl TableBuilder {
}
pub fn finish(mut self) -> Table {
+ self.adjust_table_geometry_for_columns_and_colgroups();
self.do_missing_cells_fixup();
- self.remove_extra_columns_and_column_groups();
self.reorder_first_thead_and_tfoot();
self.do_final_rowspan_calculation();
self.table
@@ -287,26 +287,16 @@ impl TableBuilder {
}
/// It's possible to define more table columns via `
` and `` elements
- /// than actually exist in the table. In that case, remove these bogus columns
- /// to prevent using them later in layout.
- fn remove_extra_columns_and_column_groups(&mut self) {
- let number_of_actual_table_columns = self.table.size.width;
- self.table.columns.truncate(number_of_actual_table_columns);
-
- let mut remove_from = None;
- for (group_index, column_group) in self.table.column_groups.iter_mut().enumerate() {
- if column_group.track_range.start >= number_of_actual_table_columns {
- remove_from = Some(group_index);
- break;
- }
- column_group.track_range.end = column_group
- .track_range
- .end
- .min(number_of_actual_table_columns);
- }
-
- if let Some(remove_from) = remove_from {
- self.table.column_groups.truncate(remove_from);
+ /// than actually exist in the table. In that case, increase the size of the table.
+ ///
+ /// However, if the table has no row nor row group, remove the extra columns instead.
+ /// This matches WebKit, and some tests require it, but Gecko and Blink don't do it.
+ fn adjust_table_geometry_for_columns_and_colgroups(&mut self) {
+ if self.table.rows.is_empty() && self.table.row_groups.is_empty() {
+ self.table.columns.truncate(0);
+ self.table.column_groups.truncate(0);
+ } else {
+ self.table.size.width = self.table.size.width.max(self.table.columns.len());
}
}
diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs
index f49c1d82c5c..e52bab12400 100644
--- a/components/layout_2020/table/layout.rs
+++ b/components/layout_2020/table/layout.rs
@@ -805,7 +805,9 @@ impl<'a> TableLayout<'a> {
/// Distribute width to columns, performing step 2.4 of table layout from
/// .
fn distribute_width_to_columns(&self) -> Vec {
- if self.table.slots.is_empty() {
+ // No need to do anything if there is no column.
+ // Note that tables without rows may still have columns.
+ if self.table.size.width.is_zero() {
return Vec::new();
}
@@ -935,7 +937,7 @@ impl<'a> TableLayout<'a> {
"A deviation of more than one Au per column is unlikely to be caused by float imprecision"
);
- // We checked if the table was empty at the top of the function, so there
+ // We checked if the table had columns at the top of the function, so there
// always is a first column
widths[0] += remaining_assignable_width;
}
diff --git a/tests/wpt/meta/css/css-tables/column-track-merging.html.ini b/tests/wpt/meta/css/css-tables/column-track-merging.html.ini
index c2a25a416d7..f41d3d824eb 100644
--- a/tests/wpt/meta/css/css-tables/column-track-merging.html.ini
+++ b/tests/wpt/meta/css/css-tables/column-track-merging.html.ini
@@ -5,10 +5,13 @@
[main table 4]
expected: FAIL
- [main table 10]
+ [main table 6]
expected: FAIL
- [main table 11]
+ [main table 7]
+ expected: FAIL
+
+ [main table 8]
expected: FAIL
[main table 12]
@@ -19,3 +22,6 @@
[main table 3]
expected: FAIL
+
+ [main table 13]
+ expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/html5-table-formatting-1.html.ini b/tests/wpt/meta/css/css-tables/html5-table-formatting-1.html.ini
index 24641c85454..423f8e91681 100644
--- a/tests/wpt/meta/css/css-tables/html5-table-formatting-1.html.ini
+++ b/tests/wpt/meta/css/css-tables/html5-table-formatting-1.html.ini
@@ -1,9 +1,3 @@
[html5-table-formatting-1.html]
- [Table-columns are taken into account after missing cells are generated (empty line)]
- expected: FAIL
-
- [Table-columns are taken into account after missing cells are generated (partially empty line)]
- expected: FAIL
-
[Empty tables do not take table-rows into account]
expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/html5-table-formatting-2.html.ini b/tests/wpt/meta/css/css-tables/html5-table-formatting-2.html.ini
deleted file mode 100644
index 59e902346fd..00000000000
--- a/tests/wpt/meta/css/css-tables/html5-table-formatting-2.html.ini
+++ /dev/null
@@ -1,9 +0,0 @@
-[html5-table-formatting-2.html]
- [Explicitely defined columns are not merged]
- expected: FAIL
-
- [Border-spacing is added between any two unmerged columns (1)]
- expected: FAIL
-
- [Border-spacing is added between any two unmerged columns (5)]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/table-model-fixup-2.html.ini b/tests/wpt/meta/css/css-tables/table-model-fixup-2.html.ini
index 42047b7a07c..640ea9a062e 100644
--- a/tests/wpt/meta/css/css-tables/table-model-fixup-2.html.ini
+++ b/tests/wpt/meta/css/css-tables/table-model-fixup-2.html.ini
@@ -11,9 +11,6 @@
[Replaced elements inside a table cannot be table-row and are considered inline -- input elements (top)]
expected: FAIL
- [Replaced elements inside a table cannot be table-column and are considered inline -- input elements (top)]
- expected: FAIL
-
[Replaced elements outside a table cannot be table-row and are considered inline -- input=file elements]
expected: FAIL