2024-03-05 19:06:32 -03:00
|
|
|
/*
|
|
|
|
|
* 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>
|
2026-01-21 18:29:00 -03:00
|
|
|
#include <math.h>
|
2024-03-05 19:06:32 -03:00
|
|
|
|
|
|
|
|
namespace Web {
|
|
|
|
|
|
2025-03-15 18:07:53 -03:00
|
|
|
KeyEvent KeyEvent::clone_without_browser_data() const
|
2024-03-05 19:06:32 -03:00
|
|
|
{
|
2026-06-03 07:26:44 -03:00
|
|
|
return { type, key, modifiers, code_point, repeat, should_insert_text, nullptr };
|
2024-03-05 19:06:32 -03:00
|
|
|
}
|
|
|
|
|
|
2025-03-15 18:07:53 -03:00
|
|
|
MouseEvent MouseEvent::clone_without_browser_data() const
|
2024-03-05 19:06:32 -03:00
|
|
|
{
|
2026-05-11 16:42:02 -03:00
|
|
|
return { type, position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, click_count, nullptr, async_scroll_performed_default_action };
|
2024-03-05 19:06:32 -03:00
|
|
|
}
|
|
|
|
|
|
2025-03-15 18:07:53 -03:00
|
|
|
DragEvent DragEvent::clone_without_browser_data() const
|
2024-08-17 14:29:55 -03:00
|
|
|
{
|
|
|
|
|
return { type, position, screen_position, button, buttons, modifiers, {}, nullptr };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 19:06:32 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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));
|
2024-10-22 10:32:42 -03:00
|
|
|
TRY(encoder.encode(event.repeat));
|
2026-06-03 07:26:44 -03:00
|
|
|
TRY(encoder.encode(event.should_insert_text));
|
2024-03-05 19:06:32 -03:00
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
ErrorOr<Web::KeyEvent> IPC::decode(Decoder& decoder)
|
|
|
|
|
{
|
|
|
|
|
auto type = TRY(decoder.decode<Web::KeyEvent::Type>());
|
2024-06-06 16:29:08 -03:00
|
|
|
auto key = TRY(decoder.decode<Web::UIEvents::KeyCode>());
|
|
|
|
|
auto modifiers = TRY(decoder.decode<Web::UIEvents::KeyModifier>());
|
2024-03-05 19:06:32 -03:00
|
|
|
auto code_point = TRY(decoder.decode<u32>());
|
2024-10-22 10:32:42 -03:00
|
|
|
auto repeat = TRY(decoder.decode<bool>());
|
2026-06-03 07:26:44 -03:00
|
|
|
auto should_insert_text = TRY(decoder.decode<bool>());
|
2024-03-05 19:06:32 -03:00
|
|
|
|
2026-06-03 07:26:44 -03:00
|
|
|
return Web::KeyEvent { type, key, modifiers, code_point, repeat, should_insert_text, nullptr };
|
2024-03-05 19:06:32 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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));
|
2026-03-07 03:06:07 -03:00
|
|
|
TRY(encoder.encode(event.click_count));
|
2026-05-11 16:42:02 -03:00
|
|
|
TRY(encoder.encode(event.async_scroll_performed_default_action));
|
2024-03-05 19:06:32 -03:00
|
|
|
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>());
|
2024-06-02 14:00:42 -03:00
|
|
|
auto button = TRY(decoder.decode<Web::UIEvents::MouseButton>());
|
|
|
|
|
auto buttons = TRY(decoder.decode<Web::UIEvents::MouseButton>());
|
2024-06-06 16:29:08 -03:00
|
|
|
auto modifiers = TRY(decoder.decode<Web::UIEvents::KeyModifier>());
|
LibWeb: Use double precision for wheel scroll deltas
Wheel deltas were truncated to int at the platform input boundary,
which dropped the sub-pixel tail of trackpad momentum scrolls. Each
NSEvent's scrollingDeltaY arrived as a CGFloat, got cast to int, and
flowed through IPC, EventHandler, and PaintableBox::scroll_by as int,
losing fractional information that never came back.
Widen Web::MouseEvent::wheel_delta_{x,y} to double and propagate
through Page, EventHandler, Paintable, PaintableBox, and the AppKit,
Qt, and GTK input paths.
2026-05-12 05:40:45 -03:00
|
|
|
auto wheel_delta_x = TRY(decoder.decode<double>());
|
|
|
|
|
auto wheel_delta_y = TRY(decoder.decode<double>());
|
2026-03-07 03:06:07 -03:00
|
|
|
auto click_count = TRY(decoder.decode<int>());
|
2026-05-11 16:42:02 -03:00
|
|
|
auto async_scroll_performed_default_action = TRY(decoder.decode<bool>());
|
2024-03-05 19:06:32 -03:00
|
|
|
|
2026-05-11 16:42:02 -03:00
|
|
|
return Web::MouseEvent { type, position, screen_position, button, buttons, modifiers, wheel_delta_x, wheel_delta_y, click_count, nullptr, async_scroll_performed_default_action };
|
2024-03-05 19:06:32 -03:00
|
|
|
}
|
2024-08-17 14:36:28 -03:00
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
ErrorOr<void> IPC::encode(Encoder& encoder, Web::DragEvent 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.files));
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
ErrorOr<Web::DragEvent> IPC::decode(Decoder& decoder)
|
|
|
|
|
{
|
|
|
|
|
auto type = TRY(decoder.decode<Web::DragEvent::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 files = TRY(decoder.decode<Vector<Web::HTML::SelectedFile>>());
|
|
|
|
|
|
|
|
|
|
return Web::DragEvent { type, position, screen_position, button, buttons, modifiers, move(files), nullptr };
|
|
|
|
|
}
|
2025-10-08 18:59:50 -03:00
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
WEB_API ErrorOr<void> IPC::encode(Encoder& encoder, Web::PinchEvent const& event)
|
|
|
|
|
{
|
|
|
|
|
TRY(encoder.encode(event.position));
|
2026-05-26 23:04:15 -03:00
|
|
|
TRY(encoder.encode(event.modifiers));
|
2025-10-08 18:59:50 -03:00
|
|
|
TRY(encoder.encode(event.scale_delta));
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
WEB_API ErrorOr<Web::PinchEvent> IPC::decode(Decoder& decoder)
|
|
|
|
|
{
|
|
|
|
|
auto position = TRY(decoder.decode<Web::DevicePixelPoint>());
|
2026-05-26 23:04:15 -03:00
|
|
|
auto modifiers = TRY(decoder.decode<Web::UIEvents::KeyModifier>());
|
2025-10-08 18:59:50 -03:00
|
|
|
auto scale_delta = TRY(decoder.decode<double>());
|
2026-01-21 18:29:00 -03:00
|
|
|
|
|
|
|
|
if (isnan(scale_delta) || isinf(scale_delta))
|
|
|
|
|
return Error::from_string_literal("IPC: Invalid scale_delta value");
|
|
|
|
|
|
2026-05-26 23:04:15 -03:00
|
|
|
return Web::PinchEvent { position, modifiers, scale_delta };
|
2025-10-08 18:59:50 -03:00
|
|
|
}
|