diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/content/TopLevelVideoDocument.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | toolkit/content/TopLevelVideoDocument.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/toolkit/content/TopLevelVideoDocument.js b/toolkit/content/TopLevelVideoDocument.js new file mode 100644 index 0000000000..4505a93d18 --- /dev/null +++ b/toolkit/content/TopLevelVideoDocument.js @@ -0,0 +1,69 @@ +/* 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"; + +// Hide our variables from the web content, even though the spec allows them +// (and the DOM) to be accessible (see bug 1474832) +{ + // <video> is used for top-level audio documents as well + let videoElement = document.getElementsByTagName("video")[0]; + + let setFocusToVideoElement = function (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 && e.target == videoElement) { + return; + } + videoElement.focus(); + }; + + // Redirect focus to the video element whenever the document receives + // focus. + document.addEventListener("focus", setFocusToVideoElement, true); + + // Focus on the video in the newly created document. + setFocusToVideoElement(); + + // Opt out of moving focus away if the DOM tree changes (from add-on or web content) + let observer = new MutationObserver(() => { + observer.disconnect(); + document.removeEventListener("focus", setFocusToVideoElement, true); + }); + observer.observe(document.documentElement, { + childList: true, + subtree: 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. + // Don't break leaving that mode, so do nothing here. + if (window.fullScreen) { + return; + } + + // If we're not in browser fullscreen mode, prevent entering into that, + // so we don't end up there after pressing Esc. + ev.preventDefault(); + ev.stopPropagation(); + + if (!document.fullscreenElement) { + videoElement.requestFullscreen(); + } else { + document.exitFullscreen(); + } + } + }); +} |