Bug 1641546 - Focus the Picture-in-Picture player after it opens. r=mstriemer
authorMike Conley <mconley@mozilla.com>
Fri, 05 Jun 2020 15:32:41 +0000
changeset 534158 2652e1c084a77120435b075939c36026b4811e69
parent 534157 72a62a455c476a293bafb9a0f1c205b44838c0ab
child 534159 1e1c9d28eb43d98c61d95a642785caf0567dcaf7
push id37483
push userapavel@mozilla.com
push dateFri, 05 Jun 2020 21:40:11 +0000
treeherdermozilla-central@dadc7312128e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstriemer
bugs1641546
milestone79.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 1641546 - Focus the Picture-in-Picture player after it opens. r=mstriemer The other patches in this stack made it so that alwaysontop windows don't focus by default when they open. We do, however, want the Picture-in-Picture player window to take focus after it opens. Differential Revision: https://phabricator.services.mozilla.com/D78523
toolkit/components/pictureinpicture/content/player.js
--- a/toolkit/components/pictureinpicture/content/player.js
+++ b/toolkit/components/pictureinpicture/content/player.js
@@ -149,16 +149,23 @@ let Player = {
     this.recordEvent("create", {
       width: window.outerWidth.toString(),
       height: window.outerHeight.toString(),
       screenX: window.screenX.toString(),
       screenY: window.screenY.toString(),
     });
 
     this.computeAndSetMinimumSize(window.outerWidth, window.outerHeight);
+
+    // alwaysontop windows are not focused by default, so we have to do it
+    // ourselves. We use requestAnimationFrame since we have to wait until the
+    // window is visible before it can focus.
+    window.requestAnimationFrame(() => {
+      window.focus();
+    });
   },
 
   uninit() {
     this.resizeDebouncer.disarm();
     PictureInPicture.unload(window);
   },
 
   handleEvent(event) {