summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-10-02 19:03:10 +0200
committerAndreas Kling <kling@serenityos.org>2020-10-02 19:03:10 +0200
commit44f9637e20c3e47b5c97578d6df0f6a49c2589af (patch)
treed256aca564342db43fdfbf1b4242907403b05a6b
parent91b49dd9d017acb1e979d28a0e2bc212cb297bba (diff)
downloadserenity-44f9637e20c3e47b5c97578d6df0f6a49c2589af.zip
Browser: Add a special context menu for images
Now, right-clicking on an image allows you to open that image in this tab or a new tab. You can also copy the image URL, and even copy the image itself to the clipboard! :^) Copying to the clipboard will not work in a multi-process context yet, since we need to send the image bitmap across the IPC boundary and this patch does not do that.
-rw-r--r--Applications/Browser/Tab.cpp26
-rw-r--r--Applications/Browser/Tab.h5
2 files changed, 31 insertions, 0 deletions
diff --git a/Applications/Browser/Tab.cpp b/Applications/Browser/Tab.cpp
index 2fdda3e5fd..eff5930669 100644
--- a/Applications/Browser/Tab.cpp
+++ b/Applications/Browser/Tab.cpp
@@ -187,6 +187,32 @@ Tab::Tab(Type type)
m_link_context_menu->popup(screen_position, m_link_context_menu_default_action);
};
+ m_image_context_menu = GUI::Menu::construct();
+ m_image_context_menu->add_action(GUI::Action::create("Open image", [this](auto&) {
+ hooks().on_link_click(m_image_context_menu_url, "", 0);
+ }));
+ m_image_context_menu->add_action(GUI::Action::create("Open image in new tab", [this](auto&) {
+ hooks().on_link_click(m_image_context_menu_url, "_blank", 0);
+ }));
+ m_image_context_menu->add_separator();
+ m_image_context_menu->add_action(GUI::Action::create("Copy image", [this](auto&) {
+ if (m_image_context_menu_bitmap.is_valid())
+ GUI::Clipboard::the().set_bitmap(*m_image_context_menu_bitmap.bitmap());
+ }));
+ m_image_context_menu->add_action(GUI::Action::create("Copy image URL", [this](auto&) {
+ GUI::Clipboard::the().set_plain_text(m_image_context_menu_url.to_string());
+ }));
+ m_image_context_menu->add_separator();
+ m_image_context_menu->add_action(GUI::Action::create("Download", [this](auto&) {
+ start_download(m_image_context_menu_url);
+ }));
+
+ hooks().on_image_context_menu_request = [this](auto& image_url, auto& screen_position, const Gfx::ShareableBitmap& shareable_bitmap) {
+ m_image_context_menu_url = image_url;
+ m_image_context_menu_bitmap = shareable_bitmap;
+ m_image_context_menu->popup(screen_position);
+ };
+
hooks().on_link_middle_click = [this](auto& href, auto&, auto) {
hooks().on_link_click(href, "_blank", 0);
};
diff --git a/Applications/Browser/Tab.h b/Applications/Browser/Tab.h
index 99d03fffa9..79f86e4931 100644
--- a/Applications/Browser/Tab.h
+++ b/Applications/Browser/Tab.h
@@ -29,6 +29,7 @@
#include "History.h"
#include <AK/URL.h>
#include <LibGUI/Widget.h>
+#include <LibGfx/ShareableBitmap.h>
#include <LibHTTP/HttpJob.h>
#include <LibWeb/Forward.h>
@@ -104,6 +105,10 @@ private:
RefPtr<GUI::Action> m_link_context_menu_default_action;
URL m_link_context_menu_url;
+ RefPtr<GUI::Menu> m_image_context_menu;
+ Gfx::ShareableBitmap m_image_context_menu_bitmap;
+ URL m_image_context_menu_url;
+
RefPtr<GUI::Menu> m_tab_context_menu;
RefPtr<GUI::Menu> m_page_context_menu;