mirror of
https://github.com/servo/servo.git
synced 2025-09-10 15:08:21 +01:00
script: Modify Element::determine_scroll_into_view_position
to take a ScrollingBox
(#39107)
There is no need to separate the two kinds of scrolling boxes into `Element` and `Viewport` more than once. This also eliminates a potentially panicking `unwrap()`. Testing: This doesn't change behavior and is thus covered by existing tests. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
dab195ca80
commit
fa7d6d4004
1 changed files with 131 additions and 137 deletions
|
@ -899,7 +899,7 @@ impl Element {
|
|||
// determine the scroll-into-view position of `target` with `behavior` as the scroll
|
||||
// behavior, `block` as the block flow position, `inline` as the inline base direction
|
||||
// position and `scrolling box` as the scrolling box.
|
||||
let position = self.determine_scroll_into_view_position(&node, block, inline);
|
||||
let position = self.determine_scroll_into_view_position(&scrolling_box, block, inline);
|
||||
|
||||
// Step 1.3: If `position` is not the same as `scrolling box`’s current scroll position, or
|
||||
// `scrolling box` has an ongoing smooth scroll,
|
||||
|
@ -942,7 +942,7 @@ impl Element {
|
|||
/// <https://drafts.csswg.org/cssom-view/#element-scrolling-members>
|
||||
fn determine_scroll_into_view_position(
|
||||
&self,
|
||||
scrolling_node: &Node,
|
||||
scrolling_box: &ScrollingBox,
|
||||
block: ScrollLogicalPosition,
|
||||
inline: ScrollLogicalPosition,
|
||||
) -> LayoutVector2D {
|
||||
|
@ -975,11 +975,9 @@ impl Element {
|
|||
let element_right = element_left + element_width;
|
||||
let element_bottom = element_top + element_height;
|
||||
|
||||
let (target_x, target_y) = if scrolling_node.is::<Document>() {
|
||||
// Handle document-specific scrolling
|
||||
// Viewport bounds and current scroll position
|
||||
let owner_doc = self.upcast::<Node>().owner_doc();
|
||||
let window = owner_doc.window();
|
||||
let (target_x, target_y) = match scrolling_box {
|
||||
ScrollingBox::Viewport(document) => {
|
||||
let window = document.window();
|
||||
let viewport_width = window.InnerWidth() as f32;
|
||||
let viewport_height = window.InnerHeight() as f32;
|
||||
let current_scroll_x = window.ScrollX() as f32;
|
||||
|
@ -1009,9 +1007,9 @@ impl Element {
|
|||
current_scroll_y,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
// Handle element-specific scrolling
|
||||
// Scrolling box bounds and current scroll position
|
||||
},
|
||||
ScrollingBox::Element(scrolling_element) => {
|
||||
let scrolling_node = scrolling_element.upcast::<Node>();
|
||||
let scrolling_box = scrolling_node.border_box().unwrap_or_default();
|
||||
let scrolling_left = scrolling_box.origin.x.to_nearest_pixel(device_pixel_ratio);
|
||||
let scrolling_top = scrolling_box.origin.y.to_nearest_pixel(device_pixel_ratio);
|
||||
|
@ -1024,13 +1022,6 @@ impl Element {
|
|||
.height
|
||||
.to_nearest_pixel(device_pixel_ratio);
|
||||
|
||||
// TODO: This function should accept `Element` and not `Node`.
|
||||
let scrolling_element = scrolling_node
|
||||
.downcast::<Element>()
|
||||
.expect("Should be provided an Element.");
|
||||
let current_scroll_x = scrolling_element.ScrollLeft() as f32;
|
||||
let current_scroll_y = scrolling_element.ScrollTop() as f32;
|
||||
|
||||
// Calculate element position in scroller's content coordinate system
|
||||
// Element's viewport position relative to scroller, then add scroll offset to get content position
|
||||
let viewport_relative_left = element_left - scrolling_left;
|
||||
|
@ -1102,6 +1093,8 @@ impl Element {
|
|||
final_coords
|
||||
};
|
||||
|
||||
let current_scroll_x = scrolling_element.ScrollLeft() as f32;
|
||||
let current_scroll_y = scrolling_element.ScrollTop() as f32;
|
||||
let content_element_left = adjusted_relative_left + current_scroll_x;
|
||||
let content_element_top = adjusted_relative_top + current_scroll_y;
|
||||
let content_element_right = adjusted_relative_right + current_scroll_x;
|
||||
|
@ -1125,6 +1118,7 @@ impl Element {
|
|||
current_scroll_y,
|
||||
),
|
||||
)
|
||||
},
|
||||
};
|
||||
|
||||
Vector2D::new(target_x, target_y)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue