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

@ -91,23 +91,25 @@ pub(crate) enum BlockLevelBox {
impl BlockLevelBox {
pub(crate) fn invalidate_cached_fragment(&self) {
self.with_base(LayoutBoxBase::invalidate_cached_fragment);
}
pub(crate) fn fragments(&self) -> Vec<Fragment> {
self.with_base(LayoutBoxBase::fragments)
}
pub(crate) fn with_base<T>(&self, callback: impl Fn(&LayoutBoxBase) -> T) -> T {
match self {
BlockLevelBox::Independent(independent_formatting_context) => {
&independent_formatting_context.base
callback(&independent_formatting_context.base)
},
BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(positioned_box) => {
positioned_box
.borrow()
.context
.base
.invalidate_cached_fragment();
return;
callback(&positioned_box.borrow().context.base)
},
BlockLevelBox::OutOfFlowFloatBox(float_box) => &float_box.contents.base,
BlockLevelBox::OutsideMarker(outside_marker) => &outside_marker.base,
BlockLevelBox::SameFormattingContextBlock { base, .. } => base,
BlockLevelBox::OutOfFlowFloatBox(float_box) => callback(&float_box.contents.base),
BlockLevelBox::OutsideMarker(outside_marker) => callback(&outside_marker.base),
BlockLevelBox::SameFormattingContextBlock { base, .. } => callback(base),
}
.invalidate_cached_fragment();
}
fn contains_floats(&self) -> bool {
@ -770,7 +772,7 @@ impl BlockLevelBox {
collapsible_with_parent_start_margin: Option<CollapsibleWithParentStartMargin>,
ignore_block_margins_for_stretch: LogicalSides1D<bool>,
) -> Fragment {
match self {
let fragment = match self {
BlockLevelBox::SameFormattingContextBlock { base, contents, .. } => Fragment::Box(
ArcRefCell::new(positioning_context.layout_maybe_position_relative_fragment(
layout_context,
@ -836,7 +838,11 @@ impl BlockLevelBox {
sequential_layout_state,
collapsible_with_parent_start_margin,
),
}
};
self.with_base(|base| base.set_fragment(fragment.clone()));
fragment
}
fn inline_content_sizes(