diff options
Diffstat (limited to 'components/layout/table/construct.rs')
-rw-r--r-- | components/layout/table/construct.rs | 105 |
1 files changed, 50 insertions, 55 deletions
diff --git a/components/layout/table/construct.rs b/components/layout/table/construct.rs index 56e11320be4..133904db7ae 100644 --- a/components/layout/table/construct.rs +++ b/components/layout/table/construct.rs @@ -8,7 +8,7 @@ use std::iter::repeat; use atomic_refcell::AtomicRef; use log::warn; -use script_layout_interface::wrapper_traits::ThreadSafeLayoutNode; +use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode}; use servo_arc::Arc; use style::properties::ComputedValues; use style::properties::style_structs::Font; @@ -22,14 +22,14 @@ use super::{ use crate::PropagatedBoxTreeData; use crate::cell::ArcRefCell; use crate::context::LayoutContext; -use crate::dom::{BoxSlot, LayoutBox, NodeExt}; +use crate::dom::{BoxSlot, LayoutBox}; use crate::dom_traversal::{Contents, NodeAndStyleInfo, NonReplacedContents, TraversalHandler}; use crate::flow::{BlockContainerBuilder, BlockFormattingContext}; use crate::formatting_contexts::{ IndependentFormattingContext, IndependentFormattingContextContents, IndependentNonReplacedContents, }; -use crate::fragment_tree::BaseFragmentInfo; +use crate::fragment_tree::{BackgroundStyle, BaseFragmentInfo, SharedBackgroundStyle}; use crate::layout_box_base::LayoutBoxBase; use crate::style_ext::{DisplayGeneratingBox, DisplayLayoutInternal}; @@ -50,17 +50,17 @@ impl ResolvedSlotAndLocation<'_> { } } -pub(crate) enum AnonymousTableContent<'dom, Node> { - Text(NodeAndStyleInfo<Node>, Cow<'dom, str>), +pub(crate) enum AnonymousTableContent<'dom> { + Text(NodeAndStyleInfo<'dom>, Cow<'dom, str>), Element { - info: NodeAndStyleInfo<Node>, + info: NodeAndStyleInfo<'dom>, display: DisplayGeneratingBox, contents: Contents, box_slot: BoxSlot<'dom>, }, } -impl<Node> AnonymousTableContent<'_, Node> { +impl AnonymousTableContent<'_> { fn is_whitespace_only(&self) -> bool { match self { Self::Element { .. } => false, @@ -74,9 +74,9 @@ impl<Node> AnonymousTableContent<'_, Node> { } impl Table { - pub(crate) fn construct<'dom>( + pub(crate) fn construct( context: &LayoutContext, - info: &NodeAndStyleInfo<impl NodeExt<'dom>>, + info: &NodeAndStyleInfo, grid_style: Arc<ComputedValues>, contents: NonReplacedContents, propagated_data: PropagatedBoxTreeData, @@ -91,15 +91,12 @@ impl Table { traversal.finish() } - pub(crate) fn construct_anonymous<'dom, Node>( + pub(crate) fn construct_anonymous<'dom>( context: &LayoutContext, - parent_info: &NodeAndStyleInfo<Node>, - contents: Vec<AnonymousTableContent<'dom, Node>>, + parent_info: &NodeAndStyleInfo<'dom>, + contents: Vec<AnonymousTableContent<'dom>>, propagated_data: PropagatedBoxTreeData, - ) -> (NodeAndStyleInfo<Node>, IndependentFormattingContext) - where - Node: crate::dom::NodeExt<'dom>, - { + ) -> (NodeAndStyleInfo<'dom>, IndependentFormattingContext) { let table_info = parent_info .pseudo(context, PseudoElement::ServoAnonymousTable) .expect("Should never fail to create anonymous table info."); @@ -645,9 +642,9 @@ impl TableBuilder { } } -pub(crate) struct TableBuilderTraversal<'style, 'dom, Node> { +pub(crate) struct TableBuilderTraversal<'style, 'dom> { context: &'style LayoutContext<'style>, - info: &'style NodeAndStyleInfo<Node>, + info: &'style NodeAndStyleInfo<'dom>, /// The value of the [`PropagatedBoxTreeData`] to use, either for the row group /// if processing one or for the table itself if outside a row group. @@ -657,19 +654,16 @@ pub(crate) struct TableBuilderTraversal<'style, 'dom, Node> { /// into another struct so that we can write unit tests against the builder. builder: TableBuilder, - current_anonymous_row_content: Vec<AnonymousTableContent<'dom, Node>>, + current_anonymous_row_content: Vec<AnonymousTableContent<'dom>>, /// The index of the current row group, if there is one. current_row_group_index: Option<usize>, } -impl<'style, 'dom, Node> TableBuilderTraversal<'style, 'dom, Node> -where - Node: NodeExt<'dom>, -{ +impl<'style, 'dom> TableBuilderTraversal<'style, 'dom> { pub(crate) fn new( context: &'style LayoutContext<'style>, - info: &'style NodeAndStyleInfo<Node>, + info: &'style NodeAndStyleInfo<'dom>, grid_style: Arc<ComputedValues>, propagated_data: PropagatedBoxTreeData, ) -> Self { @@ -728,9 +722,10 @@ where let style = anonymous_info.style.clone(); self.push_table_row(ArcRefCell::new(TableTrack { - base: LayoutBoxBase::new((&anonymous_info).into(), style), + base: LayoutBoxBase::new((&anonymous_info).into(), style.clone()), group_index: self.current_row_group_index, is_anonymous: true, + shared_background_style: SharedBackgroundStyle::new(BackgroundStyle(style)), })); } @@ -745,11 +740,8 @@ where } } -impl<'dom, Node: 'dom> TraversalHandler<'dom, Node> for TableBuilderTraversal<'_, 'dom, Node> -where - Node: NodeExt<'dom>, -{ - fn handle_text(&mut self, info: &NodeAndStyleInfo<Node>, text: Cow<'dom, str>) { +impl<'dom> TraversalHandler<'dom> for TableBuilderTraversal<'_, 'dom> { + fn handle_text(&mut self, info: &NodeAndStyleInfo<'dom>, text: Cow<'dom, str>) { self.current_anonymous_row_content .push(AnonymousTableContent::Text(info.clone(), text)); } @@ -757,7 +749,7 @@ where /// <https://html.spec.whatwg.org/multipage/#forming-a-table> fn handle_element( &mut self, - info: &NodeAndStyleInfo<Node>, + info: &NodeAndStyleInfo<'dom>, display: DisplayGeneratingBox, contents: Contents, box_slot: BoxSlot<'dom>, @@ -775,6 +767,9 @@ where base: LayoutBoxBase::new(info.into(), info.style.clone()), group_type: internal.into(), track_range: next_row_index..next_row_index, + shared_background_style: SharedBackgroundStyle::new(BackgroundStyle( + info.style.clone(), + )), }); self.builder.table.row_groups.push(row_group.clone()); @@ -817,6 +812,9 @@ where base: LayoutBoxBase::new(info.into(), info.style.clone()), group_index: self.current_row_group_index, is_anonymous: false, + shared_background_style: SharedBackgroundStyle::new(BackgroundStyle( + info.style.clone(), + )), }); self.push_table_row(row.clone()); box_slot.set(LayoutBox::TableLevelBox(TableLevelBox::Track(row))); @@ -862,6 +860,9 @@ where base: LayoutBoxBase::new(info.into(), info.style.clone()), group_type: internal.into(), track_range: first_column..self.builder.table.columns.len(), + shared_background_style: SharedBackgroundStyle::new(BackgroundStyle( + info.style.clone(), + )), }); self.builder.table.column_groups.push(column_group.clone()); box_slot.set(LayoutBox::TableLevelBox(TableLevelBox::TrackGroup( @@ -916,26 +917,23 @@ where } } -struct TableRowBuilder<'style, 'builder, 'dom, 'a, Node> { - table_traversal: &'builder mut TableBuilderTraversal<'style, 'dom, Node>, +struct TableRowBuilder<'style, 'builder, 'dom, 'a> { + table_traversal: &'builder mut TableBuilderTraversal<'style, 'dom>, /// The [`NodeAndStyleInfo`] of this table row, which we use to /// construct anonymous table cells. - info: &'a NodeAndStyleInfo<Node>, + info: &'a NodeAndStyleInfo<'dom>, - current_anonymous_cell_content: Vec<AnonymousTableContent<'dom, Node>>, + current_anonymous_cell_content: Vec<AnonymousTableContent<'dom>>, /// The [`PropagatedBoxTreeData`] to use for all children of this row. propagated_data: PropagatedBoxTreeData, } -impl<'style, 'builder, 'dom, 'a, Node: 'dom> TableRowBuilder<'style, 'builder, 'dom, 'a, Node> -where - Node: NodeExt<'dom>, -{ +impl<'style, 'builder, 'dom, 'a> TableRowBuilder<'style, 'builder, 'dom, 'a> { fn new( - table_traversal: &'builder mut TableBuilderTraversal<'style, 'dom, Node>, - info: &'a NodeAndStyleInfo<Node>, + table_traversal: &'builder mut TableBuilderTraversal<'style, 'dom>, + info: &'a NodeAndStyleInfo<'dom>, propagated_data: PropagatedBoxTreeData, ) -> Self { table_traversal.builder.start_row(); @@ -996,11 +994,8 @@ where } } -impl<'dom, Node: 'dom> TraversalHandler<'dom, Node> for TableRowBuilder<'_, '_, 'dom, '_, Node> -where - Node: NodeExt<'dom>, -{ - fn handle_text(&mut self, info: &NodeAndStyleInfo<Node>, text: Cow<'dom, str>) { +impl<'dom> TraversalHandler<'dom> for TableRowBuilder<'_, '_, 'dom, '_> { + fn handle_text(&mut self, info: &NodeAndStyleInfo<'dom>, text: Cow<'dom, str>) { self.current_anonymous_cell_content .push(AnonymousTableContent::Text(info.clone(), text)); } @@ -1008,7 +1003,7 @@ where /// <https://html.spec.whatwg.org/multipage/#algorithm-for-processing-rows> fn handle_element( &mut self, - info: &NodeAndStyleInfo<Node>, + info: &NodeAndStyleInfo<'dom>, display: DisplayGeneratingBox, contents: Contents, box_slot: BoxSlot<'dom>, @@ -1091,14 +1086,11 @@ struct TableColumnGroupBuilder { columns: Vec<ArcRefCell<TableTrack>>, } -impl<'dom, Node: 'dom> TraversalHandler<'dom, Node> for TableColumnGroupBuilder -where - Node: NodeExt<'dom>, -{ - fn handle_text(&mut self, _info: &NodeAndStyleInfo<Node>, _text: Cow<'dom, str>) {} +impl<'dom> TraversalHandler<'dom> for TableColumnGroupBuilder { + fn handle_text(&mut self, _info: &NodeAndStyleInfo<'dom>, _text: Cow<'dom, str>) {} fn handle_element( &mut self, - info: &NodeAndStyleInfo<Node>, + info: &NodeAndStyleInfo<'dom>, display: DisplayGeneratingBox, _contents: Contents, box_slot: BoxSlot<'dom>, @@ -1134,9 +1126,9 @@ impl From<DisplayLayoutInternal> for TableTrackGroupType { } } -fn add_column<'dom, Node: NodeExt<'dom>>( +fn add_column( collection: &mut Vec<ArcRefCell<TableTrack>>, - column_info: &NodeAndStyleInfo<Node>, + column_info: &NodeAndStyleInfo, group_index: Option<usize>, is_anonymous: bool, ) -> ArcRefCell<TableTrack> { @@ -1153,6 +1145,9 @@ fn add_column<'dom, Node: NodeExt<'dom>>( base: LayoutBoxBase::new(column_info.into(), column_info.style.clone()), group_index, is_anonymous, + shared_background_style: SharedBackgroundStyle::new(BackgroundStyle( + column_info.style.clone(), + )), }); collection.extend(repeat(column.clone()).take(span as usize)); column |