Browser: Add a simple context menu for hyperlinks

This only has "Open" and "Open in new tab" for now. :^)
This commit is contained in:
Andreas Kling 2020-05-05 22:42:50 +02:00
parent f32989a3e7
commit 588e18721d
2 changed files with 16 additions and 0 deletions

View file

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

View file

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