2024-03-03 22:07:49 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
#include <AK/Variant.h>
|
2024-08-17 13:29:55 -04:00
|
|
|
#include <AK/Vector.h>
|
2024-03-03 22:07:49 -05:00
|
|
|
#include <LibGfx/Point.h>
|
2024-03-05 17:06:32 -05:00
|
|
|
#include <LibIPC/Forward.h>
|
2024-08-17 13:29:55 -04:00
|
|
|
#include <LibWeb/HTML/SelectedFile.h>
|
2024-03-03 22:07:49 -05:00
|
|
|
#include <LibWeb/PixelUnits.h>
|
2024-06-06 13:29:08 -06:00
|
|
|
#include <LibWeb/UIEvents/KeyCode.h>
|
2024-06-02 19:00:42 +02:00
|
|
|
#include <LibWeb/UIEvents/MouseButton.h>
|
2024-03-03 22:07:49 -05:00
|
|
|
|
|
|
|
namespace Web {
|
|
|
|
|
2025-03-15 17:07:53 -04:00
|
|
|
struct BrowserInputData {
|
|
|
|
virtual ~BrowserInputData() = default;
|
2024-03-03 22:07:49 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
struct KeyEvent {
|
|
|
|
enum class Type {
|
|
|
|
KeyDown,
|
|
|
|
KeyUp,
|
|
|
|
};
|
|
|
|
|
2025-03-15 17:07:53 -04:00
|
|
|
KeyEvent clone_without_browser_data() const;
|
2024-03-05 17:06:32 -05:00
|
|
|
|
2024-03-03 22:07:49 -05:00
|
|
|
Type type;
|
2024-06-06 13:29:08 -06:00
|
|
|
UIEvents::KeyCode key { UIEvents::KeyCode::Key_Invalid };
|
|
|
|
UIEvents::KeyModifier modifiers { UIEvents::KeyModifier::Mod_None };
|
2024-03-03 22:07:49 -05:00
|
|
|
u32 code_point { 0 };
|
2024-10-22 15:32:42 +02:00
|
|
|
bool repeat { false };
|
2024-03-03 22:07:49 -05:00
|
|
|
|
2025-03-15 17:07:53 -04:00
|
|
|
OwnPtr<BrowserInputData> browser_data;
|
2024-03-03 22:07:49 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MouseEvent {
|
|
|
|
enum class Type {
|
|
|
|
MouseDown,
|
|
|
|
MouseUp,
|
|
|
|
MouseMove,
|
|
|
|
MouseWheel,
|
|
|
|
DoubleClick,
|
|
|
|
};
|
|
|
|
|
2025-03-15 17:07:53 -04:00
|
|
|
MouseEvent clone_without_browser_data() const;
|
2024-03-05 17:06:32 -05:00
|
|
|
|
2024-03-03 22:07:49 -05:00
|
|
|
Type type;
|
|
|
|
Web::DevicePixelPoint position;
|
|
|
|
Web::DevicePixelPoint screen_position;
|
2024-06-02 19:00:42 +02:00
|
|
|
UIEvents::MouseButton button { UIEvents::MouseButton::None };
|
|
|
|
UIEvents::MouseButton buttons { UIEvents::MouseButton::None };
|
2024-06-06 13:29:08 -06:00
|
|
|
UIEvents::KeyModifier modifiers { UIEvents::KeyModifier::Mod_None };
|
2024-03-03 22:07:49 -05:00
|
|
|
int wheel_delta_x { 0 };
|
|
|
|
int wheel_delta_y { 0 };
|
|
|
|
|
2025-03-15 17:07:53 -04:00
|
|
|
OwnPtr<BrowserInputData> browser_data;
|
2024-03-03 22:07:49 -05:00
|
|
|
};
|
|
|
|
|
2024-08-17 13:29:55 -04:00
|
|
|
struct DragEvent {
|
|
|
|
enum class Type {
|
|
|
|
DragStart,
|
|
|
|
DragMove,
|
|
|
|
DragEnd,
|
|
|
|
Drop,
|
|
|
|
};
|
|
|
|
|
2025-03-15 17:07:53 -04:00
|
|
|
DragEvent clone_without_browser_data() const;
|
2024-08-17 13:29:55 -04:00
|
|
|
|
|
|
|
Type type;
|
|
|
|
Web::DevicePixelPoint position;
|
|
|
|
Web::DevicePixelPoint screen_position;
|
|
|
|
UIEvents::MouseButton button { UIEvents::MouseButton::None };
|
|
|
|
UIEvents::MouseButton buttons { UIEvents::MouseButton::None };
|
|
|
|
UIEvents::KeyModifier modifiers { UIEvents::KeyModifier::Mod_None };
|
|
|
|
Vector<HTML::SelectedFile> files;
|
|
|
|
|
2025-03-15 17:07:53 -04:00
|
|
|
OwnPtr<BrowserInputData> browser_data;
|
2024-08-17 13:29:55 -04:00
|
|
|
};
|
|
|
|
|
2024-08-17 13:36:28 -04:00
|
|
|
using InputEvent = Variant<KeyEvent, MouseEvent, DragEvent>;
|
2024-03-03 22:07:49 -05:00
|
|
|
|
2025-02-14 23:25:12 +01:00
|
|
|
struct QueuedInputEvent {
|
|
|
|
u64 page_id { 0 };
|
|
|
|
InputEvent event;
|
|
|
|
size_t coalesced_event_count { 0 };
|
|
|
|
};
|
|
|
|
|
2024-03-03 22:07:49 -05:00
|
|
|
}
|
2024-03-05 17:06:32 -05:00
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
|
|
template<>
|
|
|
|
ErrorOr<void> encode(Encoder&, Web::KeyEvent const&);
|
|
|
|
|
|
|
|
template<>
|
|
|
|
ErrorOr<Web::KeyEvent> decode(Decoder&);
|
|
|
|
|
|
|
|
template<>
|
|
|
|
ErrorOr<void> encode(Encoder&, Web::MouseEvent const&);
|
|
|
|
|
|
|
|
template<>
|
|
|
|
ErrorOr<Web::MouseEvent> decode(Decoder&);
|
|
|
|
|
2024-08-17 13:36:28 -04:00
|
|
|
template<>
|
|
|
|
ErrorOr<void> encode(Encoder&, Web::DragEvent const&);
|
|
|
|
|
|
|
|
template<>
|
|
|
|
ErrorOr<Web::DragEvent> decode(Decoder&);
|
|
|
|
|
2024-03-05 17:06:32 -05:00
|
|
|
}
|