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

LibWeb: Bring MouseEvent a bit closer to spec

This commit is contained in:
Igor Pissolati 2022-04-09 12:44:42 -03:00 committed by Andreas Kling
parent a2bc97a9c2
commit 1b94b4c593
6 changed files with 75 additions and 18 deletions

View file

@ -12,16 +12,27 @@
namespace Web::UIEvents {
struct MouseEventInit : public EventModifierInit {
double offset_x = 0;
double offset_y = 0;
double client_x = 0;
double client_y = 0;
i16 button = 0;
};
class MouseEvent final : public UIEvent {
public:
using WrapperType = Bindings::MouseEventWrapper;
static NonnullRefPtr<MouseEvent> create(FlyString const& event_name, double offset_x, double offset_y, double client_x, double client_y)
static NonnullRefPtr<MouseEvent> create(FlyString const& event_name, MouseEventInit const& event_init = {})
{
return adopt_ref(*new MouseEvent(event_name, offset_x, offset_y, client_x, client_y));
return adopt_ref(*new MouseEvent(event_name, event_init));
}
virtual ~MouseEvent() override;
static NonnullRefPtr<MouseEvent> create_from_platform_event(FlyString const& event_name, double offset_x, double offset_y, double client_x, double client_y, unsigned mouse_button = 1);
virtual ~MouseEvent() override = default;
double offset_x() const { return m_offset_x; }
double offset_y() const { return m_offset_y; }
@ -32,16 +43,18 @@ public:
double x() const { return client_x(); }
double y() const { return client_y(); }
protected:
MouseEvent(FlyString const& event_name, double offset_x, double offset_y, double client_x, double client_y);
i16 button() const { return m_button; }
private:
MouseEvent(FlyString const& event_name, MouseEventInit const& event_init);
void set_event_characteristics();
double m_offset_x { 0 };
double m_offset_y { 0 };
double m_client_x { 0 };
double m_client_y { 0 };
i16 m_button { 0 };
};
}