Title: [225201] trunk
Revision
225201
Author
[email protected]
Date
2017-11-27 15:51:21 -0800 (Mon, 27 Nov 2017)

Log Message

Pressing the space bar while watching a fullscreen video doesn't play or pause
https://bugs.webkit.org/show_bug.cgi?id=180033
<rdar://problem/33610443>

Patch by Antoine Quint <[email protected]> on 2017-11-27
Reviewed by Eric Carlson.

Source/WebCore:

We register a "keydown" event to track when the space bar is pressed, and if the media is playing
in fullscreen, we toggle playback. This does not interfere with full keyboard access since activating
one of the media controls using the keyboard will not let the events we register for be dispatched
this far along the event dispatch phase.

Test: media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html

* Modules/modern-media-controls/media/media-controller.js:
(MediaController):
(MediaController.prototype.togglePlayback): Add a catch() statement since calling play() could sometime
lead to some extraneous unhandled promise console logging that pollutes test output.
(MediaController.prototype.handleEvent):

LayoutTests:

Adding a new macOS-only test that checks that pressing the space bar while playing fullscreen
pauses the media and resumes it when pressing the space bar again.

* media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback-expected.txt: Added.
* media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html: Added.
* platform/ios-simulator/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225200 => 225201)


--- trunk/LayoutTests/ChangeLog	2017-11-27 23:30:46 UTC (rev 225200)
+++ trunk/LayoutTests/ChangeLog	2017-11-27 23:51:21 UTC (rev 225201)
@@ -1,3 +1,18 @@
+2017-11-27  Antoine Quint  <[email protected]>
+
+        Pressing the space bar while watching a fullscreen video doesn't play or pause
+        https://bugs.webkit.org/show_bug.cgi?id=180033
+        <rdar://problem/33610443>
+
+        Reviewed by Eric Carlson.
+
+        Adding a new macOS-only test that checks that pressing the space bar while playing fullscreen
+        pauses the media and resumes it when pressing the space bar again.
+
+        * media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback-expected.txt: Added.
+        * media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html: Added.
+        * platform/ios-simulator/TestExpectations:
+
 2017-11-27  Matt Lewis  <[email protected]>
 
         Unreviewed, rolling out r225173.

Added: trunk/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback-expected.txt (0 => 225201)


--- trunk/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback-expected.txt	2017-11-27 23:51:21 UTC (rev 225201)
@@ -0,0 +1,26 @@
+Testing media is paused and resumed when pressing the space bar in fullscreen.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+Obtained a 'play' event.
+
+Entering fullscreen.
+
+Obtained a 'webkitfullscreenchange' event.
+PASS media.webkitDisplayingFullscreen is true
+PASS media.paused is false
+
+Pressing the space bar.
+
+Obtained a 'pause' event.
+
+Pressing the space bar.
+
+Obtained a 'play' event.
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html (0 => 225201)


--- trunk/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html	                        (rev 0)
+++ trunk/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html	2017-11-27 23:51:21 UTC (rev 225201)
@@ -0,0 +1,77 @@
+<!DOCTYPE html>
+<script src=""
+<script src="" type="text/_javascript_"></script>
+<body>
+<video src="" style="width: 320px; height: 240px;" controls autoplay></video>
+<script type="text/_javascript_">
+
+window.jsTestIsAsync = true;
+
+description("Testing media is paused and resumed when pressing the space bar in fullscreen.");
+
+const media = document.querySelector("video");
+const button = document.body.appendChild(document.createElement("button"));
+button.textContent = "Enter Fullscreen";
+
+media.addEventListener("webkitfullscreenchange", () => {
+    debug("");
+    debug("Obtained a 'webkitfullscreenchange' event.");
+    shouldBeTrue("media.webkitDisplayingFullscreen");
+    shouldBeFalse("media.paused");
+    
+    // Test pressing the space bar while the media is playing.
+    pressSpace();
+});
+
+let playCount = 0;
+media.addEventListener("play", () => {
+    playCount++;
+
+    debug("");
+    debug("Obtained a 'play' event.");
+
+    // Starting point.
+    if (playCount == 1)
+        enterFullscreen();
+    else {
+        debug("");
+        button.remove();
+        media.remove();
+        finishJSTest();
+    }
+});
+
+media.addEventListener("pause", () => {
+    debug("");
+    debug("Obtained a 'pause' event.");
+
+    // Test pressing the space bar while the media is paused.
+    pressSpace();
+});
+
+
+function enterFullscreen() {
+    debug("");
+    debug("Entering fullscreen.");
+    button.addEventListener("click", () => {
+        try {
+            media.webkitEnterFullscreen();
+        } catch(e) {
+            debug("Toggling fullscreen failed");
+            finishJSTest();
+        }
+    });
+
+    pressOnElement(button);
+}
+
+function pressSpace()
+{
+    debug("");
+    debug("Pressing the space bar.");
+    eventSender.keyDown(" ");
+}
+
+</script>
+<script src=""
+</body>

Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (225200 => 225201)


