From aa54a0b1a63e6a1af12449e71b4c7b3af961cad0 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Thu, 23 Jan 2025 04:38:24 -0800 Subject: [PATCH] layout: simplify `CollapsedBorderLine` (#35125) This used to be a struct that had a list of `CollapsedBorder`s, and the maximum border width among that list. However, this cached maximum border width was only used when resolving the borders of the table. Therefore, for all grid lines except the first and last ones per axis, this data was useless. Also, in order to address #35123 I plan to retroactively zero out some collapsed borders, which could invalidate this cache. So this patch just removes the field and turns `CollapsedBorderLine` into an alias of `Vec`. Signed-off-by: Oriol Brufau --- components/layout_2020/display_list/mod.rs | 8 +-- components/layout_2020/table/layout.rs | 67 ++++++++++------------ components/layout_2020/table/mod.rs | 6 +- 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/components/layout_2020/display_list/mod.rs b/components/layout_2020/display_list/mod.rs index b566184b008..6fd9be1c8aa 100644 --- a/components/layout_2020/display_list/mod.rs +++ b/components/layout_2020/display_list/mod.rs @@ -915,10 +915,10 @@ impl<'a> BuilderForBoxFragment<'a> { for (x, column_size) in table_info.track_sizes.x.iter().enumerate() { let mut row_sum = Au::zero(); for (y, row_size) in table_info.track_sizes.y.iter().enumerate() { - let left_border = &table_info.collapsed_borders.x[x].list[y]; - let right_border = &table_info.collapsed_borders.x[x + 1].list[y]; - let top_border = &table_info.collapsed_borders.y[y].list[x]; - let bottom_border = &table_info.collapsed_borders.y[y + 1].list[x]; + let left_border = &table_info.collapsed_borders.x[x][y]; + let right_border = &table_info.collapsed_borders.x[x + 1][y]; + let top_border = &table_info.collapsed_borders.y[y][x]; + let bottom_border = &table_info.collapsed_borders.y[y + 1][x]; let details = wr::BorderDetails::Normal(wr::NormalBorder { left: self.build_border_side(left_border.style_color.clone()), right: self.build_border_side(right_border.style_color.clone()), diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs index dc5d4adc66e..da7d03f0fb4 100644 --- a/components/layout_2020/table/layout.rs +++ b/components/layout_2020/table/layout.rs @@ -143,6 +143,12 @@ impl CollapsedBorder { *self = other.clone(); } } + + fn max_assign_to_slice(&self, slice: &mut [CollapsedBorder]) { + for collapsed_border in slice { + collapsed_border.max_assign(self) + } + } } /// @@ -179,15 +185,6 @@ impl PartialOrd for CollapsedBorder { impl Eq for CollapsedBorder {} -impl CollapsedBorderLine { - fn max_assign(&mut self, collapsed_border: &CollapsedBorder, range: &Range) { - self.max_width.max_assign(collapsed_border.width); - for index in range.clone() { - self.list[index].max_assign(collapsed_border) - } - } -} - /// A helper struct that performs the layout of the box tree version /// of a table into the fragment tree version. This implements /// @@ -1900,7 +1897,7 @@ impl<'a> TableLayout<'a> { track_sizes.inline.reverse(); collapsed_borders.inline.reverse(); for border_line in &mut collapsed_borders.block { - border_line.list.reverse(); + border_line.reverse(); } } SpecificLayoutInfo::TableGridWithCollapsedBorders(Box::new(SpecificTableGridInfo { @@ -2104,17 +2101,11 @@ impl<'a> TableLayout<'a> { let mut collapsed_borders = LogicalVec2 { block: vec![ - CollapsedBorderLine { - max_width: Au::zero(), - list: vec![Default::default(); self.table.size.width], - }; + vec![Default::default(); self.table.size.width]; self.table.size.height + 1 ], inline: vec![ - CollapsedBorderLine { - max_width: Au::zero(), - list: vec![Default::default(); self.table.size.height], - }; + vec![Default::default(); self.table.size.height]; self.table.size.width + 1 ], }; @@ -2122,10 +2113,18 @@ impl<'a> TableLayout<'a> { let mut apply_border = |layout_style: &LayoutStyle, block: &Range, inline: &Range| { let border = CollapsedBorder::from_layout_style(layout_style, writing_mode); - collapsed_borders.block[block.start].max_assign(&border.block_start, inline); - collapsed_borders.block[block.end].max_assign(&border.block_end, inline); - collapsed_borders.inline[inline.start].max_assign(&border.inline_start, block); - collapsed_borders.inline[inline.end].max_assign(&border.inline_end, block); + border + .block_start + .max_assign_to_slice(&mut collapsed_borders.block[block.start][inline.clone()]); + border + .block_end + .max_assign_to_slice(&mut collapsed_borders.block[block.end][inline.clone()]); + border.inline_start.max_assign_to_slice( + &mut collapsed_borders.inline[inline.start][block.clone()], + ); + border + .inline_end + .max_assign_to_slice(&mut collapsed_borders.inline[inline.end][block.clone()]); }; let all_rows = 0..self.table.size.height; let all_columns = 0..self.table.size.width; @@ -2188,20 +2187,10 @@ impl<'a> TableLayout<'a> { slice_widths.max().unwrap_or_default() }; Some(area.map_inline_and_block_axes( - |column| max_width(&collapsed_borders.inline[*column].list[rows()]) / 2, - |row| max_width(&collapsed_borders.block[*row].list[columns()]) / 2, + |column| max_width(&collapsed_borders.inline[*column][rows()]) / 2, + |row| max_width(&collapsed_borders.block[*row][columns()]) / 2, )) } - - fn get_collapsed_border_widths_for_table(&self) -> Option> { - let collapsed_borders = self.collapsed_borders.as_ref()?; - Some(LogicalSides { - inline_start: collapsed_borders.inline[0].max_width / 2, - inline_end: collapsed_borders.inline[self.table.size.width].max_width / 2, - block_start: collapsed_borders.block[0].max_width / 2, - block_end: collapsed_borders.block[self.table.size.height].max_width / 2, - }) - } } struct RowFragmentLayout<'a> { @@ -2715,13 +2704,19 @@ impl TableLayoutStyle<'_> { pub(crate) fn halved_collapsed_border_widths(&self) -> LogicalSides { debug_assert!(self.collapses_borders()); + let area = LogicalSides { + inline_start: 0, + inline_end: self.table.size.width, + block_start: 0, + block_end: self.table.size.height, + }; if let Some(layout) = self.layout { - layout.get_collapsed_border_widths_for_table() + layout.get_collapsed_border_widths_for_area(area) } else { // TODO: this should be cached. let mut layout = TableLayout::new(self.table); layout.compute_border_collapse(self.style().writing_mode); - layout.get_collapsed_border_widths_for_table() + layout.get_collapsed_border_widths_for_area(area) } .expect("Collapsed borders should be computed") } diff --git a/components/layout_2020/table/mod.rs b/components/layout_2020/table/mod.rs index 05d46df808b..2c16853f2f9 100644 --- a/components/layout_2020/table/mod.rs +++ b/components/layout_2020/table/mod.rs @@ -327,11 +327,7 @@ pub(crate) struct CollapsedBorder { } /// Represents a piecewise sequence of collapsed borders along a line. -#[derive(Clone, Debug, Default)] -pub(crate) struct CollapsedBorderLine { - max_width: Au, - pub list: Vec, -} +pub(crate) type CollapsedBorderLine = Vec; #[derive(Clone, Debug)] pub(crate) struct SpecificTableGridInfo {