diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-05-17 12:37:31 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-17 19:47:05 +0200 |
commit | 6970f1b6c15073e2386362a817b8c7bf25a73827 (patch) | |
tree | 95d2e93e0b6f2510e932463fc4e5b8d0ea5d3c48 /Userland/Applications | |
parent | c113d780c6a587c0698c94c032d0de02aa524847 (diff) | |
download | serenity-6970f1b6c15073e2386362a817b8c7bf25a73827.zip |
Browser+Ladybird+LibWebView: Handle trivial content APIs in LibWebView
The goal here is to reduce the amount of WebContent client APIs that are
duplicated across every ViewImplementation. Across our three browsers,
we currently:
Ladybird - Mix some AK::Function callbacks and Qt signals to notify
tabs of WebContent events.
Browser - Use only AK::Function callbacks.
headless-browser - Drop most events on the floor.
Instead, let's only use AK::Function callbacks across all three browsers
to propagate events to tabs. This allows us to invoke those callbacks
directly from LibWebView instead of all three browsers needing to define
a trivial `if (callback) callback();` override of a LibWebView virtual
function. For headless-browser, we can simply not set these callbacks.
As a first pass, this only converts WebContent events that are trivial
to this approach. That is, events that were simply passed onto the tab
or handled without much fuss.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/Browser/Tab.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index af7e7a5c7c..18f099b386 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -336,8 +336,10 @@ Tab::Tab(BrowserWindow& window) m_link_context_menu->add_separator(); m_link_context_menu->add_action(window.inspect_dom_node_action()); - view().on_link_context_menu_request = [this](auto& url, auto screen_position) { + view().on_link_context_menu_request = [this](auto& url, auto widget_position) { m_link_context_menu_url = url; + + auto screen_position = view().screen_relative_rect().location().translated(widget_position); m_link_context_menu->popup(screen_position, m_link_context_menu_default_action); }; @@ -363,9 +365,11 @@ Tab::Tab(BrowserWindow& window) m_image_context_menu->add_separator(); m_image_context_menu->add_action(window.inspect_dom_node_action()); - view().on_image_context_menu_request = [this](auto& image_url, auto screen_position, Gfx::ShareableBitmap const& shareable_bitmap) { + view().on_image_context_menu_request = [this](auto& image_url, auto widget_position, Gfx::ShareableBitmap const& shareable_bitmap) { m_image_context_menu_url = image_url; m_image_context_menu_bitmap = shareable_bitmap; + + auto screen_position = view().screen_relative_rect().location().translated(widget_position); m_image_context_menu->popup(screen_position); }; @@ -401,7 +405,7 @@ Tab::Tab(BrowserWindow& window) m_video_context_menu->add_separator(); m_video_context_menu->add_action(window.inspect_dom_node_action()); - view().on_video_context_menu_request = [this](auto& video_url, auto screen_position, bool is_playing, bool has_user_agent_controls, bool is_looping) { + view().on_video_context_menu_request = [this](auto& video_url, auto widget_position, bool is_playing, bool has_user_agent_controls, bool is_looping) { m_video_context_menu_url = video_url; if (is_playing) { @@ -415,6 +419,7 @@ Tab::Tab(BrowserWindow& window) m_video_context_menu_controls_action->set_checked(has_user_agent_controls); m_video_context_menu_loop_action->set_checked(is_looping); + auto screen_position = view().screen_relative_rect().location().translated(widget_position); m_video_context_menu->popup(screen_position); }; @@ -507,14 +512,12 @@ Tab::Tab(BrowserWindow& window) m_statusbar = *find_descendant_of_type_named<GUI::Statusbar>("statusbar"); view().on_link_hover = [this](auto& url) { - if (url.is_valid()) - update_status(url.to_deprecated_string()); - else - update_status(); + update_status(url.to_deprecated_string()); }; - view().on_url_drop = [this](auto& url) { - load(url); + view().on_link_unhover = [this]() { + view().set_override_cursor(Gfx::StandardCursor::None); + update_status(); }; view().on_back_button = [this] { @@ -588,7 +591,9 @@ Tab::Tab(BrowserWindow& window) m_page_context_menu->add_action(window.view_source_action()); m_page_context_menu->add_action(window.inspect_dom_tree_action()); m_page_context_menu->add_action(window.inspect_dom_node_action()); - view().on_context_menu_request = [&](auto screen_position) { + + view().on_context_menu_request = [&](auto widget_position) { + auto screen_position = view().screen_relative_rect().location().translated(widget_position); m_page_context_menu->popup(screen_position); }; } |