diff options
author | Martin Robinson <mrobinson@igalia.com> | 2023-04-25 09:11:28 +0200 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2023-04-25 21:25:01 +0200 |
commit | 404ee8b98468970f0108d1e011f44b694975acb7 (patch) | |
tree | 9c18fe52d97d2024b023d41e64082be63c83834b /components | |
parent | eca0acf4598c173c71765b961bd2079c0bb48cd2 (diff) | |
download | servo-404ee8b98468970f0108d1e011f44b694975acb7.tar.gz servo-404ee8b98468970f0108d1e011f44b694975acb7.zip |
Fix scrolling from script in Layout 2020
Script will only scroll if it detects that an element has a scrolling
box, so this change adds an implementation of the scroll area query to
Layout 2020. This allows some scrolling tests to start passing.
This change also updates all expected results in css-backgrounds and
cssom-view.
Diffstat (limited to 'components')
-rw-r--r-- | components/layout_2020/flow/root.rs | 33 | ||||
-rw-r--r-- | components/layout_2020/query.rs | 11 | ||||
-rw-r--r-- | components/layout_thread_2020/lib.rs | 3 |
3 files changed, 44 insertions, 3 deletions
diff --git a/components/layout_2020/flow/root.rs b/components/layout_2020/flow/root.rs index 80a42c70701..fb05049f4a8 100644 --- a/components/layout_2020/flow/root.rs +++ b/components/layout_2020/flow/root.rs @@ -538,6 +538,39 @@ impl FragmentTree { }) .unwrap_or_else(Rect::zero) } + + pub fn get_scroll_area_for_node(&self, requested_node: OpaqueNode) -> Rect<i32> { + let mut scroll_area: PhysicalRect<Length> = PhysicalRect::zero(); + let tag_to_find = Tag::Node(requested_node); + self.find(|fragment, _, containing_block| { + if fragment.tag() != Some(tag_to_find) { + return None::<()>; + } + + scroll_area = match fragment { + Fragment::Box(fragment) => fragment + .scrollable_overflow(&containing_block) + .translate(containing_block.origin.to_vector()), + Fragment::Text(_) | + Fragment::AbsoluteOrFixedPositioned(_) | + Fragment::Image(_) | + Fragment::IFrame(_) | + Fragment::Anonymous(_) => return None, + }; + None::<()> + }); + + Rect::new( + Point2D::new( + scroll_area.origin.x.px() as i32, + scroll_area.origin.y.px() as i32, + ), + Size2D::new( + scroll_area.size.width.px() as i32, + scroll_area.size.height.px() as i32, + ), + ) + } } /// https://drafts.csswg.org/css-backgrounds/#root-background diff --git a/components/layout_2020/query.rs b/components/layout_2020/query.rs index 0e99ec88fac..f59163a3a7c 100644 --- a/components/layout_2020/query.rs +++ b/components/layout_2020/query.rs @@ -201,8 +201,15 @@ pub fn process_node_scroll_id_request<'dom>( } /// https://drafts.csswg.org/cssom-view/#scrolling-area -pub fn process_node_scroll_area_request(_requested_node: OpaqueNode) -> Rect<i32> { - Rect::zero() +pub fn process_node_scroll_area_request( + requested_node: OpaqueNode, + fragment_tree: Option<Arc<FragmentTree>>, +) -> Rect<i32> { + if let Some(fragment_tree) = fragment_tree { + fragment_tree.get_scroll_area_for_node(requested_node) + } else { + Rect::zero() + } } /// Return the resolved value of property for a given (pseudo)element. diff --git a/components/layout_thread_2020/lib.rs b/components/layout_thread_2020/lib.rs index 0a1dff2d284..18851ef905c 100644 --- a/components/layout_thread_2020/lib.rs +++ b/components/layout_thread_2020/lib.rs @@ -1184,7 +1184,8 @@ impl LayoutThread { process_node_geometry_request(node, self.fragment_tree.borrow().clone()); }, &QueryMsg::NodeScrollGeometryQuery(node) => { - rw_data.scroll_area_response = process_node_scroll_area_request(node); + rw_data.scroll_area_response = + process_node_scroll_area_request(node, self.fragment_tree.borrow().clone()); }, &QueryMsg::NodeScrollIdQuery(node) => { let node = unsafe { ServoLayoutNode::new(&node) }; |