layout: Add a query for getting the effective overflow of an element and use it in script (#42251)

In layout calculation within script, Instead of relying on the computed
values for overflow, query the overflow from layout for its used value
to accurately reflect whether an element establish a scroll container.
This query will be used for `IntersectionObserver` as well.

Testing: There are new `IntersectionObserver` WPT failures:
- `intersection-observer/isIntersecting-change-events.html`
- `intersection-observer/containing-block.html`

The failures are more than likely a false positive because intersection
observation steps wasn't supposed to trigger a reflow, but it was
before. It could be caused by the implementation of
`IntersectionObserver` in major UAs being a little bit different from
the spec in the calculation of `threshold` and `isIntersecting` .

---------

Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Steven Novaryo
2026-03-05 19:35:32 +08:00
committed by GitHub
parent 1b2ce4aaad
commit a672397f2d
13 changed files with 193 additions and 61 deletions

View File

@@ -55,11 +55,12 @@ use js::rust::{
MutableHandleValue,
};
use layout_api::{
BoxAreaType, CSSPixelRectIterator, ElementsFromPointFlags, ElementsFromPointResult,
FragmentType, Layout, LayoutImageDestination, PendingImage, PendingImageState,
PendingRasterizationImage, PhysicalSides, QueryMsg, ReflowGoal, ReflowPhasesRun, ReflowRequest,
ReflowRequestRestyle, ReflowStatistics, RestyleReason, ScrollContainerQueryFlags,
ScrollContainerResponse, TrustedNodeAddress, combine_id_with_fragment_type,
AxesOverflow, BoxAreaType, CSSPixelRectIterator, ElementsFromPointFlags,
ElementsFromPointResult, FragmentType, Layout, LayoutImageDestination, PendingImage,
PendingImageState, PendingRasterizationImage, PhysicalSides, QueryMsg, ReflowGoal,
ReflowPhasesRun, ReflowRequest, ReflowRequestRestyle, ReflowStatistics, RestyleReason,
ScrollContainerQueryFlags, ScrollContainerResponse, TrustedNodeAddress,
combine_id_with_fragment_type,
};
use malloc_size_of::MallocSizeOf;
use media::WindowGLContext;
@@ -3023,6 +3024,20 @@ impl Window {
self.layout().query_elements_from_point(point, flags)
}
pub(crate) fn query_effective_overflow(&self, node: &Node) -> Option<AxesOverflow> {
self.layout_reflow(QueryMsg::EffectiveOverflow);
self.query_effective_overflow_without_reflow(node)
}
pub(crate) fn query_effective_overflow_without_reflow(
&self,
node: &Node,
) -> Option<AxesOverflow> {
self.layout
.borrow()
.query_effective_overflow(node.to_trusted_node_address())
}
pub(crate) fn hit_test_from_input_event(
&self,
input_event: &ConstellationInputEvent,