layout: Consider transform for bounding box queries (#37871)

The recent changes that cached the Scroll Tree present an opportunity to
calculate the queries that consider transform and scroll (dubbed as post
composite queries) accurately.

This PR propose a solution for this calculation by noting the lowest
scroll tree nodes that would affect a fragment. To do this, each
fragment would store a new attribute `spatial_tree_node` -- scroll tree
node id that we could use for the query. This referencing is considered
because the scroll tree node construction is managed by the fragment
itself. Therefore it would ease the managing the possibly stale
reference and future query cache invalidation considering the
development of incremental layout.

The bounding box query then could transform the bounding content rect of
a fragment using the computed current transformation matrix.

Fixes: https://github.com/servo/servo/issues/35768
Testing: Existing and new WPT

---------

Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
Signed-off-by: Jo Steven Novaryo <jo.steven.novaryo@huawei.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Jo Steven Novaryo 2025-07-30 16:13:54 +08:00 committed by GitHub
parent 37ac4ffeb4
commit 900dd8d191
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 304 additions and 146 deletions

View file

@ -4,6 +4,7 @@
use app_units::{Au, MAX_AU, MIN_AU};
use atomic_refcell::AtomicRefCell;
use base::id::ScrollTreeNodeId;
use base::print_tree::PrintTree;
use malloc_size_of_derive::MallocSizeOf;
use servo_arc::Arc as ServoArc;
@ -109,6 +110,12 @@ pub(crate) struct BoxFragment {
/// Additional information for block-level boxes.
pub block_level_layout_info: Option<Box<BlockLevelLayoutInfo>>,
/// The containing spatial tree node of this [`BoxFragment`]. This is assigned during
/// `StackingContextTree` construction, so isn't available before that time. This is
/// used to for determining final viewport size and position of this node and will
/// also be used in the future for hit testing.
pub spatial_tree_node: AtomicRefCell<Option<ScrollTreeNodeId>>,
}
impl BoxFragment {
@ -138,6 +145,7 @@ impl BoxFragment {
background_mode: BackgroundMode::Normal,
specific_layout_info,
block_level_layout_info: None,
spatial_tree_node: AtomicRefCell::default(),
}
}
@ -270,6 +278,10 @@ impl BoxFragment {
rect.translate(self.cumulative_containing_block_rect.origin.to_vector())
}
pub(crate) fn cumulative_border_box_rect(&self) -> PhysicalRect<Au> {
self.offset_by_containing_block(&self.border_rect())
}
pub(crate) fn padding_rect(&self) -> PhysicalRect<Au> {
self.content_rect.outer_rect(self.padding)
}