diff options
Diffstat (limited to 'components/layout_2020/table')
-rw-r--r-- | components/layout_2020/table/construct.rs | 15 | ||||
-rw-r--r-- | components/layout_2020/table/layout.rs | 118 | ||||
-rw-r--r-- | components/layout_2020/table/mod.rs | 33 |
3 files changed, 91 insertions, 75 deletions
diff --git a/components/layout_2020/table/construct.rs b/components/layout_2020/table/construct.rs index 13615183788..f20360d3b56 100644 --- a/components/layout_2020/table/construct.rs +++ b/components/layout_2020/table/construct.rs @@ -728,8 +728,7 @@ where let style = anonymous_info.style.clone(); self.push_table_row(ArcRefCell::new(TableTrack { - base_fragment_info: (&anonymous_info).into(), - style, + base: LayoutBoxBase::new((&anonymous_info).into(), style), group_index: self.current_row_group_index, is_anonymous: true, })); @@ -773,8 +772,7 @@ where let next_row_index = self.builder.table.rows.len(); let row_group = ArcRefCell::new(TableTrackGroup { - base_fragment_info: info.into(), - style: info.style.clone(), + base: LayoutBoxBase::new(info.into(), info.style.clone()), group_type: internal.into(), track_range: next_row_index..next_row_index, }); @@ -816,8 +814,7 @@ where row_builder.finish(); let row = ArcRefCell::new(TableTrack { - base_fragment_info: info.into(), - style: info.style.clone(), + base: LayoutBoxBase::new(info.into(), info.style.clone()), group_index: self.current_row_group_index, is_anonymous: false, }); @@ -862,8 +859,7 @@ where } let column_group = ArcRefCell::new(TableTrackGroup { - base_fragment_info: info.into(), - style: info.style.clone(), + base: LayoutBoxBase::new(info.into(), info.style.clone()), group_type: internal.into(), track_range: first_column..self.builder.table.columns.len(), }); @@ -1155,8 +1151,7 @@ fn add_column<'dom, Node: NodeExt<'dom>>( }; let column = ArcRefCell::new(TableTrack { - base_fragment_info: column_info.into(), - style: column_info.style.clone(), + base: LayoutBoxBase::new(column_info.into(), column_info.style.clone()), group_index, is_anonymous, }); diff --git a/components/layout_2020/table/layout.rs b/components/layout_2020/table/layout.rs index bc38c5e6227..57b48ae0bca 100644 --- a/components/layout_2020/table/layout.rs +++ b/components/layout_2020/table/layout.rs @@ -32,7 +32,7 @@ use super::{ use crate::context::LayoutContext; use crate::formatting_contexts::Baselines; use crate::fragment_tree::{ - BaseFragmentInfo, BoxFragment, CollapsedBlockMargins, ExtraBackground, Fragment, FragmentFlags, + BoxFragment, CollapsedBlockMargins, ExtraBackground, Fragment, FragmentFlags, PositioningFragment, SpecificLayoutInfo, }; use crate::geom::{ @@ -396,13 +396,13 @@ impl<'a> TableLayout<'a> { for column_index in 0..self.table.size.width { if let Some(column) = self.table.columns.get(column_index) { let column = column.borrow(); - if is_length(&column.style.box_size(writing_mode).inline) { + if is_length(&column.base.style.box_size(writing_mode).inline) { self.columns[column_index].constrained = true; continue; } if let Some(column_group_index) = column.group_index { let column_group = self.table.column_groups[column_group_index].borrow(); - if is_length(&column_group.style.box_size(writing_mode).inline) { + if is_length(&column_group.base.style.box_size(writing_mode).inline) { self.columns[column_index].constrained = true; continue; } @@ -413,13 +413,13 @@ impl<'a> TableLayout<'a> { for row_index in 0..self.table.size.height { if let Some(row) = self.table.rows.get(row_index) { let row = row.borrow(); - if is_length(&row.style.box_size(writing_mode).block) { + if is_length(&row.base.style.box_size(writing_mode).block) { self.rows[row_index].constrained = true; continue; } if let Some(row_group_index) = row.group_index { let row_group = self.table.row_groups[row_group_index].borrow(); - if is_length(&row_group.style.box_size(writing_mode).block) { + if is_length(&row_group.base.style.box_size(writing_mode).block) { self.rows[row_index].constrained = true; continue; } @@ -1086,13 +1086,15 @@ impl<'a> TableLayout<'a> { row.group_index.is_some_and(|group_index| { self.table.row_groups[group_index] .borrow() + .base .style .establishes_containing_block_for_absolute_descendants( FragmentFlags::empty(), ) }); row_group_collects_for_nearest_positioned_ancestor || - row.style + row.base + .style .establishes_containing_block_for_absolute_descendants( FragmentFlags::empty(), ) @@ -1650,6 +1652,8 @@ impl<'a> TableLayout<'a> { &caption_fragment, original_positioning_context_length, ); + + caption.context.base.set_fragment(caption_fragment.clone()); Some(caption_fragment) })); @@ -1745,6 +1749,8 @@ impl<'a> TableLayout<'a> { &caption_fragment, original_positioning_context_length, ); + + caption.context.base.set_fragment(caption_fragment.clone()); Some(caption_fragment) })); @@ -1845,18 +1851,18 @@ impl<'a> TableLayout<'a> { if table_row.group_index != old_row_group_index { // First create the Fragment for any existing RowGroupFragmentLayout. if let Some(old_row_group_layout) = row_group_fragment_layout.take() { - table_fragments.push(Fragment::Box(old_row_group_layout.finish( + table_fragments.push(old_row_group_layout.finish( layout_context, positioning_context, containing_block_for_logical_conversion, containing_block_for_children, - ))); + )); } // Then, create a new RowGroupFragmentLayout for the current and potentially subsequent rows. if let Some(new_group_index) = table_row.group_index { row_group_fragment_layout = Some(RowGroupFragmentLayout::new( - &self.table.row_groups[new_group_index].borrow(), + self.table.row_groups[new_group_index].clone(), new_group_index, &table_and_track_dimensions, )); @@ -1881,13 +1887,13 @@ impl<'a> TableLayout<'a> { ); } - let row_fragment = Fragment::Box(row_fragment_layout.finish( + let row_fragment = row_fragment_layout.finish( layout_context, positioning_context, containing_block_for_logical_conversion, containing_block_for_children, &mut row_group_fragment_layout, - )); + ); match row_group_fragment_layout.as_mut() { Some(layout) => layout.fragments.push(row_fragment), @@ -1896,12 +1902,12 @@ impl<'a> TableLayout<'a> { } if let Some(row_group_layout) = row_group_fragment_layout.take() { - table_fragments.push(Fragment::Box(row_group_layout.finish( + table_fragments.push(row_group_layout.finish( layout_context, positioning_context, containing_block_for_logical_conversion, containing_block_for_children, - ))); + )); } let content_rect = LogicalRect { @@ -1973,14 +1979,14 @@ impl<'a> TableLayout<'a> { }; let row = row.borrow(); - if row.style.get_inherited_box().visibility == Visibility::Collapse { + if row.base.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].borrow(), None => return false, }; - row_group.style.get_inherited_box().visibility == Visibility::Collapse + row_group.base.style.get_inherited_box().visibility == Visibility::Collapse } fn is_column_collapsed(&self, column_index: usize) -> bool { @@ -1988,14 +1994,14 @@ impl<'a> TableLayout<'a> { return false; }; let column = column.borrow(); - if column.style.get_inherited_box().visibility == Visibility::Collapse { + if column.base.style.get_inherited_box().visibility == Visibility::Collapse { return true; } let col_group = match column.group_index { Some(group_index) => self.table.column_groups[group_index].borrow(), None => return false, }; - col_group.style.get_inherited_box().visibility == Visibility::Collapse + col_group.base.style.get_inherited_box().visibility == Visibility::Collapse } #[allow(clippy::too_many_arguments)] @@ -2088,7 +2094,7 @@ impl<'a> TableLayout<'a> { let column_group = column_group.borrow(); let rect = make_relative_to_row_start(dimensions.get_column_group_rect(&column_group)); fragment.add_extra_background(ExtraBackground { - style: column_group.style.clone(), + style: column_group.base.style.clone(), rect, }) } @@ -2097,7 +2103,7 @@ impl<'a> TableLayout<'a> { if !column.is_anonymous { let rect = make_relative_to_row_start(dimensions.get_column_rect(column_index)); fragment.add_extra_background(ExtraBackground { - style: column.style.clone(), + style: column.base.style.clone(), rect, }) } @@ -2110,7 +2116,7 @@ impl<'a> TableLayout<'a> { let rect = make_relative_to_row_start(dimensions.get_row_group_rect(&row_group.borrow())); fragment.add_extra_background(ExtraBackground { - style: row_group.borrow().style.clone(), + style: row_group.borrow().base.style.clone(), rect, }) } @@ -2118,13 +2124,14 @@ impl<'a> TableLayout<'a> { let row = row.borrow(); let rect = make_relative_to_row_start(row_fragment_layout.rect); fragment.add_extra_background(ExtraBackground { - style: row.style.clone(), + style: row.base.style.clone(), rect, }) } - row_fragment_layout - .fragments - .push(Fragment::Box(ArcRefCell::new(fragment))); + + let fragment = Fragment::Box(ArcRefCell::new(fragment)); + cell.base.set_fragment(fragment.clone()); + row_fragment_layout.fragments.push(fragment); } fn make_fragments_for_columns_and_column_groups( @@ -2136,11 +2143,11 @@ impl<'a> TableLayout<'a> { let column_group = column_group.borrow(); if !column_group.is_empty() { fragments.push(Fragment::Positioning(PositioningFragment::new_empty( - column_group.base_fragment_info, + column_group.base.base_fragment_info, dimensions .get_column_group_rect(&column_group) .as_physical(None), - column_group.style.clone(), + column_group.base.style.clone(), ))); } } @@ -2148,9 +2155,9 @@ impl<'a> TableLayout<'a> { for (column_index, column) in self.table.columns.iter().enumerate() { let column = column.borrow(); fragments.push(Fragment::Positioning(PositioningFragment::new_empty( - column.base_fragment_info, + column.base.base_fragment_info, dimensions.get_column_rect(column_index).as_physical(None), - column.style.clone(), + column.base.style.clone(), ))); } } @@ -2314,7 +2321,7 @@ impl<'a> RowFragmentLayout<'a> { Self { row: table_row, rect, - positioning_context: PositioningContext::new_for_style(&table_row.style), + positioning_context: PositioningContext::new_for_style(&table_row.base.style), containing_block, fragments: Vec::new(), } @@ -2326,10 +2333,10 @@ impl<'a> RowFragmentLayout<'a> { containing_block_for_logical_conversion: &ContainingBlock, containing_block_for_children: &ContainingBlock, row_group_fragment_layout: &mut Option<RowGroupFragmentLayout>, - ) -> ArcRefCell<BoxFragment> { + ) -> Fragment { if self.positioning_context.is_some() { self.rect.start_corner += - relative_adjustement(&self.row.style, containing_block_for_children); + relative_adjustement(&self.row.base.style, containing_block_for_children); } let (inline_size, block_size) = if let Some(row_group_layout) = row_group_fragment_layout { @@ -2354,8 +2361,8 @@ impl<'a> RowFragmentLayout<'a> { }; let mut row_fragment = BoxFragment::new( - self.row.base_fragment_info, - self.row.style.clone(), + self.row.base.base_fragment_info, + self.row.base.style.clone(), self.fragments, self.rect.as_physical(Some(&row_group_containing_block)), PhysicalSides::zero(), /* padding */ @@ -2375,13 +2382,14 @@ impl<'a> RowFragmentLayout<'a> { positioning_context.append(row_positioning_context); } - ArcRefCell::new(row_fragment) + let fragment = Fragment::Box(ArcRefCell::new(row_fragment)); + self.row.base.set_fragment(fragment.clone()); + fragment } } struct RowGroupFragmentLayout { - base_fragment_info: BaseFragmentInfo, - style: Arc<ComputedValues>, + row_group: ArcRefCell<TableTrackGroup>, rect: LogicalRect<Au>, positioning_context: Option<PositioningContext>, index: usize, @@ -2390,16 +2398,21 @@ struct RowGroupFragmentLayout { impl RowGroupFragmentLayout { fn new( - row_group: &TableTrackGroup, + row_group: ArcRefCell<TableTrackGroup>, index: usize, dimensions: &TableAndTrackDimensions, ) -> Self { - let rect = dimensions.get_row_group_rect(row_group); + let (rect, positioning_context) = { + let row_group = row_group.borrow(); + ( + dimensions.get_row_group_rect(&row_group), + PositioningContext::new_for_style(&row_group.base.style), + ) + }; Self { - base_fragment_info: row_group.base_fragment_info, - style: row_group.style.clone(), + row_group, rect, - positioning_context: PositioningContext::new_for_style(&row_group.style), + positioning_context, index, fragments: Vec::new(), } @@ -2411,15 +2424,16 @@ impl RowGroupFragmentLayout { table_positioning_context: &mut PositioningContext, containing_block_for_logical_conversion: &ContainingBlock, containing_block_for_children: &ContainingBlock, - ) -> ArcRefCell<BoxFragment> { + ) -> Fragment { + let row_group = self.row_group.borrow(); if self.positioning_context.is_some() { self.rect.start_corner += - relative_adjustement(&self.style, containing_block_for_children); + relative_adjustement(&row_group.base.style, containing_block_for_children); } let mut row_group_fragment = BoxFragment::new( - self.base_fragment_info, - self.style, + row_group.base.base_fragment_info, + row_group.base.style.clone(), self.fragments, self.rect .as_physical(Some(containing_block_for_logical_conversion)), @@ -2436,7 +2450,9 @@ impl RowGroupFragmentLayout { table_positioning_context.append(row_positioning_context); } - ArcRefCell::new(row_group_fragment) + let fragment = Fragment::Box(ArcRefCell::new(row_group_fragment)); + row_group.base.set_fragment(fragment.clone()); + fragment } } @@ -2634,7 +2650,7 @@ impl Table { max: max_size, percentage: percentage_size, } = CellOrColumnOuterSizes::new( - &column.style, + &column.base.style, writing_mode, &Default::default(), is_in_fixed_mode, @@ -2672,8 +2688,8 @@ impl Table { // (except for new layout boxes like grid and flex containers). Note that // other browsers don't seem to use the min and max sizing properties here. let row = row.borrow(); - let size = row.style.box_size(writing_mode); - let max_size = row.style.max_box_size(writing_mode); + let size = row.base.style.box_size(writing_mode); + let max_size = row.base.style.max_box_size(writing_mode); let percentage_contribution = get_size_percentage_contribution(&size, &max_size); CellOrTrackMeasure { @@ -2769,14 +2785,14 @@ impl Table { impl TableTrack { #[inline] pub(crate) fn layout_style(&self) -> LayoutStyle { - LayoutStyle::Default(&self.style) + LayoutStyle::Default(&self.base.style) } } impl TableTrackGroup { #[inline] pub(crate) fn layout_style(&self) -> LayoutStyle { - LayoutStyle::Default(&self.style) + LayoutStyle::Default(&self.base.style) } } diff --git a/components/layout_2020/table/mod.rs b/components/layout_2020/table/mod.rs index 749c2fbac04..42978416a23 100644 --- a/components/layout_2020/table/mod.rs +++ b/components/layout_2020/table/mod.rs @@ -84,7 +84,7 @@ use super::flow::BlockFormattingContext; use crate::cell::ArcRefCell; use crate::flow::BlockContainer; use crate::formatting_contexts::IndependentFormattingContext; -use crate::fragment_tree::BaseFragmentInfo; +use crate::fragment_tree::{BaseFragmentInfo, Fragment}; use crate::geom::PhysicalVec; use crate::layout_box_base::LayoutBoxBase; use crate::style_ext::BorderStyleColor; @@ -272,13 +272,10 @@ impl TableSlot { } /// A row or column of a table. -#[derive(Clone, Debug)] +#[derive(Debug)] pub struct TableTrack { - /// The [`BaseFragmentInfo`] of this cell. - base_fragment_info: BaseFragmentInfo, - - /// The style of this table column. - style: Arc<ComputedValues>, + /// The [`LayoutBoxBase`] of this [`TableTrack`]. + base: LayoutBoxBase, /// The index of the table row or column group parent in the table's list of row or column /// groups. @@ -299,11 +296,8 @@ pub enum TableTrackGroupType { #[derive(Debug)] pub struct TableTrackGroup { - /// The [`BaseFragmentInfo`] of this [`TableTrackGroup`]. - base_fragment_info: BaseFragmentInfo, - - /// The style of this [`TableTrackGroup`]. - style: Arc<ComputedValues>, + /// The [`LayoutBoxBase`] of this [`TableTrackGroup`]. + base: LayoutBoxBase, /// The type of this [`TableTrackGroup`]. group_type: TableTrackGroupType, @@ -366,8 +360,19 @@ impl TableLevelBox { TableLevelBox::Cell(cell) => { cell.borrow().base.invalidate_cached_fragment(); }, - TableLevelBox::TrackGroup(..) => {}, - TableLevelBox::Track(..) => {}, + TableLevelBox::TrackGroup(track_group) => { + track_group.borrow().base.invalidate_cached_fragment() + }, + TableLevelBox::Track(track) => track.borrow().base.invalidate_cached_fragment(), + } + } + + pub(crate) fn fragments(&self) -> Vec<Fragment> { + match self { + TableLevelBox::Caption(caption) => caption.borrow().context.base.fragments(), + TableLevelBox::Cell(cell) => cell.borrow().base.fragments(), + TableLevelBox::TrackGroup(track_group) => track_group.borrow().base.fragments(), + TableLevelBox::Track(track) => track.borrow().base.fragments(), } } } |