mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibWeb: Add a PageClient callback for image context menu requests
When the user right-clicks on an image, you might want to show a special context menu, separate from the regular link context menu. This patch only implements enough of the functionality to get this working in a single-process context.
This commit is contained in:
parent
d00bfd0eaa
commit
91b49dd9d0
Notes:
sideshowbarker
2024-07-19 02:05:48 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/91b49dd9d01
5 changed files with 22 additions and 0 deletions
|
@ -36,6 +36,7 @@
|
|||
#include <LibGUI/ScrollBar.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibGfx/ImageDecoder.h>
|
||||
#include <LibGfx/ShareableBitmap.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
|
@ -171,6 +172,16 @@ void InProcessWebView::page_did_request_link_context_menu(const Gfx::IntPoint& c
|
|||
on_link_context_menu_request(url, screen_relative_rect().location().translated(to_widget_position(content_position)));
|
||||
}
|
||||
|
||||
void InProcessWebView::page_did_request_image_context_menu(const Gfx::IntPoint& content_position, const URL& url, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers, const Gfx::Bitmap* bitmap)
|
||||
{
|
||||
if (!on_image_context_menu_request)
|
||||
return;
|
||||
Gfx::ShareableBitmap shareable_bitmap;
|
||||
if (bitmap)
|
||||
shareable_bitmap = Gfx::ShareableBitmap(*bitmap);
|
||||
on_image_context_menu_request(url, screen_relative_rect().location().translated(to_widget_position(content_position)), shareable_bitmap);
|
||||
}
|
||||
|
||||
void InProcessWebView::page_did_click_link(const URL& url, const String& target, unsigned modifiers)
|
||||
{
|
||||
if (on_link_click)
|
||||
|
|
|
@ -94,6 +94,7 @@ private:
|
|||
virtual void page_did_request_cursor_change(Gfx::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 URL&, const String& target, unsigned modifiers) override;
|
||||
virtual void page_did_request_image_context_menu(const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers, const Gfx::Bitmap*) 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;
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
||||
#include <LibWeb/HTML/HTMLIFrameElement.h>
|
||||
#include <LibWeb/HTML/HTMLImageElement.h>
|
||||
#include <LibWeb/InProcessWebView.h>
|
||||
#include <LibWeb/Layout/LayoutDocument.h>
|
||||
#include <LibWeb/Page/EventHandler.h>
|
||||
|
@ -154,6 +155,13 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
|
|||
if (!layout_root())
|
||||
return true;
|
||||
|
||||
if (button == GUI::MouseButton::Right && is<HTML::HTMLImageElement>(*node)) {
|
||||
auto& image_element = downcast<HTML::HTMLImageElement>(*node);
|
||||
auto image_url = image_element.document().complete_url(image_element.src());
|
||||
page_client.page_did_request_image_context_menu(m_frame.to_main_frame_position(position), image_url, "", modifiers, image_element.bitmap());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (RefPtr<HTML::HTMLAnchorElement> link = node->enclosing_link_element()) {
|
||||
auto href = link->href();
|
||||
auto url = document->complete_url(href);
|
||||
|
|
|
@ -87,6 +87,7 @@ public:
|
|||
virtual void page_did_request_cursor_change(Gfx::StandardCursor) { }
|
||||
virtual void page_did_request_context_menu(const Gfx::IntPoint&) { }
|
||||
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_request_image_context_menu(const Gfx::IntPoint&, const URL&, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers, const Gfx::Bitmap*) { }
|
||||
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&) { }
|
||||
|
|
|
@ -37,6 +37,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 URL&, const Gfx::IntPoint& screen_position)> on_link_context_menu_request;
|
||||
Function<void(const URL&, const Gfx::IntPoint& screen_position, const Gfx::ShareableBitmap&)> on_image_context_menu_request;
|
||||
Function<void(const URL&, const String& target, unsigned modifiers)> on_link_middle_click;
|
||||
Function<void(const URL&)> on_link_hover;
|
||||
Function<void(const String&)> on_title_change;
|
||||
|
|
Loading…
Add table
Reference in a new issue