Ladybird: Add a context menu for link elements

This commit is contained in:
Timothy Flynn 2023-05-15 12:48:46 -04:00 committed by Andreas Kling
parent 1b2394d92e
commit 0d1b5e7f7a
Notes: sideshowbarker 2024-07-17 09:49:33 +09:00
3 changed files with 38 additions and 3 deletions

View File

@ -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()));

View File

@ -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;

View File

@ -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)