2020-04-06 11:09:01 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-06 11:09:01 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-03-21 18:17:18 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-11-21 18:32:39 +00:00
|
|
|
#include <AK/TypeCasts.h>
|
2021-10-01 20:44:50 +03:00
|
|
|
#include <LibWeb/UIEvents/EventModifier.h>
|
2020-07-28 19:38:25 +02:00
|
|
|
#include <LibWeb/UIEvents/UIEvent.h>
|
2020-03-21 18:17:18 +01:00
|
|
|
|
2020-07-28 17:21:23 +02:00
|
|
|
namespace Web::UIEvents {
|
2020-03-21 18:17:18 +01:00
|
|
|
|
2022-04-09 12:44:42 -03:00
|
|
|
struct MouseEventInit : public EventModifierInit {
|
|
|
|
|
double offset_x = 0;
|
|
|
|
|
double offset_y = 0;
|
|
|
|
|
double client_x = 0;
|
|
|
|
|
double client_y = 0;
|
|
|
|
|
|
|
|
|
|
i16 button = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2021-09-27 23:22:21 +02:00
|
|
|
class MouseEvent final : public UIEvent {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(MouseEvent, UIEvent);
|
2022-08-08 22:29:40 +02:00
|
|
|
|
2020-03-21 18:17:18 +01:00
|
|
|
public:
|
2022-09-25 18:06:11 -06:00
|
|
|
static MouseEvent* create(JS::Realm&, FlyString const& event_name, MouseEventInit const& event_init = {});
|
|
|
|
|
static MouseEvent* create_from_platform_event(JS::Realm&, FlyString const& event_name, double offset_x, double offset_y, double client_x, double client_y, unsigned mouse_button = 1);
|
2020-03-21 18:17:18 +01:00
|
|
|
|
2022-08-08 22:29:40 +02:00
|
|
|
virtual ~MouseEvent() override;
|
2022-04-09 12:44:42 -03:00
|
|
|
|
2021-10-01 20:44:50 +03:00
|
|
|
double offset_x() const { return m_offset_x; }
|
|
|
|
|
double offset_y() const { return m_offset_y; }
|
2022-02-07 13:23:33 +01:00
|
|
|
|
2021-10-01 20:44:50 +03:00
|
|
|
double client_x() const { return m_client_x; }
|
|
|
|
|
double client_y() const { return m_client_y; }
|
2020-03-21 18:17:18 +01:00
|
|
|
|
2022-02-07 13:23:33 +01:00
|
|
|
double x() const { return client_x(); }
|
|
|
|
|
double y() const { return client_y(); }
|
|
|
|
|
|
2022-04-09 12:44:42 -03:00
|
|
|
i16 button() const { return m_button; }
|
2020-03-21 18:17:18 +01:00
|
|
|
|
2022-04-09 12:45:05 -03:00
|
|
|
virtual u32 which() const override { return m_button + 1; }
|
|
|
|
|
|
2020-03-21 18:17:18 +01:00
|
|
|
private:
|
2022-09-25 18:06:11 -06:00
|
|
|
MouseEvent(JS::Realm&, FlyString const& event_name, MouseEventInit const& event_init);
|
|
|
|
|
|
2020-11-21 18:32:39 +00:00
|
|
|
void set_event_characteristics();
|
|
|
|
|
|
2021-10-01 20:44:50 +03:00
|
|
|
double m_offset_x { 0 };
|
|
|
|
|
double m_offset_y { 0 };
|
|
|
|
|
double m_client_x { 0 };
|
|
|
|
|
double m_client_y { 0 };
|
2022-04-09 12:44:42 -03:00
|
|
|
i16 m_button { 0 };
|
2020-03-21 18:17:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|