ladybird/Userland/Libraries/LibWeb/Page/InputEvent.h
Timothy Flynn baf359354b LibWebView+WebContent: Use Web::InputEvent for WebContent input IPC
Now that all input events are handled by LibWebView, replace the IPCs
which send the fields of Web::KeyEvent / Web::MouseEvent individually
with one IPC per event type (key or mouse).

We can also replace the ad-hoc queued input structure with a smaller
struct that simply holds the tranferred Web::KeyEvent / Web::MouseEvent.

In the future, we can also adapt Web::EventHandler to use these structs.
2024-03-06 07:46:18 +01:00

85 lines
1.8 KiB
C++

/*
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/OwnPtr.h>
#include <AK/Variant.h>
#include <LibGfx/Point.h>
#include <LibIPC/Forward.h>
#include <LibWeb/PixelUnits.h>
// FIXME: These should not be included outside of Serenity. This FIXME appears in several locations across the Ladybird
// chromes. The classes in this file provide a good opportunity to remove LibGUI and Kernel types from LibWeb.
#include <Kernel/API/KeyCode.h>
#include <LibGUI/Event.h>
namespace Web {
struct ChromeInputData {
virtual ~ChromeInputData() = default;
};
struct KeyEvent {
public:
enum class Type {
KeyDown,
KeyUp,
};
KeyEvent clone_without_chrome_data() const;
Type type;
KeyCode key { KeyCode::Key_Invalid };
KeyModifier modifiers { KeyModifier::Mod_None };
u32 code_point { 0 };
OwnPtr<ChromeInputData> chrome_data;
};
struct MouseEvent {
public:
enum class Type {
MouseDown,
MouseUp,
MouseMove,
MouseWheel,
DoubleClick,
};
MouseEvent clone_without_chrome_data() const;
Type type;
Web::DevicePixelPoint position;
Web::DevicePixelPoint screen_position;
GUI::MouseButton button { GUI::MouseButton::None };
GUI::MouseButton buttons { GUI::MouseButton::None };
KeyModifier modifiers { KeyModifier::Mod_None };
int wheel_delta_x { 0 };
int wheel_delta_y { 0 };
OwnPtr<ChromeInputData> chrome_data;
};
using InputEvent = Variant<KeyEvent, MouseEvent>;
}
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&);
}