script/layout: Implement HTMLElement.scrollParent (#39110)

This new API allows getting the element which establishes an element's
scroll container. This will be used to properly implement
`scrollIntoView`. There is still work to do for this API and
`offsetParent` to properly handle ancestors which are
closed-shadow-hidden from the original query element.

In addition, fix an issue where inline boxes were establishing scrolling
containers (they shouldn't do that).

Testing: There are tests for this change.
Fixes: #39096.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2025-09-03 11:52:15 -07:00 committed by GitHub
parent 5c7ea4bdee
commit 2c7866eb24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 173 additions and 49 deletions

View file

@ -56,8 +56,8 @@ use js::rust::{
use layout_api::{
BoxAreaType, ElementsFromPointFlags, ElementsFromPointResult, FragmentType, Layout,
PendingImage, PendingImageState, PendingRasterizationImage, QueryMsg, ReflowGoal,
ReflowPhasesRun, ReflowRequest, ReflowRequestRestyle, RestyleReason, TrustedNodeAddress,
combine_id_with_fragment_type,
ReflowPhasesRun, ReflowRequest, ReflowRequestRestyle, RestyleReason, ScrollParentResponse,
TrustedNodeAddress, combine_id_with_fragment_type,
};
use malloc_size_of::MallocSizeOf;
use media::WindowGLContext;
@ -2599,6 +2599,23 @@ impl Window {
(element, response.rect)
}
#[allow(unsafe_code)]
pub(crate) fn scroll_parent_query(&self, node: &Node) -> Option<DomRoot<Element>> {
self.layout_reflow(QueryMsg::ScrollParentQuery);
self.layout
.borrow()
.query_scroll_parent(node.to_trusted_node_address())
.and_then(|response| match response {
ScrollParentResponse::DocumentScrollingElement => {
self.Document().GetScrollingElement()
},
ScrollParentResponse::Element(parent_node_address) => {
let node = unsafe { from_untrusted_node_address(parent_node_address) };
DomRoot::downcast(node)
},
})
}
pub(crate) fn text_index_query(
&self,
node: &Node,