layout: Store Fragment results in LayoutBoxBase and start using them for queries (#36583)

Start storing a link to laid-out `Fragment`s in `LayoutBoxBase`, so that
these are accessible for queries and eventually for incremental layout.
Some box tree data structures lacked a `LayoutBoxBase`, such as table
tracks and table track groups[^1].

In addition, start using these `Fragment`s for queries instead of
walking the entire `Fragment` tree. Currently, this isn't possible for
most queries as `Fragment`s do not cache their absolute offsets (which
are often necessary). This change uses the new box tree `Fragment`s for
most resolved style queries.

[^1]: Note that only rows and row groups store `Fragment`s as columsn
and
   colgroups do not produce any.

Testing: This is covered by existing tests.
Fixes: This is part of #36525.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2025-04-18 11:40:29 +02:00 committed by GitHub
parent fc201927ae
commit 2ee8427665
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 387 additions and 222 deletions

View file

@ -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(),
}
}
}