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

LibWeb+LibWebView: Migrate Browser's input event handling to LibWebView

The Serenity chrome is the only chrome thus far that sends all input key
and mouse events to WebContent, including shortcut activations. This is
necessary for all chromes - we must give web pages a chance to intercept
input events before handling them ourselves.

To make this easier for other chromes, this patch moves Serenity's input
event handling to LibWebView. To do so, we add the Web::InputEvent type,
which models the event data we need within LibWeb. Chromes will then be
responsible for converting between this type and their native events.

This class lives in LibWeb (rather than LibWebView) because the plan is
to use it wholesale throughout the Page's event handler and across IPC.
Right now, we still send the individual fields of the event over IPC,
but it will be an easy refactor to send the event itself. We just can't
do this until all chromes have been ported to this event queueing.

Also note that we now only handle key input events back in the chrome.
WebContent handles all mouse events that it possibly can. If it was not
able to handle a mouse event, there's nothing for the chrome to do (i.e.
there is no clicking, scrolling, etc. the chrome is able to do if the
WebContent couldn't).
This commit is contained in:
Timothy Flynn 2024-03-03 22:07:49 -05:00 committed by Andreas Kling
parent f2204e2b3a
commit ea682207d0
7 changed files with 191 additions and 148 deletions

View file

@ -0,0 +1,64 @@
/*
* 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 <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,
};
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,
};
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>;
}