Bug 1478484 - avoid focusing the video element if we get focus events for the controls, r?jaws
MozReview-Commit-ID: 1FEu4Ly701o
--- 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.