layout: Store shared styles for table backgrounds in SharedBackgroundStyle (#36893)

Table cells share background styles with their track and track group
boxes. When a track and track group style is repaired, this new data
structure will allow reparing the style of the cell `Fragment`s without
having to lay the table out again or walk through `Fragment`s and
individually repair their background styles.

Testing: This doesn't change behavior and is thus tested by existing
WPT tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2025-05-07 13:44:59 +02:00 committed by GitHub
parent 68a76baea3
commit 348eede37b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 38 additions and 10 deletions

View file

@ -29,7 +29,7 @@ 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};
@ -722,9 +722,10 @@ impl<'style, 'dom> TableBuilderTraversal<'style, 'dom> {
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)),
}));
}
@ -766,6 +767,9 @@ impl<'dom> TraversalHandler<'dom> for TableBuilderTraversal<'_, 'dom> {
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());
@ -808,6 +812,9 @@ impl<'dom> TraversalHandler<'dom> for TableBuilderTraversal<'_, 'dom> {
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)));
@ -853,6 +860,9 @@ impl<'dom> TraversalHandler<'dom> for TableBuilderTraversal<'_, 'dom> {
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(
@ -1135,6 +1145,9 @@ fn add_column(
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