diff --git a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp index b3f67346242..8f18d637cba 100644 --- a/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/IPCCompiler/main.cpp @@ -70,7 +70,7 @@ static bool is_primitive_type(ByteString const& type) static bool is_simple_type(ByteString const& type) { // Small types that it makes sense just to pass by value. - return type.is_one_of("Gfx::Color", "Web::DevicePixels", "Gfx::IntPoint", "Gfx::FloatPoint", "Web::DevicePixelPoint", "Gfx::IntSize", "Gfx::FloatSize", "Web::DevicePixelSize", "Core::File::OpenMode", "Web::Cookie::Source", "Web::HTML::AllowMultipleFiles"); + return type.is_one_of("Gfx::Color", "Web::DevicePixels", "Gfx::IntPoint", "Gfx::FloatPoint", "Web::DevicePixelPoint", "Gfx::IntSize", "Gfx::FloatSize", "Web::DevicePixelSize", "Core::File::OpenMode", "Web::Cookie::Source", "Web::HTML::AllowMultipleFiles", "Web::HTML::AudioPlayState"); } static bool is_primitive_or_simple_type(ByteString const& type) diff --git a/Userland/Libraries/LibWeb/HTML/AudioPlayState.h b/Userland/Libraries/LibWeb/HTML/AudioPlayState.h new file mode 100644 index 00000000000..bd6c22f14e2 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/AudioPlayState.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +namespace Web::HTML { + +enum class AudioPlayState { + Paused, + Playing, +}; + +} diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index bf6ab8a3f7b..f243a9ba8a6 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,7 @@ #include #include #include +#include #include #include @@ -1602,6 +1604,9 @@ void HTMLMediaElement::set_paused(bool paused) if (auto* paintable = this->paintable()) paintable->set_needs_display(); set_needs_style_update(true); + + if (m_audio_tracks->has_enabled_track()) + document().page().client().page_did_change_audio_play_state(paused ? AudioPlayState::Paused : AudioPlayState::Playing); } // https://html.spec.whatwg.org/multipage/media.html#blocked-media-element diff --git a/Userland/Libraries/LibWeb/Page/Page.h b/Userland/Libraries/LibWeb/Page/Page.h index adb749f9e7a..c7d0181691a 100644 --- a/Userland/Libraries/LibWeb/Page/Page.h +++ b/Userland/Libraries/LibWeb/Page/Page.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -295,6 +296,8 @@ public: virtual void page_did_insert_clipboard_entry([[maybe_unused]] String data, [[maybe_unused]] String presentation_style, [[maybe_unused]] String mime_type) { } + virtual void page_did_change_audio_play_state(HTML::AudioPlayState) { } + virtual WebView::SocketPair request_worker_agent() { return { -1, -1 }; } virtual void inspector_did_load() { } diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp index 20703761a5b..ea386f90f65 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.cpp +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -315,6 +315,14 @@ void ViewImplementation::toggle_media_controls_state() client().async_toggle_media_controls_state(page_id()); } +void ViewImplementation::did_change_audio_play_state(Badge, Web::HTML::AudioPlayState play_state) +{ + m_audio_play_state = play_state; + + if (on_audio_play_state_changed) + on_audio_play_state_changed(m_audio_play_state); +} + void ViewImplementation::handle_resize() { resize_backing_stores_if_needed(WindowResizeInProgress::Yes); diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 901176cdbae..d5190cf7fd7 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -101,6 +102,9 @@ public: void toggle_media_loop_state(); void toggle_media_controls_state(); + void did_change_audio_play_state(Badge, Web::HTML::AudioPlayState); + Web::HTML::AudioPlayState audio_play_state() const { return m_audio_play_state; } + enum class ScreenshotType { Visible, Full, @@ -178,6 +182,7 @@ public: Function on_text_test_finish; Function on_theme_color_change; Function on_insert_clipboard_entry; + Function on_audio_play_state_changed; Function on_inspector_loaded; Function const&)> on_inspector_selected_dom_node; Function on_inspector_set_dom_node_text; @@ -252,6 +257,8 @@ protected: RefPtr m_repeated_crash_timer; RefPtr> m_pending_screenshot; + + Web::HTML::AudioPlayState m_audio_play_state { Web::HTML::AudioPlayState::Paused }; }; } diff --git a/Userland/Libraries/LibWebView/WebContentClient.cpp b/Userland/Libraries/LibWebView/WebContentClient.cpp index de0dd5c1520..705a71d557b 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.cpp +++ b/Userland/Libraries/LibWebView/WebContentClient.cpp @@ -870,6 +870,18 @@ void WebContentClient::did_insert_clipboard_entry(u64 page_id, String const& dat view.on_insert_clipboard_entry(data, presentation_style, mime_type); } +void WebContentClient::did_change_audio_play_state(u64 page_id, Web::HTML::AudioPlayState play_state) +{ + auto maybe_view = m_views.get(page_id); + if (!maybe_view.has_value()) { + dbgln("Received insert clipboard entry for unknown page ID {}", page_id); + return; + } + + auto& view = *maybe_view.value(); + view.did_change_audio_play_state({}, play_state); +} + void WebContentClient::inspector_did_load(u64 page_id) { auto maybe_view = m_views.get(page_id); diff --git a/Userland/Libraries/LibWebView/WebContentClient.h b/Userland/Libraries/LibWebView/WebContentClient.h index 19cbf621070..3a625d16f06 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.h +++ b/Userland/Libraries/LibWebView/WebContentClient.h @@ -96,6 +96,7 @@ private: virtual void did_finish_text_test(u64 page_id) override; virtual void did_change_theme_color(u64 page_id, Gfx::Color color) override; virtual void did_insert_clipboard_entry(u64 page_id, String const& data, String const& presentation_style, String const& mime_type) override; + virtual void did_change_audio_play_state(u64 page_id, Web::HTML::AudioPlayState) override; virtual void inspector_did_load(u64 page_id) override; virtual void inspector_did_select_dom_node(u64 page_id, i32 node_id, Optional const& pseudo_element) override; virtual void inspector_did_set_dom_node_text(u64 page_id, i32 node_id, String const& text) override; diff --git a/Userland/Services/WebContent/PageClient.cpp b/Userland/Services/WebContent/PageClient.cpp index 0ea02a26d05..12366e4202e 100644 --- a/Userland/Services/WebContent/PageClient.cpp +++ b/Userland/Services/WebContent/PageClient.cpp @@ -577,6 +577,11 @@ void PageClient::page_did_insert_clipboard_entry(String data, String presentatio client().async_did_insert_clipboard_entry(m_id, move(data), move(presentation_style), move(mime_type)); } +void PageClient::page_did_change_audio_play_state(Web::HTML::AudioPlayState play_state) +{ + client().async_did_change_audio_play_state(m_id, play_state); +} + WebView::SocketPair PageClient::request_worker_agent() { auto response = client().send_sync_but_allow_failure(m_id); diff --git a/Userland/Services/WebContent/PageClient.h b/Userland/Services/WebContent/PageClient.h index 82f36e81d75..ab7aa48d5ef 100644 --- a/Userland/Services/WebContent/PageClient.h +++ b/Userland/Services/WebContent/PageClient.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -140,6 +141,7 @@ private: virtual void page_did_finish_text_test() override; virtual void page_did_change_theme_color(Gfx::Color color) override; virtual void page_did_insert_clipboard_entry(String data, String presentation_style, String mime_type) override; + virtual void page_did_change_audio_play_state(Web::HTML::AudioPlayState) override; virtual WebView::SocketPair request_worker_agent() override; virtual void inspector_did_load() override; virtual void inspector_did_select_dom_node(i32 node_id, Optional const& pseudo_element) override; diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc index 7da0fec32a1..dcd224f90a2 100644 --- a/Userland/Services/WebContent/WebContentClient.ipc +++ b/Userland/Services/WebContent/WebContentClient.ipc @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -78,6 +79,8 @@ endpoint WebContentClient did_change_theme_color(u64 page_id, Gfx::Color color) =| did_insert_clipboard_entry(u64 page_id, String data, String presentation_style, String mime_type) =| + did_change_audio_play_state(u64 page_id, Web::HTML::AudioPlayState play_state) =| + did_output_js_console_message(u64 page_id, i32 message_index) =| did_get_js_console_messages(u64 page_id, i32 start_index, Vector message_types, Vector messages) =|