mirror of
https://github.com/SerenityOS/serenity
synced 2026-05-03 04:42:19 +02:00
This cherrypicks most of commit d90a9ab70c7ef73577775f0abed8552907899f75
It doesn't actually remove Kernel/API/KeyCode.h though, since we still
need that :^)
Patch created by running (in zsh, where the `${=foo}` syntax is needed
to tell zsh to convert space-separated strings into separate args):
files=$(git show --name-only --pretty='' d90a9ab70c7e |
rg -v 'CMakeLists.txt|KeyCode.h' | tr '\n' ' ')
git show d90a9ab70c7e -- ${=files} | git apply -3 -
74 lines
2.3 KiB
C++
74 lines
2.3 KiB
C++
/*
|
|
* 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<Web::UIEvents::KeyCode>());
|
|
auto modifiers = TRY(decoder.decode<Web::UIEvents::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<Web::UIEvents::MouseButton>());
|
|
auto buttons = TRY(decoder.decode<Web::UIEvents::MouseButton>());
|
|
auto modifiers = TRY(decoder.decode<Web::UIEvents::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 };
|
|
}
|