Bug 1215249 - Keyboard shortcuts don't work with local media files without explicitly focusing the <video> element. r=bz
authorSteffen Wilberg <steffen.wilberg@web.de>
Fri, 16 Oct 2015 22:36:40 +0200
changeset 304485 27a8c3b1f861dd56bb5f7c49c42305b0efc311b2
parent 304484 aadaca56ce9962a7675e1b0dd88a52263c097ce9
child 304486 1bce0debbdcd0200cbc00207ffdc7885a912df6e
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1215249
milestone44.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 1215249 - Keyboard shortcuts don't work with local media files without explicitly focusing the <video> element. r=bz
toolkit/content/TopLevelVideoDocument.js
--- a/toolkit/content/TopLevelVideoDocument.js
+++ b/toolkit/content/TopLevelVideoDocument.js
@@ -1,28 +1,24 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-window.addEventListener("load", () => {
-  // <video> is used for top-level audio documents as well
-  let videoElement = document.getElementsByTagName("video")[0];
-  if (!videoElement)
+// <video> is used for top-level audio documents as well
+let videoElement = document.getElementsByTagName("video")[0];
+
+// Send keystrokes to the video element when the body element is focused,
+// to be received by the event listener in videocontrols.xml.
+document.addEventListener("keypress", ev => {
+  if (ev.synthetic) // prevent recursion
     return;
 
-  // Send keystrokes to the video element when the body element is focused,
-  // to be received by the event listener in videocontrols.xml.
-  document.addEventListener("keypress", ev => {
-    if (ev.synthetic) // prevent recursion
-      return;
+  // Check if the video element is focused, so it already receives
+  // keystrokes, and don't send it another one from here.
+  if (document.activeElement == videoElement)
+    return;
 
-    // Check if the video element is focused, so it already receives
-    // keystrokes, and don't send it another one from here.
-    if (document.activeElement == videoElement)
-      return;
-
-    let newEvent = new KeyboardEvent("keypress", ev);
-    newEvent.synthetic = true;
-    videoElement.dispatchEvent(newEvent);
-  });
+  let newEvent = new KeyboardEvent("keypress", ev);
+  newEvent.synthetic = true;
+  videoElement.dispatchEvent(newEvent);
 });