2022-10-05 10:23:41 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2022-2023, Andreas Kling <andreas@ladybird.org>
|
2023-01-12 11:39:53 -03:00
|
|
|
* Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
|
2025-02-20 09:17:29 -03:00
|
|
|
* Copyright (c) 2024-2025, Sam Atkins <sam@ladybird.org>
|
2022-10-05 10:23:41 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <AK/Assertions.h>
|
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
|
#include <AK/Format.h>
|
|
|
|
|
#include <AK/LexicalPath.h>
|
|
|
|
|
#include <AK/NonnullOwnPtr.h>
|
|
|
|
|
#include <AK/Types.h>
|
|
|
|
|
#include <LibCore/EventLoop.h>
|
2023-11-05 11:46:28 -03:00
|
|
|
#include <LibCore/Resource.h>
|
2022-10-05 10:23:41 -03:00
|
|
|
#include <LibCore/Timer.h>
|
|
|
|
|
#include <LibGfx/Bitmap.h>
|
|
|
|
|
#include <LibGfx/Font/FontDatabase.h>
|
2023-03-21 15:58:06 -03:00
|
|
|
#include <LibGfx/ImageFormats/PNGWriter.h>
|
2023-03-15 18:56:47 -03:00
|
|
|
#include <LibGfx/Palette.h>
|
2022-10-05 10:23:41 -03:00
|
|
|
#include <LibGfx/Rect.h>
|
2022-12-17 21:50:53 -03:00
|
|
|
#include <LibGfx/SystemTheme.h>
|
2024-06-06 16:29:08 -03:00
|
|
|
#include <LibWeb/UIEvents/KeyCode.h>
|
2024-06-02 14:00:42 -03:00
|
|
|
#include <LibWeb/UIEvents/MouseButton.h>
|
2024-07-30 15:01:05 -03:00
|
|
|
#include <LibWebView/Application.h>
|
2026-06-20 20:22:50 -03:00
|
|
|
#include <LibWebView/PlatformColors.h>
|
2026-05-20 13:37:49 -03:00
|
|
|
#include <LibWebView/Utilities.h>
|
2022-10-05 10:23:41 -03:00
|
|
|
#include <LibWebView/WebContentClient.h>
|
2024-11-09 14:50:33 -03:00
|
|
|
#include <UI/Qt/Application.h>
|
2026-06-20 20:22:50 -03:00
|
|
|
#ifdef AK_OS_MACOS
|
|
|
|
|
# include <UI/Qt/MacWindow.h>
|
|
|
|
|
#endif
|
2024-11-09 14:50:33 -03:00
|
|
|
#include <UI/Qt/StringUtils.h>
|
|
|
|
|
#include <UI/Qt/WebContentView.h>
|
|
|
|
|
|
2022-10-05 10:23:41 -03:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QCursor>
|
2023-06-12 07:52:44 -03:00
|
|
|
#include <QGuiApplication>
|
2022-10-05 10:23:41 -03:00
|
|
|
#include <QIcon>
|
2026-05-26 13:03:07 -03:00
|
|
|
#include <QKeySequence>
|
2023-01-07 13:40:04 -03:00
|
|
|
#include <QMimeData>
|
2022-10-05 10:23:41 -03:00
|
|
|
#include <QMouseEvent>
|
2026-05-31 21:55:31 -03:00
|
|
|
#include <QNativeGestureEvent>
|
2022-10-05 10:23:41 -03:00
|
|
|
#include <QPaintEvent>
|
|
|
|
|
#include <QPainter>
|
2023-03-15 18:56:47 -03:00
|
|
|
#include <QPalette>
|
2026-06-10 21:26:41 -03:00
|
|
|
#include <QPixmap>
|
2022-10-05 10:23:41 -03:00
|
|
|
#include <QScrollBar>
|
2026-05-25 16:22:50 -03:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
|
|
|
|
# include <QStyleHints>
|
|
|
|
|
#endif
|
2022-10-05 10:23:41 -03:00
|
|
|
#include <QTextEdit>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QToolTip>
|
|
|
|
|
|
2023-08-02 14:52:59 -03:00
|
|
|
namespace Ladybird {
|
|
|
|
|
|
2023-04-29 13:35:06 -03:00
|
|
|
bool is_using_dark_system_theme(QWidget&);
|
|
|
|
|
|
2026-06-01 05:40:42 -03:00
|
|
|
static QWidget* initial_web_content_view_parent([[maybe_unused]] QWidget* window)
|
|
|
|
|
{
|
|
|
|
|
#ifdef AK_OS_MACOS
|
|
|
|
|
return nullptr;
|
|
|
|
|
#else
|
|
|
|
|
return window;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-25 12:43:27 -03:00
|
|
|
WebContentView::WebContentView(QWidget* window, RefPtr<WebView::WebContentClient> parent_client, size_t page_index, WebContentViewInitialState initial_state)
|
2026-06-01 05:40:42 -03:00
|
|
|
: WebContentViewBase(initial_web_content_view_parent(window))
|
2022-10-05 10:23:41 -03:00
|
|
|
{
|
2026-06-01 06:45:00 -03:00
|
|
|
#ifdef LADYBIRD_QT_USE_METAL_RHI_WIDGET
|
2026-06-01 05:40:42 -03:00
|
|
|
// Keep the QRhiWidget out of the top-level QWidget backing store. If it is
|
|
|
|
|
// parented before becoming native, Qt propagates its RHI config to the whole
|
|
|
|
|
// browser window and uploads the full backing store texture on chrome repaints.
|
|
|
|
|
setAttribute(Qt::WA_DontCreateNativeAncestors);
|
|
|
|
|
setAttribute(Qt::WA_NativeWindow);
|
|
|
|
|
setParent(window);
|
2026-05-31 21:29:15 -03:00
|
|
|
setApi(QRhiWidget::Api::Metal);
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-01-30 13:12:14 -03:00
|
|
|
m_client_state.client = parent_client;
|
|
|
|
|
m_client_state.page_index = page_index;
|
|
|
|
|
|
2024-08-12 09:06:41 -03:00
|
|
|
setAttribute(Qt::WA_InputMethodEnabled, true);
|
2022-10-05 10:23:41 -03:00
|
|
|
setMouseTracking(true);
|
2023-01-07 13:40:04 -03:00
|
|
|
setAcceptDrops(true);
|
2022-10-05 10:23:41 -03:00
|
|
|
|
2022-10-11 06:38:03 -03:00
|
|
|
setFocusPolicy(Qt::FocusPolicy::StrongFocus);
|
|
|
|
|
|
2026-06-01 06:45:00 -03:00
|
|
|
#ifdef LADYBIRD_QT_USE_VULKAN_WINDOW
|
|
|
|
|
create_vulkan_window();
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-01-12 11:39:05 -03:00
|
|
|
m_device_pixel_ratio = devicePixelRatio();
|
2025-07-25 12:43:27 -03:00
|
|
|
m_maximum_frames_per_second = initial_state.maximum_frames_per_second;
|
2026-05-28 14:04:22 -03:00
|
|
|
m_display_id = initial_state.display_id;
|
2026-05-26 20:11:14 -03:00
|
|
|
set_page_background_color_to_system_canvas(is_using_dark_system_theme(*this));
|
2022-10-05 10:23:41 -03:00
|
|
|
|
2024-04-05 14:19:50 -03:00
|
|
|
QObject::connect(qGuiApp, &QGuiApplication::screenRemoved, [this](QScreen*) {
|
|
|
|
|
update_screen_rects();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QObject::connect(qGuiApp, &QGuiApplication::screenAdded, [this](QScreen*) {
|
|
|
|
|
update_screen_rects();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-25 16:22:50 -03:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
|
|
|
|
QObject::connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this, [this] {
|
|
|
|
|
QTimer::singleShot(0, this, [this] {
|
|
|
|
|
update_palette();
|
2026-06-01 06:45:00 -03:00
|
|
|
schedule_repaint();
|
2026-05-25 16:22:50 -03:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-07-02 09:16:24 -03:00
|
|
|
m_tooltip_hover_timer.setSingleShot(true);
|
|
|
|
|
|
|
|
|
|
QObject::connect(&m_tooltip_hover_timer, &QTimer::timeout, [this] {
|
|
|
|
|
if (m_tooltip_text.has_value())
|
|
|
|
|
QToolTip::showText(
|
|
|
|
|
QCursor::pos(),
|
|
|
|
|
qstring_from_ak_string(m_tooltip_text.value()),
|
|
|
|
|
this);
|
|
|
|
|
});
|
|
|
|
|
|
2024-01-30 13:12:14 -03:00
|
|
|
initialize_client((parent_client == nullptr) ? CreateNewClient::Yes : CreateNewClient::No);
|
2023-05-20 11:50:05 -03:00
|
|
|
|
|
|
|
|
on_ready_to_paint = [this]() {
|
2026-06-01 06:45:00 -03:00
|
|
|
schedule_repaint();
|
2023-05-20 11:50:05 -03:00
|
|
|
};
|
2023-08-23 11:43:27 -03:00
|
|
|
|
|
|
|
|
on_cursor_change = [this](auto cursor) {
|
|
|
|
|
update_cursor(cursor);
|
|
|
|
|
};
|
2023-08-23 12:11:39 -03:00
|
|
|
|
2024-07-02 11:48:57 -03:00
|
|
|
on_request_tooltip_override = [this](auto position, auto const& tooltip) {
|
|
|
|
|
m_tooltip_override = true;
|
|
|
|
|
if (m_tooltip_hover_timer.isActive())
|
|
|
|
|
m_tooltip_hover_timer.stop();
|
|
|
|
|
|
|
|
|
|
auto tooltip_without_carriage_return = tooltip.contains("\r"sv)
|
|
|
|
|
? tooltip.replace("\r\n"sv, "\n"sv, ReplaceMode::All).replace("\r"sv, "\n"sv, ReplaceMode::All)
|
|
|
|
|
: tooltip;
|
|
|
|
|
QToolTip::showText(
|
|
|
|
|
mapToGlobal(QPoint(position.x(), position.y())),
|
|
|
|
|
qstring_from_ak_string(tooltip_without_carriage_return),
|
|
|
|
|
this);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
on_stop_tooltip_override = [this]() {
|
|
|
|
|
m_tooltip_override = false;
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-02 09:16:24 -03:00
|
|
|
on_enter_tooltip_area = [this](auto const& tooltip) {
|
|
|
|
|
m_tooltip_text = tooltip.contains("\r"sv)
|
2024-03-08 21:11:30 -03:00
|
|
|
? tooltip.replace("\r\n"sv, "\n"sv, ReplaceMode::All).replace("\r"sv, "\n"sv, ReplaceMode::All)
|
|
|
|
|
: tooltip;
|
2023-08-23 12:11:39 -03:00
|
|
|
};
|
|
|
|
|
|
2024-07-02 09:16:24 -03:00
|
|
|
on_leave_tooltip_area = [this]() {
|
|
|
|
|
m_tooltip_text.clear();
|
2023-08-23 12:11:39 -03:00
|
|
|
};
|
2024-01-06 17:13:59 -03:00
|
|
|
|
2024-03-05 09:53:57 -03:00
|
|
|
on_finish_handling_key_event = [this](auto const& event) {
|
|
|
|
|
finish_handling_key_event(event);
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-17 15:47:28 -03:00
|
|
|
on_finish_handling_drag_event = [this](auto const& event) {
|
|
|
|
|
finish_handling_drag_event(event);
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-21 07:10:41 -03:00
|
|
|
m_select_dropdown = new QMenu("Select Dropdown", this);
|
|
|
|
|
QObject::connect(m_select_dropdown, &QMenu::aboutToHide, this, [this]() {
|
|
|
|
|
if (!m_select_dropdown->activeAction())
|
|
|
|
|
select_dropdown_closed({});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
on_request_select_dropdown = [this](Gfx::IntPoint content_position, i32 minimum_width, Vector<Web::HTML::SelectItem> items) {
|
|
|
|
|
m_select_dropdown->clear();
|
2025-03-21 11:53:59 -03:00
|
|
|
m_select_dropdown->setMinimumWidth(minimum_width);
|
2024-08-21 07:10:41 -03:00
|
|
|
|
|
|
|
|
auto add_menu_item = [this](Web::HTML::SelectItemOption const& item_option, bool in_option_group) {
|
2026-05-26 14:26:09 -03:00
|
|
|
auto label = in_option_group ? qformatted(" {}", item_option.label) : qstring_from_ak_string(item_option.label);
|
|
|
|
|
|
|
|
|
|
QAction* action = new QAction(label, this);
|
2024-08-21 07:10:41 -03:00
|
|
|
action->setCheckable(true);
|
|
|
|
|
action->setChecked(item_option.selected);
|
|
|
|
|
action->setDisabled(item_option.disabled);
|
|
|
|
|
action->setData(QVariant(static_cast<uint>(item_option.id)));
|
|
|
|
|
QObject::connect(action, &QAction::triggered, this, &WebContentView::select_dropdown_action);
|
|
|
|
|
m_select_dropdown->addAction(action);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (auto const& item : items) {
|
|
|
|
|
if (item.has<Web::HTML::SelectItemOptionGroup>()) {
|
|
|
|
|
auto const& item_option_group = item.get<Web::HTML::SelectItemOptionGroup>();
|
|
|
|
|
QAction* subtitle = new QAction(qstring_from_ak_string(item_option_group.label), this);
|
|
|
|
|
subtitle->setDisabled(true);
|
|
|
|
|
m_select_dropdown->addAction(subtitle);
|
|
|
|
|
|
|
|
|
|
for (auto const& item_option : item_option_group.items)
|
|
|
|
|
add_menu_item(item_option, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.has<Web::HTML::SelectItemOption>())
|
|
|
|
|
add_menu_item(item.get<Web::HTML::SelectItemOption>(), false);
|
|
|
|
|
|
|
|
|
|
if (item.has<Web::HTML::SelectItemSeparator>())
|
|
|
|
|
m_select_dropdown->addSeparator();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_select_dropdown->exec(map_point_to_global_position(content_position));
|
|
|
|
|
};
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
|
|
|
|
|
2026-05-31 21:29:15 -03:00
|
|
|
WebContentView::~WebContentView()
|
|
|
|
|
{
|
|
|
|
|
#ifdef AK_OS_MACOS
|
|
|
|
|
release_metal_resources();
|
2026-06-01 06:45:00 -03:00
|
|
|
#elif defined(LADYBIRD_QT_USE_VULKAN_WINDOW)
|
|
|
|
|
destroy_vulkan_window();
|
2026-05-31 21:29:15 -03:00
|
|
|
#endif
|
|
|
|
|
}
|
2022-10-05 10:23:41 -03:00
|
|
|
|
2024-08-21 07:10:41 -03:00
|
|
|
void WebContentView::select_dropdown_action()
|
|
|
|
|
{
|
|
|
|
|
QAction* action = qobject_cast<QAction*>(sender());
|
|
|
|
|
select_dropdown_closed(action->data().value<uint>());
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 15:48:41 -03:00
|
|
|
static Web::UIEvents::MouseButton get_button_from_qt_mouse_button(Qt::MouseButton button)
|
2022-10-05 10:23:41 -03:00
|
|
|
{
|
2024-08-17 15:47:28 -03:00
|
|
|
if (button == Qt::MouseButton::LeftButton)
|
2024-06-02 14:00:42 -03:00
|
|
|
return Web::UIEvents::MouseButton::Primary;
|
2024-08-17 15:47:28 -03:00
|
|
|
if (button == Qt::MouseButton::RightButton)
|
2024-06-02 14:00:42 -03:00
|
|
|
return Web::UIEvents::MouseButton::Secondary;
|
2024-08-17 15:47:28 -03:00
|
|
|
if (button == Qt::MouseButton::MiddleButton)
|
2024-06-02 14:00:42 -03:00
|
|
|
return Web::UIEvents::MouseButton::Middle;
|
2024-08-17 15:47:28 -03:00
|
|
|
if (button == Qt::MouseButton::BackButton)
|
2024-06-02 14:00:42 -03:00
|
|
|
return Web::UIEvents::MouseButton::Backward;
|
2024-08-17 15:47:28 -03:00
|
|
|
if (button == Qt::MouseButton::ForwardButton)
|
2024-06-02 14:00:42 -03:00
|
|
|
return Web::UIEvents::MouseButton::Forward;
|
|
|
|
|
return Web::UIEvents::MouseButton::None;
|
2024-03-05 09:53:57 -03:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 15:48:41 -03:00
|
|
|
static Web::UIEvents::MouseButton get_buttons_from_qt_mouse_buttons(Qt::MouseButtons buttons)
|
2024-03-05 09:53:57 -03:00
|
|
|
{
|
2024-08-17 15:47:28 -03:00
|
|
|
auto result = Web::UIEvents::MouseButton::None;
|
|
|
|
|
if (buttons.testFlag(Qt::MouseButton::LeftButton))
|
|
|
|
|
result |= Web::UIEvents::MouseButton::Primary;
|
|
|
|
|
if (buttons.testFlag(Qt::MouseButton::RightButton))
|
|
|
|
|
result |= Web::UIEvents::MouseButton::Secondary;
|
|
|
|
|
if (buttons.testFlag(Qt::MouseButton::MiddleButton))
|
|
|
|
|
result |= Web::UIEvents::MouseButton::Middle;
|
|
|
|
|
if (buttons.testFlag(Qt::MouseButton::BackButton))
|
|
|
|
|
result |= Web::UIEvents::MouseButton::Backward;
|
|
|
|
|
if (buttons.testFlag(Qt::MouseButton::ForwardButton))
|
|
|
|
|
result |= Web::UIEvents::MouseButton::Forward;
|
|
|
|
|
return result;
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 15:48:41 -03:00
|
|
|
static Web::UIEvents::KeyModifier get_modifiers_from_qt_keyboard_modifiers(Qt::KeyboardModifiers modifiers)
|
2022-10-05 10:23:41 -03:00
|
|
|
{
|
2024-08-17 15:47:28 -03:00
|
|
|
auto result = Web::UIEvents::KeyModifier::Mod_None;
|
|
|
|
|
if (modifiers.testFlag(Qt::AltModifier))
|
|
|
|
|
result |= Web::UIEvents::KeyModifier::Mod_Alt;
|
|
|
|
|
if (modifiers.testFlag(Qt::ShiftModifier))
|
|
|
|
|
result |= Web::UIEvents::KeyModifier::Mod_Shift;
|
2026-05-31 22:09:15 -03:00
|
|
|
#if defined(AK_OS_MACOS)
|
|
|
|
|
if (modifiers.testFlag(Qt::ControlModifier))
|
|
|
|
|
result |= Web::UIEvents::KeyModifier::Mod_Super;
|
|
|
|
|
if (modifiers.testFlag(Qt::MetaModifier))
|
|
|
|
|
result |= Web::UIEvents::KeyModifier::Mod_Ctrl;
|
|
|
|
|
#else
|
|
|
|
|
if (modifiers.testFlag(Qt::ControlModifier))
|
|
|
|
|
result |= Web::UIEvents::KeyModifier::Mod_Ctrl;
|
|
|
|
|
if (modifiers.testFlag(Qt::MetaModifier))
|
|
|
|
|
result |= Web::UIEvents::KeyModifier::Mod_Super;
|
|
|
|
|
#endif
|
2024-08-17 15:47:28 -03:00
|
|
|
return result;
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
|
|
|
|
|
2024-08-20 15:48:41 -03:00
|
|
|
static Web::UIEvents::KeyModifier get_modifiers_from_qt_key_event(QKeyEvent const& event)
|
2022-10-05 10:23:41 -03:00
|
|
|
{
|
2026-05-31 22:09:15 -03:00
|
|
|
auto modifiers = get_modifiers_from_qt_keyboard_modifiers(event.modifiers());
|
2023-07-08 17:01:32 -03:00
|
|
|
if (event.modifiers().testFlag(Qt::KeypadModifier))
|
2024-06-06 16:29:08 -03:00
|
|
|
modifiers |= Web::UIEvents::KeyModifier::Mod_Keypad;
|
2022-10-05 10:23:41 -03:00
|
|
|
return modifiers;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 15:48:41 -03:00
|
|
|
static Web::UIEvents::KeyCode get_keycode_from_qt_key_event(QKeyEvent const& event)
|
2022-10-05 10:23:41 -03:00
|
|
|
{
|
|
|
|
|
struct Mapping {
|
2024-06-06 16:29:08 -03:00
|
|
|
constexpr Mapping(Qt::Key q, Web::UIEvents::KeyCode s)
|
2022-10-05 10:23:41 -03:00
|
|
|
: qt_key(q)
|
|
|
|
|
, serenity_key(s)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::Key qt_key;
|
2024-06-06 16:29:08 -03:00
|
|
|
Web::UIEvents::KeyCode serenity_key;
|
2022-10-05 10:23:41 -03:00
|
|
|
};
|
|
|
|
|
|
2024-10-09 09:56:55 -03:00
|
|
|
// FIXME: Qt does not differentiate between left-and-right modifier keys. Unfortunately, it seems like we would have
|
|
|
|
|
// to inspect event.nativeScanCode() / event.nativeVirtualKey() to do so, which has platform-dependent values.
|
|
|
|
|
// For now, we default to left keys.
|
|
|
|
|
|
2023-07-08 17:58:22 -03:00
|
|
|
// https://doc.qt.io/qt-6/qt.html#Key-enum
|
2024-10-09 09:56:55 -03:00
|
|
|
static constexpr Mapping mappings[] = {
|
2024-06-06 16:29:08 -03:00
|
|
|
{ Qt::Key_0, Web::UIEvents::Key_0 },
|
|
|
|
|
{ Qt::Key_1, Web::UIEvents::Key_1 },
|
|
|
|
|
{ Qt::Key_2, Web::UIEvents::Key_2 },
|
|
|
|
|
{ Qt::Key_3, Web::UIEvents::Key_3 },
|
|
|
|
|
{ Qt::Key_4, Web::UIEvents::Key_4 },
|
|
|
|
|
{ Qt::Key_5, Web::UIEvents::Key_5 },
|
|
|
|
|
{ Qt::Key_6, Web::UIEvents::Key_6 },
|
|
|
|
|
{ Qt::Key_7, Web::UIEvents::Key_7 },
|
|
|
|
|
{ Qt::Key_8, Web::UIEvents::Key_8 },
|
|
|
|
|
{ Qt::Key_9, Web::UIEvents::Key_9 },
|
|
|
|
|
{ Qt::Key_A, Web::UIEvents::Key_A },
|
2024-10-09 09:56:55 -03:00
|
|
|
{ Qt::Key_Alt, Web::UIEvents::Key_LeftAlt },
|
2024-06-06 16:29:08 -03:00
|
|
|
{ Qt::Key_Ampersand, Web::UIEvents::Key_Ampersand },
|
|
|
|
|
{ Qt::Key_Apostrophe, Web::UIEvents::Key_Apostrophe },
|
|
|
|
|
{ Qt::Key_AsciiCircum, Web::UIEvents::Key_Circumflex },
|
|
|
|
|
{ Qt::Key_AsciiTilde, Web::UIEvents::Key_Tilde },
|
|
|
|
|
{ Qt::Key_Asterisk, Web::UIEvents::Key_Asterisk },
|
|
|
|
|
{ Qt::Key_At, Web::UIEvents::Key_AtSign },
|
|
|
|
|
{ Qt::Key_B, Web::UIEvents::Key_B },
|
|
|
|
|
{ Qt::Key_Backslash, Web::UIEvents::Key_Backslash },
|
|
|
|
|
{ Qt::Key_Backspace, Web::UIEvents::Key_Backspace },
|
|
|
|
|
{ Qt::Key_Bar, Web::UIEvents::Key_Pipe },
|
|
|
|
|
{ Qt::Key_BraceLeft, Web::UIEvents::Key_LeftBrace },
|
|
|
|
|
{ Qt::Key_BraceRight, Web::UIEvents::Key_RightBrace },
|
|
|
|
|
{ Qt::Key_BracketLeft, Web::UIEvents::Key_LeftBracket },
|
|
|
|
|
{ Qt::Key_BracketRight, Web::UIEvents::Key_RightBracket },
|
|
|
|
|
{ Qt::Key_C, Web::UIEvents::Key_C },
|
|
|
|
|
{ Qt::Key_CapsLock, Web::UIEvents::Key_CapsLock },
|
|
|
|
|
{ Qt::Key_Colon, Web::UIEvents::Key_Colon },
|
|
|
|
|
{ Qt::Key_Comma, Web::UIEvents::Key_Comma },
|
2024-10-09 09:56:55 -03:00
|
|
|
{ Qt::Key_Control, Web::UIEvents::Key_LeftControl },
|
2024-06-06 16:29:08 -03:00
|
|
|
{ Qt::Key_D, Web::UIEvents::Key_D },
|
|
|
|
|
{ Qt::Key_Delete, Web::UIEvents::Key_Delete },
|
|
|
|
|
{ Qt::Key_Dollar, Web::UIEvents::Key_Dollar },
|
|
|
|
|
{ Qt::Key_Down, Web::UIEvents::Key_Down },
|
|
|
|
|
{ Qt::Key_E, Web::UIEvents::Key_E },
|
|
|
|
|
{ Qt::Key_End, Web::UIEvents::Key_End },
|
|
|
|
|
{ Qt::Key_Equal, Web::UIEvents::Key_Equal },
|
|
|
|
|
{ Qt::Key_Enter, Web::UIEvents::Key_Return },
|
|
|
|
|
{ Qt::Key_Escape, Web::UIEvents::Key_Escape },
|
|
|
|
|
{ Qt::Key_Exclam, Web::UIEvents::Key_ExclamationPoint },
|
|
|
|
|
{ Qt::Key_exclamdown, Web::UIEvents::Key_ExclamationPoint },
|
|
|
|
|
{ Qt::Key_F, Web::UIEvents::Key_F },
|
|
|
|
|
{ Qt::Key_F1, Web::UIEvents::Key_F1 },
|
|
|
|
|
{ Qt::Key_F10, Web::UIEvents::Key_F10 },
|
|
|
|
|
{ Qt::Key_F11, Web::UIEvents::Key_F11 },
|
|
|
|
|
{ Qt::Key_F12, Web::UIEvents::Key_F12 },
|
|
|
|
|
{ Qt::Key_F2, Web::UIEvents::Key_F2 },
|
|
|
|
|
{ Qt::Key_F3, Web::UIEvents::Key_F3 },
|
|
|
|
|
{ Qt::Key_F4, Web::UIEvents::Key_F4 },
|
|
|
|
|
{ Qt::Key_F5, Web::UIEvents::Key_F5 },
|
|
|
|
|
{ Qt::Key_F6, Web::UIEvents::Key_F6 },
|
|
|
|
|
{ Qt::Key_F7, Web::UIEvents::Key_F7 },
|
|
|
|
|
{ Qt::Key_F8, Web::UIEvents::Key_F8 },
|
|
|
|
|
{ Qt::Key_F9, Web::UIEvents::Key_F9 },
|
|
|
|
|
{ Qt::Key_G, Web::UIEvents::Key_G },
|
|
|
|
|
{ Qt::Key_Greater, Web::UIEvents::Key_GreaterThan },
|
|
|
|
|
{ Qt::Key_H, Web::UIEvents::Key_H },
|
|
|
|
|
{ Qt::Key_Home, Web::UIEvents::Key_Home },
|
|
|
|
|
{ Qt::Key_I, Web::UIEvents::Key_I },
|
|
|
|
|
{ Qt::Key_Insert, Web::UIEvents::Key_Insert },
|
|
|
|
|
{ Qt::Key_J, Web::UIEvents::Key_J },
|
|
|
|
|
{ Qt::Key_K, Web::UIEvents::Key_K },
|
|
|
|
|
{ Qt::Key_L, Web::UIEvents::Key_L },
|
|
|
|
|
{ Qt::Key_Left, Web::UIEvents::Key_Left },
|
|
|
|
|
{ Qt::Key_Less, Web::UIEvents::Key_LessThan },
|
|
|
|
|
{ Qt::Key_M, Web::UIEvents::Key_M },
|
|
|
|
|
{ Qt::Key_Menu, Web::UIEvents::Key_Menu },
|
2024-10-09 09:56:55 -03:00
|
|
|
{ Qt::Key_Meta, Web::UIEvents::Key_LeftSuper },
|
2024-06-06 16:29:08 -03:00
|
|
|
{ Qt::Key_Minus, Web::UIEvents::Key_Minus },
|
|
|
|
|
{ Qt::Key_N, Web::UIEvents::Key_N },
|
|
|
|
|
{ Qt::Key_NumberSign, Web::UIEvents::Key_Hashtag },
|
|
|
|
|
{ Qt::Key_NumLock, Web::UIEvents::Key_NumLock },
|
|
|
|
|
{ Qt::Key_O, Web::UIEvents::Key_O },
|
|
|
|
|
{ Qt::Key_P, Web::UIEvents::Key_P },
|
|
|
|
|
{ Qt::Key_PageDown, Web::UIEvents::Key_PageDown },
|
|
|
|
|
{ Qt::Key_PageUp, Web::UIEvents::Key_PageUp },
|
|
|
|
|
{ Qt::Key_ParenLeft, Web::UIEvents::Key_LeftParen },
|
|
|
|
|
{ Qt::Key_ParenRight, Web::UIEvents::Key_RightParen },
|
|
|
|
|
{ Qt::Key_Percent, Web::UIEvents::Key_Percent },
|
|
|
|
|
{ Qt::Key_Period, Web::UIEvents::Key_Period },
|
|
|
|
|
{ Qt::Key_Plus, Web::UIEvents::Key_Plus },
|
|
|
|
|
{ Qt::Key_Print, Web::UIEvents::Key_PrintScreen },
|
|
|
|
|
{ Qt::Key_Q, Web::UIEvents::Key_Q },
|
|
|
|
|
{ Qt::Key_Question, Web::UIEvents::Key_QuestionMark },
|
|
|
|
|
{ Qt::Key_QuoteDbl, Web::UIEvents::Key_DoubleQuote },
|
|
|
|
|
{ Qt::Key_QuoteLeft, Web::UIEvents::Key_Backtick },
|
|
|
|
|
{ Qt::Key_R, Web::UIEvents::Key_R },
|
|
|
|
|
{ Qt::Key_Return, Web::UIEvents::Key_Return },
|
|
|
|
|
{ Qt::Key_Right, Web::UIEvents::Key_Right },
|
|
|
|
|
{ Qt::Key_S, Web::UIEvents::Key_S },
|
|
|
|
|
{ Qt::Key_ScrollLock, Web::UIEvents::Key_ScrollLock },
|
|
|
|
|
{ Qt::Key_Semicolon, Web::UIEvents::Key_Semicolon },
|
|
|
|
|
{ Qt::Key_Shift, Web::UIEvents::Key_LeftShift },
|
|
|
|
|
{ Qt::Key_Slash, Web::UIEvents::Key_Slash },
|
|
|
|
|
{ Qt::Key_Space, Web::UIEvents::Key_Space },
|
2024-10-09 09:56:55 -03:00
|
|
|
{ Qt::Key_Super_L, Web::UIEvents::Key_LeftSuper },
|
|
|
|
|
{ Qt::Key_Super_R, Web::UIEvents::Key_RightSuper },
|
2024-06-06 16:29:08 -03:00
|
|
|
{ Qt::Key_SysReq, Web::UIEvents::Key_SysRq },
|
|
|
|
|
{ Qt::Key_T, Web::UIEvents::Key_T },
|
|
|
|
|
{ Qt::Key_Tab, Web::UIEvents::Key_Tab },
|
|
|
|
|
{ Qt::Key_U, Web::UIEvents::Key_U },
|
|
|
|
|
{ Qt::Key_Underscore, Web::UIEvents::Key_Underscore },
|
|
|
|
|
{ Qt::Key_Up, Web::UIEvents::Key_Up },
|
|
|
|
|
{ Qt::Key_V, Web::UIEvents::Key_V },
|
|
|
|
|
{ Qt::Key_W, Web::UIEvents::Key_W },
|
|
|
|
|
{ Qt::Key_X, Web::UIEvents::Key_X },
|
|
|
|
|
{ Qt::Key_Y, Web::UIEvents::Key_Y },
|
|
|
|
|
{ Qt::Key_Z, Web::UIEvents::Key_Z },
|
2022-10-05 10:23:41 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (auto const& mapping : mappings) {
|
|
|
|
|
if (event.key() == mapping.qt_key)
|
|
|
|
|
return mapping.serenity_key;
|
|
|
|
|
}
|
2024-06-06 16:29:08 -03:00
|
|
|
return Web::UIEvents::Key_Invalid;
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
|
|
|
|
|
2026-05-26 14:58:58 -03:00
|
|
|
static bool is_browser_reserved_shortcut(QKeyEvent const& event)
|
|
|
|
|
{
|
2026-05-31 09:26:58 -03:00
|
|
|
// Browser chrome shortcuts that manage tabs, windows, or focus should not wait for
|
2026-05-26 14:58:58 -03:00
|
|
|
// WebContent to decide whether the page wants to suppress them.
|
|
|
|
|
if (event.matches(QKeySequence::StandardKey::AddTab)
|
|
|
|
|
|| event.matches(QKeySequence::StandardKey::Close)
|
|
|
|
|
|| event.matches(QKeySequence::StandardKey::New)
|
|
|
|
|
|| event.matches(QKeySequence::StandardKey::Quit))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
auto const modifiers = event.modifiers() & (Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier | Qt::MetaModifier);
|
|
|
|
|
auto const key = event.key();
|
|
|
|
|
|
|
|
|
|
if (modifiers == (Qt::ControlModifier | Qt::ShiftModifier) && key == Qt::Key_T)
|
|
|
|
|
return true;
|
|
|
|
|
|
2026-05-31 09:26:58 -03:00
|
|
|
if (modifiers == Qt::ControlModifier && (key == Qt::Key_L || key == Qt::Key_Tab || key == Qt::Key_PageDown))
|
2026-05-26 14:58:58 -03:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (modifiers == (Qt::ControlModifier | Qt::ShiftModifier) && (key == Qt::Key_Tab || key == Qt::Key_Backtab))
|
|
|
|
|
return true;
|
|
|
|
|
|
2026-06-01 05:13:33 -03:00
|
|
|
#if defined(AK_OS_MACOS)
|
|
|
|
|
if (modifiers == Qt::MetaModifier && key == Qt::Key_Tab)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (modifiers == (Qt::MetaModifier | Qt::ShiftModifier) && (key == Qt::Key_Tab || key == Qt::Key_Backtab))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (modifiers == (Qt::ControlModifier | Qt::ShiftModifier) && (key == Qt::Key_BracketLeft || key == Qt::Key_BracketRight))
|
|
|
|
|
return true;
|
|
|
|
|
#endif
|
|
|
|
|
|
2026-05-26 14:58:58 -03:00
|
|
|
if (modifiers == Qt::ControlModifier && key == Qt::Key_PageUp)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 09:53:57 -03:00
|
|
|
void WebContentView::keyPressEvent(QKeyEvent* event)
|
|
|
|
|
{
|
2026-05-28 08:18:49 -03:00
|
|
|
if (is_node_picker_active()) {
|
|
|
|
|
if (event->key() == Qt::Key_Escape)
|
|
|
|
|
node_picker_cancel();
|
|
|
|
|
event->accept();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 09:53:57 -03:00
|
|
|
enqueue_native_event(Web::KeyEvent::Type::KeyDown, *event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContentView::keyReleaseEvent(QKeyEvent* event)
|
|
|
|
|
{
|
2026-05-28 08:18:49 -03:00
|
|
|
if (is_node_picker_active()) {
|
|
|
|
|
event->accept();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 09:53:57 -03:00
|
|
|
enqueue_native_event(Web::KeyEvent::Type::KeyUp, *event);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-12 09:06:41 -03:00
|
|
|
void WebContentView::inputMethodEvent(QInputMethodEvent* event)
|
|
|
|
|
{
|
2026-05-28 08:18:49 -03:00
|
|
|
if (is_node_picker_active()) {
|
|
|
|
|
event->accept();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-12 09:06:41 -03:00
|
|
|
if (!event->commitString().isEmpty()) {
|
|
|
|
|
QKeyEvent keyEvent(QEvent::KeyPress, 0, Qt::NoModifier, event->commitString());
|
|
|
|
|
keyPressEvent(&keyEvent);
|
|
|
|
|
}
|
|
|
|
|
event->accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant WebContentView::inputMethodQuery(Qt::InputMethodQuery) const
|
|
|
|
|
{
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-27 10:55:26 -03:00
|
|
|
void WebContentView::leaveEvent(QEvent* event)
|
|
|
|
|
{
|
2026-05-28 08:18:49 -03:00
|
|
|
if (is_node_picker_active()) {
|
|
|
|
|
clear_node_picker();
|
2026-05-31 21:29:15 -03:00
|
|
|
WebContentViewBase::leaveEvent(event);
|
2026-05-28 08:18:49 -03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-28 13:57:31 -03:00
|
|
|
static QMouseEvent mouse_event { QEvent::Type::Leave, {}, {}, Qt::MouseButton::NoButton, Qt::MouseButton::NoButton, Qt::KeyboardModifier::NoModifier };
|
|
|
|
|
enqueue_native_event(Web::MouseEvent::Type::MouseLeave, mouse_event);
|
2025-07-27 10:55:26 -03:00
|
|
|
|
2026-05-31 21:29:15 -03:00
|
|
|
WebContentViewBase::leaveEvent(event);
|
2025-07-27 10:55:26 -03:00
|
|
|
}
|
|
|
|
|
|
2022-10-05 10:23:41 -03:00
|
|
|
void WebContentView::mouseMoveEvent(QMouseEvent* event)
|
|
|
|
|
{
|
2026-05-28 08:18:49 -03:00
|
|
|
if (is_node_picker_active()) {
|
|
|
|
|
node_picker_hover(node_picker_position_for(*event));
|
|
|
|
|
event->accept();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 11:48:57 -03:00
|
|
|
if (!m_tooltip_override) {
|
|
|
|
|
if (QToolTip::isVisible())
|
|
|
|
|
QToolTip::hideText();
|
|
|
|
|
m_tooltip_hover_timer.start(600);
|
|
|
|
|
}
|
2024-07-02 09:16:24 -03:00
|
|
|
|
2024-03-05 09:53:57 -03:00
|
|
|
enqueue_native_event(Web::MouseEvent::Type::MouseMove, *event);
|
2026-05-31 21:29:15 -03:00
|
|
|
WebContentViewBase::mouseMoveEvent(event);
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContentView::mousePressEvent(QMouseEvent* event)
|
|
|
|
|
{
|
2026-05-28 08:18:49 -03:00
|
|
|
if (is_node_picker_active()) {
|
|
|
|
|
if (event->button() == Qt::MouseButton::LeftButton) {
|
|
|
|
|
auto position = node_picker_position_for(*event);
|
|
|
|
|
if (event->modifiers().testFlag(Qt::ControlModifier))
|
|
|
|
|
node_picker_preview(position);
|
|
|
|
|
else
|
|
|
|
|
node_picker_pick(position);
|
|
|
|
|
}
|
|
|
|
|
event->accept();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 09:07:15 -03:00
|
|
|
auto elapsed = event->timestamp() - m_last_click_timestamp;
|
|
|
|
|
auto distance = (event->position() - m_last_click_position).manhattanLength();
|
|
|
|
|
|
2026-03-07 03:30:48 -03:00
|
|
|
if (elapsed < static_cast<u64>(QApplication::doubleClickInterval()) && distance < QApplication::startDragDistance()) {
|
2026-02-05 09:07:15 -03:00
|
|
|
++m_click_count;
|
2026-03-07 03:30:48 -03:00
|
|
|
if (m_click_count < 1)
|
|
|
|
|
m_click_count = 1;
|
|
|
|
|
} else {
|
2026-02-05 09:07:15 -03:00
|
|
|
m_click_count = 1;
|
2026-03-07 03:30:48 -03:00
|
|
|
}
|
2026-02-05 09:07:15 -03:00
|
|
|
m_last_click_timestamp = event->timestamp();
|
|
|
|
|
m_last_click_position = event->position();
|
|
|
|
|
|
2026-03-07 03:06:07 -03:00
|
|
|
enqueue_native_event(Web::MouseEvent::Type::MouseDown, *event);
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContentView::mouseReleaseEvent(QMouseEvent* event)
|
|
|
|
|
{
|
2026-05-28 08:18:49 -03:00
|
|
|
if (is_node_picker_active()) {
|
|
|
|
|
event->accept();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 09:53:57 -03:00
|
|
|
enqueue_native_event(Web::MouseEvent::Type::MouseUp, *event);
|
2022-11-07 22:00:24 -03:00
|
|
|
|
2024-09-22 14:29:27 -03:00
|
|
|
if (event->button() == Qt::MouseButton::BackButton)
|
2026-06-13 11:06:49 -03:00
|
|
|
(void)traverse_the_history_by_delta(-1);
|
2024-09-22 14:29:27 -03:00
|
|
|
else if (event->button() == Qt::MouseButton::ForwardButton)
|
2026-06-13 11:06:49 -03:00
|
|
|
(void)traverse_the_history_by_delta(1);
|
2023-12-15 13:46:09 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContentView::wheelEvent(QWheelEvent* event)
|
|
|
|
|
{
|
2026-05-28 08:18:49 -03:00
|
|
|
if (is_node_picker_active()) {
|
|
|
|
|
event->accept();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 09:21:00 -03:00
|
|
|
if (event->modifiers().testFlag(Qt::ControlModifier)) {
|
|
|
|
|
event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 09:53:57 -03:00
|
|
|
enqueue_native_event(Web::MouseEvent::Type::MouseWheel, *event);
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
|
|
|
|
|
2023-05-13 11:55:10 -03:00
|
|
|
void WebContentView::mouseDoubleClickEvent(QMouseEvent* event)
|
|
|
|
|
{
|
2026-02-05 09:07:15 -03:00
|
|
|
// NOTE: Qt calls this instead of mousePressEvent on the 2nd click. Forward to mousePressEvent so our click
|
|
|
|
|
// counting logic handles double and triple clicks uniformly.
|
|
|
|
|
mousePressEvent(event);
|
2023-05-13 11:55:10 -03:00
|
|
|
}
|
|
|
|
|
|
2023-01-07 13:40:04 -03:00
|
|
|
void WebContentView::dragEnterEvent(QDragEnterEvent* event)
|
|
|
|
|
{
|
2026-05-28 08:18:49 -03:00
|
|
|
if (is_node_picker_active()) {
|
|
|
|
|
event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-17 15:47:28 -03:00
|
|
|
if (!event->mimeData()->hasUrls())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
enqueue_native_event(Web::DragEvent::Type::DragStart, *event);
|
|
|
|
|
event->acceptProposedAction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContentView::dragMoveEvent(QDragMoveEvent* event)
|
|
|
|
|
{
|
2026-05-28 08:18:49 -03:00
|
|
|
if (is_node_picker_active()) {
|
|
|
|
|
event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-17 15:47:28 -03:00
|
|
|
enqueue_native_event(Web::DragEvent::Type::DragMove, *event);
|
|
|
|
|
event->acceptProposedAction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContentView::dragLeaveEvent(QDragLeaveEvent*)
|
|
|
|
|
{
|
2026-05-28 08:18:49 -03:00
|
|
|
if (is_node_picker_active())
|
|
|
|
|
return;
|
|
|
|
|
|
2024-08-17 15:47:28 -03:00
|
|
|
// QDragLeaveEvent does not contain any mouse position or button information.
|
|
|
|
|
Web::DragEvent event {};
|
|
|
|
|
event.type = Web::DragEvent::Type::DragEnd;
|
|
|
|
|
|
|
|
|
|
enqueue_input_event(AK::move(event));
|
2023-01-07 13:40:04 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContentView::dropEvent(QDropEvent* event)
|
|
|
|
|
{
|
2026-05-28 08:18:49 -03:00
|
|
|
if (is_node_picker_active()) {
|
|
|
|
|
event->ignore();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-17 15:47:28 -03:00
|
|
|
enqueue_native_event(Web::DragEvent::Type::Drop, *event);
|
2023-01-07 13:40:04 -03:00
|
|
|
event->acceptProposedAction();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-11 06:38:03 -03:00
|
|
|
void WebContentView::focusInEvent(QFocusEvent*)
|
|
|
|
|
{
|
2024-02-02 22:00:48 -03:00
|
|
|
client().async_set_has_focus(m_client_state.page_index, true);
|
2022-10-11 06:38:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContentView::focusOutEvent(QFocusEvent*)
|
|
|
|
|
{
|
2024-02-02 22:00:48 -03:00
|
|
|
client().async_set_has_focus(m_client_state.page_index, false);
|
2022-10-11 06:38:03 -03:00
|
|
|
}
|
|
|
|
|
|
2026-05-31 21:29:15 -03:00
|
|
|
Optional<WebContentView::Paintable> WebContentView::current_paintable() const
|
2022-10-05 10:23:41 -03:00
|
|
|
{
|
2026-05-31 21:29:15 -03:00
|
|
|
Gfx::SharedImageBuffer const* shared_image_buffer = nullptr;
|
2023-05-14 13:57:14 -03:00
|
|
|
Gfx::IntSize bitmap_size;
|
|
|
|
|
|
|
|
|
|
if (m_client_state.has_usable_bitmap) {
|
2026-04-07 13:35:26 -03:00
|
|
|
VERIFY(m_client_state.front_bitmap.shared_image_buffer);
|
2026-05-31 21:29:15 -03:00
|
|
|
shared_image_buffer = m_client_state.front_bitmap.shared_image_buffer.ptr();
|
2023-12-14 03:17:00 -03:00
|
|
|
bitmap_size = m_client_state.front_bitmap.last_painted_size.to_type<int>();
|
2026-04-07 13:35:26 -03:00
|
|
|
} else if (m_backup_shared_image_buffer) {
|
2026-05-31 21:29:15 -03:00
|
|
|
shared_image_buffer = m_backup_shared_image_buffer.ptr();
|
2023-12-14 03:17:00 -03:00
|
|
|
bitmap_size = m_backup_bitmap_size.to_type<int>();
|
2023-05-14 13:57:14 -03:00
|
|
|
}
|
|
|
|
|
|
2026-05-31 21:29:15 -03:00
|
|
|
if (!shared_image_buffer)
|
|
|
|
|
return {};
|
|
|
|
|
return Paintable { shared_image_buffer, bitmap_size };
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-01 06:45:00 -03:00
|
|
|
void WebContentView::schedule_repaint()
|
|
|
|
|
{
|
|
|
|
|
#ifdef LADYBIRD_QT_USE_VULKAN_WINDOW
|
|
|
|
|
schedule_vulkan_window_update();
|
|
|
|
|
#else
|
|
|
|
|
update();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef LADYBIRD_QT_USE_RHI_WIDGET
|
2026-05-31 21:29:15 -03:00
|
|
|
void WebContentView::paintEvent(QPaintEvent*)
|
|
|
|
|
{
|
|
|
|
|
QPainter painter(this);
|
|
|
|
|
painter.scale(1 / m_device_pixel_ratio, 1 / m_device_pixel_ratio);
|
|
|
|
|
|
|
|
|
|
auto paintable = current_paintable();
|
|
|
|
|
Gfx::Bitmap const* bitmap = nullptr;
|
|
|
|
|
Gfx::IntSize bitmap_size;
|
|
|
|
|
if (paintable.has_value()) {
|
|
|
|
|
bitmap = paintable->shared_image_buffer->bitmap().ptr();
|
|
|
|
|
bitmap_size = paintable->bitmap_size;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-14 13:57:14 -03:00
|
|
|
if (bitmap) {
|
2024-06-26 12:56:20 -03:00
|
|
|
QImage q_image(bitmap->scanline_u8(0), bitmap->width(), bitmap->height(), bitmap->pitch(), QImage::Format_RGB32);
|
2023-05-14 13:57:14 -03:00
|
|
|
painter.drawImage(QPoint(0, 0), q_image, QRect(0, 0, bitmap_size.width(), bitmap_size.height()));
|
|
|
|
|
|
2026-05-24 15:44:30 -03:00
|
|
|
auto background_color = page_background_color();
|
|
|
|
|
auto fallback_color = QColor(background_color.red(), background_color.green(), background_color.blue());
|
2026-05-29 07:04:52 -03:00
|
|
|
if (bitmap_size.width() < m_viewport_size.width()) {
|
|
|
|
|
painter.fillRect(bitmap_size.width(), 0, m_viewport_size.width() - bitmap_size.width(), bitmap->height(), fallback_color);
|
2023-05-14 13:57:14 -03:00
|
|
|
}
|
2026-05-29 07:04:52 -03:00
|
|
|
if (bitmap_size.height() < m_viewport_size.height()) {
|
|
|
|
|
painter.fillRect(0, bitmap_size.height(), m_viewport_size.width(), m_viewport_size.height() - bitmap_size.height(), fallback_color);
|
2023-05-14 13:57:14 -03:00
|
|
|
}
|
|
|
|
|
|
2022-10-05 10:23:41 -03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-24 15:44:30 -03:00
|
|
|
auto background_color = page_background_color();
|
2026-05-29 07:04:52 -03:00
|
|
|
painter.fillRect(QRect(0, 0, m_viewport_size.width(), m_viewport_size.height()), QColor(background_color.red(), background_color.green(), background_color.blue()));
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
2026-05-31 21:29:15 -03:00
|
|
|
#endif
|
2022-10-05 10:23:41 -03:00
|
|
|
|
2026-06-10 21:26:41 -03:00
|
|
|
Optional<QPixmap> WebContentView::tab_preview_pixmap(QSize const& maximum_size) const
|
|
|
|
|
{
|
|
|
|
|
auto paintable = current_paintable();
|
|
|
|
|
if (!paintable.has_value())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
auto const* bitmap = paintable->shared_image_buffer->bitmap().ptr();
|
|
|
|
|
if (!bitmap)
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
auto width = min(bitmap->width(), paintable->bitmap_size.width());
|
|
|
|
|
auto height = min(bitmap->height(), paintable->bitmap_size.height());
|
|
|
|
|
if (width <= 0 || height <= 0 || maximum_size.isEmpty())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
QImage image(bitmap->scanline_u8(0), bitmap->width(), bitmap->height(), bitmap->pitch(), QImage::Format_RGB32);
|
|
|
|
|
auto snapshot = image.copy(0, 0, width, height);
|
|
|
|
|
if (snapshot.isNull())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
auto preview_size = snapshot.size().scaled(maximum_size, Qt::KeepAspectRatio);
|
|
|
|
|
if (preview_size.isEmpty())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
auto preview = QPixmap::fromImage(snapshot).scaled(preview_size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
|
|
|
if (preview.isNull())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
return preview;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-05 10:23:41 -03:00
|
|
|
void WebContentView::resizeEvent(QResizeEvent* event)
|
|
|
|
|
{
|
2026-05-31 21:29:15 -03:00
|
|
|
WebContentViewBase::resizeEvent(event);
|
2026-06-01 06:45:00 -03:00
|
|
|
#ifdef LADYBIRD_QT_USE_VULKAN_WINDOW
|
|
|
|
|
update_vulkan_window_geometry();
|
|
|
|
|
#endif
|
2024-06-03 11:53:55 -03:00
|
|
|
update_viewport_size();
|
2023-05-15 02:59:51 -03:00
|
|
|
handle_resize();
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
|
|
|
|
|
2023-01-30 17:38:19 -03:00
|
|
|
void WebContentView::set_viewport_rect(Gfx::IntRect rect)
|
|
|
|
|
{
|
2024-06-03 11:53:55 -03:00
|
|
|
m_viewport_size = rect.size();
|
2026-02-20 18:09:39 -03:00
|
|
|
handle_resize();
|
2023-01-30 17:38:19 -03:00
|
|
|
}
|
|
|
|
|
|
2023-12-13 15:10:05 -03:00
|
|
|
void WebContentView::set_device_pixel_ratio(double device_pixel_ratio)
|
|
|
|
|
{
|
|
|
|
|
m_device_pixel_ratio = device_pixel_ratio;
|
2024-06-03 11:53:55 -03:00
|
|
|
update_viewport_size();
|
2023-12-13 15:10:05 -03:00
|
|
|
handle_resize();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-05 22:05:10 -03:00
|
|
|
void WebContentView::set_zoom_level(double zoom_level)
|
|
|
|
|
{
|
|
|
|
|
m_zoom_level = zoom_level;
|
|
|
|
|
client().async_set_zoom_level(m_client_state.page_index, m_zoom_level);
|
|
|
|
|
update_zoom();
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-25 12:43:27 -03:00
|
|
|
void WebContentView::set_maximum_frames_per_second(double maximum_frames_per_second)
|
|
|
|
|
{
|
2026-05-28 14:04:22 -03:00
|
|
|
set_display_metadata(m_display_id, maximum_frames_per_second);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContentView::set_display_metadata(Optional<u64> display_id, double maximum_frames_per_second)
|
|
|
|
|
{
|
|
|
|
|
m_display_id = display_id;
|
2025-07-25 12:43:27 -03:00
|
|
|
m_maximum_frames_per_second = maximum_frames_per_second;
|
|
|
|
|
client().async_set_maximum_frames_per_second(m_client_state.page_index, m_maximum_frames_per_second);
|
2026-05-28 14:04:22 -03:00
|
|
|
update_compositor_display_metadata();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContentView::update_compositor_display_metadata()
|
|
|
|
|
{
|
|
|
|
|
if (!m_client_state.client)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
auto compositor_context_id = client().compositor_context_id_for_page(m_client_state.page_index);
|
|
|
|
|
WebView::Application::the().update_compositor_display_metadata(compositor_context_id, m_display_id, m_maximum_frames_per_second);
|
2025-07-25 12:43:27 -03:00
|
|
|
}
|
|
|
|
|
|
2024-06-03 11:53:55 -03:00
|
|
|
void WebContentView::update_viewport_size()
|
2022-10-05 10:23:41 -03:00
|
|
|
{
|
2024-11-07 14:46:45 -03:00
|
|
|
auto scaled_width = int(width() * m_device_pixel_ratio);
|
|
|
|
|
auto scaled_height = int(height() * m_device_pixel_ratio);
|
2024-06-03 11:53:55 -03:00
|
|
|
Gfx::IntRect rect(0, 0, scaled_width, scaled_height);
|
2022-10-05 10:23:41 -03:00
|
|
|
|
2023-01-30 17:38:19 -03:00
|
|
|
set_viewport_rect(rect);
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 11:39:53 -03:00
|
|
|
void WebContentView::update_zoom()
|
|
|
|
|
{
|
2025-09-10 08:23:15 -03:00
|
|
|
ViewImplementation::update_zoom();
|
2024-06-03 11:53:55 -03:00
|
|
|
update_viewport_size();
|
2023-01-12 11:39:53 -03:00
|
|
|
}
|
|
|
|
|
|
2022-10-05 10:23:41 -03:00
|
|
|
void WebContentView::showEvent(QShowEvent* event)
|
|
|
|
|
{
|
2026-05-31 21:29:15 -03:00
|
|
|
WebContentViewBase::showEvent(event);
|
2024-11-13 13:24:16 -03:00
|
|
|
set_system_visibility_state(Web::HTML::VisibilityState::Visible);
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContentView::hideEvent(QHideEvent* event)
|
|
|
|
|
{
|
2026-05-31 21:29:15 -03:00
|
|
|
WebContentViewBase::hideEvent(event);
|
2024-11-13 13:24:16 -03:00
|
|
|
set_system_visibility_state(Web::HTML::VisibilityState::Hidden);
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
|
|
|
|
|
2023-04-22 22:57:08 -03:00
|
|
|
static Core::AnonymousBuffer make_system_theme_from_qt_palette(QWidget& widget, WebContentView::PaletteMode mode)
|
2023-03-15 18:56:47 -03:00
|
|
|
{
|
|
|
|
|
auto qt_palette = widget.palette();
|
|
|
|
|
|
2023-04-22 22:57:08 -03:00
|
|
|
auto theme_file = mode == WebContentView::PaletteMode::Default ? "Default"sv : "Dark"sv;
|
2023-11-05 11:46:28 -03:00
|
|
|
auto theme_ini = MUST(Core::Resource::load_from_uri(MUST(String::formatted("resource://themes/{}.ini", theme_file))));
|
2023-12-16 11:19:34 -03:00
|
|
|
auto theme = Gfx::load_system_theme(theme_ini->filesystem_path().to_byte_string()).release_value_but_fixme_should_propagate_errors();
|
2023-11-05 11:46:28 -03:00
|
|
|
|
2023-03-15 18:56:47 -03:00
|
|
|
auto palette_impl = Gfx::PaletteImpl::create_with_anonymous_buffer(theme);
|
|
|
|
|
auto palette = Gfx::Palette(move(palette_impl));
|
|
|
|
|
|
|
|
|
|
auto translate = [&](Gfx::ColorRole gfx_color_role, QPalette::ColorRole qt_color_role) {
|
2025-11-23 09:07:38 -03:00
|
|
|
auto new_color = Gfx::Color::from_bgra(qt_palette.color(qt_color_role).rgba());
|
2023-03-15 18:56:47 -03:00
|
|
|
palette.set_color(gfx_color_role, new_color);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
translate(Gfx::ColorRole::ThreedHighlight, QPalette::ColorRole::Light);
|
|
|
|
|
translate(Gfx::ColorRole::ThreedShadow1, QPalette::ColorRole::Mid);
|
|
|
|
|
translate(Gfx::ColorRole::ThreedShadow2, QPalette::ColorRole::Dark);
|
|
|
|
|
translate(Gfx::ColorRole::HoverHighlight, QPalette::ColorRole::Light);
|
|
|
|
|
translate(Gfx::ColorRole::Link, QPalette::ColorRole::Link);
|
|
|
|
|
translate(Gfx::ColorRole::VisitedLink, QPalette::ColorRole::LinkVisited);
|
|
|
|
|
translate(Gfx::ColorRole::Button, QPalette::ColorRole::Button);
|
|
|
|
|
translate(Gfx::ColorRole::ButtonText, QPalette::ColorRole::ButtonText);
|
2026-06-20 20:22:50 -03:00
|
|
|
#ifdef AK_OS_MACOS
|
|
|
|
|
palette.set_color(Gfx::ColorRole::Selection, WebView::macos_web_selection_color());
|
|
|
|
|
palette.set_color(Gfx::ColorRole::InactiveSelection, appkit_web_inactive_selection_color());
|
|
|
|
|
palette.set_color(Gfx::ColorRole::InactiveSelectionText, appkit_web_inactive_selection_text_color());
|
|
|
|
|
#else
|
2023-03-15 18:56:47 -03:00
|
|
|
translate(Gfx::ColorRole::Selection, QPalette::ColorRole::Highlight);
|
2026-06-20 20:22:50 -03:00
|
|
|
#endif
|
2023-03-15 18:56:47 -03:00
|
|
|
|
2023-04-29 13:35:06 -03:00
|
|
|
palette.set_flag(Gfx::FlagRole::IsDark, is_using_dark_system_theme(widget));
|
|
|
|
|
|
2023-03-15 18:56:47 -03:00
|
|
|
return theme;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-22 22:57:08 -03:00
|
|
|
void WebContentView::update_palette(PaletteMode mode)
|
2023-03-15 18:56:47 -03:00
|
|
|
{
|
2026-05-26 20:11:14 -03:00
|
|
|
set_page_background_color_to_system_canvas(is_using_dark_system_theme(*this));
|
2024-02-02 22:00:48 -03:00
|
|
|
client().async_update_system_theme(m_client_state.page_index, make_system_theme_from_qt_palette(*this, mode));
|
2023-03-15 18:56:47 -03:00
|
|
|
}
|
|
|
|
|
|
2024-05-11 00:00:00 -03:00
|
|
|
void WebContentView::update_screen_rects()
|
|
|
|
|
{
|
|
|
|
|
auto screens = QGuiApplication::screens();
|
|
|
|
|
|
|
|
|
|
if (!screens.empty()) {
|
|
|
|
|
Vector<Web::DevicePixelRect> screen_rects;
|
|
|
|
|
for (auto const& screen : screens) {
|
2024-05-29 18:37:39 -03:00
|
|
|
// NOTE: QScreen::geometry() returns the 'device-independent pixels', we multiply
|
|
|
|
|
// by the device pixel ratio to get the 'physical pixels' of the display.
|
2024-05-11 00:00:00 -03:00
|
|
|
auto geometry = screen->geometry();
|
2024-05-29 18:37:39 -03:00
|
|
|
auto device_pixel_ratio = screen->devicePixelRatio();
|
|
|
|
|
screen_rects.append(Web::DevicePixelRect(geometry.x(), geometry.y(), geometry.width() * device_pixel_ratio, geometry.height() * device_pixel_ratio));
|
2024-05-11 00:00:00 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: The first item in QGuiApplication::screens is always the primary screen.
|
|
|
|
|
// This is not specified in the documentation but QGuiApplication::primaryScreen
|
|
|
|
|
// always returns the first item in the list if it isn't empty.
|
|
|
|
|
client().async_update_screen_rects(m_client_state.page_index, screen_rects, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 13:12:14 -03:00
|
|
|
void WebContentView::initialize_client(WebView::ViewImplementation::CreateNewClient create_new_client)
|
2022-10-05 10:23:41 -03:00
|
|
|
{
|
2024-11-13 18:35:17 -03:00
|
|
|
ViewImplementation::initialize_client(create_new_client);
|
2024-11-13 13:31:06 -03:00
|
|
|
|
2026-05-28 14:04:22 -03:00
|
|
|
update_compositor_display_metadata();
|
2024-11-13 13:31:06 -03:00
|
|
|
update_palette();
|
2024-05-11 00:00:00 -03:00
|
|
|
update_screen_rects();
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
|
|
|
|
|
2025-02-20 09:17:29 -03:00
|
|
|
void WebContentView::update_cursor(Gfx::Cursor cursor)
|
|
|
|
|
{
|
|
|
|
|
cursor.visit([this](Gfx::StandardCursor standard_cursor) {
|
|
|
|
|
switch (standard_cursor) {
|
|
|
|
|
case Gfx::StandardCursor::Hidden:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::BlankCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::Arrow:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::ArrowCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::Crosshair:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::CrossCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::IBeam:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::IBeamCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::ResizeHorizontal:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::SizeHorCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::ResizeVertical:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::SizeVerCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::ResizeDiagonalTLBR:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::SizeFDiagCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::ResizeDiagonalBLTR:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::SizeBDiagCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::ResizeColumn:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::SplitHCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::ResizeRow:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::SplitVCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::Hand:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::PointingHandCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::Help:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::WhatsThisCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
2025-09-06 13:19:21 -03:00
|
|
|
case Gfx::StandardCursor::OpenHand:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::OpenHandCursor);
|
2025-09-06 13:19:21 -03:00
|
|
|
break;
|
2025-02-20 09:17:29 -03:00
|
|
|
case Gfx::StandardCursor::Drag:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::ClosedHandCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::DragCopy:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::DragCopyCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::Move:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::DragMoveCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::Wait:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::BusyCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::Disallowed:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::ForbiddenCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
case Gfx::StandardCursor::Eyedropper:
|
|
|
|
|
case Gfx::StandardCursor::Zoom:
|
|
|
|
|
// FIXME: No corresponding Qt cursors, default to Arrow
|
|
|
|
|
default:
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(Qt::ArrowCursor);
|
2025-02-20 09:17:29 -03:00
|
|
|
break;
|
|
|
|
|
} },
|
|
|
|
|
[this](Gfx::ImageCursor const& image_cursor) {
|
|
|
|
|
if (!image_cursor.bitmap.is_valid()) {
|
|
|
|
|
dbgln("Failed to set cursor: Bitmap is invalid.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto const& bitmap = *image_cursor.bitmap.bitmap();
|
|
|
|
|
auto qimage = QImage { bitmap.scanline_u8(0), bitmap.width(), bitmap.height(), QImage::Format_ARGB32 };
|
|
|
|
|
if (qimage.isNull()) {
|
|
|
|
|
dbgln("Failed to set cursor: Null QImage.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
auto qpixmap = QPixmap::fromImage(qimage);
|
|
|
|
|
if (qimage.isNull()) {
|
|
|
|
|
dbgln("Failed to set cursor: Couldn't create QPixmap from QImage.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-06-01 06:45:00 -03:00
|
|
|
apply_web_content_cursor(QCursor { qpixmap, image_cursor.hotspot.x(), image_cursor.hotspot.y() });
|
2025-02-20 09:17:29 -03:00
|
|
|
});
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
|
|
|
|
|
2026-06-01 06:45:00 -03:00
|
|
|
void WebContentView::apply_web_content_cursor(QCursor const& cursor)
|
|
|
|
|
{
|
|
|
|
|
setCursor(cursor);
|
|
|
|
|
#ifdef LADYBIRD_QT_USE_VULKAN_WINDOW
|
|
|
|
|
set_vulkan_window_cursor(cursor);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-28 08:18:49 -03:00
|
|
|
Web::DevicePixelPoint WebContentView::node_picker_position_for(QSinglePointEvent const& event) const
|
|
|
|
|
{
|
|
|
|
|
return { event.position().x() * m_device_pixel_ratio, event.position().y() * m_device_pixel_ratio };
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-03 11:53:55 -03:00
|
|
|
Web::DevicePixelSize WebContentView::viewport_size() const
|
2022-10-05 10:23:41 -03:00
|
|
|
{
|
2024-06-03 11:53:55 -03:00
|
|
|
return m_viewport_size.to_type<Web::DevicePixels>();
|
2022-10-05 10:23:41 -03:00
|
|
|
}
|
2022-10-11 12:17:49 -03:00
|
|
|
|
2024-03-10 23:15:06 -03:00
|
|
|
QPoint WebContentView::map_point_to_global_position(Gfx::IntPoint position) const
|
|
|
|
|
{
|
|
|
|
|
return mapToGlobal(QPoint { position.x(), position.y() } / device_pixel_ratio());
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 11:12:13 -03:00
|
|
|
Gfx::IntPoint WebContentView::to_content_position(Gfx::IntPoint widget_position) const
|
|
|
|
|
{
|
2024-06-03 11:53:55 -03:00
|
|
|
return widget_position;
|
2023-05-17 11:12:13 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Gfx::IntPoint WebContentView::to_widget_position(Gfx::IntPoint content_position) const
|
|
|
|
|
{
|
2024-06-03 11:53:55 -03:00
|
|
|
return content_position;
|
2023-05-17 11:12:13 -03:00
|
|
|
}
|
|
|
|
|
|
2022-10-11 12:17:49 -03:00
|
|
|
bool WebContentView::event(QEvent* event)
|
|
|
|
|
{
|
|
|
|
|
// NOTE: We have to implement event() manually as Qt's focus navigation mechanism
|
|
|
|
|
// eats all the Tab key presses by default.
|
|
|
|
|
|
|
|
|
|
if (event->type() == QEvent::KeyPress) {
|
|
|
|
|
keyPressEvent(static_cast<QKeyEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (event->type() == QEvent::KeyRelease) {
|
|
|
|
|
keyReleaseEvent(static_cast<QKeyEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2026-05-31 21:55:31 -03:00
|
|
|
if (event->type() == QEvent::NativeGesture) {
|
|
|
|
|
auto const& native_gesture_event = *static_cast<QNativeGestureEvent const*>(event);
|
|
|
|
|
if (native_gesture_event.gestureType() == Qt::ZoomNativeGesture) {
|
|
|
|
|
Web::PinchEvent pinch_event;
|
|
|
|
|
auto const local_position = mapFromGlobal(native_gesture_event.globalPosition());
|
|
|
|
|
pinch_event.position = { local_position.x() * m_device_pixel_ratio, local_position.y() * m_device_pixel_ratio };
|
|
|
|
|
pinch_event.modifiers = get_modifiers_from_qt_keyboard_modifiers(native_gesture_event.modifiers());
|
|
|
|
|
pinch_event.scale_delta = native_gesture_event.value();
|
|
|
|
|
enqueue_input_event(AK::move(pinch_event));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-15 18:56:47 -03:00
|
|
|
|
2026-05-25 16:22:50 -03:00
|
|
|
if (event->type() == QEvent::PaletteChange || event->type() == QEvent::ApplicationPaletteChange || event->type() == QEvent::ThemeChange) {
|
|
|
|
|
QTimer::singleShot(0, this, [this] {
|
|
|
|
|
update_palette();
|
2026-06-01 06:45:00 -03:00
|
|
|
schedule_repaint();
|
2026-05-25 16:22:50 -03:00
|
|
|
});
|
2026-05-31 21:29:15 -03:00
|
|
|
return WebContentViewBase::event(event);
|
2023-03-15 18:56:47 -03:00
|
|
|
}
|
|
|
|
|
|
2024-03-05 09:53:57 -03:00
|
|
|
if (event->type() == QEvent::ShortcutOverride) {
|
2026-05-26 13:03:07 -03:00
|
|
|
auto* key_event = static_cast<QKeyEvent*>(event);
|
2026-05-26 14:58:58 -03:00
|
|
|
if (is_browser_reserved_shortcut(*key_event)) {
|
2026-05-26 13:03:07 -03:00
|
|
|
event->ignore();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 09:53:57 -03:00
|
|
|
event->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 21:29:15 -03:00
|
|
|
return WebContentViewBase::event(event);
|
2022-10-11 12:17:49 -03:00
|
|
|
}
|
2022-11-21 13:36:26 -03:00
|
|
|
|
2026-06-01 06:45:00 -03:00
|
|
|
#ifdef LADYBIRD_QT_USE_VULKAN_WINDOW
|
|
|
|
|
bool WebContentView::handle_vulkan_window_event(QEvent* event)
|
|
|
|
|
{
|
|
|
|
|
switch (event->type()) {
|
|
|
|
|
case QEvent::KeyPress:
|
|
|
|
|
keyPressEvent(static_cast<QKeyEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::KeyRelease:
|
|
|
|
|
keyReleaseEvent(static_cast<QKeyEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::MouseMove:
|
|
|
|
|
mouseMoveEvent(static_cast<QMouseEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
|
mousePressEvent(static_cast<QMouseEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
|
mouseReleaseEvent(static_cast<QMouseEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::MouseButtonDblClick:
|
|
|
|
|
mouseDoubleClickEvent(static_cast<QMouseEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::Wheel:
|
|
|
|
|
wheelEvent(static_cast<QWheelEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::Leave:
|
|
|
|
|
leaveEvent(event);
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::FocusIn:
|
|
|
|
|
focusInEvent(static_cast<QFocusEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::FocusOut:
|
|
|
|
|
focusOutEvent(static_cast<QFocusEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::InputMethod:
|
|
|
|
|
inputMethodEvent(static_cast<QInputMethodEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::DragEnter:
|
|
|
|
|
dragEnterEvent(static_cast<QDragEnterEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::DragMove:
|
|
|
|
|
dragMoveEvent(static_cast<QDragMoveEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::DragLeave:
|
|
|
|
|
dragLeaveEvent(static_cast<QDragLeaveEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::Drop:
|
|
|
|
|
dropEvent(static_cast<QDropEvent*>(event));
|
|
|
|
|
return true;
|
|
|
|
|
case QEvent::NativeGesture: {
|
|
|
|
|
auto const& native_gesture_event = *static_cast<QNativeGestureEvent const*>(event);
|
|
|
|
|
if (native_gesture_event.gestureType() == Qt::ZoomNativeGesture) {
|
|
|
|
|
Web::PinchEvent pinch_event;
|
|
|
|
|
auto const local_position = mapFromGlobal(native_gesture_event.globalPosition());
|
|
|
|
|
pinch_event.position = { local_position.x() * m_device_pixel_ratio, local_position.y() * m_device_pixel_ratio };
|
|
|
|
|
pinch_event.modifiers = get_modifiers_from_qt_keyboard_modifiers(native_gesture_event.modifiers());
|
|
|
|
|
pinch_event.scale_delta = native_gesture_event.value();
|
|
|
|
|
enqueue_input_event(AK::move(pinch_event));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
case QEvent::ShortcutOverride: {
|
|
|
|
|
auto* key_event = static_cast<QKeyEvent*>(event);
|
|
|
|
|
if (is_browser_reserved_shortcut(*key_event)) {
|
|
|
|
|
event->ignore();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-03-05 09:53:57 -03:00
|
|
|
void WebContentView::enqueue_native_event(Web::MouseEvent::Type type, QSinglePointEvent const& event)
|
|
|
|
|
{
|
2024-06-03 11:53:55 -03:00
|
|
|
Web::DevicePixelPoint position = { event.position().x() * m_device_pixel_ratio, event.position().y() * m_device_pixel_ratio };
|
2024-03-05 09:53:57 -03:00
|
|
|
auto screen_position = Gfx::IntPoint { event.globalPosition().x() * m_device_pixel_ratio, event.globalPosition().y() * m_device_pixel_ratio };
|
|
|
|
|
|
2024-08-20 15:48:41 -03:00
|
|
|
auto button = get_button_from_qt_mouse_button(event.button());
|
|
|
|
|
auto buttons = get_buttons_from_qt_mouse_buttons(event.buttons());
|
|
|
|
|
auto modifiers = get_modifiers_from_qt_keyboard_modifiers(event.modifiers());
|
2024-03-05 09:53:57 -03:00
|
|
|
|
|
|
|
|
if (button == 0 && (type == Web::MouseEvent::Type::MouseDown || type == Web::MouseEvent::Type::MouseUp)) {
|
|
|
|
|
// We could not convert Qt buttons to something that LibWeb can recognize - don't even bother propagating this
|
|
|
|
|
// to the web engine as it will not handle it anyway, and it will (currently) assert.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
double wheel_delta_x = 0;
|
|
|
|
|
double wheel_delta_y = 0;
|
2024-03-05 09:53:57 -03:00
|
|
|
|
2024-03-06 09:21:00 -03:00
|
|
|
if (type == Web::MouseEvent::Type::MouseWheel) {
|
2024-03-05 09:53:57 -03:00
|
|
|
auto const& wheel_event = static_cast<QWheelEvent const&>(event);
|
|
|
|
|
|
|
|
|
|
if (auto pixel_delta = -wheel_event.pixelDelta(); !pixel_delta.isNull()) {
|
|
|
|
|
wheel_delta_x = pixel_delta.x();
|
|
|
|
|
wheel_delta_y = pixel_delta.y();
|
|
|
|
|
} else {
|
|
|
|
|
auto angle_delta = -wheel_event.angleDelta();
|
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
|
|
|
double delta_x = -static_cast<double>(angle_delta.x()) / 120.0;
|
|
|
|
|
double delta_y = static_cast<double>(angle_delta.y()) / 120.0;
|
2024-03-05 09:53:57 -03:00
|
|
|
|
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
|
|
|
static constexpr double scroll_step_size = 40;
|
2026-05-31 22:07:38 -03:00
|
|
|
auto step_x = delta_x * static_cast<double>(QApplication::wheelScrollLines());
|
|
|
|
|
auto step_y = delta_y * static_cast<double>(QApplication::wheelScrollLines());
|
2024-03-05 09:53:57 -03:00
|
|
|
|
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
|
|
|
wheel_delta_x = step_x * scroll_step_size;
|
|
|
|
|
wheel_delta_y = step_y * scroll_step_size;
|
2024-03-05 09:53:57 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-07 03:06:07 -03:00
|
|
|
enqueue_input_event(Web::MouseEvent { type, position, screen_position.to_type<Web::DevicePixels>(), button, buttons, modifiers, wheel_delta_x, wheel_delta_y, m_click_count, nullptr });
|
2024-03-05 09:53:57 -03:00
|
|
|
}
|
|
|
|
|
|
2025-03-15 18:07:53 -03:00
|
|
|
struct DragData : Web::BrowserInputData {
|
2024-08-17 15:47:28 -03:00
|
|
|
explicit DragData(QDropEvent const& event)
|
|
|
|
|
: urls(event.mimeData()->urls())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QUrl> urls;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void WebContentView::enqueue_native_event(Web::DragEvent::Type type, QDropEvent const& event)
|
|
|
|
|
{
|
|
|
|
|
Web::DevicePixelPoint position = { event.position().x() * m_device_pixel_ratio, event.position().y() * m_device_pixel_ratio };
|
|
|
|
|
|
|
|
|
|
auto global_position = mapToGlobal(event.position());
|
|
|
|
|
auto screen_position = Gfx::IntPoint { global_position.x() * m_device_pixel_ratio, global_position.y() * m_device_pixel_ratio };
|
|
|
|
|
|
2024-08-20 15:48:41 -03:00
|
|
|
auto button = get_button_from_qt_mouse_button(Qt::LeftButton);
|
|
|
|
|
auto buttons = get_buttons_from_qt_mouse_buttons(event.buttons());
|
|
|
|
|
auto modifiers = get_modifiers_from_qt_keyboard_modifiers(event.modifiers());
|
2024-08-17 15:47:28 -03:00
|
|
|
|
|
|
|
|
Vector<Web::HTML::SelectedFile> files;
|
2025-03-15 18:07:53 -03:00
|
|
|
OwnPtr<DragData> browser_data;
|
2024-08-17 15:47:28 -03:00
|
|
|
|
|
|
|
|
if (type == Web::DragEvent::Type::DragStart) {
|
|
|
|
|
VERIFY(event.mimeData()->hasUrls());
|
|
|
|
|
|
|
|
|
|
for (auto const& url : event.mimeData()->urls()) {
|
|
|
|
|
auto file_path = ak_byte_string_from_qstring(url.toLocalFile());
|
|
|
|
|
|
2026-05-20 13:37:49 -03:00
|
|
|
if (auto file = WebView::create_selected_file(file_path); file.is_error())
|
2024-08-17 15:47:28 -03:00
|
|
|
warnln("Unable to open file {}: {}", file_path, file.error());
|
|
|
|
|
else
|
|
|
|
|
files.append(file.release_value());
|
|
|
|
|
}
|
|
|
|
|
} else if (type == Web::DragEvent::Type::Drop) {
|
2025-03-15 18:07:53 -03:00
|
|
|
browser_data = make<DragData>(event);
|
2024-08-17 15:47:28 -03:00
|
|
|
}
|
|
|
|
|
|
2025-03-15 18:07:53 -03:00
|
|
|
enqueue_input_event(Web::DragEvent { type, position, screen_position.to_type<Web::DevicePixels>(), button, buttons, modifiers, AK::move(files), AK::move(browser_data) });
|
2024-08-17 15:47:28 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContentView::finish_handling_drag_event(Web::DragEvent const& event)
|
|
|
|
|
{
|
|
|
|
|
if (event.type != Web::DragEvent::Type::Drop)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-03-15 18:07:53 -03:00
|
|
|
auto const& browser_data = as<DragData>(*event.browser_data);
|
|
|
|
|
emit urls_dropped(browser_data.urls);
|
2024-08-17 15:47:28 -03:00
|
|
|
}
|
|
|
|
|
|
2025-03-15 18:07:53 -03:00
|
|
|
struct KeyData : Web::BrowserInputData {
|
2024-03-05 09:53:57 -03:00
|
|
|
explicit KeyData(QKeyEvent const& event)
|
|
|
|
|
: event(adopt_own(*event.clone()))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NonnullOwnPtr<QKeyEvent> event;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void WebContentView::enqueue_native_event(Web::KeyEvent::Type type, QKeyEvent const& event)
|
|
|
|
|
{
|
2024-08-20 15:48:41 -03:00
|
|
|
auto keycode = get_keycode_from_qt_key_event(event);
|
|
|
|
|
auto modifiers = get_modifiers_from_qt_key_event(event);
|
2024-03-05 09:53:57 -03:00
|
|
|
|
|
|
|
|
auto text = event.text();
|
|
|
|
|
auto code_point = text.isEmpty() ? 0u : event.text()[0].unicode();
|
2026-06-03 07:26:44 -03:00
|
|
|
auto should_insert_text = type == Web::KeyEvent::Type::KeyDown && !text.isEmpty();
|
2024-03-05 09:53:57 -03:00
|
|
|
|
|
|
|
|
auto to_web_event = [&]() -> Web::KeyEvent {
|
|
|
|
|
if (event.key() == Qt::Key_Backtab) {
|
|
|
|
|
// Qt transforms Shift+Tab into a "Backtab", so we undo that transformation here.
|
2026-06-03 07:26:44 -03:00
|
|
|
return { type, Web::UIEvents::KeyCode::Key_Tab, Web::UIEvents::Mod_Shift, '\t', event.isAutoRepeat(), false, make<KeyData>(event) };
|
2024-03-05 09:53:57 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.key() == Qt::Key_Enter || event.key() == Qt::Key_Return) {
|
|
|
|
|
// This ensures consistent behavior between systems that treat Enter as '\n' and '\r\n'
|
2026-06-03 07:26:44 -03:00
|
|
|
return { type, Web::UIEvents::KeyCode::Key_Return, modifiers, '\n', event.isAutoRepeat(), should_insert_text, make<KeyData>(event) };
|
2024-03-05 09:53:57 -03:00
|
|
|
}
|
|
|
|
|
|
2026-06-03 07:26:44 -03:00
|
|
|
return { type, keycode, modifiers, code_point, event.isAutoRepeat(), should_insert_text, make<KeyData>(event) };
|
2024-03-05 09:53:57 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enqueue_input_event(to_web_event());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContentView::finish_handling_key_event(Web::KeyEvent const& key_event)
|
|
|
|
|
{
|
2025-03-15 18:07:53 -03:00
|
|
|
auto& browser_data = as<KeyData>(*key_event.browser_data);
|
|
|
|
|
auto& event = *browser_data.event;
|
2024-03-05 09:53:57 -03:00
|
|
|
|
|
|
|
|
switch (key_event.type) {
|
|
|
|
|
case Web::KeyEvent::Type::KeyDown:
|
2026-05-31 21:29:15 -03:00
|
|
|
WebContentViewBase::keyPressEvent(&event);
|
2024-03-05 09:53:57 -03:00
|
|
|
break;
|
|
|
|
|
case Web::KeyEvent::Type::KeyUp:
|
2026-05-31 21:29:15 -03:00
|
|
|
WebContentViewBase::keyReleaseEvent(&event);
|
2024-03-05 09:53:57 -03:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!event.isAccepted())
|
|
|
|
|
QApplication::sendEvent(parent(), &event);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 14:52:59 -03:00
|
|
|
}
|