LibWebView+UI: Generate application context menus

This migrates all duplicated context menus from the UIs to LibWebView.
The context menu actions are now largely handled directly in LibWebView,
with some UI-specific callbacks added to display e.g. confirmation
dialogs.

Actions that only ever apply to a specific web view are stored on the
ViewImplementation itself. Actions that need to be dynamically applied
to the active web view are stored on the Application.
This commit is contained in:
Timothy Flynn
2025-09-01 08:20:14 -04:00
committed by Tim Flynn
parent a5be0f0a18
commit 5d8d9b337a
Notes: github-actions[bot] 2025-09-11 18:25:14 +00:00
18 changed files with 553 additions and 1172 deletions

View File

@@ -19,6 +19,7 @@
#include <LibWebView/Database.h>
#include <LibWebView/HeadlessWebView.h>
#include <LibWebView/HelperProcess.h>
#include <LibWebView/Menu.h>
#include <LibWebView/URL.h>
#include <LibWebView/UserAgent.h>
#include <LibWebView/Utilities.h>
@@ -268,6 +269,7 @@ ErrorOr<void> Application::initialize(Main::Arguments const& arguments)
};
create_platform_options(m_browser_options, m_web_content_options);
initialize_actions();
m_event_loop = create_platform_event_loop();
TRY(launch_services());
@@ -609,6 +611,32 @@ void Application::display_error_dialog(StringView error_message) const
warnln("{}", error_message);
}
void Application::initialize_actions()
{
m_reload_action = Action::create("Reload"sv, ActionID::Reload, [this]() {
if (auto view = active_web_view(); view.has_value())
view->reload();
});
m_copy_selection_action = Action::create("Copy"sv, ActionID::CopySelection, [this]() {
if (auto view = active_web_view(); view.has_value())
view->insert_text_into_clipboard(view->selected_text());
});
m_paste_action = Action::create("Paste"sv, ActionID::Paste, [this]() {
if (auto view = active_web_view(); view.has_value())
view->paste_text_from_clipboard();
});
m_select_all_action = Action::create("Select All"sv, ActionID::SelectAll, [this]() {
if (auto view = active_web_view(); view.has_value())
view->select_all();
});
m_view_source_action = Action::create("View Source"sv, ActionID::ViewSource, [this]() {
if (auto view = active_web_view(); view.has_value())
view->get_source();
});
}
ErrorOr<Application::DevtoolsState> Application::toggle_devtools_enabled()
{
if (m_devtools) {