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>
|
|
|
|
#include <LibWeb/HTML/EventNames.h>
|
|
|
|
#include <LibWeb/UIEvents/EventNames.h>
|
|
|
|
#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 {
|
|
|
|
|
2023-09-08 16:57:06 +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, unsigned modifiers)
|
|
|
|
: MouseEvent(realm, event_name, event_init, page_x, page_y, offset_x, offset_y, modifiers)
|
2022-10-17 17:54:01 +00:00
|
|
|
, m_delta_x(event_init.delta_x)
|
|
|
|
, m_delta_y(event_init.delta_y)
|
|
|
|
, m_delta_mode(event_init.delta_mode)
|
|
|
|
{
|
|
|
|
set_event_characteristics();
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2023-01-10 11:28:20 +00:00
|
|
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::WheelEventPrototype>(realm, "WheelEvent"));
|
|
|
|
}
|
|
|
|
|
2023-09-08 16:57:06 +00:00
|
|
|
JS::NonnullGCPtr<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, unsigned modifiers)
|
2022-10-17 17:54:01 +00:00
|
|
|
{
|
2023-09-08 16:57:06 +00:00
|
|
|
return realm.heap().allocate<WheelEvent>(realm, realm, event_name, event_init, page_x, page_y, offset_x, offset_y, modifiers);
|
2022-10-17 17:54:01 +00:00
|
|
|
}
|
|
|
|
|
2023-09-08 16:57:06 +00:00
|
|
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<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 {};
|
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;
|
2023-09-08 16:57:06 +00:00
|
|
|
return WheelEvent::create(realm, event_name, event_init, page.x().to_double(), page.y().to_double(), offset.x().to_double(), offset.y().to_double(), modifiers);
|
2022-10-17 17:54:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WheelEvent::set_event_characteristics()
|
|
|
|
{
|
|
|
|
set_bubbles(true);
|
|
|
|
set_cancelable(true);
|
|
|
|
set_composed(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|