1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:07:36 +00:00

LibWeb: Partially implement MouseEvent.movementX/movementY

Currently doesn't handle the mouse leaving and entering the window per
the spec, and uses clientX/Y instead of screenX/Y. See FIXMEs.
This commit is contained in:
circl 2023-08-24 17:47:13 +02:00 committed by Andrew Kaster
parent ebb7079795
commit e0e67a2b27
5 changed files with 51 additions and 8 deletions

View file

@ -21,6 +21,8 @@ MouseEvent::MouseEvent(JS::Realm& realm, FlyString const& event_name, MouseEvent
, m_client_y(event_init.client_y)
, m_page_x(event_init.page_x)
, m_page_y(event_init.page_y)
, m_movement_x(event_init.movement_x)
, m_movement_y(event_init.movement_y)
, m_button(event_init.button)
, m_buttons(event_init.buttons)
{
@ -59,7 +61,7 @@ JS::NonnullGCPtr<MouseEvent> MouseEvent::create(JS::Realm& realm, FlyString cons
return realm.heap().allocate<MouseEvent>(realm, realm, event_name, event_init);
}
WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> MouseEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, CSSPixelPoint offset, CSSPixelPoint client_offset, CSSPixelPoint page_offset, unsigned buttons, unsigned mouse_button)
WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> MouseEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, CSSPixelPoint offset, CSSPixelPoint client_offset, CSSPixelPoint page_offset, Optional<CSSPixelPoint> movement, unsigned buttons, unsigned mouse_button)
{
MouseEventInit event_init {};
event_init.offset_x = offset.x().to_double();
@ -68,6 +70,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> MouseEvent::create_from_platfo
event_init.client_y = client_offset.y().to_double();
event_init.page_x = page_offset.x().to_double();
event_init.page_y = page_offset.y().to_double();
if (movement.has_value()) {
event_init.movement_x = movement.value().x().to_double();
event_init.movement_y = movement.value().y().to_double();
}
event_init.button = determine_button(mouse_button);
event_init.buttons = buttons;
return MouseEvent::create(realm, event_name, event_init);