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

@ -53,9 +53,9 @@ use js::rust::{
MutableHandleValue,
};
use layout_api::{
ElementsFromPointFlags, ElementsFromPointResult, FragmentType, Layout, PendingImage,
PendingImageState, PendingRasterizationImage, QueryMsg, ReflowGoal, ReflowPhasesRun,
ReflowRequest, ReflowRequestRestyle, RestyleReason, TrustedNodeAddress,
BoxAreaType, ElementsFromPointFlags, ElementsFromPointResult, FragmentType, Layout,
PendingImage, PendingImageState, PendingRasterizationImage, QueryMsg, ReflowGoal,
ReflowPhasesRun, ReflowRequest, ReflowRequestRestyle, RestyleReason, TrustedNodeAddress,
combine_id_with_fragment_type,
};
use malloc_size_of::MallocSizeOf;
@ -2403,26 +2403,30 @@ impl Window {
)
}
/// Do the same kind of query as `Self::content_box_query`, but do not force a reflow.
/// Do the same kind of query as `Self::box_area_query`, but do not force a reflow.
/// This is used for things like `IntersectionObserver` which should observe the value
/// from the most recent reflow, but do not need it to reflect the current state of
/// the DOM / style.
pub(crate) fn content_box_query_without_reflow(&self, node: &Node) -> Option<UntypedRect<Au>> {
pub(crate) fn box_area_query_without_reflow(
&self,
node: &Node,
area: BoxAreaType,
) -> Option<UntypedRect<Au>> {
let layout = self.layout.borrow();
layout.ensure_stacking_context_tree(self.viewport_details.get());
layout.query_content_box(node.to_trusted_node_address())
layout.query_box_area(node.to_trusted_node_address(), area)
}
pub(crate) fn content_box_query(&self, node: &Node) -> Option<UntypedRect<Au>> {
self.layout_reflow(QueryMsg::ContentBox);
self.content_box_query_without_reflow(node)
pub(crate) fn box_area_query(&self, node: &Node, area: BoxAreaType) -> Option<UntypedRect<Au>> {
self.layout_reflow(QueryMsg::BoxArea);
self.box_area_query_without_reflow(node, area)
}
pub(crate) fn content_boxes_query(&self, node: &Node) -> Vec<UntypedRect<Au>> {
self.layout_reflow(QueryMsg::ContentBoxes);
pub(crate) fn box_areas_query(&self, node: &Node, area: BoxAreaType) -> Vec<UntypedRect<Au>> {
self.layout_reflow(QueryMsg::BoxAreas);
self.layout
.borrow()
.query_content_boxes(node.to_trusted_node_address())
.query_box_areas(node.to_trusted_node_address(), area)
}
pub(crate) fn client_rect_query(&self, node: &Node) -> UntypedRect<i32> {