layout: Parameterize content box query (#38935)

Parameterize and rename both `Layout::content_box_query` and
`Layout::content_boxes_query` to support the query of rendered padding
area and content area that accounts for transform and scroll. Both of
these query have been misleading for a time since they are using border
box, instead of content box of a Node.

This PR adds a new type `layout_api::BoxAreaType` to be passed from
`ScriptThread` to `LayoutThread` to query the respective area. It is
then used for the query within `IntersectionObserver` to pass several
WPTs.

Testing: Existing WPT Coverage.

---------

Signed-off-by: Jo Steven Novaryo <jo.steven.novaryo@huawei.com>
This commit is contained in:
Jo Steven Novaryo 2025-08-27 10:27:53 +08:00 committed by GitHub
parent 32aba08be7
commit 10ca3b6fde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 125 additions and 125 deletions

View file

@ -302,6 +302,14 @@ impl BoxFragment {
rect.translate(self.cumulative_containing_block_rect.origin.to_vector())
}
pub(crate) fn cumulative_content_box_rect(&self) -> PhysicalRect<Au> {
self.offset_by_containing_block(&self.margin_rect())
}
pub(crate) fn cumulative_padding_box_rect(&self) -> PhysicalRect<Au> {
self.offset_by_containing_block(&self.padding_rect())
}
pub(crate) fn cumulative_border_box_rect(&self) -> PhysicalRect<Au> {
self.offset_by_containing_block(&self.border_rect())
}

View file

@ -9,6 +9,7 @@ use base::id::PipelineId;
use base::print_tree::PrintTree;
use euclid::{Point2D, Rect, Size2D, UnknownUnit};
use fonts::{ByteIndex, FontMetrics, GlyphStore};
use layout_api::BoxAreaType;
use malloc_size_of_derive::MallocSizeOf;
use range::Range as ServoRange;
use servo_arc::Arc as ServoArc;
@ -202,11 +203,13 @@ impl Fragment {
}
}
pub(crate) fn cumulative_border_box_rect(&self) -> Option<PhysicalRect<Au>> {
pub(crate) fn cumulative_box_area_rect(&self, area: BoxAreaType) -> Option<PhysicalRect<Au>> {
match self {
Fragment::Box(fragment) | Fragment::Float(fragment) => {
Some(fragment.borrow().cumulative_border_box_rect())
},
Fragment::Box(fragment) | Fragment::Float(fragment) => Some(match area {
BoxAreaType::Content => fragment.borrow().cumulative_content_box_rect(),
BoxAreaType::Padding => fragment.borrow().cumulative_padding_box_rect(),
BoxAreaType::Border => fragment.borrow().cumulative_border_box_rect(),
}),
Fragment::Positioning(fragment) => {
let fragment = fragment.borrow();
Some(fragment.offset_by_containing_block(&fragment.rect))