Bug 1478484 - avoid focusing the video element if we get focus events for the controls, r?jaws draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 26 Jul 2018 15:12:22 +0100
changeset 823011 777ea507180b3531ec9e3919449741c00bc3ff2c
parent 821479 143984185dcece46031c970179ddea4837a6c01d
push id117557
push userbmo:gijskruitbosch+bugs@gmail.com
push dateThu, 26 Jul 2018 14:12:55 +0000
reviewersjaws
bugs1478484
milestone63.0a1
Bug 1478484 - avoid focusing the video element if we get focus events for the controls, r?jaws MozReview-Commit-ID: 1FEu4Ly701o
toolkit/content/TopLevelVideoDocument.js
--- a/toolkit/content/TopLevelVideoDocument.js
+++ b/toolkit/content/TopLevelVideoDocument.js
@@ -4,17 +4,26 @@
 
 "use strict";
 
 // <video> is used for top-level audio documents as well
 let videoElement = document.getElementsByTagName("video")[0];
 
 // Redirect focus to the video element whenever the document receives
 // focus.
-document.addEventListener("focus", () => videoElement.focus(), true);
+document.addEventListener("focus", (e) => {
+  // We don't want to retarget focus if it goes to the controls in
+  // the video element. Because they're anonymous content, the target
+  // will be the video element in that case. Avoid calling .focus()
+  // for those events:
+  if (e.target == videoElement) {
+    return;
+  }
+  videoElement.focus();
+}, true);
 
 // Handle fullscreen mode
 document.addEventListener("keypress", ev => {
   // Maximize the standalone video when pressing F11,
   // but ignore audio elements
   if (ev.key == "F11" && videoElement.videoWidth != 0 && videoElement.videoHeight != 0) {
     // If we're in browser fullscreen mode, it means the user pressed F11
     // while browser chrome or another tab had focus.