layout: Improve sizing of tables in collapsed-borders mode (#34932)

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2025-01-10 15:22:32 -08:00 committed by GitHub
parent 754ec455bc
commit 25a94efcdf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 44 additions and 42 deletions

View file

@ -616,6 +616,23 @@ impl ComputedValuesExt for ComputedValues {
fn border_width(&self, containing_block_writing_mode: WritingMode) -> LogicalSides<Au> { fn border_width(&self, containing_block_writing_mode: WritingMode) -> LogicalSides<Au> {
let border = self.get_border(); let border = self.get_border();
if self.get_box().display.inside() == stylo::DisplayInside::Table &&
!matches!(self.pseudo(), Some(PseudoElement::ServoTableGrid)) &&
self.get_inherited_table().border_collapse == BorderCollapse::Collapse
{
// For tables in collapsed-borders mode we halve the border widths, because
// > in this model, the width of the table includes half the table border.
// https://www.w3.org/TR/CSS22/tables.html#collapsing-borders
return LogicalSides::from_physical(
&PhysicalSides::new(
border.border_top_width / 2,
border.border_right_width / 2,
border.border_bottom_width / 2,
border.border_left_width / 2,
),
containing_block_writing_mode,
);
}
LogicalSides::from_physical( LogicalSides::from_physical(
&PhysicalSides::new( &PhysicalSides::new(
border.border_top_width, border.border_top_width,

View file

@ -1626,8 +1626,6 @@ impl<'a> TableLayout<'a> {
containing_block_for_table: &ContainingBlock, containing_block_for_table: &ContainingBlock,
) -> IndependentLayout { ) -> IndependentLayout {
let table_writing_mode = containing_block_for_children.style.writing_mode; let table_writing_mode = containing_block_for_children.style.writing_mode;
let grid_min_max = self.compute_grid_min_max(layout_context, table_writing_mode);
let caption_minimum_inline_size = self.compute_caption_minimum_inline_size(layout_context);
self.pbm = self self.pbm = self
.table .table
.style .style
@ -1635,6 +1633,8 @@ impl<'a> TableLayout<'a> {
table_writing_mode, table_writing_mode,
containing_block_for_table.size.inline, containing_block_for_table.size.inline,
); );
let grid_min_max = self.compute_grid_min_max(layout_context, table_writing_mode);
let caption_minimum_inline_size = self.compute_caption_minimum_inline_size(layout_context);
self.compute_table_width( self.compute_table_width(
containing_block_for_children, containing_block_for_children,
grid_min_max, grid_min_max,
@ -2197,6 +2197,7 @@ impl<'a> TableLayout<'a> {
}; };
let all_rows = 0..self.table.size.height; let all_rows = 0..self.table.size.height;
let all_columns = 0..self.table.size.width; let all_columns = 0..self.table.size.width;
apply_border(&self.table.grid_style, &all_rows, &all_columns);
for column_group in &self.table.column_groups { for column_group in &self.table.column_groups {
apply_border(&column_group.style, &all_rows, &column_group.track_range); apply_border(&column_group.style, &all_rows, &column_group.track_range);
} }
@ -2242,16 +2243,24 @@ impl<'a> TableLayout<'a> {
block_end: collapsed_borders.block[end_y].width, block_end: collapsed_borders.block[end_y].width,
}; };
if coordinates.x != 0 { if coordinates.x == 0 {
result.inline_start -= self.pbm.border.inline_start;
} else {
result.inline_start /= 2; result.inline_start /= 2;
} }
if coordinates.y != 0 { if coordinates.y == 0 {
result.block_start -= self.pbm.border.block_start;
} else {
result.block_start /= 2; result.block_start /= 2;
} }
if end_x != self.table.size.width { if end_x == self.table.size.width {
result.inline_end -= self.pbm.border.inline_end;
} else {
result.inline_end /= 2; result.inline_end /= 2;
} }
if end_y != self.table.size.height { if end_y == self.table.size.height {
result.block_end -= self.pbm.border.block_end;
} else {
result.block_end /= 2; result.block_end /= 2;
} }
@ -2680,6 +2689,12 @@ impl ComputeInlineContentSizes for Table {
) -> InlineContentSizesResult { ) -> InlineContentSizesResult {
let writing_mode = constraint_space.writing_mode; let writing_mode = constraint_space.writing_mode;
let mut layout = TableLayout::new(self); let mut layout = TableLayout::new(self);
layout.pbm = self
.style
.padding_border_margin_with_writing_mode_and_containing_block_inline_size(
writing_mode,
Au::zero(),
);
let mut table_content_sizes = layout.compute_grid_min_max(layout_context, writing_mode); let mut table_content_sizes = layout.compute_grid_min_max(layout_context, writing_mode);
let mut caption_minimum_inline_size = let mut caption_minimum_inline_size =

View file

@ -1,2 +0,0 @@
[table-backgrounds-bc-cell-001.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table-backgrounds-bc-colgroup-001.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table-backgrounds-bc-column-001.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table-backgrounds-bc-row-001.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table-backgrounds-bc-rowgroup-001.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table-backgrounds-bc-table-001.xht]
expected: FAIL

View file

@ -0,0 +1,2 @@
[border-collapse-double-border.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[border-collapse-dynamic-oof.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[row-group-margin-border-padding.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[row-margin-border-padding.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[subpixel-collapsed-borders-001.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[subpixel-collapsed-borders-002.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[background-image-column-collapsed.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[background-image-row-collapsed.html]
expected: FAIL

View file

@ -1,6 +0,0 @@
[td-box-sizing-002.html]
[.t 6]
expected: FAIL
[.t 13]
expected: FAIL

View file

@ -1,3 +0,0 @@
[table-offset-props.html]
[Table with collapsed border]
expected: FAIL

View file

@ -1,3 +0,0 @@
[table-scroll-props.html]
[Table with collapsed border]
expected: FAIL

View file

@ -0,0 +1,2 @@
[356774-1.html]
expected: FAIL