mirror of
https://github.com/servo/servo.git
synced 2025-09-11 15:38:24 +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
|
// 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
|
// behavior, `block` as the block flow position, `inline` as the inline base direction
|
||||||
// position and `scrolling box` as the scrolling box.
|
// 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
|
// Step 1.3: If `position` is not the same as `scrolling box`’s current scroll position, or
|
||||||
// `scrolling box` has an ongoing smooth scroll,
|
// `scrolling box` has an ongoing smooth scroll,
|
||||||
|
@ -942,7 +942,7 @@ impl Element {
|
||||||
/// <https://drafts.csswg.org/cssom-view/#element-scrolling-members>
|
/// <https://drafts.csswg.org/cssom-view/#element-scrolling-members>
|
||||||
fn determine_scroll_into_view_position(
|
fn determine_scroll_into_view_position(
|
||||||
&self,
|
&self,
|
||||||
scrolling_node: &Node,
|
scrolling_box: &ScrollingBox,
|
||||||
block: ScrollLogicalPosition,
|
block: ScrollLogicalPosition,
|
||||||
inline: ScrollLogicalPosition,
|
inline: ScrollLogicalPosition,
|
||||||
) -> LayoutVector2D {
|
) -> LayoutVector2D {
|
||||||
|
@ -975,11 +975,9 @@ impl Element {
|
||||||
let element_right = element_left + element_width;
|
let element_right = element_left + element_width;
|
||||||
let element_bottom = element_top + element_height;
|
let element_bottom = element_top + element_height;
|
||||||
|
|
||||||
let (target_x, target_y) = if scrolling_node.is::<Document>() {
|
let (target_x, target_y) = match scrolling_box {
|
||||||
// Handle document-specific scrolling
|
ScrollingBox::Viewport(document) => {
|
||||||
// Viewport bounds and current scroll position
|
let window = document.window();
|
||||||
let owner_doc = self.upcast::<Node>().owner_doc();
|
|
||||||
let window = owner_doc.window();
|
|
||||||
let viewport_width = window.InnerWidth() as f32;
|
let viewport_width = window.InnerWidth() as f32;
|
||||||
let viewport_height = window.InnerHeight() as f32;
|
let viewport_height = window.InnerHeight() as f32;
|
||||||
let current_scroll_x = window.ScrollX() as f32;
|
let current_scroll_x = window.ScrollX() as f32;
|
||||||
|
@ -1009,9 +1007,9 @@ impl Element {
|
||||||
current_scroll_y,
|
current_scroll_y,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
} else {
|
},
|
||||||
// Handle element-specific scrolling
|
ScrollingBox::Element(scrolling_element) => {
|
||||||
// Scrolling box bounds and current scroll position
|
let scrolling_node = scrolling_element.upcast::<Node>();
|
||||||
let scrolling_box = scrolling_node.border_box().unwrap_or_default();
|
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_left = scrolling_box.origin.x.to_nearest_pixel(device_pixel_ratio);
|
||||||
let scrolling_top = scrolling_box.origin.y.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
|
.height
|
||||||
.to_nearest_pixel(device_pixel_ratio);
|
.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
|
// Calculate element position in scroller's content coordinate system
|
||||||
// Element's viewport position relative to scroller, then add scroll offset to get content position
|
// Element's viewport position relative to scroller, then add scroll offset to get content position
|
||||||
let viewport_relative_left = element_left - scrolling_left;
|
let viewport_relative_left = element_left - scrolling_left;
|
||||||
|
@ -1102,6 +1093,8 @@ impl Element {
|
||||||
final_coords
|
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_left = adjusted_relative_left + current_scroll_x;
|
||||||
let content_element_top = adjusted_relative_top + current_scroll_y;
|
let content_element_top = adjusted_relative_top + current_scroll_y;
|
||||||
let content_element_right = adjusted_relative_right + current_scroll_x;
|
let content_element_right = adjusted_relative_right + current_scroll_x;
|
||||||
|
@ -1125,6 +1118,7 @@ impl Element {
|
||||||
current_scroll_y,
|
current_scroll_y,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector2D::new(target_x, target_y)
|
Vector2D::new(target_x, target_y)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue