aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOriol Brufau <obrufau@igalia.com>2024-05-21 20:02:53 +0200
committerGitHub <noreply@github.com>2024-05-21 18:02:53 +0000
commit5d5ac4ec646d702efa4a0ae3e29a192512756cc9 (patch)
tree13bfd1370a1f983d7e166b20d755bff4c6021d88
parentadd18db67ed7cf48433d13d8fa1f0b1d85c2c8a8 (diff)
downloadservo-5d5ac4ec646d702efa4a0ae3e29a192512756cc9.tar.gz
servo-5d5ac4ec646d702efa4a0ae3e29a192512756cc9.zip
Implement 'visibility: collapse' on table parts (#32333)
https://drafts.csswg.org/css2/#dynamic-effects Co-authored-by: Martin Robinson <mrobinson@igalia.com>
-rw-r--r--components/layout_2020/table/layout.rs83
-rw-r--r--tests/wpt/meta/css/CSS2/tables/row-visibility-001.xht.ini2
-rw-r--r--tests/wpt/meta/css/CSS2/tables/row-visibility-002.xht.ini2
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-border-spacing.html.ini2
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-col-001.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-col-002.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-col-003.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-col-004-dynamic.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-colspan-001.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-colspan-002.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-row-001.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-row-002-dynamic.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-row-003-dynamic.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-row-005.html.ini6
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-row-group-001.html.ini9
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-row-group-002.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-rowcol-001.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-rowcol-002.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-002-border-separate.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-002.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-003-border-separate.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-003.html.ini3
-rw-r--r--tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-004-dynamic.html.ini12
23 files changed, 64 insertions, 100 deletions
diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs
index 952a6fff74b..f1f29473c50 100644
--- a/components/layout_2020/table/layout.rs
+++ b/components/layout_2020/table/layout.rs
@@ -8,9 +8,10 @@ use app_units::{Au, MAX_AU};
use log::warn;
use servo_arc::Arc;
use style::computed_values::border_collapse::T as BorderCollapse;
+use style::computed_values::box_sizing::T as BoxSizing;
+use style::computed_values::empty_cells::T as EmptyCells;
+use style::computed_values::visibility::T as Visibility;
use style::logical_geometry::WritingMode;
-use style::properties::longhands::box_sizing::computed_value::T as BoxSizing;
-use style::properties::longhands::empty_cells::computed_value::T as EmptyCells;
use style::properties::ComputedValues;
use style::values::computed::{
CSSPixelLength, Length, LengthPercentage as ComputedLengthPercentage, Percentage,
@@ -1480,6 +1481,27 @@ impl<'a> TableLayout<'a> {
let mut row_group_fragment_layout = None;
for row_index in 0..self.table.size.height {
+ // From <https://drafts.csswg.org/css-align-3/#baseline-export>
+ // > If any cells in the row participate in first baseline/last baseline alignment along
+ // > the inline axis, the first/last baseline set of the row is generated from their
+ // > shared alignment baseline and the row’s first available font, after alignment has
+ // > been performed. Otherwise, the first/last baseline set of the row is synthesized from
+ // > the lowest and highest content edges of the cells in the row. [CSS2]
+ //
+ // If any cell below has baseline alignment, these values will be overwritten,
+ // but they are initialized to the content edge of the first row.
+ if row_index == 0 {
+ let row_end = table_and_track_dimensions
+ .get_row_rect(0)
+ .max_block_position();
+ baselines.first = Some(row_end);
+ baselines.last = Some(row_end);
+ }
+
+ if self.is_row_collapsed(row_index) {
+ continue;
+ }
+
let table_row = &self.table.rows[row_index];
let mut row_fragment_layout =
RowFragmentLayout::new(table_row, row_index, &table_and_track_dimensions);
@@ -1507,26 +1529,13 @@ impl<'a> TableLayout<'a> {
}
}
- // From <https://drafts.csswg.org/css-align-3/#baseline-export>
- // > If any cells in the row participate in first baseline/last baseline alignment along
- // > the inline axis, the first/last baseline set of the row is generated from their
- // > shared alignment baseline and the row’s first available font, after alignment has
- // > been performed. Otherwise, the first/last baseline set of the row is synthesized from
- // > the lowest and highest content edges of the cells in the row. [CSS2]
- //
- // If any cell below has baseline alignment, these values will be overwritten,
- // but they are initialized to the content edge of the first row.
- if row_index == 0 {
- let row_end = table_and_track_dimensions
- .get_row_rect(0)
- .max_block_position();
- baselines.first = Some(row_end);
- baselines.last = Some(row_end);
- }
-
let column_indices = 0..self.table.size.width;
row_fragment_layout.fragments.reserve(self.table.size.width);
for column_index in column_indices {
+ if self.is_column_collapsed(column_index) {
+ continue;
+ }
+
// The PositioningContext for cells is, in order or preference, the PositioningContext of the row,
// the PositioningContext of the row group, or the PositioningContext of the table.
let row_group_positioning_context = row_group_fragment_layout
@@ -1580,6 +1589,34 @@ impl<'a> TableLayout<'a> {
}
}
+ fn is_row_collapsed(&self, row_index: usize) -> bool {
+ let Some(row) = &self.table.rows.get(row_index) else {
+ return false;
+ };
+ if row.style.get_inherited_box().visibility == Visibility::Collapse {
+ return true;
+ }
+ let row_group = match row.group_index {
+ Some(group_index) => &self.table.row_groups[group_index],
+ None => return false,
+ };
+ row_group.style.get_inherited_box().visibility == Visibility::Collapse
+ }
+
+ fn is_column_collapsed(&self, column_index: usize) -> bool {
+ let Some(col) = &self.table.columns.get(column_index) else {
+ return false;
+ };
+ if col.style.get_inherited_box().visibility == Visibility::Collapse {
+ return true;
+ }
+ let col_group = match col.group_index {
+ Some(group_index) => &self.table.column_groups[group_index],
+ None => return false,
+ };
+ col_group.style.get_inherited_box().visibility == Visibility::Collapse
+ }
+
#[allow(clippy::too_many_arguments)]
fn do_final_cell_layout(
&mut self,
@@ -1913,6 +1950,10 @@ impl TableAndTrackDimensions {
border_spacing.inline
};
for column_index in 0..table_layout.table.size.width {
+ if table_layout.is_column_collapsed(column_index) {
+ column_dimensions.push((column_offset, column_offset));
+ continue;
+ }
let column_size = table_layout.distributed_column_widths[column_index];
column_dimensions.push((column_offset, column_offset + column_size));
column_offset += column_size + border_spacing.inline;
@@ -1925,6 +1966,10 @@ impl TableAndTrackDimensions {
border_spacing.block
};
for row_index in 0..table_layout.table.size.height {
+ if table_layout.is_row_collapsed(row_index) {
+ row_dimensions.push((row_offset, row_offset));
+ continue;
+ }
let row_size = table_layout.row_sizes[row_index];
row_dimensions.push((row_offset, row_offset + row_size));
row_offset += row_size + border_spacing.block;
diff --git a/tests/wpt/meta/css/CSS2/tables/row-visibility-001.xht.ini b/tests/wpt/meta/css/CSS2/tables/row-visibility-001.xht.ini
deleted file mode 100644
index 723b6885faa..00000000000
--- a/tests/wpt/meta/css/CSS2/tables/row-visibility-001.xht.ini
+++ /dev/null
@@ -1,2 +0,0 @@
-[row-visibility-001.xht]
- expected: FAIL
diff --git a/tests/wpt/meta/css/CSS2/tables/row-visibility-002.xht.ini b/tests/wpt/meta/css/CSS2/tables/row-visibility-002.xht.ini
deleted file mode 100644
index 61fbc5acc76..00000000000
--- a/tests/wpt/meta/css/CSS2/tables/row-visibility-002.xht.ini
+++ /dev/null
@@ -1,2 +0,0 @@
-[row-visibility-002.xht]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-border-spacing.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-border-spacing.html.ini
deleted file mode 100644
index 43b3c65884f..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-border-spacing.html.ini
+++ /dev/null
@@ -1,2 +0,0 @@
-[visibility-collapse-border-spacing.html]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-col-001.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-col-001.html.ini
deleted file mode 100644
index 22e94f9a93c..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-col-001.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[visibility-collapse-col-001.html]
- [col visibility:collapse changes table width]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-col-002.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-col-002.html.ini
deleted file mode 100644
index 8e3fc5a7979..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-col-002.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[visibility-collapse-col-002.html]
- [col visibility:collapse changes table width]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-col-003.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-col-003.html.ini
deleted file mode 100644
index bae33f466c5..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-col-003.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[visibility-collapse-col-003.html]
- [col visibility:collapse changes table width]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-col-004-dynamic.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-col-004-dynamic.html.ini
deleted file mode 100644
index c5aaa6b0953..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-col-004-dynamic.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[visibility-collapse-col-004-dynamic.html]
- [col visibility:collapse changes table width]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-colspan-001.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-colspan-001.html.ini
deleted file mode 100644
index 79a63004561..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-colspan-001.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[visibility-collapse-colspan-001.html]
- [col visibility:collapse changes table width]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-colspan-002.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-colspan-002.html.ini
deleted file mode 100644
index e726d42c66c..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-colspan-002.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[visibility-collapse-colspan-002.html]
- [col visibility:collapse changes table width]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-row-001.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-row-001.html.ini
deleted file mode 100644
index 9441076fb20..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-row-001.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[visibility-collapse-row-001.html]
- [row visibility:collapse changes table height, unlike visibility:hidden]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-row-002-dynamic.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-row-002-dynamic.html.ini
deleted file mode 100644
index 07bed03cbb4..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-row-002-dynamic.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[visibility-collapse-row-002-dynamic.html]
- [row visibility:collapse changes table height, unlike visibility:hidden]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-row-003-dynamic.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-row-003-dynamic.html.ini
deleted file mode 100644
index 9ca256e3307..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-row-003-dynamic.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[visibility-collapse-row-003-dynamic.html]
- [row visibility:collapse changes table height, unlike visibility:hidden]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-row-005.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-row-005.html.ini
deleted file mode 100644
index b2665eaf590..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-row-005.html.ini
+++ /dev/null
@@ -1,6 +0,0 @@
-[visibility-collapse-row-005.html]
- [collapsed row should not contribute to overflow]
- expected: FAIL
-
- [collapsed section should not contribute to overflow]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-row-group-001.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-row-group-001.html.ini
deleted file mode 100644
index a97baf9ec43..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-row-group-001.html.ini
+++ /dev/null
@@ -1,9 +0,0 @@
-[visibility-collapse-row-group-001.html]
- [row group visibility:collapse changes table height]
- expected: FAIL
-
- [the first row should be collapsed]
- expected: FAIL
-
- [the second row should be collapsed]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-row-group-002.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-row-group-002.html.ini
deleted file mode 100644
index 099dd7a2eac..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-row-group-002.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[visibility-collapse-row-group-002.html]
- [row group visibility:collapse changes table height]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-rowcol-001.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-rowcol-001.html.ini
index 7cb8c548023..f0813ddb0fe 100644
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-rowcol-001.html.ini
+++ b/tests/wpt/meta/css/css-tables/visibility-collapse-rowcol-001.html.ini
@@ -1,6 +1,3 @@
[visibility-collapse-rowcol-001.html]
[spanning col visibility:collapse changes table width]
expected: FAIL
-
- [spanning row visibility:collapse changes height]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-rowcol-002.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-rowcol-002.html.ini
index 0cd066792b7..5ae403b640f 100644
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-rowcol-002.html.ini
+++ b/tests/wpt/meta/css/css-tables/visibility-collapse-rowcol-002.html.ini
@@ -1,6 +1,3 @@
[visibility-collapse-rowcol-002.html]
[spanning row visibility:collapse doesn't change table width]
expected: FAIL
-
- [spanning row visibility:collapse doesn't change height in this case]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-002-border-separate.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-002-border-separate.html.ini
index bd22dfeb3e0..2adc27f445d 100644
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-002-border-separate.html.ini
+++ b/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-002-border-separate.html.ini
@@ -1,6 +1,3 @@
[visibility-collapse-rowspan-002-border-separate.html]
[spanning cell shrinks to sum of remaining three rows' height]
expected: FAIL
-
- [spanning row visibility:collapse makes row height 0]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-002.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-002.html.ini
index 8d062d5c74c..de808e0731a 100644
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-002.html.ini
+++ b/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-002.html.ini
@@ -1,6 +1,3 @@
[visibility-collapse-rowspan-002.html]
[spanning cell shrinks to sum of remaining three rows' height]
expected: FAIL
-
- [spanning row visibility:collapse makes row height 0]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-003-border-separate.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-003-border-separate.html.ini
deleted file mode 100644
index 5f7a6fe9baa..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-003-border-separate.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[visibility-collapse-rowspan-003-border-separate.html]
- [collapsed row has zero height]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-003.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-003.html.ini
deleted file mode 100644
index bd40ed0a982..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-003.html.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[visibility-collapse-rowspan-003.html]
- [collapsed row has zero height]
- expected: FAIL
diff --git a/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-004-dynamic.html.ini b/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-004-dynamic.html.ini
deleted file mode 100644
index a7d5292bed6..00000000000
--- a/tests/wpt/meta/css/css-tables/visibility-collapse-rowspan-004-dynamic.html.ini
+++ /dev/null
@@ -1,12 +0,0 @@
-[visibility-collapse-rowspan-004-dynamic.html]
- [spanning cell shrinks to sum of remaining three rows' height]
- expected: FAIL
-
- [(2nd collapse) spanning cell shrinks to sum of remaining three rows' height]
- expected: FAIL
-
- [third row visibility:collapse makes row height 0]
- expected: FAIL
-
- [(2nd collapse) third row visibility:collapse makes row height 0]
- expected: FAIL