--- trunk/LayoutTests/platform/ios-simulator/TestExpectations	2017-11-27 23:30:46 UTC (rev 225200)
+++ trunk/LayoutTests/platform/ios-simulator/TestExpectations	2017-11-27 23:51:21 UTC (rev 225201)
@@ -127,6 +127,7 @@
 media/modern-media-controls/media-controller/media-controller-click-on-video-background-should-pause-fullscreen.html [ Skip ]
 media/modern-media-controls/media-controller/media-controller-click-on-video-background-should-pause.html [ Skip ]
 media/modern-media-controls/media-controller/media-controller-click-on-video-background-to-dismiss-tracks-panel-should-not-toggle-playback.html [ Skip ]
+media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html [ Skip ]
 media/modern-media-controls/media-documents/media-document-audio-mac-sizing.html [ Skip ]
 media/modern-media-controls/media-documents/media-document-video-mac-sizing.html [ Skip ]
 media/modern-media-controls/playback-support/playback-support-button-click.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (225200 => 225201)


--- trunk/Source/WebCore/ChangeLog	2017-11-27 23:30:46 UTC (rev 225200)
+++ trunk/Source/WebCore/ChangeLog	2017-11-27 23:51:21 UTC (rev 225201)
@@ -1,3 +1,24 @@
+2017-11-27  Antoine Quint  <[email protected]>
+
+        Pressing the space bar while watching a fullscreen video doesn't play or pause
+        https://bugs.webkit.org/show_bug.cgi?id=180033
+        <rdar://problem/33610443>
+
+        Reviewed by Eric Carlson.
+
+        We register a "keydown" event to track when the space bar is pressed, and if the media is playing
+        in fullscreen, we toggle playback. This does not interfere with full keyboard access since activating
+        one of the media controls using the keyboard will not let the events we register for be dispatched
+        this far along the event dispatch phase.
+
+        Test: media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html
+
+        * Modules/modern-media-controls/media/media-controller.js:
+        (MediaController):
+        (MediaController.prototype.togglePlayback): Add a catch() statement since calling play() could sometime
+        lead to some extraneous unhandled promise console logging that pollutes test output.
+        (MediaController.prototype.handleEvent):
+
 2017-11-27  Matt Lewis  <[email protected]>
 
         Unreviewed, rolling out r225173.

Modified: trunk/Source/WebCore/Modules/modern-media-controls/media/media-controller.js (225200 => 225201)


--- trunk/Source/WebCore/Modules/modern-media-controls/media/media-controller.js	2017-11-27 23:30:46 UTC (rev 225200)
+++ trunk/Source/WebCore/Modules/modern-media-controls/media/media-controller.js	2017-11-27 23:51:21 UTC (rev 225201)
@@ -57,6 +57,8 @@
         media.videoTracks.addEventListener("removetrack", this);
 
         media.addEventListener(this.fullscreenChangeEventType, this);
+
+        window.addEventListener("keydown", this);
     }
 
     // Public
@@ -100,7 +102,7 @@
     togglePlayback()
     {
         if (this.media.paused)
-            this.media.play();
+            this.media.play().catch(e => {});
         else
             this.media.pause();
     }
@@ -158,6 +160,9 @@
             this._updateControlsIfNeeded();
             if (event.type === "webkitpresentationmodechanged")
                 this._returnMediaLayerToInlineIfNeeded();
+        } else if (event.type === "keydown" && this.isFullscreen && event.key === " ") {
+            this.togglePlayback();
+            event.preventDefault();
         }
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to