1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 17:15:08 +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:
Andreas Kling 2020-10-02 19:01:51 +02:00
parent d00bfd0eaa
commit 91b49dd9d0
5 changed files with 22 additions and 0 deletions

View file

@ -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);