mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:17:35 +00:00
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.
This commit is contained in:
parent
2c31ef11bc
commit
baf359354b
8 changed files with 164 additions and 228 deletions
|
@ -492,6 +492,7 @@ set(SOURCES
|
|||
NavigationTiming/PerformanceTiming.cpp
|
||||
Page/EditEventHandler.cpp
|
||||
Page/EventHandler.cpp
|
||||
Page/InputEvent.cpp
|
||||
Page/Page.cpp
|
||||
Painting/AudioPaintable.cpp
|
||||
Painting/BackgroundPainting.cpp
|
||||
|
|
73
Userland/Libraries/LibWeb/Page/InputEvent.cpp
Normal file
73
Userland/Libraries/LibWeb/Page/InputEvent.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibIPC/Decoder.h>
|
||||
#include <LibIPC/Encoder.h>
|
||||
#include <LibWeb/Page/InputEvent.h>
|
||||
|
||||
namespace Web {
|
||||
|
||||
KeyEvent KeyEvent::clone_without_chrome_data() const
|
||||
{
|
||||
return { type, key, modifiers, code_point, nullptr };
|
||||
}
|
||||
|
||||
MouseEvent MouseEvent::clone_without_chrome_data() const
|
||||
{
|
||||
return { type, position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, nullptr };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> IPC::encode(Encoder& encoder, Web::KeyEvent const& event)
|
||||
{
|
||||
TRY(encoder.encode(event.type));
|
||||
TRY(encoder.encode(event.key));
|
||||
TRY(encoder.encode(event.modifiers));
|
||||
TRY(encoder.encode(event.code_point));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<Web::KeyEvent> IPC::decode(Decoder& decoder)
|
||||
{
|
||||
auto type = TRY(decoder.decode<Web::KeyEvent::Type>());
|
||||
auto key = TRY(decoder.decode<KeyCode>());
|
||||
auto modifiers = TRY(decoder.decode<KeyModifier>());
|
||||
auto code_point = TRY(decoder.decode<u32>());
|
||||
|
||||
return Web::KeyEvent { type, key, modifiers, code_point, nullptr };
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> IPC::encode(Encoder& encoder, Web::MouseEvent const& event)
|
||||
{
|
||||
TRY(encoder.encode(event.type));
|
||||
TRY(encoder.encode(event.position));
|
||||
TRY(encoder.encode(event.screen_position));
|
||||
TRY(encoder.encode(event.button));
|
||||
TRY(encoder.encode(event.buttons));
|
||||
TRY(encoder.encode(event.modifiers));
|
||||
TRY(encoder.encode(event.wheel_delta_x));
|
||||
TRY(encoder.encode(event.wheel_delta_y));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<Web::MouseEvent> IPC::decode(Decoder& decoder)
|
||||
{
|
||||
auto type = TRY(decoder.decode<Web::MouseEvent::Type>());
|
||||
auto position = TRY(decoder.decode<Web::DevicePixelPoint>());
|
||||
auto screen_position = TRY(decoder.decode<Web::DevicePixelPoint>());
|
||||
auto button = TRY(decoder.decode<GUI::MouseButton>());
|
||||
auto buttons = TRY(decoder.decode<GUI::MouseButton>());
|
||||
auto modifiers = TRY(decoder.decode<KeyModifier>());
|
||||
auto wheel_delta_x = TRY(decoder.decode<int>());
|
||||
auto wheel_delta_y = TRY(decoder.decode<int>());
|
||||
|
||||
return Web::MouseEvent { type, position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, nullptr };
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
#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
|
||||
|
@ -29,6 +30,8 @@ public:
|
|||
KeyUp,
|
||||
};
|
||||
|
||||
KeyEvent clone_without_chrome_data() const;
|
||||
|
||||
Type type;
|
||||
KeyCode key { KeyCode::Key_Invalid };
|
||||
KeyModifier modifiers { KeyModifier::Mod_None };
|
||||
|
@ -47,6 +50,8 @@ public:
|
|||
DoubleClick,
|
||||
};
|
||||
|
||||
MouseEvent clone_without_chrome_data() const;
|
||||
|
||||
Type type;
|
||||
Web::DevicePixelPoint position;
|
||||
Web::DevicePixelPoint screen_position;
|
||||
|
@ -62,3 +67,19 @@ public:
|
|||
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&);
|
||||
|
||||
}
|
||||
|
|
|
@ -119,36 +119,12 @@ void ViewImplementation::enqueue_input_event(Web::InputEvent event)
|
|||
// process the next one.
|
||||
m_pending_input_events.enqueue(move(event));
|
||||
|
||||
// FIXME: Replace these IPCs with a singular "async_input_event".
|
||||
m_pending_input_events.tail().visit(
|
||||
[this](Web::KeyEvent const& event) {
|
||||
switch (event.type) {
|
||||
case Web::KeyEvent::Type::KeyDown:
|
||||
client().async_key_down(m_client_state.page_index, event.key, event.modifiers, event.code_point);
|
||||
break;
|
||||
case Web::KeyEvent::Type::KeyUp:
|
||||
client().async_key_up(m_client_state.page_index, event.key, event.modifiers, event.code_point);
|
||||
break;
|
||||
}
|
||||
client().async_key_event(m_client_state.page_index, event.clone_without_chrome_data());
|
||||
},
|
||||
[this](Web::MouseEvent const& event) {
|
||||
switch (event.type) {
|
||||
case Web::MouseEvent::Type::MouseDown:
|
||||
client().async_mouse_down(m_client_state.page_index, event.position, event.screen_position, event.button, event.buttons, event.modifiers);
|
||||
break;
|
||||
case Web::MouseEvent::Type::MouseUp:
|
||||
client().async_mouse_up(m_client_state.page_index, event.position, event.screen_position, event.button, event.buttons, event.modifiers);
|
||||
break;
|
||||
case Web::MouseEvent::Type::MouseMove:
|
||||
client().async_mouse_move(m_client_state.page_index, event.position, event.screen_position, event.button, event.buttons, event.modifiers);
|
||||
break;
|
||||
case Web::MouseEvent::Type::MouseWheel:
|
||||
client().async_mouse_wheel(m_client_state.page_index, event.position, event.screen_position, event.button, event.buttons, event.modifiers, event.wheel_delta_x, event.wheel_delta_y);
|
||||
break;
|
||||
case Web::MouseEvent::Type::DoubleClick:
|
||||
client().async_doubleclick(m_client_state.page_index, event.position, event.screen_position, event.button, event.buttons, event.modifiers);
|
||||
break;
|
||||
}
|
||||
client().async_mouse_event(m_client_state.page_index, event.clone_without_chrome_data());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue