summaryrefslogtreecommitdiffstats
path: root/toolkit/content/TopLevelVideoDocument.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /toolkit/content/TopLevelVideoDocument.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/content/TopLevelVideoDocument.js')
-rw-r--r--toolkit/content/TopLevelVideoDocument.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/toolkit/content/TopLevelVideoDocument.js b/toolkit/content/TopLevelVideoDocument.js
new file mode 100644
index 000000000..5a2b8a857
--- /dev/null
+++ b/toolkit/content/TopLevelVideoDocument.js
@@ -0,0 +1,48 @@
+/* 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";
+
+// <video> is used for top-level audio documents as well
+let videoElement = document.getElementsByTagName("video")[0];
+
+// 1. Handle fullscreen mode;
+// 2. Send keystrokes to the video element if 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;
+
+ // 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 broser fullscreen mode, prevent entering into that,
+ // so we don't end up there after pressing Esc.
+ ev.preventDefault();
+ ev.stopPropagation();
+
+ if (!document.mozFullScreenElement) {
+ videoElement.mozRequestFullScreen();
+ } else {
+ document.mozCancelFullScreen();
+ }
+ 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);
+});