summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-06 20:00:56 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-06 20:00:56 +0200
commitfd65a2483492dfd50cae61b613d9bd8ed95306b3 (patch)
tree994b02a5b583a6ad4bae3edc4908ab162bddd254
parent02c5e22f06dbe198fdc51eef488929518856d5c8 (diff)
downloadserenity-fd65a2483492dfd50cae61b613d9bd8ed95306b3.zip
LibWeb: Make the link context menu hook include the destination URL
-rw-r--r--Applications/Browser/Tab.cpp12
-rw-r--r--Applications/Browser/Tab.h2
-rw-r--r--Libraries/LibWeb/Frame/EventHandler.cpp2
-rw-r--r--Libraries/LibWeb/Page.h2
-rw-r--r--Libraries/LibWeb/PageView.cpp4
-rw-r--r--Libraries/LibWeb/PageView.h4
6 files changed, 13 insertions, 13 deletions
diff --git a/Applications/Browser/Tab.cpp b/Applications/Browser/Tab.cpp
index 8093e6942e..9045588f6f 100644
--- a/Applications/Browser/Tab.cpp
+++ b/Applications/Browser/Tab.cpp
@@ -164,19 +164,19 @@ Tab::Tab()
m_link_context_menu = GUI::Menu::construct();
m_link_context_menu->add_action(GUI::Action::create("Open", [this](auto&) {
- m_page_view->on_link_click(m_link_context_menu_href, "", 0);
+ m_page_view->on_link_click(m_link_context_menu_url, "", 0);
}));
m_link_context_menu->add_action(GUI::Action::create("Open in new tab", [this](auto&) {
- m_page_view->on_link_click(m_link_context_menu_href, "_blank", 0);
+ m_page_view->on_link_click(m_link_context_menu_url, "_blank", 0);
}));
m_link_context_menu->add_action(GUI::Action::create("Copy link", [this](auto&) {
- GUI::Clipboard::the().set_data(m_page_view->document()->complete_url(m_link_context_menu_href).to_string());
+ GUI::Clipboard::the().set_data(m_link_context_menu_url.to_string());
}));
m_link_context_menu->add_separator();
m_link_context_menu->add_action(GUI::Action::create("Download", [this](auto&) {
auto window = GUI::Window::construct();
window->set_rect(300, 300, 300, 150);
- auto url = m_page_view->document()->complete_url(m_link_context_menu_href);
+ auto url = m_link_context_menu_url;
window->set_title(String::format("0%% of %s", url.basename().characters()));
window->set_resizable(false);
window->set_main_widget<DownloadWidget>(url);
@@ -184,8 +184,8 @@ Tab::Tab()
(void)window.leak_ref();
}));
- m_page_view->on_link_context_menu_request = [this](auto& href, auto& screen_position) {
- m_link_context_menu_href = href;
+ m_page_view->on_link_context_menu_request = [this](auto& url, auto& screen_position) {
+ m_link_context_menu_url = url;
m_link_context_menu->popup(screen_position);
};
diff --git a/Applications/Browser/Tab.h b/Applications/Browser/Tab.h
index ecf9338619..ddf285675a 100644
--- a/Applications/Browser/Tab.h
+++ b/Applications/Browser/Tab.h
@@ -73,7 +73,7 @@ private:
RefPtr<GUI::ToolBarContainer> m_toolbar_container;
RefPtr<GUI::Menu> m_link_context_menu;
- String m_link_context_menu_href;
+ URL m_link_context_menu_url;
RefPtr<GUI::Menu> m_tab_context_menu;
RefPtr<GUI::Menu> m_page_context_menu;
diff --git a/Libraries/LibWeb/Frame/EventHandler.cpp b/Libraries/LibWeb/Frame/EventHandler.cpp
index 97bdfb327c..c24636bad7 100644
--- a/Libraries/LibWeb/Frame/EventHandler.cpp
+++ b/Libraries/LibWeb/Frame/EventHandler.cpp
@@ -145,7 +145,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
}
}
} else if (button == GUI::MouseButton::Right) {
- page_client.page_did_request_link_context_menu(m_frame.to_main_frame_position(position), link->href(), link->target(), modifiers);
+ page_client.page_did_request_link_context_menu(m_frame.to_main_frame_position(position), url, link->target(), modifiers);
} else if (button == GUI::MouseButton::Middle) {
page_client.page_did_middle_click_link(url, link->target(), modifiers);
}
diff --git a/Libraries/LibWeb/Page.h b/Libraries/LibWeb/Page.h
index d33d2b5cdc..5ac8af8c44 100644
--- a/Libraries/LibWeb/Page.h
+++ b/Libraries/LibWeb/Page.h
@@ -75,7 +75,7 @@ public:
virtual void page_did_change_selection() { }
virtual void page_did_request_cursor_change(GUI::StandardCursor) { }
virtual void page_did_request_context_menu(const Gfx::IntPoint&) { }
- virtual void page_did_request_link_context_menu(const Gfx::IntPoint&, [[maybe_unused]] const String& href, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { }
+ virtual void page_did_request_link_context_menu(const Gfx::IntPoint&, const URL&, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { }
virtual void page_did_click_link(const URL&, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { }
virtual void page_did_middle_click_link(const URL&, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { }
virtual void page_did_enter_tooltip_area(const Gfx::IntPoint&, const String&) { }
diff --git a/Libraries/LibWeb/PageView.cpp b/Libraries/LibWeb/PageView.cpp
index b55b185a18..b53f816951 100644
--- a/Libraries/LibWeb/PageView.cpp
+++ b/Libraries/LibWeb/PageView.cpp
@@ -201,10 +201,10 @@ void PageView::page_did_request_context_menu(const Gfx::IntPoint& content_positi
on_context_menu_request(screen_relative_rect().location().translated(to_widget_position(content_position)));
}
-void PageView::page_did_request_link_context_menu(const Gfx::IntPoint& content_position, const String& href, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers)
+void PageView::page_did_request_link_context_menu(const Gfx::IntPoint& content_position, const URL& url, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers)
{
if (on_link_context_menu_request)
- on_link_context_menu_request(href, screen_relative_rect().location().translated(to_widget_position(content_position)));
+ on_link_context_menu_request(url, screen_relative_rect().location().translated(to_widget_position(content_position)));
}
void PageView::page_did_click_link(const URL& url, const String& target, unsigned modifiers)
diff --git a/Libraries/LibWeb/PageView.h b/Libraries/LibWeb/PageView.h
index c44814059f..83af62053e 100644
--- a/Libraries/LibWeb/PageView.h
+++ b/Libraries/LibWeb/PageView.h
@@ -61,7 +61,7 @@ public:
Function<void(const Gfx::IntPoint& screen_position)> on_context_menu_request;
Function<void(const URL&, const String& target, unsigned modifiers)> on_link_click;
- Function<void(const String& href, const Gfx::IntPoint& screen_position)> on_link_context_menu_request;
+ Function<void(const URL&, const Gfx::IntPoint& screen_position)> on_link_context_menu_request;
Function<void(const URL&)> on_link_middle_click;
Function<void(const URL&)> on_link_hover;
Function<void(const String&)> on_title_change;
@@ -102,7 +102,7 @@ private:
virtual void page_did_change_selection() override;
virtual void page_did_request_cursor_change(GUI::StandardCursor) override;
virtual void page_did_request_context_menu(const Gfx::IntPoint&) override;
- virtual void page_did_request_link_context_menu(const Gfx::IntPoint&, const String& href, const String& target, unsigned modifiers) override;
+ virtual void page_did_request_link_context_menu(const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers) override;
virtual void page_did_click_link(const URL&, const String& target, unsigned modifiers) override;
virtual void page_did_middle_click_link(const URL&, const String& target, unsigned modifiers) override;
virtual void page_did_enter_tooltip_area(const Gfx::IntPoint&, const String&) override;