Truly independent web browser
LibWeb: Show a placeholder in place of a video in Picture-in-Picture
Luke Wilde780b39176733
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex 335e02de08a..52c461dbf90 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -167,12 +167,14 @@#include <LibWeb/HTML/HTMLImageElement.h>#include <LibWeb/HTML/HTMLInputElement.h>#include <LibWeb/HTML/HTMLLinkElement.h>+#include <LibWeb/HTML/HTMLMediaElement.h>#include <LibWeb/HTML/HTMLMetaElement.h>#include <LibWeb/HTML/HTMLObjectElement.h>#include <LibWeb/HTML/HTMLScriptElement.h>#include <LibWeb/HTML/HTMLStyleElement.h>#include <LibWeb/HTML/HTMLTextAreaElement.h>#include <LibWeb/HTML/HTMLTitleElement.h>+#include <LibWeb/HTML/HTMLVideoElement.h>#include <LibWeb/HTML/HashChangeEvent.h>#include <LibWeb/HTML/History.h>#include <LibWeb/HTML/ListOfAvailableImages.h>@@ -227,6 +229,7 @@#include <LibWeb/Painting/CompositorAnimationEffectState.h>#include <LibWeb/Painting/DocumentPaintState.h>#include <LibWeb/Painting/HitTestDisplayList.h>+#include <LibWeb/Painting/PaintFacts.h>#include <LibWeb/Painting/PaintableTypes.h>#include <LibWeb/Painting/PaintingRustBridge.h>#include <LibWeb/PictureInPicture/PictureInPictureController.h>@@ -10562,6 +10565,17 @@ void Document::set_picture_in_picture_element(GC::Ptr<Element> element)CSS::record_element_state_changed(*old_element, CSS::PseudoClass::PictureInPicture, false);if (element)CSS::record_element_state_changed(*element, CSS::PseudoClass::PictureInPicture, true);++ if (auto* media_element = as_if<HTML::HTMLMediaElement>(old_element.ptr()))+ media_element->update_controls();+ if (auto* media_element = as_if<HTML::HTMLMediaElement>(element.ptr()))+ media_element->update_controls();++ // Being the Picture-in-Picture element is part of a video's paint facts, apart from anything its controls change.+ if (auto* video_element = as_if<HTML::HTMLVideoElement>(old_element.ptr()))+ Painting::push_video_paint_facts(*video_element);+ if (auto* video_element = as_if<HTML::HTMLVideoElement>(element.ptr()))+ Painting::push_video_paint_facts(*video_element);}// https://w3c.github.io/picture-in-picture/#dom-documentorshadowroot-pictureinpictureelementdiff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cppindex 62da312a76e..bc49a5e0251 100644--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp@@ -276,10 +276,7 @@ void HTMLMediaElement::attribute_changed(Utf16FlyString const& name, Optional<Ut} else if (!namespace_.has_value() && name == HTML::AttributeNames::crossorigin) {m_crossorigin = cors_setting_attribute_from_keyword(value.map([](auto const& value) { return value.utf16_view(); }));} else if (name == HTML::AttributeNames::controls) {- if (value.has_value() || is_scripting_disabled())- create_controls();- else- destroy_controls();+ update_controls();} else if (name == HTML::AttributeNames::loop) {// AD-HOC: Other browsers reflect the loop attribute in the ended attribute immediately, rather than once the// event loop reaches step 1.@@ -3479,23 +3476,34 @@ void HTMLMediaElement::reject_pending_play_promises(ReadonlySpan<GC::Ref<WebIDL:WebIDL::reject_promise(promise, error);}-void HTMLMediaElement::create_controls()+// https://html.spec.whatwg.org/multipage/media.html#attr-media-controls+bool HTMLMediaElement::should_expose_user_interface() const{- if (!m_controls.has_value())- m_controls.emplace(*this, media_element_for_controls());+ // If the attribute is present, or if scripting is disabled for the media element, then the user agent should+ // expose a user interface to the user.+ return has_attribute(AttributeNames::controls) || is_scripting_disabled();}-void HTMLMediaElement::media_element_for_controls_changed()+void HTMLMediaElement::update_controls(){- if (!m_controls.has_value())+ // The controls also show the Picture-in-Picture placeholder, so they exist while either is shown.+ if (!should_expose_user_interface() && !is_picture_in_picture_element()) {+ m_controls.clear();return;- m_controls.clear();- create_controls();+ }++ if (m_controls.has_value())+ m_controls->update_visibility();+ else+ m_controls.emplace(*this, media_element_for_controls());}-void HTMLMediaElement::destroy_controls()+void HTMLMediaElement::media_element_for_controls_changed(){+ if (!m_controls.has_value())+ return;m_controls.clear();+ update_controls();}void HTMLMediaElement::set_picture_in_picture_window_controls_in_use(bool in_use)diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Libraries/LibWeb/HTML/HTMLMediaElement.hindex 7546e21654e..c5363e51c6b 100644--- a/Libraries/LibWeb/HTML/HTMLMediaElement.h+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.h@@ -182,8 +182,8 @@ public:return *m_playback_manager;}- void create_controls();- void destroy_controls();+ bool should_expose_user_interface() const;+ void update_controls();void media_element_for_controls_changed();void set_picture_in_picture_window_controls_in_use(bool);diff --git a/Libraries/LibWeb/HTML/MediaControls.cpp b/Libraries/LibWeb/HTML/MediaControls.cppindex e2c2fc9b99e..b92d0fdc22e 100644--- a/Libraries/LibWeb/HTML/MediaControls.cpp+++ b/Libraries/LibWeb/HTML/MediaControls.cpp@@ -52,6 +52,15 @@ void MediaControls::visit_edges(GC::Cell::Visitor& visitor)(void)visitor;}+void MediaControls::update_visibility()+{+ auto& host = *m_host;++ MUST(m_dom->container->class_list()->toggle("controls-hidden"_utf16, !host.should_expose_user_interface()));+ MUST(m_dom->container->class_list()->toggle("picture-in-picture"_utf16, host.is_picture_in_picture_element()));+ update_placeholder_visibility();+}+void MediaControls::create_shadow_tree(){auto& host = *m_host;@@ -83,7 +92,7 @@ void MediaControls::create_shadow_tree()update_timestamp();update_volume_and_mute_indicator();update_fullscreen_icon();- update_placeholder_visibility();+ update_visibility();show_controls();}@@ -422,6 +431,9 @@ void MediaControls::set_up_event_listeners()add_event_listener(realm, host, UIEvents::EventNames::keydown, [this](UIEvents::KeyboardEvent const& event) {VERIFY(m_media_element);+ if (!m_host->should_expose_user_interface())+ return false;+constexpr double arrow_time_step = 5.0;constexpr double arrow_volume_step = 0.1;@@ -763,6 +775,9 @@ bool MediaControls::should_show_placeholder() constVERIFY(m_media_element);VERIFY(m_dom->placeholder_circle);+ if (m_host->is_picture_in_picture_element())+ return false;+auto const& video_element = as<HTMLVideoElement>(*m_media_element);return video_element.current_representation() != HTMLVideoElement::Representation::VideoFrame;}diff --git a/Libraries/LibWeb/HTML/MediaControls.css b/Libraries/LibWeb/HTML/MediaControls.cssindex 29f7e98d41a..67af74b1a82 100644--- a/Libraries/LibWeb/HTML/MediaControls.css+++ b/Libraries/LibWeb/HTML/MediaControls.css@@ -182,6 +182,37 @@justify-content: center;}+.container.controls-hidden > .video-overlay,+.container.controls-hidden > .controls {+ display: none;+}++.picture-in-picture-placeholder {+ display: none;+ flex-direction: column;+ align-items: center;+ justify-content: center;+ gap: 8px;+ width: 100%;+ height: 100%;+ background-color: rgb(12, 12, 13);+ color: white;+ font-family: sans-serif;+ font-size: 14px;+ text-align: center;+}++.container.picture-in-picture > .picture-in-picture-placeholder {+ display: flex;+}++.picture-in-picture-placeholder-icon {+ width: 48px;+ height: 48px;+ fill: currentColor;+ fill-rule: evenodd;+}+.fullscreen-icon path {display: none;}diff --git a/Libraries/LibWeb/HTML/MediaControls.h b/Libraries/LibWeb/HTML/MediaControls.hindex c57382250cb..e19e47eec60 100644--- a/Libraries/LibWeb/HTML/MediaControls.h+++ b/Libraries/LibWeb/HTML/MediaControls.h@@ -26,6 +26,7 @@ public:void visit_edges(GC::Cell::Visitor&);+ void update_visibility();void set_picture_in_picture_window_controls_in_use(bool);private:diff --git a/Libraries/LibWeb/HTML/MediaControls.html b/Libraries/LibWeb/HTML/MediaControls.htmlindex 6fbc6e9e13e..23e3b41da8b 100644--- a/Libraries/LibWeb/HTML/MediaControls.html+++ b/Libraries/LibWeb/HTML/MediaControls.html@@ -1,5 +1,11 @@<link rel="stylesheet" href="MediaControls.css"><div data-name="container" class="container">+ <div data-option="video" class="picture-in-picture-placeholder">+ <svg class="picture-in-picture-placeholder-icon" viewBox="0 0 24 24">+ <path d="M2 4h20v16H2Zm2 2v12h16V6Zm7 5h8v6h-8Z"/>+ </svg>+ <span>Playing in Picture-in-Picture</span>+ </div><div data-name="video-overlay" data-option="video" class="video-overlay"><div data-name="placeholder-circle" class="placeholder-circle"><svg class="placeholder-icon" viewBox="0 0 24 24">diff --git a/Libraries/LibWeb/Painting/PaintFacts.cpp b/Libraries/LibWeb/Painting/PaintFacts.cppindex b2772002eff..814b5d5357d 100644--- a/Libraries/LibWeb/Painting/PaintFacts.cpp+++ b/Libraries/LibWeb/Painting/PaintFacts.cpp@@ -221,8 +221,15 @@ static void queue_video_paint_facts(HTML::HTMLVideoElement const& element)// An element that shows another element's frames paints whatever that element would.auto const& video_element = element.visual_source() ? *element.visual_source() : element;+ // https://w3c.github.io/picture-in-picture/#pip+ // It is RECOMMENDED that video frames are not rendered in the page and in the Picture-in-Picture window at the+ // same time but if they are, they MUST be kept in sync.+ auto representation = element.is_picture_in_picture_element()+ ? HTML::HTMLVideoElement::Representation::TransparentBlack+ : video_element.current_representation();+Layout::RustFFI::FfiVideoPaintFacts facts {};- switch (video_element.current_representation()) {+ switch (representation) {case HTML::HTMLVideoElement::Representation::FirstVideoFrame:case HTML::HTMLVideoElement::Representation::VideoFrame: {facts.representation = Layout::RustFFI::FfiVideoRepresentation::VideoFrame;diff --git a/Tests/LibWeb/Layout/expected/PictureInPicture/placeholder-is-removed-on-exit.txt b/Tests/LibWeb/Layout/expected/PictureInPicture/placeholder-is-removed-on-exit.txtnew file mode 100644index 00000000000..6fcc3a301d8--- /dev/null+++ b/Tests/LibWeb/Layout/expected/PictureInPicture/placeholder-is-removed-on-exit.txt@@ -0,0 +1,10 @@+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline overflow: [0,0 862x600]+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 499.203125 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 483.203125 0+0+8] children: inline+ frag 0 from VideoBox start: 0, length: 0, rect: [8,8 854x480] baseline: 480+ VideoBox <video> at [8,8] inline-block [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] children: not-inline+ TextNode <#text> (not painted)+ TextNode <#text> (not painted)++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x499.203125] (z-index: auto)diff --git a/Tests/LibWeb/Layout/expected/PictureInPicture/placeholder-replaces-video-without-controls.txt b/Tests/LibWeb/Layout/expected/PictureInPicture/placeholder-replaces-video-without-controls.txtnew file mode 100644index 00000000000..0c9de530be6--- /dev/null+++ b/Tests/LibWeb/Layout/expected/PictureInPicture/placeholder-replaces-video-without-controls.txt@@ -0,0 +1,19 @@+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline overflow: [0,0 862x600]+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 499.203125 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 483.203125 0+0+8] children: inline+ frag 0 from VideoBox start: 0, length: 0, rect: [8,8 854x480] baseline: 480+ VideoBox <video> at [8,8] inline-block [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] children: not-inline+ BlockContainer <(anonymous)> at [8,8] inline-block [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] [BFC] children: not-inline+ BlockContainer <div.container.video.controls-hidden.picture-in-picture> at [8,8] positioned [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] [BFC] children: not-inline+ Box <div.picture-in-picture-placeholder> at [8,8] flex-container(column) [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] [FFC] children: not-inline+ SVGSVGBox <svg.picture-in-picture-placeholder-icon> at [411,213] flex-item [0+0+0 48 0+0+0] [0+0+0 48 0+0+0] viewport-transform=[2 0 0 2 0 0] [SVG] children: not-inline+ SVGGeometryBox <path> at [2,4] [0+0+0 20 0+0+0] [0+0+0 16 0+0+0] children: not-inline+ BlockContainer <span> at [334.515625,269] flex-item [0+0+0 200.96875 0+0+0] [0+0+0 14 0+0+0] [BFC] children: inline+ frag 0 from TextNode start: 0, length: 29, rect: [334.515625,269 200.96875x14] baseline: 11.203125+ "Playing in Picture-in-Picture"+ TextNode <#text> (not painted)+ TextNode <#text> (not painted)+ TextNode <#text> (not painted)++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x499.203125] (z-index: auto)diff --git a/Tests/LibWeb/Layout/expected/PictureInPicture/placeholder-stays-after-controls-are-removed.txt b/Tests/LibWeb/Layout/expected/PictureInPicture/placeholder-stays-after-controls-are-removed.txtnew file mode 100644index 00000000000..2c965265e53--- /dev/null+++ b/Tests/LibWeb/Layout/expected/PictureInPicture/placeholder-stays-after-controls-are-removed.txt@@ -0,0 +1,19 @@+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline overflow: [0,0 862x600]+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 499.203125 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 483.203125 0+0+8] children: inline+ frag 0 from VideoBox start: 0, length: 0, rect: [8,8 854x480] baseline: 480+ VideoBox <video> at [8,8] inline-block [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] children: not-inline+ BlockContainer <(anonymous)> at [8,8] inline-block [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] [BFC] children: not-inline+ BlockContainer <div.container.video.picture-in-picture.controls-hidden> at [8,8] positioned [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] [BFC] children: not-inline+ Box <div.picture-in-picture-placeholder> at [8,8] flex-container(column) [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] [FFC] children: not-inline+ SVGSVGBox <svg.picture-in-picture-placeholder-icon> at [411,213] flex-item [0+0+0 48 0+0+0] [0+0+0 48 0+0+0] viewport-transform=[2 0 0 2 0 0] [SVG] children: not-inline+ SVGGeometryBox <path> at [2,4] [0+0+0 20 0+0+0] [0+0+0 16 0+0+0] children: not-inline+ BlockContainer <span> at [334.515625,269] flex-item [0+0+0 200.96875 0+0+0] [0+0+0 14 0+0+0] [BFC] children: inline+ frag 0 from TextNode start: 0, length: 29, rect: [334.515625,269 200.96875x14] baseline: 11.203125+ "Playing in Picture-in-Picture"+ TextNode <#text> (not painted)+ TextNode <#text> (not painted)+ TextNode <#text> (not painted)++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x499.203125] (z-index: auto)diff --git a/Tests/LibWeb/Layout/expected/PictureInPicture/placeholder-stays-when-controls-are-added.txt b/Tests/LibWeb/Layout/expected/PictureInPicture/placeholder-stays-when-controls-are-added.txtnew file mode 100644index 00000000000..be2c1363c86--- /dev/null+++ b/Tests/LibWeb/Layout/expected/PictureInPicture/placeholder-stays-when-controls-are-added.txt@@ -0,0 +1,44 @@+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline overflow: [0,0 862x600]+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 499.203125 0+0+0] [BFC] children: not-inline+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 483.203125 0+0+8] children: inline+ frag 0 from VideoBox start: 0, length: 0, rect: [8,8 854x480] baseline: 480+ VideoBox <video> at [8,8] inline-block [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] children: not-inline+ BlockContainer <(anonymous)> at [8,8] inline-block [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] [BFC] children: not-inline+ BlockContainer <div.container.video.picture-in-picture> at [8,8] positioned [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] [BFC] children: not-inline+ Box <div.picture-in-picture-placeholder> at [8,8] flex-container(column) [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] [FFC] children: not-inline+ SVGSVGBox <svg.picture-in-picture-placeholder-icon> at [411,213] flex-item [0+0+0 48 0+0+0] [0+0+0 48 0+0+0] viewport-transform=[2 0 0 2 0 0] [SVG] children: not-inline+ SVGGeometryBox <path> at [2,4] [0+0+0 20 0+0+0] [0+0+0 16 0+0+0] children: not-inline+ BlockContainer <span> at [334.515625,269] flex-item [0+0+0 200.96875 0+0+0] [0+0+0 14 0+0+0] [BFC] children: inline+ frag 0 from TextNode start: 0, length: 29, rect: [334.515625,269 200.96875x14] baseline: 11.203125+ "Playing in Picture-in-Picture"+ TextNode <#text> (not painted)+ Box <div.video-overlay> at [8,8] positioned flex-container(row) [0+0+0 854 0+0+0] [0+0+0 480 0+0+0] [FFC] children: not-inline+ Box <div.controls.visible> at [8,445] positioned flex-container(column) [0+0+0 854 0+0+0] [0+0+0 43 0+0+0] [FFC] children: not-inline+ BlockContainer <div.timeline> at [8,445] flex-item [0+0+0 854 0+0+0] [-5+0+5 5 5+0+-5] [BFC] children: not-inline+ BlockContainer <div.timeline-track> at [8,445] positioned [0+0+0 854 0+0+0] [0+0+0 5 0+0+0] children: not-inline+ BlockContainer <div.timeline-fill> at [8,445] [0+0+0 0 0+0+854] [0+0+0 5 0+0+0] children: not-inline+ Box <div.button-bar> at [16,454] flex-container(row) flex-item [0+0+8 838 8+0+0] [0+0+4 30 4+0+0] [FFC] children: not-inline+ Box <button.control-button.play-pause-button> at [16,457] flex-container(row) flex-item [0+0+0 24 0+0+0] [0+0+0 24 0+0+0] [FFC] children: not-inline+ SVGSVGBox <svg.icon.play-pause-icon> at [16,457] flex-item [0+0+0 24 0+0+0] [0+0+0 24 0+0+0] viewport-transform=[1 0 0 1 0 0] [SVG] children: not-inline+ SVGGeometryBox <path.play-path> at [6,5] [0+0+0 13 0+0+0] [0+0+0 14 0+0+0] children: not-inline+ BlockContainer <span.timestamp> at [48,463] flex-item [0+0+0 77.8125 0+0+0] [0+0+0 12 0+0+0] [BFC] children: inline+ frag 0 from TextNode start: 0, length: 13, rect: [48,463 77.8125x12] baseline: 9.59375+ "00:00 / 00:12"+ TextNode <#text> (not painted)+ Box <button.control-button.mute-button.high> at [730,457] flex-container(row) flex-item [0+0+0 24 0+0+0] [0+0+0 24 0+0+0] [FFC] children: not-inline+ SVGSVGBox <svg.icon> at [730,457] flex-item [0+0+0 24 0+0+0] [0+0+0 24 0+0+0] viewport-transform=[1 0 0 1 0 0] [SVG] children: not-inline+ SVGGeometryBox <path.volume-high> at [14,4.078125] [0+0+0 6 0+0+0] [0+0+0 15.84375 0+0+0] children: not-inline+ SVGGeometryBox <path.volume-low> at [14,7.671875] [0+0+0 2.03125 0+0+0] [0+0+0 8.65625 0+0+0] children: not-inline+ SVGGeometryBox <path.speaker> at [4,4] [0+0+0 8 0+0+0] [0+0+0 16 0+0+0] children: not-inline+ BlockContainer <div.volume-area> at [762,466] flex-item [-5+0+5 60 5+0+-5] [-5+0+5 6 5+0+-5] [BFC] children: not-inline+ BlockContainer <div.volume> at [762,466] positioned [0+0+0 60 0+0+0] [0+0+0 6 0+0+0] [BFC] children: not-inline+ BlockContainer <div.volume-fill> at [762,466] [0+0+0 60 0+0+0] [0+0+0 6 0+0+0] children: not-inline+ Box <button.control-button.fullscreen-button> at [830,457] flex-container(row) flex-item [0+0+0 24 0+0+0] [0+0+0 24 0+0+0] [FFC] children: not-inline+ SVGSVGBox <svg.icon.fullscreen-icon> at [830,457] flex-item [0+0+0 24 0+0+0] [0+0+0 24 0+0+0] viewport-transform=[1 0 0 1 0 0] [SVG] children: not-inline+ SVGGeometryBox <path.fullscreen-maximize-path> at [3,3] [0+0+0 18 0+0+0] [0+0+0 18 0+0+0] children: not-inline+ TextNode <#text> (not painted)+ TextNode <#text> (not painted)++SC for Viewport<#document> [0,0 800x600] (z-index: auto)+ SC for BlockContainer<HTML> [0,0 800x499.203125] (z-index: auto)+ SC for BlockContainer<DIV>.timeline [8,445 854x5] (z-index: 1)diff --git a/Tests/LibWeb/Layout/input/PictureInPicture/placeholder-is-removed-on-exit.html b/Tests/LibWeb/Layout/input/PictureInPicture/placeholder-is-removed-on-exit.htmlnew file mode 100644index 00000000000..be7ae0da35a--- /dev/null+++ b/Tests/LibWeb/Layout/input/PictureInPicture/placeholder-is-removed-on-exit.html@@ -0,0 +1,13 @@+<!DOCTYPE html>+<html class="test-wait">+<video src="../../../Assets/test-webm.webm"></video>+<script>+ const video = document.querySelector("video");+ video.addEventListener("loadedmetadata", async () => {+ internals.grantTransientActivation();+ await video.requestPictureInPicture();+ await document.exitPictureInPicture();+ document.documentElement.classList.remove("test-wait");+ }, { once: true });+</script>+</html>diff --git a/Tests/LibWeb/Layout/input/PictureInPicture/placeholder-replaces-video-without-controls.html b/Tests/LibWeb/Layout/input/PictureInPicture/placeholder-replaces-video-without-controls.htmlnew file mode 100644index 00000000000..4bd8eaf53e9--- /dev/null+++ b/Tests/LibWeb/Layout/input/PictureInPicture/placeholder-replaces-video-without-controls.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<html class="test-wait">+<video src="../../../Assets/test-webm.webm"></video>+<script>+ const video = document.querySelector("video");+ video.addEventListener("loadedmetadata", async () => {+ internals.grantTransientActivation();+ await video.requestPictureInPicture();+ document.documentElement.classList.remove("test-wait");+ }, { once: true });+</script>+</html>diff --git a/Tests/LibWeb/Layout/input/PictureInPicture/placeholder-stays-after-controls-are-removed.html b/Tests/LibWeb/Layout/input/PictureInPicture/placeholder-stays-after-controls-are-removed.htmlnew file mode 100644index 00000000000..e3b83af055f--- /dev/null+++ b/Tests/LibWeb/Layout/input/PictureInPicture/placeholder-stays-after-controls-are-removed.html@@ -0,0 +1,13 @@+<!DOCTYPE html>+<html class="test-wait">+<video src="../../../Assets/test-webm.webm" controls></video>+<script>+ const video = document.querySelector("video");+ video.addEventListener("loadedmetadata", async () => {+ internals.grantTransientActivation();+ await video.requestPictureInPicture();+ video.controls = false;+ document.documentElement.classList.remove("test-wait");+ }, { once: true });+</script>+</html>diff --git a/Tests/LibWeb/Layout/input/PictureInPicture/placeholder-stays-when-controls-are-added.html b/Tests/LibWeb/Layout/input/PictureInPicture/placeholder-stays-when-controls-are-added.htmlnew file mode 100644index 00000000000..a03b3f5e0d5--- /dev/null+++ b/Tests/LibWeb/Layout/input/PictureInPicture/placeholder-stays-when-controls-are-added.html@@ -0,0 +1,20 @@+<!DOCTYPE html>+<html class="test-wait">+<video src="../../../Assets/test-webm.webm"></video>+<script>+ const video = document.querySelector("video");++ (async () => {+ // Once loading is done, no later media event can redraw the new controls' timeline with its buffered range.+ if (video.readyState < HTMLMediaElement.HAVE_ENOUGH_DATA)+ await new Promise(resolve => video.addEventListener("canplaythrough", resolve, { once: true }));++ internals.grantTransientActivation();+ await video.requestPictureInPicture();+ video.controls = true;+ // Controls hide a second after they show, unless their bar is hovered.+ internals.mouseMove(400, 470);+ document.documentElement.classList.remove("test-wait");+ })();+</script>+</html>diff --git a/Tests/LibWeb/Text/expected/PictureInPicture/keys-control-video-only-with-controls.txt b/Tests/LibWeb/Text/expected/PictureInPicture/keys-control-video-only-with-controls.txtnew file mode 100644index 00000000000..e514258c56a--- /dev/null+++ b/Tests/LibWeb/Text/expected/PictureInPicture/keys-control-video-only-with-controls.txt@@ -0,0 +1,2 @@+paused after Space without controls: true+paused after Space with controls: falsediff --git a/Tests/LibWeb/Text/expected/PictureInPicture/video-frames-are-not-painted-in-page-while-in-window.txt b/Tests/LibWeb/Text/expected/PictureInPicture/video-frames-are-not-painted-in-page-while-in-window.txtnew file mode 100644index 00000000000..9e037c92dd6--- /dev/null+++ b/Tests/LibWeb/Text/expected/PictureInPicture/video-frames-are-not-painted-in-page-while-in-window.txt@@ -0,0 +1,9 @@+paints video frames before Picture-in-Picture: true+Without controls:+paints video frames while the window opens: true+paints video frames in Picture-in-Picture: false+paints video frames after exiting: true+With controls:+paints video frames while the window opens: true+paints video frames in Picture-in-Picture: false+paints video frames after exiting: truediff --git a/Tests/LibWeb/Text/input/PictureInPicture/keys-control-video-only-with-controls.html b/Tests/LibWeb/Text/input/PictureInPicture/keys-control-video-only-with-controls.htmlnew file mode 100644index 00000000000..974cd46f3d0--- /dev/null+++ b/Tests/LibWeb/Text/input/PictureInPicture/keys-control-video-only-with-controls.html@@ -0,0 +1,24 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<video tabindex="0" src="../../../Assets/test-webm.webm"></video>+<script>+ asyncTest(async done => {+ const video = document.querySelector("video");+ if (video.readyState === HTMLMediaElement.HAVE_NOTHING)+ await new Promise(resolve => video.addEventListener("loadedmetadata", resolve, { once: true }));++ internals.grantTransientActivation();+ await video.requestPictureInPicture();++ internals.sendKey(video, "Space");+ println(`paused after Space without controls: ${video.paused}`);++ video.controls = true;+ internals.sendKey(video, "Space");+ println(`paused after Space with controls: ${video.paused}`);++ video.pause();+ await document.exitPictureInPicture();+ done();+ });+</script>diff --git a/Tests/LibWeb/Text/input/PictureInPicture/video-frames-are-not-painted-in-page-while-in-window.html b/Tests/LibWeb/Text/input/PictureInPicture/video-frames-are-not-painted-in-page-while-in-window.htmlnew file mode 100644index 00000000000..028f2fba552--- /dev/null+++ b/Tests/LibWeb/Text/input/PictureInPicture/video-frames-are-not-painted-in-page-while-in-window.html@@ -0,0 +1,39 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<video src="../../../Assets/test-webm.webm"></video>+<script>+ function paintsVideoFrame() {+ return internals.dumpDisplayList().includes("DrawVideoFrame");+ }++ async function enterAndExitPictureInPicture(video) {+ internals.grantTransientActivation();+ const entered = video.requestPictureInPicture();++ // A new box for the video takes its paint facts afresh, before the window has opened.+ video.style.display = video.style.display === "block" ? "" : "block";+ println(`paints video frames while the window opens: ${paintsVideoFrame()}`);++ await entered;+ println(`paints video frames in Picture-in-Picture: ${paintsVideoFrame()}`);++ await document.exitPictureInPicture();+ println(`paints video frames after exiting: ${paintsVideoFrame()}`);+ }++ asyncTest(async done => {+ const video = document.querySelector("video");+ if (video.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)+ await new Promise(resolve => video.addEventListener("loadeddata", resolve, { once: true }));+ println(`paints video frames before Picture-in-Picture: ${paintsVideoFrame()}`);++ println("Without controls:");+ await enterAndExitPictureInPicture(video);++ println("With controls:");+ video.controls = true;+ await enterAndExitPictureInPicture(video);++ done();+ });+</script>