diff options
author | Oriol Brufau <obrufau@igalia.com> | 2024-06-10 11:26:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-10 09:26:46 +0000 |
commit | 6f414df867cb8aea02dbc7009000096c17eeb3ab (patch) | |
tree | 437a70ec679bbb713a688ec1d187cb8da7604a88 /components/layout_2020/table/construct.rs | |
parent | 712f751d48ee7ec49f61484f5682a575ec49c402 (diff) | |
download | servo-6f414df867cb8aea02dbc7009000096c17eeb3ab.tar.gz servo-6f414df867cb8aea02dbc7009000096c17eeb3ab.zip |
Fix and unify 'span' attribute for table columns (#32467)
The attribute was only taken into account on columns that are immediate
children of tables, and on column groups. It was ignored on columns
within column groups.
This patch moves the logic into a helper function that is then called
from the three consumers.
Diffstat (limited to 'components/layout_2020/table/construct.rs')
-rw-r--r-- | components/layout_2020/table/construct.rs | 75 |
1 files changed, 41 insertions, 34 deletions
diff --git a/components/layout_2020/table/construct.rs b/components/layout_2020/table/construct.rs index ac689c951e1..fd2441daf18 100644 --- a/components/layout_2020/table/construct.rs +++ b/components/layout_2020/table/construct.rs @@ -777,20 +777,12 @@ where ::std::mem::forget(box_slot) }, DisplayLayoutInternal::TableColumn => { - let span = info - .node - .and_then(|node| node.to_threadsafe().get_span()) - .unwrap_or(1) - .min(1000); - - for _ in 0..span + 1 { - self.builder.table.columns.push(TableTrack { - base_fragment_info: info.into(), - style: info.style.clone(), - group_index: None, - is_anonymous: false, - }) - } + add_column( + &mut self.builder.table.columns, + info, + None, /* group_index */ + false, /* is_anonymous */ + ); // We are doing this until we have actually set a Box for this `BoxSlot`. ::std::mem::forget(box_slot) @@ -810,20 +802,11 @@ where let first_column = self.builder.table.columns.len(); if column_group_builder.columns.is_empty() { - let span = info - .node - .and_then(|node| node.to_threadsafe().get_span()) - .unwrap_or(1) - .min(1000) as usize; - - self.builder.table.columns.extend( - repeat(TableTrack { - base_fragment_info: info.into(), - style: info.style.clone(), - group_index: Some(column_group_index), - is_anonymous: true, - }) - .take(span), + add_column( + &mut self.builder.table.columns, + info, + Some(column_group_index), + true, /* is_anonymous */ ); } else { self.builder @@ -1068,12 +1051,12 @@ where ) { return; } - self.columns.push(TableTrack { - base_fragment_info: info.into(), - style: info.style.clone(), - group_index: Some(self.column_group_index), - is_anonymous: false, - }); + add_column( + &mut self.columns, + info, + Some(self.column_group_index), + false, /* is_anonymous */ + ); } } @@ -1088,3 +1071,27 @@ impl From<DisplayLayoutInternal> for TableTrackGroupType { } } } + +fn add_column<'dom, Node>( + collection: &mut Vec<TableTrack>, + column_info: &NodeAndStyleInfo<Node>, + group_index: Option<usize>, + is_anonymous: bool, +) where + Node: NodeExt<'dom>, +{ + let span = column_info + .node + .and_then(|node| node.to_threadsafe().get_span()) + .map_or(1, |span| span.min(1000) as usize); + + collection.extend( + repeat(TableTrack { + base_fragment_info: column_info.into(), + style: column_info.style.clone(), + group_index, + is_anonymous, + }) + .take(span), + ); +} |