summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-05 22:42:50 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-05 22:42:50 +0200
commit588e18721d74027c68609c244516fa636bdd149d (patch)
treea59a7455cc1b583f2b408cb473c7dce223f76419 /Applications
parentf32989a3e71ee665f084f2f3887969d57fef335a (diff)
downloadserenity-588e18721d74027c68609c244516fa636bdd149d.zip
Browser: Add a simple context menu for hyperlinks
This only has "Open" and "Open in new tab" for now. :^)
Diffstat (limited to 'Applications')
-rw-r--r--Applications/Browser/Tab.cpp13
-rw-r--r--Applications/Browser/Tab.h3
2 files changed, 16 insertions, 0 deletions
diff --git a/Applications/Browser/Tab.cpp b/Applications/Browser/Tab.cpp
index 963839b666..970386e038 100644
--- a/Applications/Browser/Tab.cpp
+++ b/Applications/Browser/Tab.cpp
@@ -136,6 +136,19 @@ Tab::Tab()
}
};
+ m_link_context_menu = GUI::Menu::construct();
+ m_link_context_menu->add_action(GUI::Action::create("Open", [this](auto&) {
+ m_html_widget->on_link_click(m_link_context_menu_href, "", 0);
+ }));
+ m_link_context_menu->add_action(GUI::Action::create("Open in new tab", [this](auto&) {
+ m_html_widget->on_link_click(m_link_context_menu_href, "_blank", 0);
+ }));
+
+ m_html_widget->on_link_context_menu_request = [this](auto& href, auto& screen_position) {
+ m_link_context_menu_href = href;
+ m_link_context_menu->popup(screen_position);
+ };
+
m_html_widget->on_title_change = [this](auto& title) {
if (title.is_null()) {
m_title = m_html_widget->main_frame().document()->url().to_string();
diff --git a/Applications/Browser/Tab.h b/Applications/Browser/Tab.h
index 78bd04328e..0c8946a083 100644
--- a/Applications/Browser/Tab.h
+++ b/Applications/Browser/Tab.h
@@ -69,6 +69,9 @@ private:
RefPtr<GUI::MenuBar> m_menubar;
RefPtr<GUI::ToolBarContainer> m_toolbar_container;
+ RefPtr<GUI::Menu> m_link_context_menu;
+ String m_link_context_menu_href;
+
String m_title;
RefPtr<const Gfx::Bitmap> m_icon;