1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:27:45 +00:00

Browser+LibWeb+WebContent: Broadcast video element context menu requests

This just sets up the IPC to notify the browser process of context menu
requests on video elements. The IPC contains a few pieces of information
about the state of the video element.
This commit is contained in:
Timothy Flynn 2023-05-15 09:42:56 -04:00 committed by Andreas Kling
parent 5f473bcb5f
commit d8f03dda08
14 changed files with 54 additions and 0 deletions

View file

@ -13,6 +13,7 @@
#include <LibWeb/HTML/HTMLAnchorElement.h>
#include <LibWeb/HTML/HTMLIFrameElement.h>
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/HTML/HTMLVideoElement.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Page/EventHandler.h>
#include <LibWeb/Page/Page.h>
@ -302,6 +303,17 @@ bool EventHandler::handle_mouseup(CSSPixelPoint position, unsigned button, unsig
auto image_url = image_element.document().parse_url(image_element.src());
if (auto* page = m_browsing_context->page())
page->client().page_did_request_image_context_menu(m_browsing_context->to_top_level_position(position), image_url, "", modifiers, image_element.bitmap());
} else if (is<HTML::HTMLVideoElement>(*node)) {
auto& video_element = verify_cast<HTML::HTMLVideoElement>(*node);
auto video_id = video_element.id();
auto video_url = video_element.document().parse_url(video_element.current_src());
auto is_playing = !video_element.potentially_playing();
auto has_user_agent_controls = video_element.has_attribute(HTML::AttributeNames::controls);
auto is_looping = video_element.has_attribute(HTML::AttributeNames::loop);
if (auto* page = m_browsing_context->page())
page->did_request_video_context_menu(video_id, m_browsing_context->to_top_level_position(position), video_url, "", modifiers, is_playing, has_user_agent_controls, is_looping);
} else if (auto* page = m_browsing_context->page()) {
page->client().page_did_request_context_menu(m_browsing_context->to_top_level_position(position));
}

View file

@ -275,4 +275,10 @@ void Page::accept_dialog()
}
}
void Page::did_request_video_context_menu(i32 video_id, CSSPixelPoint position, AK::URL const& url, DeprecatedString const& target, unsigned modifiers, bool is_playing, bool has_user_agent_controls, bool is_looping)
{
m_video_context_menu_element_id = video_id;
client().page_did_request_video_context_menu(position, url, target, modifiers, is_playing, has_user_agent_controls, is_looping);
}
}

View file

@ -115,6 +115,8 @@ public:
void dismiss_dialog();
void accept_dialog();
void did_request_video_context_menu(i32 video_id, CSSPixelPoint, AK::URL const&, DeprecatedString const& target, unsigned modifiers, bool is_playing, bool has_user_agent_controls, bool is_looping);
bool pdf_viewer_supported() const { return m_pdf_viewer_supported; }
private:
@ -143,6 +145,8 @@ private:
Optional<bool> m_pending_confirm_response;
Optional<Optional<String>> m_pending_prompt_response;
Optional<int> m_video_context_menu_element_id;
// https://html.spec.whatwg.org/multipage/system-state.html#pdf-viewer-supported
// Each user agent has a PDF viewer supported boolean, whose value is implementation-defined (and might vary according to user preferences).
// Spec Note: This value also impacts the navigation processing model.
@ -178,6 +182,7 @@ public:
virtual void page_did_request_context_menu(CSSPixelPoint) { }
virtual void page_did_request_link_context_menu(CSSPixelPoint, AK::URL const&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers) { }
virtual void page_did_request_image_context_menu(CSSPixelPoint, AK::URL const&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers, Gfx::Bitmap const*) { }
virtual void page_did_request_video_context_menu(CSSPixelPoint, AK::URL const&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers, [[maybe_unused]] bool is_playing, [[maybe_unused]] bool has_user_agent_controls, [[maybe_unused]] bool is_looping) { }
virtual void page_did_click_link(const AK::URL&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers) { }
virtual void page_did_middle_click_link(const AK::URL&, [[maybe_unused]] DeprecatedString const& target, [[maybe_unused]] unsigned modifiers) { }
virtual void page_did_enter_tooltip_area(CSSPixelPoint, DeprecatedString const&) { }