From 53f9be4ea89ba3ec9896c6aa34305e8fc3750e43 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 5 Dec 2023 12:58:55 +0000 Subject: [PATCH] Browser: Implement "Copy Email/Phone" menu item for links --- Userland/Applications/Browser/Tab.cpp | 19 ++++++++++++++++--- Userland/Applications/Browser/Tab.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index de80fb25b6..87ae4994df 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -310,9 +310,10 @@ Tab::Tab(BrowserWindow& window) view().on_link_click(m_link_context_menu_url, "_blank", 0); })); m_link_context_menu->add_separator(); - m_link_context_menu->add_action(GUI::Action::create("Copy &URL", g_icon_bag.copy, [this](auto&) { - GUI::Clipboard::the().set_plain_text(m_link_context_menu_url.to_deprecated_string()); - })); + m_link_copy_action = GUI::Action::create("Copy &URL", g_icon_bag.copy, [this](auto&) { + GUI::Clipboard::the().set_plain_text(WebView::url_text_to_copy(m_link_context_menu_url)); + }); + m_link_context_menu->add_action(*m_link_copy_action); m_link_context_menu->add_separator(); m_link_context_menu->add_action(GUI::Action::create("&Download", g_icon_bag.download, [this](auto&) { start_download(m_link_context_menu_url); @@ -323,6 +324,18 @@ Tab::Tab(BrowserWindow& window) view().on_link_context_menu_request = [this](auto& url, auto widget_position) { m_link_context_menu_url = url; + switch (WebView::url_type(url)) { + case WebView::URLType::Email: + m_link_copy_action->set_text("Copy &Email Address"); + break; + case WebView::URLType::Telephone: + m_link_copy_action->set_text("Copy &Phone Number"); + break; + case WebView::URLType::Other: + m_link_copy_action->set_text("Copy &URL"); + break; + } + auto screen_position = view().screen_relative_rect().location().translated(widget_position); m_link_context_menu->popup(screen_position, m_link_context_menu_default_action); }; diff --git a/Userland/Applications/Browser/Tab.h b/Userland/Applications/Browser/Tab.h index c07d99a087..7eccbd432e 100644 --- a/Userland/Applications/Browser/Tab.h +++ b/Userland/Applications/Browser/Tab.h @@ -132,6 +132,7 @@ private: RefPtr m_link_context_menu; RefPtr m_link_context_menu_default_action; + RefPtr m_link_copy_action; URL m_link_context_menu_url; RefPtr m_image_context_menu;