diff --git a/Ladybird/Tab.cpp b/Ladybird/Tab.cpp index ed902677f6..ee19ef1593 100644 --- a/Ladybird/Tab.cpp +++ b/Ladybird/Tab.cpp @@ -10,11 +10,13 @@ #include "Settings.h" #include "Utilities.h" #include +#include #include #include #include #include #include +#include #include #include #include @@ -230,6 +232,60 @@ Tab::Tab(BrowserWindow* window, StringView webdriver_content_ipc_path, WebView:: m_link_context_menu->exec(screen_position); }; + auto* open_image_action = new QAction("&Open Image", this); + open_image_action->setIcon(QIcon(QString("%1/res/icons/16x16/filetype-image.png").arg(s_serenity_resource_root.characters()))); + QObject::connect(open_image_action, &QAction::triggered, this, [this]() { + open_link(m_image_context_menu_url); + }); + + auto* open_image_in_new_tab_action = new QAction("&Open Image in New &Tab", this); + open_image_in_new_tab_action->setIcon(QIcon(QString("%1/res/icons/16x16/new-tab.png").arg(s_serenity_resource_root.characters()))); + QObject::connect(open_image_in_new_tab_action, &QAction::triggered, this, [this]() { + open_link_in_new_tab(m_image_context_menu_url); + }); + + auto* copy_image_action = new QAction("&Copy Image", this); + copy_image_action->setIcon(QIcon(QString("%1/res/icons/16x16/edit-copy.png").arg(s_serenity_resource_root.characters()))); + QObject::connect(copy_image_action, &QAction::triggered, this, [this]() { + auto* bitmap = m_image_context_menu_bitmap.bitmap(); + if (bitmap == nullptr) + return; + + auto data = Gfx::BMPWriter::encode(*bitmap); + if (data.is_error()) + return; + + auto image = QImage::fromData(data.value().data(), data.value().size(), "BMP"); + if (image.isNull()) + return; + + auto* clipboard = QGuiApplication::clipboard(); + clipboard->setImage(image); + }); + + auto* copy_image_url_action = new QAction("Copy Image &URL", this); + copy_image_url_action->setIcon(QIcon(QString("%1/res/icons/16x16/edit-copy.png").arg(s_serenity_resource_root.characters()))); + QObject::connect(copy_image_url_action, &QAction::triggered, this, [this]() { + copy_link_url(m_image_context_menu_url); + }); + + m_image_context_menu = make("Image context menu", this); + m_image_context_menu->addAction(open_image_action); + m_image_context_menu->addAction(open_image_in_new_tab_action); + m_image_context_menu->addSeparator(); + m_image_context_menu->addAction(copy_image_action); + m_image_context_menu->addAction(copy_image_url_action); + m_image_context_menu->addSeparator(); + m_image_context_menu->addAction(&m_window->inspect_dom_node_action()); + + view().on_image_context_menu_request = [this](auto& image_url, auto widget_position, Gfx::ShareableBitmap const& shareable_bitmap) { + m_image_context_menu_url = image_url; + m_image_context_menu_bitmap = shareable_bitmap; + + auto screen_position = mapToGlobal(QPoint { widget_position.x(), widget_position.y() }); + m_image_context_menu->exec(screen_position); + }; + m_video_context_menu_play_icon = make(QString("%1/res/icons/16x16/play.png").arg(s_serenity_resource_root.characters())); m_video_context_menu_pause_icon = make(QString("%1/res/icons/16x16/pause.png").arg(s_serenity_resource_root.characters())); diff --git a/Ladybird/Tab.h b/Ladybird/Tab.h index acb673c416..77598303dc 100644 --- a/Ladybird/Tab.h +++ b/Ladybird/Tab.h @@ -76,6 +76,10 @@ private: OwnPtr m_link_context_menu; URL m_link_context_menu_url; + OwnPtr m_image_context_menu; + Gfx::ShareableBitmap m_image_context_menu_bitmap; + URL m_image_context_menu_url; + OwnPtr m_video_context_menu; OwnPtr m_video_context_menu_play_icon; OwnPtr m_video_context_menu_pause_icon; diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index 829d66326b..e1470f4205 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -878,10 +878,8 @@ void WebContentView::notify_server_did_request_link_context_menu(Badge, Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const&, unsigned, Gfx::ShareableBitmap const& bitmap) { - // FIXME - (void)content_position; - (void)url; - (void)bitmap; + if (on_image_context_menu_request) + on_image_context_menu_request(url, to_widget(content_position), bitmap); } void WebContentView::notify_server_did_request_video_context_menu(Badge, Gfx::IntPoint content_position, AK::URL const& url, DeprecatedString const&, unsigned, bool is_playing, bool has_user_agent_controls, bool is_looping)