From 4332c1e4058970346f07d65dfa8de29a16cc31d8 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Mon, 13 Jan 2025 03:50:25 -0800 Subject: [PATCH] layout: Improve logic for block size of table (#34947) The containing block for children already has the size coming from the style and the rules of the parent formatting context, so no need to try to recompute it. This allows removing a bunch of functions, and fixes some problems when the table is a flex item. Signed-off-by: Oriol Brufau --- components/layout_2020/geom.rs | 16 ----- components/layout_2020/style_ext.rs | 66 ------------------- components/layout_2020/table/layout.rs | 27 +++----- .../abspos/table-align-self-stretch.html.ini | 6 -- ...exbox-align-self-horiz-001-table.xhtml.ini | 2 - ...le-as-item-inflexible-in-column-1.html.ini | 2 - ...le-as-item-inflexible-in-column-2.html.ini | 2 - .../table-as-item-min-height-1.html.ini | 2 - .../table-as-item-narrow-content-2.html.ini | 2 - ...-as-item-specified-width-vertical.html.ini | 2 - 10 files changed, 8 insertions(+), 119 deletions(-) delete mode 100644 tests/wpt/meta/css/css-flexbox/flexbox-align-self-horiz-001-table.xhtml.ini delete mode 100644 tests/wpt/meta/css/css-flexbox/table-as-item-inflexible-in-column-1.html.ini delete mode 100644 tests/wpt/meta/css/css-flexbox/table-as-item-inflexible-in-column-2.html.ini delete mode 100644 tests/wpt/meta/css/css-flexbox/table-as-item-min-height-1.html.ini delete mode 100644 tests/wpt/meta/css/css-flexbox/table-as-item-narrow-content-2.html.ini delete mode 100644 tests/wpt/meta/css/css-flexbox/table-as-item-specified-width-vertical.html.ini diff --git a/components/layout_2020/geom.rs b/components/layout_2020/geom.rs index c4598d31770..2cc7ae434bf 100644 --- a/components/layout_2020/geom.rs +++ b/components/layout_2020/geom.rs @@ -733,22 +733,6 @@ impl From for Size { } impl LogicalVec2> { - pub(crate) fn percentages_relative_to( - &self, - containing_block: &ContainingBlock, - ) -> LogicalVec2> { - self.map_inline_and_block_axes( - |inline_size| inline_size.map(|lp| lp.to_used_value(containing_block.size.inline)), - |block_size| { - block_size - .maybe_map(|lp| { - lp.maybe_to_used_value(containing_block.size.block.to_definite()) - }) - .unwrap_or_default() - }, - ) - } - pub(crate) fn maybe_percentages_relative_to_basis( &self, basis: &LogicalVec2>, diff --git a/components/layout_2020/style_ext.rs b/components/layout_2020/style_ext.rs index f76782c35fc..c1ce588dd76 100644 --- a/components/layout_2020/style_ext.rs +++ b/components/layout_2020/style_ext.rs @@ -263,31 +263,11 @@ pub(crate) trait ComputedValuesExt { &self, containing_block_writing_mode: WritingMode, ) -> LogicalVec2>; - fn content_box_size( - &self, - containing_block: &ContainingBlock, - pbm: &PaddingBorderMargin, - ) -> LogicalVec2>; - fn content_box_size_deprecated( - &self, - containing_block: &ContainingBlock, - pbm: &PaddingBorderMargin, - ) -> LogicalVec2; fn content_box_size_for_box_size( &self, box_size: LogicalVec2>, pbm: &PaddingBorderMargin, ) -> LogicalVec2>; - fn content_min_box_size( - &self, - containing_block: &ContainingBlock, - pbm: &PaddingBorderMargin, - ) -> LogicalVec2>; - fn content_min_box_size_deprecated( - &self, - containing_block: &ContainingBlock, - pbm: &PaddingBorderMargin, - ) -> LogicalVec2; fn content_min_box_size_for_min_size( &self, box_size: LogicalVec2>, @@ -418,26 +398,6 @@ impl ComputedValuesExt for ComputedValues { ) } - fn content_box_size( - &self, - containing_block: &ContainingBlock, - pbm: &PaddingBorderMargin, - ) -> LogicalVec2> { - let box_size = self - .box_size(containing_block.style.writing_mode) - .percentages_relative_to(containing_block); - self.content_box_size_for_box_size(box_size, pbm) - } - - fn content_box_size_deprecated( - &self, - containing_block: &ContainingBlock, - pbm: &PaddingBorderMargin, - ) -> LogicalVec2 { - self.content_box_size(containing_block, pbm) - .map(Size::to_auto_or) - } - fn content_box_size_for_box_size( &self, box_size: LogicalVec2>, @@ -454,32 +414,6 @@ impl ComputedValuesExt for ComputedValues { } } - fn content_min_box_size( - &self, - containing_block: &ContainingBlock, - pbm: &PaddingBorderMargin, - ) -> LogicalVec2> { - let min_size = self - .min_box_size(containing_block.style.writing_mode) - .map_inline_and_block_sizes( - |lp| lp.to_used_value(containing_block.size.inline), - |lp| { - let cbbs = containing_block.size.block.to_definite(); - lp.to_used_value(cbbs.unwrap_or_else(Au::zero)) - }, - ); - self.content_min_box_size_for_min_size(min_size, pbm) - } - - fn content_min_box_size_deprecated( - &self, - containing_block: &ContainingBlock, - pbm: &PaddingBorderMargin, - ) -> LogicalVec2 { - self.content_min_box_size(containing_block, pbm) - .map(Size::to_auto_or) - } - fn content_min_box_size_for_min_size( &self, min_box_size: LogicalVec2>, diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs index b2f9f881f3b..8b153d05b4b 100644 --- a/components/layout_2020/table/layout.rs +++ b/components/layout_2020/table/layout.rs @@ -21,7 +21,6 @@ use style::values::computed::{ BorderStyle, LengthPercentage as ComputedLengthPercentage, Percentage, }; use style::values::generics::box_::{GenericVerticalAlign as VerticalAlign, VerticalAlignKeyword}; -use style::values::generics::length::GenericLengthPercentageOrAuto::{Auto, LengthPercentage}; use style::Zero; use super::{ @@ -1550,24 +1549,17 @@ impl<'a> TableLayout<'a> { &mut self, mut row_sizes: Vec, containing_block_for_children: &ContainingBlock, - containing_block_for_table: &ContainingBlock, ) { // The table content height is the maximum of the computed table height from style and the // sum of computed row heights from row layout plus size from borders and spacing. - // When block-size doesn't compute to auto, `containing_block_for children` will have - // the resulting length, properly clamped between min-block-size and max-block-size. - let style = &self.table.style; - let table_height_from_style = match style - .content_box_size_deprecated(containing_block_for_table, &self.pbm) - .block - { - LengthPercentage(_) => containing_block_for_children.size.block.to_auto_or(), - Auto => style - .content_min_box_size_deprecated(containing_block_for_table, &self.pbm) - .block - .map(Au::from), - } - .auto_is(Au::zero); + // TODO: for `height: stretch`, the block size of the containing block is the available + // space for the entire table wrapper, but here we are using that amount for the table grid. + // Therefore, if there is a caption, this will cause overflow. Gecko and WebKit have the + // same problem, but not Blink. + let table_height_from_style = match containing_block_for_children.size.block { + SizeConstraint::Definite(size) => size, + SizeConstraint::MinMax(min, _) => min, + }; let block_border_spacing = self.table.total_border_spacing().block; let table_height_from_rows = row_sizes.iter().sum::() + block_border_spacing; @@ -1756,7 +1748,6 @@ impl<'a> TableLayout<'a> { positioning_context, &containing_block_for_logical_conversion, containing_block_for_children, - containing_block_for_table, ); // Take the baseline of the grid fragment, after adjusting it to be in the coordinate system @@ -1853,7 +1844,6 @@ impl<'a> TableLayout<'a> { positioning_context: &mut PositioningContext, containing_block_for_logical_conversion: &ContainingBlock, containing_block_for_children: &ContainingBlock, - containing_block_for_table: &ContainingBlock, ) -> BoxFragment { self.distributed_column_widths = self.distribute_width_to_columns(); self.layout_cells_in_row( @@ -1866,7 +1856,6 @@ impl<'a> TableLayout<'a> { self.compute_table_height_and_final_row_heights( first_layout_row_heights, containing_block_for_children, - containing_block_for_table, ); assert_eq!(self.table.size.height, self.row_sizes.len()); diff --git a/tests/wpt/meta/css/css-align/abspos/table-align-self-stretch.html.ini b/tests/wpt/meta/css/css-align/abspos/table-align-self-stretch.html.ini index c3ad158fbdc..c6552a78f9c 100644 --- a/tests/wpt/meta/css/css-align/abspos/table-align-self-stretch.html.ini +++ b/tests/wpt/meta/css/css-align/abspos/table-align-self-stretch.html.ini @@ -1,10 +1,4 @@ [table-align-self-stretch.html] - [.item 1] - expected: FAIL - - [.item 3] - expected: FAIL - [.item 5] expected: FAIL diff --git a/tests/wpt/meta/css/css-flexbox/flexbox-align-self-horiz-001-table.xhtml.ini b/tests/wpt/meta/css/css-flexbox/flexbox-align-self-horiz-001-table.xhtml.ini deleted file mode 100644 index 7003e92b8fc..00000000000 --- a/tests/wpt/meta/css/css-flexbox/flexbox-align-self-horiz-001-table.xhtml.ini +++ /dev/null @@ -1,2 +0,0 @@ -[flexbox-align-self-horiz-001-table.xhtml] - expected: FAIL diff --git a/tests/wpt/meta/css/css-flexbox/table-as-item-inflexible-in-column-1.html.ini b/tests/wpt/meta/css/css-flexbox/table-as-item-inflexible-in-column-1.html.ini deleted file mode 100644 index 75267327022..00000000000 --- a/tests/wpt/meta/css/css-flexbox/table-as-item-inflexible-in-column-1.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[table-as-item-inflexible-in-column-1.html] - expected: FAIL diff --git a/tests/wpt/meta/css/css-flexbox/table-as-item-inflexible-in-column-2.html.ini b/tests/wpt/meta/css/css-flexbox/table-as-item-inflexible-in-column-2.html.ini deleted file mode 100644 index 91f810f44b5..00000000000 --- a/tests/wpt/meta/css/css-flexbox/table-as-item-inflexible-in-column-2.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[table-as-item-inflexible-in-column-2.html] - expected: FAIL diff --git a/tests/wpt/meta/css/css-flexbox/table-as-item-min-height-1.html.ini b/tests/wpt/meta/css/css-flexbox/table-as-item-min-height-1.html.ini deleted file mode 100644 index 698441f72ef..00000000000 --- a/tests/wpt/meta/css/css-flexbox/table-as-item-min-height-1.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[table-as-item-min-height-1.html] - expected: FAIL diff --git a/tests/wpt/meta/css/css-flexbox/table-as-item-narrow-content-2.html.ini b/tests/wpt/meta/css/css-flexbox/table-as-item-narrow-content-2.html.ini deleted file mode 100644 index 1b12c33297a..00000000000 --- a/tests/wpt/meta/css/css-flexbox/table-as-item-narrow-content-2.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[table-as-item-narrow-content-2.html] - expected: FAIL diff --git a/tests/wpt/meta/css/css-flexbox/table-as-item-specified-width-vertical.html.ini b/tests/wpt/meta/css/css-flexbox/table-as-item-specified-width-vertical.html.ini deleted file mode 100644 index 59aeed11f53..00000000000 --- a/tests/wpt/meta/css/css-flexbox/table-as-item-specified-width-vertical.html.ini +++ /dev/null @@ -1,2 +0,0 @@ -[table-as-item-specified-width-vertical.html] - expected: FAIL