mirror of
https://github.com/servo/servo.git
synced 2025-09-30 00:29:14 +01:00
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:
parent
5c7ea4bdee
commit
2c7866eb24
13 changed files with 173 additions and 49 deletions
|
@ -444,6 +444,11 @@ impl HTMLElementMethods<crate::DomTypeHolder> for HTMLElement {
|
|||
document.request_focus(None, FocusInitiator::Local, can_gc);
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/cssom-view/#dom-htmlelement-scrollparent>
|
||||
fn GetScrollParent(&self) -> Option<DomRoot<Element>> {
|
||||
self.owner_window().scroll_parent_query(self.upcast())
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent>
|
||||
fn GetOffsetParent(&self) -> Option<DomRoot<Element>> {
|
||||
if self.is_body_element() || self.is::<HTMLHtmlElement>() {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue