2022-10-17 17:54:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2024-04-27 00:09:58 +00:00
|
|
|
#include <LibWeb/Bindings/WheelEventPrototype.h>
|
2022-10-17 17:54:01 +00:00
|
|
|
#include <LibWeb/HTML/EventNames.h>
|
|
|
|
#include <LibWeb/UIEvents/EventNames.h>
|
2024-06-06 19:29:08 +00:00
|
|
|
#include <LibWeb/UIEvents/KeyCode.h>
|
2022-10-17 17:54:01 +00:00
|
|
|
#include <LibWeb/UIEvents/WheelEvent.h>
|
2023-02-19 09:48:02 +00:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2022-10-17 17:54:01 +00:00
|
|
|
|
|
|
|
namespace Web::UIEvents {
|
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
GC_DEFINE_ALLOCATOR(WheelEvent);
|
2023-11-19 18:47:52 +00:00
|
|
|
|
2024-01-19 17:52:45 +00:00
|
|
|
WheelEvent::WheelEvent(JS::Realm& realm, FlyString const& event_name, WheelEventInit const& event_init, double page_x, double page_y, double offset_x, double offset_y)
|
|
|
|
: MouseEvent(realm, event_name, event_init, page_x, page_y, offset_x, offset_y)
|
2022-10-17 17:54:01 +00:00
|
|
|
, m_delta_x(event_init.delta_x)
|
|
|
|
, m_delta_y(event_init.delta_y)
|
2024-05-12 10:29:11 +00:00
|
|
|
, m_delta_z(event_init.delta_z)
|
2022-10-17 17:54:01 +00:00
|
|
|
, m_delta_mode(event_init.delta_mode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WheelEvent::~WheelEvent() = default;
|
|
|
|
|
2023-08-07 06:41:28 +00:00
|
|
|
void WheelEvent::initialize(JS::Realm& realm)
|
2023-01-10 11:28:20 +00:00
|
|
|
{
|
2023-08-07 06:41:28 +00:00
|
|
|
Base::initialize(realm);
|
2024-03-16 12:13:08 +00:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(WheelEvent);
|
2023-01-10 11:28:20 +00:00
|
|
|
}
|
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
GC::Ref<WheelEvent> WheelEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, WheelEventInit const& wheel_event_init)
|
2024-05-12 10:17:37 +00:00
|
|
|
{
|
|
|
|
return create(realm, event_name, wheel_event_init);
|
|
|
|
}
|
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
GC::Ref<WheelEvent> WheelEvent::create(JS::Realm& realm, FlyString const& event_name, WheelEventInit const& event_init, double page_x, double page_y, double offset_x, double offset_y)
|
2022-10-17 17:54:01 +00:00
|
|
|
{
|
2024-11-13 16:50:17 +00:00
|
|
|
return realm.create<WheelEvent>(realm, event_name, event_init, page_x, page_y, offset_x, offset_y);
|
2022-10-17 17:54:01 +00:00
|
|
|
}
|
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<WheelEvent>> WheelEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, CSSPixelPoint screen, CSSPixelPoint page, CSSPixelPoint client, CSSPixelPoint offset, double delta_x, double delta_y, unsigned button, unsigned buttons, unsigned modifiers)
|
2022-10-17 17:54:01 +00:00
|
|
|
{
|
|
|
|
WheelEventInit event_init {};
|
2024-01-19 17:52:45 +00:00
|
|
|
event_init.ctrl_key = modifiers & Mod_Ctrl;
|
|
|
|
event_init.shift_key = modifiers & Mod_Shift;
|
|
|
|
event_init.alt_key = modifiers & Mod_Alt;
|
|
|
|
event_init.meta_key = modifiers & Mod_Super;
|
2023-09-08 16:48:44 +00:00
|
|
|
event_init.screen_x = screen.x().to_double();
|
|
|
|
event_init.screen_y = screen.y().to_double();
|
2023-09-08 15:50:53 +00:00
|
|
|
event_init.client_x = client.x().to_double();
|
|
|
|
event_init.client_y = client.y().to_double();
|
2022-10-20 17:56:38 +00:00
|
|
|
event_init.button = button;
|
|
|
|
event_init.buttons = buttons;
|
2022-10-17 17:54:01 +00:00
|
|
|
event_init.delta_x = delta_x;
|
|
|
|
event_init.delta_y = delta_y;
|
|
|
|
event_init.delta_mode = WheelDeltaMode::DOM_DELTA_PIXEL;
|
2024-01-19 17:52:45 +00:00
|
|
|
auto event = WheelEvent::create(realm, event_name, event_init, page.x().to_double(), page.y().to_double(), offset.x().to_double(), offset.y().to_double());
|
2024-01-18 19:54:28 +00:00
|
|
|
event->set_is_trusted(true);
|
2024-07-16 13:05:15 +00:00
|
|
|
event->set_bubbles(true);
|
|
|
|
event->set_cancelable(true);
|
|
|
|
event->set_composed(true);
|
2024-01-18 19:54:28 +00:00
|
|
|
return event;
|
2022-10-17 17:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|