summaryrefslogtreecommitdiff
path: root/Applications/Browser
diff options
context:
space:
mode:
authorFalseHonesty <thefalsehonesty@gmail.com>2020-05-18 18:37:12 -0400
committerAndreas Kling <kling@serenityos.org>2020-05-21 21:53:17 +0200
commit9241c3a957c0d04fb3ded503b2509c7242847ca4 (patch)
treece0d1ce23a00e57488b08644c799caab60ec6645 /Applications/Browser
parentbf2e6325a43947d36a2c55c314453dcc102fc8cd (diff)
downloadserenity-9241c3a957c0d04fb3ded503b2509c7242847ca4.zip
Browser: Pop up a context menu when one is requested on a tab
Currently, the tab's context menu only has options to reload and close, but this patch allows for those options to be quickly expanded!
Diffstat (limited to 'Applications/Browser')
-rw-r--r--Applications/Browser/Tab.cpp13
-rw-r--r--Applications/Browser/Tab.h3
-rw-r--r--Applications/Browser/main.cpp5
3 files changed, 21 insertions, 0 deletions
diff --git a/Applications/Browser/Tab.cpp b/Applications/Browser/Tab.cpp
index d5e402196e..c5ba32f83d 100644
--- a/Applications/Browser/Tab.cpp
+++ b/Applications/Browser/Tab.cpp
@@ -310,6 +310,14 @@ Tab::Tab()
auto& help_menu = m_menubar->add_menu("Help");
help_menu.add_action(WindowActions::the().about_action());
+
+ m_tab_context_menu = GUI::Menu::construct();
+ m_tab_context_menu->add_action(GUI::Action::create("Reload Tab", [this](auto&) {
+ m_reload_action->activate();
+ }));
+ m_tab_context_menu->add_action(GUI::Action::create("Close Tab", [this](auto&) {
+ on_tab_close_request(*this);
+ }));
}
Tab::~Tab()
@@ -369,4 +377,9 @@ void Tab::did_become_active()
GUI::Application::the().set_menubar(m_menubar);
}
+void Tab::context_menu_requested(const Gfx::Point& screen_position)
+{
+ m_tab_context_menu->popup(screen_position);
+}
+
}
diff --git a/Applications/Browser/Tab.h b/Applications/Browser/Tab.h
index 4f26e55a98..78abe4ddc8 100644
--- a/Applications/Browser/Tab.h
+++ b/Applications/Browser/Tab.h
@@ -43,6 +43,7 @@ public:
void load(const URL&);
void did_become_active();
+ void context_menu_requested(const Gfx::Point& screen_position);
Function<void(String)> on_title_change;
Function<void(const URL&)> on_tab_open_request;
@@ -73,6 +74,8 @@ private:
RefPtr<GUI::Menu> m_link_context_menu;
String m_link_context_menu_href;
+ RefPtr<GUI::Menu> m_tab_context_menu;
+
String m_title;
RefPtr<const Gfx::Bitmap> m_icon;
diff --git a/Applications/Browser/main.cpp b/Applications/Browser/main.cpp
index 0f5872fab2..ab93e88c9a 100644
--- a/Applications/Browser/main.cpp
+++ b/Applications/Browser/main.cpp
@@ -121,6 +121,11 @@ int main(int argc, char** argv)
tab.on_tab_close_request(tab);
};
+ tab_widget.on_context_menu_request = [&](auto& clicked_widget, const GUI::ContextMenuEvent& context_menu_event) {
+ auto& tab = static_cast<Browser::Tab&>(clicked_widget);
+ tab.context_menu_requested(context_menu_event.screen_position());
+ };
+
Browser::WindowActions window_actions(*window);
Function<void(URL url, bool activate)> create_new_tab;