Do not remove extra columns at the end of the table (#33451)

<col> and <colgroup> elements can be used to create extra columns that
have no cell. We were removing these columns and column groups, but in
general we shouldn't do that.

Now we will only remove them if the table has no row nor row group.
matching WebKit and the expectations of some tests. But note that Gecko
and Blink never remove them.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2024-09-16 10:11:36 +02:00 committed by GitHub
parent 17f796dfc1
commit 679afe5195
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 23 additions and 43 deletions

View file

@ -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 `<colgroup>` and `<col>` 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());
}
}

View file

@ -805,7 +805,9 @@ impl<'a> TableLayout<'a> {
/// Distribute width to columns, performing step 2.4 of table layout from
/// <https://drafts.csswg.org/css-tables/#table-layout-algorithm>.
fn distribute_width_to_columns(&self) -> Vec<Au> {
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;
}