Fix table track constrainedness (#33550)

* Fix table track constraindness

Only as size that isn't `auto` and doesn't contain percentages can constrain
a table track (https://drafts.csswg.org/css-tables/#constrainedness).

However, in a bunch of cases we were only checking for `auto`.

Also, we were allowing the inline-size of a cell to constrain both its
column and row. Using the block-size of the row makes more sense.
The spec doesn't define constrainedness for rows, though.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>

* Apply suggestions from code review

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Signed-off-by: Oriol Brufau <obrufau@igalia.com>

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Oriol Brufau 2024-09-26 07:06:33 -07:00 committed by GitHub
parent 1346643727
commit 0cefee48e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 27 additions and 47 deletions

View file

@ -55,6 +55,15 @@ impl<T: fmt::Debug> fmt::Debug for LogicalVec2<T> {
} }
} }
impl<T: Default> Default for LogicalVec2<T> {
fn default() -> Self {
Self {
inline: T::default(),
block: T::default(),
}
}
}
impl<T: Clone> LogicalVec2<T> { impl<T: Clone> LogicalVec2<T> {
pub fn from_physical_size(physical_size: &PhysicalSize<T>, mode: WritingMode) -> Self { pub fn from_physical_size(physical_size: &PhysicalSize<T>, mode: WritingMode) -> Self {
// https://drafts.csswg.org/css-writing-modes/#logical-to-physical // https://drafts.csswg.org/css-writing-modes/#logical-to-physical

View file

@ -369,52 +369,50 @@ impl<'a> TableLayout<'a> {
self.rows = vec![RowLayout::default(); self.table.size.height]; self.rows = vec![RowLayout::default(); self.table.size.height];
self.columns = vec![ColumnLayout::default(); self.table.size.width]; self.columns = vec![ColumnLayout::default(); self.table.size.width];
let is_length = |size: &LengthPercentageOrAuto| {
size.non_auto().is_some_and(|size| !size.has_percentage())
};
for column_index in 0..self.table.size.width { for column_index in 0..self.table.size.width {
if let Some(column) = self.table.columns.get(column_index) { if let Some(column) = self.table.columns.get(column_index) {
if !column.style.box_size(writing_mode).inline.is_auto() { if is_length(&column.style.box_size(writing_mode).inline) {
self.columns[column_index].constrained = true; self.columns[column_index].constrained = true;
continue; continue;
} }
if let Some(column_group_index) = column.group_index { if let Some(column_group_index) = column.group_index {
let column_group = &self.table.column_groups[column_group_index]; let column_group = &self.table.column_groups[column_group_index];
if !column_group.style.box_size(writing_mode).inline.is_auto() { if is_length(&column_group.style.box_size(writing_mode).inline) {
self.columns[column_index].constrained = true; self.columns[column_index].constrained = true;
continue; continue;
} }
} }
self.columns[column_index].constrained = false;
} }
} }
for row_index in 0..self.table.size.height { for row_index in 0..self.table.size.height {
if let Some(row) = self.table.rows.get(row_index) { if let Some(row) = self.table.rows.get(row_index) {
if !row.style.box_size(writing_mode).block.is_auto() { if is_length(&row.style.box_size(writing_mode).block) {
self.rows[row_index].constrained = true; self.rows[row_index].constrained = true;
continue; continue;
} }
if let Some(row_group_index) = row.group_index { if let Some(row_group_index) = row.group_index {
let row_group = &self.table.row_groups[row_group_index]; let row_group = &self.table.row_groups[row_group_index];
if !row_group.style.box_size(writing_mode).block.is_auto() { if is_length(&row_group.style.box_size(writing_mode).block) {
self.rows[row_index].constrained = true; self.rows[row_index].constrained = true;
continue; continue;
} }
} }
} }
self.rows[row_index].constrained = false;
} }
for column_index in 0..self.table.size.width { for column_index in 0..self.table.size.width {
for row_index in 0..self.table.size.height { for row_index in 0..self.table.size.height {
let coords = TableSlotCoordinates::new(column_index, row_index); let coords = TableSlotCoordinates::new(column_index, row_index);
let cell_constrained = match self.table.resolve_first_cell(coords) { let cell_constrained = match self.table.resolve_first_cell(coords) {
Some(cell) if cell.colspan == 1 => cell Some(cell) if cell.colspan == 1 => {
.style cell.style.box_size(writing_mode).map(is_length)
.box_size(writing_mode) },
.inline _ => LogicalVec2::default(),
.non_auto()
.and_then(|length_percentage| length_percentage.to_length())
.is_some(),
_ => false,
}; };
let rowspan_greater_than_1 = match self.table.slots[row_index][column_index] { let rowspan_greater_than_1 = match self.table.slots[row_index][column_index] {
@ -423,12 +421,12 @@ impl<'a> TableLayout<'a> {
}; };
self.rows[row_index].has_cell_with_span_greater_than_one |= rowspan_greater_than_1; self.rows[row_index].has_cell_with_span_greater_than_one |= rowspan_greater_than_1;
self.rows[row_index].constrained |= cell_constrained; self.rows[row_index].constrained |= cell_constrained.block;
let has_originating_cell = let has_originating_cell =
matches!(self.table.get_slot(coords), Some(TableSlot::Cell(_))); matches!(self.table.get_slot(coords), Some(TableSlot::Cell(_)));
self.columns[column_index].has_originating_cells |= has_originating_cell; self.columns[column_index].has_originating_cells |= has_originating_cell;
self.columns[column_index].constrained |= cell_constrained; self.columns[column_index].constrained |= cell_constrained.inline;
} }
} }
} }

View file

@ -1,3 +0,0 @@
[auto-layout-calc-width-001.html]
[#theTable 1]
expected: FAIL

View file

@ -1,3 +0,0 @@
[fixed-layout-calc-width-001.html]
[#theTable 1]
expected: FAIL

View file

@ -1,5 +1,5 @@
[rowspan-height-redistribution.html] [rowspan-height-redistribution.html]
[table 8] [table 17]
expected: FAIL expected: FAIL
[table 22] [table 22]

View file

@ -8,21 +8,6 @@
[table 17] [table 17]
expected: FAIL expected: FAIL
[table 18]
expected: FAIL
[table 19]
expected: FAIL
[table 20]
expected: FAIL
[table 21]
expected: FAIL
[table 22]
expected: FAIL
[table 25] [table 25]
expected: FAIL expected: FAIL

View file

@ -1,3 +0,0 @@
[visibility-collapse-row-004.html]
[collapsed row shrinks table height]
expected: FAIL

View file

@ -122,12 +122,6 @@
[table th align attribute justify is correct] [table th align attribute justify is correct]
expected: FAIL expected: FAIL
[td height attribute pixel is correct]
expected: FAIL
[th height attribute pixel is correct]
expected: FAIL
[table_td height attribute percentage is correct] [table_td height attribute percentage is correct]
expected: FAIL expected: FAIL
@ -139,3 +133,6 @@
[table cellpadding attribute is correct] [table cellpadding attribute is correct]
expected: FAIL expected: FAIL
[table_tr height attribute percentage is correct]
expected: FAIL