1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 20:28:11 +00:00

Ladybird+LibWeb+WebContent: Generalize video context menus for all media

The data we want to send out of the WebContent process is identical for
audio and video elements. Rather than just duplicating all of this for
audio, generalize the names used for this IPC for all media elements.

This also encapsulates that data into a struct. This makes adding new
fields to be sent much easier (such as an upcoming field for muting the
element).
This commit is contained in:
Timothy Flynn 2023-06-16 10:51:38 -04:00 committed by Andreas Kling
parent e81abbde7b
commit 14ca04de25
17 changed files with 198 additions and 147 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/HTMLMediaElement.h>
#include <LibWeb/HTML/HTMLVideoElement.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Page/EventHandler.h>
@ -307,17 +308,19 @@ 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);
} else if (is<HTML::HTMLMediaElement>(*node)) {
auto& media_element = verify_cast<HTML::HTMLMediaElement>(*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);
Page::MediaContextMenu menu {
.media_url = media_element.document().parse_url(media_element.current_src()),
.is_video = is<HTML::HTMLVideoElement>(*node),
.is_playing = media_element.potentially_playing(),
.has_user_agent_controls = media_element.has_attribute(HTML::AttributeNames::controls),
.is_looping = media_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);
page->did_request_media_context_menu(media_element.id(), m_browsing_context->to_top_level_position(position), "", modifiers, move(menu));
} else if (auto* page = m_browsing_context->page()) {
page->client().page_did_request_context_menu(m_browsing_context->to_top_level_position(position));
}