script: Minimize layout queries for window scroll offsets. (#38018)

These changes reduce the number of times we need to query layout for the
same information when creating mouse/pointer events.

Testing: No new tests required for maintaining existing behaviour.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-07-12 10:17:55 -04:00 committed by GitHub
parent 6dbd64e72d
commit d0a93a8b02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 32 additions and 21 deletions

View file

@ -278,9 +278,10 @@ impl MouseEventMethods<crate::DomTypeHolder> for MouseEvent {
) -> Fallible<DomRoot<MouseEvent>> {
let bubbles = EventBubbles::from(init.parent.parent.parent.bubbles);
let cancelable = EventCancelable::from(init.parent.parent.parent.cancelable);
let scroll_offset = window.scroll_offset(can_gc);
let page_point = Point2D::new(
window.ScrollX() + init.clientX,
window.ScrollY() + init.clientY,
scroll_offset.x as i32 + init.clientX,
scroll_offset.y as i32 + init.clientY,
);
let event = MouseEvent::new_with_proto(
window,
@ -478,6 +479,7 @@ impl MouseEventMethods<crate::DomTypeHolder> for MouseEvent {
meta_key_arg: bool,
button_arg: i16,
related_target_arg: Option<&EventTarget>,
can_gc: CanGc,
) {
if self.upcast::<Event>().dispatching() {
return;
@ -496,9 +498,10 @@ impl MouseEventMethods<crate::DomTypeHolder> for MouseEvent {
.set(Point2D::new(client_x_arg, client_y_arg));
let global = self.global();
let scroll_offset = global.as_window().scroll_offset(can_gc);
self.page_point.set(Point2D::new(
global.as_window().ScrollX() + client_x_arg,
global.as_window().ScrollY() + client_y_arg,
scroll_offset.x as i32 + client_x_arg,
scroll_offset.y as i32 + client_y_arg,
));
let mut modifiers = Modifiers::empty();