layout: Properly propagate text decoration values in tables (#31487)

Instead of just taking the value from the ancestor outside the table,
combine the values when constructing the table.
This commit is contained in:
Martin Robinson 2024-03-04 16:10:36 +01:00 committed by GitHub
parent e76770202c
commit f7f8c24072
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -63,8 +63,9 @@ impl Table {
contents: NonReplacedContents, contents: NonReplacedContents,
propagated_text_decoration_line: TextDecorationLine, propagated_text_decoration_line: TextDecorationLine,
) -> Self { ) -> Self {
let mut traversal = let text_decoration_line =
TableBuilderTraversal::new(context, info, propagated_text_decoration_line); propagated_text_decoration_line | info.style.clone_text_decoration_line();
let mut traversal = TableBuilderTraversal::new(context, info, text_decoration_line);
contents.traverse(context, info, &mut traversal); contents.traverse(context, info, &mut traversal);
traversal.finish() traversal.finish()
} }
@ -589,9 +590,9 @@ pub(crate) struct TableBuilderTraversal<'style, 'dom, Node> {
context: &'style LayoutContext<'style>, context: &'style LayoutContext<'style>,
info: &'style NodeAndStyleInfo<Node>, info: &'style NodeAndStyleInfo<Node>,
/// Propagated value for text-decoration-line, used to construct the block /// The value of the [`TextDecorationLine`] to use, either for the row group
/// contents of table cells. /// if processing one or for the table itself if outside a row group.
propagated_text_decoration_line: TextDecorationLine, current_text_decoration_line: TextDecorationLine,
/// The [`TableBuilder`] for this [`TableBuilderTraversal`]. This is separated /// The [`TableBuilder`] for this [`TableBuilderTraversal`]. This is separated
/// into another struct so that we can write unit tests against the builder. /// into another struct so that we can write unit tests against the builder.
@ -610,12 +611,12 @@ where
pub(crate) fn new( pub(crate) fn new(
context: &'style LayoutContext<'style>, context: &'style LayoutContext<'style>,
info: &'style NodeAndStyleInfo<Node>, info: &'style NodeAndStyleInfo<Node>,
propagated_text_decoration_line: TextDecorationLine, text_decoration_line: TextDecorationLine,
) -> Self { ) -> Self {
TableBuilderTraversal { TableBuilderTraversal {
context, context,
info, info,
propagated_text_decoration_line, current_text_decoration_line: text_decoration_line,
builder: TableBuilder::new(info.style.clone()), builder: TableBuilder::new(info.style.clone()),
current_anonymous_row_content: Vec::new(), current_anonymous_row_content: Vec::new(),
current_row_group_index: None, current_row_group_index: None,
@ -644,7 +645,8 @@ where
&self.info.style, &self.info.style,
); );
let anonymous_info = self.info.new_replacing_style(anonymous_style); let anonymous_info = self.info.new_replacing_style(anonymous_style);
let mut row_builder = TableRowBuilder::new(self, &anonymous_info); let mut row_builder =
TableRowBuilder::new(self, &anonymous_info, self.current_text_decoration_line);
for cell_content in row_content { for cell_content in row_content {
match cell_content { match cell_content {
@ -703,8 +705,13 @@ where
track_range: next_row_index..next_row_index, track_range: next_row_index..next_row_index,
}); });
let previous_text_decoration_line = self.current_text_decoration_line;
self.current_text_decoration_line =
self.current_text_decoration_line | info.style.clone_text_decoration_line();
let new_row_group_index = self.builder.table.row_groups.len() - 1; let new_row_group_index = self.builder.table.row_groups.len() - 1;
self.current_row_group_index = Some(new_row_group_index); self.current_row_group_index = Some(new_row_group_index);
NonReplacedContents::try_from(contents).unwrap().traverse( NonReplacedContents::try_from(contents).unwrap().traverse(
self.context, self.context,
info, info,
@ -712,6 +719,7 @@ where
); );
self.current_row_group_index = None; self.current_row_group_index = None;
self.current_text_decoration_line = previous_text_decoration_line;
self.builder.incoming_rowspans.clear(); self.builder.incoming_rowspans.clear();
// We are doing this until we have actually set a Box for this `BoxSlot`. // We are doing this until we have actually set a Box for this `BoxSlot`.
@ -722,7 +730,8 @@ where
let context = self.context; let context = self.context;
let mut row_builder = TableRowBuilder::new(self, info); let mut row_builder =
TableRowBuilder::new(self, info, self.current_text_decoration_line);
NonReplacedContents::try_from(contents).unwrap().traverse( NonReplacedContents::try_from(contents).unwrap().traverse(
context, context,
info, info,
@ -842,6 +851,9 @@ struct TableRowBuilder<'style, 'builder, 'dom, 'a, Node> {
info: &'a NodeAndStyleInfo<Node>, info: &'a NodeAndStyleInfo<Node>,
current_anonymous_cell_content: Vec<AnonymousTableContent<'dom, Node>>, current_anonymous_cell_content: Vec<AnonymousTableContent<'dom, Node>>,
/// The [`TextDecorationLine`] to use for all children of this row.
text_decoration_line: TextDecorationLine,
} }
impl<'style, 'builder, 'dom, 'a, Node: 'dom> TableRowBuilder<'style, 'builder, 'dom, 'a, Node> impl<'style, 'builder, 'dom, 'a, Node: 'dom> TableRowBuilder<'style, 'builder, 'dom, 'a, Node>
@ -851,13 +863,17 @@ where
fn new( fn new(
table_traversal: &'builder mut TableBuilderTraversal<'style, 'dom, Node>, table_traversal: &'builder mut TableBuilderTraversal<'style, 'dom, Node>,
info: &'a NodeAndStyleInfo<Node>, info: &'a NodeAndStyleInfo<Node>,
propagated_text_decoration_line: TextDecorationLine,
) -> Self { ) -> Self {
table_traversal.builder.start_row(); table_traversal.builder.start_row();
let text_decoration_line =
propagated_text_decoration_line | info.style.clone_text_decoration_line();
TableRowBuilder { TableRowBuilder {
table_traversal, table_traversal,
info, info,
current_anonymous_cell_content: Vec::new(), current_anonymous_cell_content: Vec::new(),
text_decoration_line,
} }
} }
@ -881,11 +897,8 @@ where
&self.info.style, &self.info.style,
); );
let anonymous_info = self.info.new_replacing_style(anonymous_style); let anonymous_info = self.info.new_replacing_style(anonymous_style);
let mut builder = BlockContainerBuilder::new( let mut builder =
context, BlockContainerBuilder::new(context, &anonymous_info, self.text_decoration_line);
&anonymous_info,
self.table_traversal.propagated_text_decoration_line,
);
for cell_content in self.current_anonymous_cell_content.drain(..) { for cell_content in self.current_anonymous_cell_content.drain(..) {
match cell_content { match cell_content {
@ -964,7 +977,7 @@ where
self.table_traversal.context, self.table_traversal.context,
info, info,
non_replaced_contents, non_replaced_contents,
self.table_traversal.propagated_text_decoration_line, self.text_decoration_line,
false, /* is_list_item */ false, /* is_list_item */
) )
}, },