Bug 1617135 - Fix keyboard shortcut for closing picture in picture window when the player window is focused. r=mconley,Gijs
authorChris Jackson <jack1391@msu.edu>
Mon, 21 Sep 2020 21:22:01 +0000
changeset 549509 0f8cb57c27acf8f1b8b0fb0571362f74110ba45f
parent 549508 3c17e3309eacd51f592e2f77c1fbbb35797f7157
child 549510 55a322e7585064840555c7fffa05e22fca0484e2
push id37801
push usermalexandru@mozilla.com
push dateTue, 22 Sep 2020 03:47:42 +0000
treeherdermozilla-central@fa0bf905d4cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley, Gijs
bugs1617135
milestone83.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1617135 - Fix keyboard shortcut for closing picture in picture window when the player window is focused. r=mconley,Gijs Differential Revision: https://phabricator.services.mozilla.com/D90038
toolkit/components/pictureinpicture/content/player.js
toolkit/components/pictureinpicture/content/player.xhtml
toolkit/components/pictureinpicture/tests/browser_keyboardShortcut.js
--- a/toolkit/components/pictureinpicture/content/player.js
+++ b/toolkit/components/pictureinpicture/content/player.js
@@ -337,16 +337,20 @@ let Player = {
     this.lastScreenY = window.screenY;
   },
 
   onResize(event) {
     this.resizeDebouncer.disarm();
     this.resizeDebouncer.arm();
   },
 
+  onCommand(event) {
+    PictureInPicture.closePipWindow({ reason: "player-shortcut" });
+  },
+
   get controls() {
     delete this.controls;
     return (this.controls = document.getElementById("controls"));
   },
 
   _isPlaying: false,
   /**
    * isPlaying returns true if the video is currently playing.
--- a/toolkit/components/pictureinpicture/content/player.xhtml
+++ b/toolkit/components/pictureinpicture/content/player.xhtml
@@ -7,21 +7,36 @@
       xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
       windowtype="Toolkit:PictureInPicture"
       chromemargin="0,0,0,0">
   <head>
     <meta charset="utf-8"/>
     <link rel="stylesheet" type="text/css"
           href="chrome://global/skin/pictureinpicture/player.css"/>
     <link rel="localization" href="toolkit/pictureinpicture/pictureinpicture.ftl"/>
+    <link rel="localization" href="browser/browserSets.ftl"/>
     <script src="chrome://global/content/pictureinpicture/player.js"></script>
     <title data-l10n-id="pictureinpicture-player-title"></title>
   </head>
 
   <body>
+    <xul:commandset>
+      <xul:command id="View:PictureInPicture" oncommand="Player.onCommand(event);"/>
+    </xul:commandset>
+
+    <xul:keyset>
+#ifndef XP_MACOSX
+      <xul:key data-l10n-id="picture-in-picture-toggle-shortcut" command="View:PictureInPicture" modifiers="accel,shift"/>
+      <xul:key data-l10n-id="picture-in-picture-toggle-shortcut-alt" command="View:PictureInPicture" modifiers="accel,shift"/>
+#else
+      <xul:key data-l10n-id="picture-in-picture-toggle-shortcut-mac" command="View:PictureInPicture" modifiers="accel,alt,shift"/>
+      <xul:key data-l10n-id="picture-in-picture-toggle-shortcut-mac-alt" command="View:PictureInPicture" modifiers="accel,alt,shift"/>
+#endif
+    </xul:keyset>
+
     <div class="player-holder">
       <xul:browser type="content" primary="true" remote="true" remoteType="web" id="browser" tabindex="-1"></xul:browser>
     </div>
     <div id="controls">
       <button id="close"
               class="control-item"
 #ifdef XP_MACOSX
               mac="true"
--- a/toolkit/components/pictureinpicture/tests/browser_keyboardShortcut.js
+++ b/toolkit/components/pictureinpicture/tests/browser_keyboardShortcut.js
@@ -45,11 +45,39 @@ add_task(async function test_pip_keyboar
       }
 
       let pipWin = await domWindowOpened;
       await videoReady;
 
       ok(pipWin, "Got Picture-in-Picture window.");
 
       await ensureMessageAndClosePiP(browser, VIDEO_ID, pipWin, false);
+
+      // Reopen PiP Window
+      pipWin = await triggerPictureInPicture(browser, VIDEO_ID);
+      await videoReady;
+
+      ok(pipWin, "Got Picture-in-Picture window.");
+
+      if (AppConstants.platform == "macosx") {
+        EventUtils.synthesizeKey(
+          "]",
+          {
+            accelKey: true,
+            shiftKey: true,
+            altKey: true,
+          },
+          pipWin
+        );
+      } else {
+        EventUtils.synthesizeKey(
+          "]",
+          { accelKey: true, shiftKey: true },
+          pipWin
+        );
+      }
+
+      await BrowserTestUtils.windowClosed(pipWin);
+
+      ok(pipWin.closed, "Picture-in-Picture window closed.");
     }
   );
 });