diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-05-15 12:48:46 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-16 12:48:39 +0200 |
commit | 0d1b5e7f7a1c093b15b6de47aec7616064ead897 (patch) | |
tree | e7c937b90a28110a30fbf43401bb6404887eced6 | |
parent | 1b2394d92ee0e448f1772a516bc11fa6a58d2c7a (diff) | |
download | serenity-0d1b5e7f7a1c093b15b6de47aec7616064ead897.zip |
Ladybird: Add a context menu for link elements
-rw-r--r-- | Ladybird/Tab.cpp | 33 | ||||
-rw-r--r-- | Ladybird/Tab.h | 3 | ||||
-rw-r--r-- | Ladybird/WebContentView.cpp | 5 |
3 files changed, 38 insertions, 3 deletions
diff --git a/Ladybird/Tab.cpp b/Ladybird/Tab.cpp index a90f26648e..ed902677f6 100644 --- a/Ladybird/Tab.cpp +++ b/Ladybird/Tab.cpp @@ -197,6 +197,39 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path, WebView:: m_page_context_menu->exec(screen_position); }; + auto* open_link_action = new QAction("&Open", this); + open_link_action->setIcon(QIcon(QString("%1/res/icons/16x16/go-forward.png").arg(s_serenity_resource_root.characters()))); + QObject::connect(open_link_action, &QAction::triggered, this, [this]() { + open_link(m_link_context_menu_url); + }); + + auto* open_link_in_new_tab_action = new QAction("&Open in New &Tab", this); + open_link_in_new_tab_action->setIcon(QIcon(QString("%1/res/icons/16x16/new-tab.png").arg(s_serenity_resource_root.characters()))); + QObject::connect(open_link_in_new_tab_action, &QAction::triggered, this, [this]() { + open_link_in_new_tab(m_link_context_menu_url); + }); + + auto* copy_url_action = new QAction("Copy &URL", this); + copy_url_action->setIcon(QIcon(QString("%1/res/icons/16x16/edit-copy.png").arg(s_serenity_resource_root.characters()))); + QObject::connect(copy_url_action, &QAction::triggered, this, [this]() { + copy_link_url(m_link_context_menu_url); + }); + + m_link_context_menu = make<QMenu>("Link context menu", this); + m_link_context_menu->addAction(open_link_action); + m_link_context_menu->addAction(open_link_in_new_tab_action); + m_link_context_menu->addSeparator(); + m_link_context_menu->addAction(copy_url_action); + m_link_context_menu->addSeparator(); + m_link_context_menu->addAction(&m_window->inspect_dom_node_action()); + + view().on_link_context_menu_request = [this](auto const& url, auto widget_position) { + m_link_context_menu_url = url; + + auto screen_position = mapToGlobal(QPoint { widget_position.x(), widget_position.y() }); + m_link_context_menu->exec(screen_position); + }; + m_video_context_menu_play_icon = make<QIcon>(QString("%1/res/icons/16x16/play.png").arg(s_serenity_resource_root.characters())); m_video_context_menu_pause_icon = make<QIcon>(QString("%1/res/icons/16x16/pause.png").arg(s_serenity_resource_root.characters())); diff --git a/Ladybird/Tab.h b/Ladybird/Tab.h index 537b4fbd64..acb673c416 100644 --- a/Ladybird/Tab.h +++ b/Ladybird/Tab.h @@ -73,6 +73,9 @@ private: OwnPtr<QMenu> m_page_context_menu; + OwnPtr<QMenu> m_link_context_menu; + URL m_link_context_menu_url; + OwnPtr<QMenu> m_video_context_menu; OwnPtr<QIcon> m_video_context_menu_play_icon; OwnPtr<QIcon> m_video_context_menu_pause_icon; diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index 82e63faecb..829d66326b 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -872,9 +872,8 @@ void WebContentView::notify_server_did_request_context_menu(Badge<WebContentClie void WebContentView::notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const&, unsigned) { - // FIXME - (void)content_position; - (void)url; + if (on_link_context_menu_request) + on_link_context_menu_request(url, to_widget(content_position)); } void WebContentView::notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const&, unsigned, Gfx::ShareableBitmap const& bitmap) |