mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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:
parent
17f796dfc1
commit
679afe5195
6 changed files with 23 additions and 43 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue