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

@ -8,7 +8,6 @@ use dom_struct::dom_struct;
use euclid::Point2D;
use js::rust::HandleObject;
use keyboard_types::Modifiers;
use script_bindings::codegen::GenericBindings::WindowBinding::WindowMethods;
use style_traits::CSSPixel;
use super::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods;
@ -234,9 +233,10 @@ impl PointerEventMethods<crate::DomTypeHolder> for PointerEvent {
) -> DomRoot<PointerEvent> {
let bubbles = EventBubbles::from(init.parent.parent.parent.parent.bubbles);
let cancelable = EventCancelable::from(init.parent.parent.parent.parent.cancelable);
let scroll_offset = window.scroll_offset(can_gc);
let page_point = Point2D::new(
window.ScrollX() + init.parent.clientX,
window.ScrollY() + init.parent.clientY,
scroll_offset.x as i32 + init.parent.clientX,
scroll_offset.y as i32 + init.parent.clientY,
);
PointerEvent::new_with_proto(
window,