From 54cd8dfc4db0688fbef9571137a1b45c99226b04 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 11 Apr 2021 16:49:25 +0200 Subject: [PATCH] LibWeb+WebContent: Support image context menus in OOPWV You can now right-click images in web content and get a context menu. --- Userland/Libraries/LibWeb/OutOfProcessWebView.cpp | 6 ++++++ Userland/Libraries/LibWeb/OutOfProcessWebView.h | 1 + Userland/Libraries/LibWeb/WebContentClient.cpp | 5 +++++ Userland/Libraries/LibWeb/WebContentClient.h | 1 + Userland/Services/WebContent/PageHost.cpp | 7 ++++++- Userland/Services/WebContent/PageHost.h | 3 ++- Userland/Services/WebContent/WebContentClient.ipc | 1 + 7 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp index c2c36024de..f417e7814c 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -322,6 +322,12 @@ void OutOfProcessWebView::notify_server_did_request_link_context_menu(Badge, const Gfx::IntPoint& content_position, const URL& url, const String&, unsigned, const Gfx::ShareableBitmap& bitmap) +{ + if (on_image_context_menu_request) + on_image_context_menu_request(url, screen_relative_rect().location().translated(to_widget_position(content_position)), bitmap); +} + void OutOfProcessWebView::notify_server_did_request_alert(Badge, const String& message) { GUI::MessageBox::show(window(), message, "Alert", GUI::MessageBox::Type::Information); diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.h b/Userland/Libraries/LibWeb/OutOfProcessWebView.h index b634bc1077..d9918a8ad7 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.h @@ -72,6 +72,7 @@ public: void notify_server_did_finish_loading(Badge, const URL&); void notify_server_did_request_context_menu(Badge, const Gfx::IntPoint&); void notify_server_did_request_link_context_menu(Badge, const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers); + void notify_server_did_request_image_context_menu(Badge, const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers, const Gfx::ShareableBitmap&); void notify_server_did_request_alert(Badge, const String& message); bool notify_server_did_request_confirm(Badge, const String& message); String notify_server_did_request_prompt(Badge, const String& message, const String& default_); diff --git a/Userland/Libraries/LibWeb/WebContentClient.cpp b/Userland/Libraries/LibWeb/WebContentClient.cpp index 3988db3d8e..aac858b3d7 100644 --- a/Userland/Libraries/LibWeb/WebContentClient.cpp +++ b/Userland/Libraries/LibWeb/WebContentClient.cpp @@ -155,6 +155,11 @@ void WebContentClient::handle(const Messages::WebContentClient::DidRequestLinkCo m_view.notify_server_did_request_link_context_menu({}, message.content_position(), message.url(), message.target(), message.modifiers()); } +void WebContentClient::handle(const Messages::WebContentClient::DidRequestImageContextMenu& message) +{ + m_view.notify_server_did_request_image_context_menu({}, message.content_position(), message.url(), message.target(), message.modifiers(), message.bitmap()); +} + void WebContentClient::handle(const Messages::WebContentClient::DidGetSource& message) { m_view.notify_server_did_get_source(message.url(), message.source()); diff --git a/Userland/Libraries/LibWeb/WebContentClient.h b/Userland/Libraries/LibWeb/WebContentClient.h index 17ae95d91c..a519734148 100644 --- a/Userland/Libraries/LibWeb/WebContentClient.h +++ b/Userland/Libraries/LibWeb/WebContentClient.h @@ -68,6 +68,7 @@ private: virtual void handle(const Messages::WebContentClient::DidStartLoading&) override; virtual void handle(const Messages::WebContentClient::DidRequestContextMenu&) override; virtual void handle(const Messages::WebContentClient::DidRequestLinkContextMenu&) override; + virtual void handle(const Messages::WebContentClient::DidRequestImageContextMenu&) override; virtual void handle(const Messages::WebContentClient::DidGetSource&) override; virtual void handle(const Messages::WebContentClient::DidJSConsoleOutput&) override; virtual void handle(const Messages::WebContentClient::DidChangeFavicon&) override; diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp index e688549663..e67ba3d366 100644 --- a/Userland/Services/WebContent/PageHost.cpp +++ b/Userland/Services/WebContent/PageHost.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2020-2021, Andreas Kling * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -203,4 +203,9 @@ void PageHost::page_did_change_favicon(const Gfx::Bitmap& favicon) m_client.post_message(Messages::WebContentClient::DidChangeFavicon(favicon.to_shareable_bitmap())); } +void PageHost::page_did_request_image_context_menu(const Gfx::IntPoint& content_position, const URL& url, const String& target, unsigned modifiers, const Gfx::Bitmap* bitmap) +{ + m_client.post_message(Messages::WebContentClient::DidRequestImageContextMenu(content_position, url, target, modifiers, bitmap->to_shareable_bitmap())); +} + } diff --git a/Userland/Services/WebContent/PageHost.h b/Userland/Services/WebContent/PageHost.h index 315b3bc34c..38c74744b8 100644 --- a/Userland/Services/WebContent/PageHost.h +++ b/Userland/Services/WebContent/PageHost.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2020-2021, Andreas Kling * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -78,6 +78,7 @@ private: virtual bool page_did_request_confirm(const String&) override; virtual String page_did_request_prompt(const String&, const String&) override; virtual void page_did_change_favicon(const Gfx::Bitmap&) override; + virtual void page_did_request_image_context_menu(const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers, const Gfx::Bitmap*) override; explicit PageHost(ClientConnection&); diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc index baa51492ad..b78a88bef9 100644 --- a/Userland/Services/WebContent/WebContentClient.ipc +++ b/Userland/Services/WebContent/WebContentClient.ipc @@ -18,6 +18,7 @@ endpoint WebContentClient = 90 DidMiddleClickLink(URL url, String target, unsigned modifiers) =| DidRequestContextMenu(Gfx::IntPoint content_position) =| DidRequestLinkContextMenu(Gfx::IntPoint content_position, URL url, String target, unsigned modifiers) =| + DidRequestImageContextMenu(Gfx::IntPoint content_position, URL url, String target, unsigned modifiers, Gfx::ShareableBitmap bitmap) =| DidRequestAlert(String message) => () DidRequestConfirm(String message) => (bool result) DidRequestPrompt(String message, String default_) => (String response)