Bug 842782 - p3: lock fullscreen video orientation. r=ralin
☠☠ backed out by 969091228f16 ☠ ☠
authorJohn Lin <jolin@mozilla.com>
Thu, 17 Aug 2017 11:07:13 +0800
changeset 377187 f3653a89b841a7f1e455937de3fc0e68cfaba1e4
parent 377186 ba812092214c146456ac1c8fedf2faf3eefc5ce5
child 377188 b3005c73d7ade36b481441bb17e258e4c9199c54
push id32402
push userarchaeopteryx@coole-files.de
push dateMon, 28 Aug 2017 14:47:04 +0000
treeherdermozilla-central@d5b6d113cf17 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersralin
bugs842782
milestone57.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 842782 - p3: lock fullscreen video orientation. r=ralin - if enabled, lock orienation when fullscreen state change - use video aspect ratio to choose which orientation to lock MozReview-Commit-ID: 3HP60YNbWcc
toolkit/content/widgets/videocontrols.xml
--- a/toolkit/content/widgets/videocontrols.xml
+++ b/toolkit/content/widgets/videocontrols.xml
@@ -1229,22 +1229,47 @@
         if (this.isVideoInFullScreen()) {
           this.fullscreenButton.setAttribute("fullscreened", "true");
         } else {
           this.fullscreenButton.removeAttribute("fullscreened");
         }
       },
 
       onFullscreenChange() {
+        this.updateOrientationState(this.isVideoInFullScreen());
         if (this.isVideoInFullScreen()) {
           Utils._hideControlsTimeout = setTimeout(this._hideControlsFn, this.HIDE_CONTROLS_TIMEOUT_MS);
         }
         this.setFullscreenButtonState();
       },
 
+      updateOrientationState(lock) {
+        if (!this.video.mozOrientationLockEnabled) {
+          return;
+        }
+        if (lock) {
+          if (this.video.mozIsOrientationLocked) {
+            return;
+          }
+          let dimenDiff = this.video.videoWidth - this.video.videoHeight;
+          if (dimenDiff > 0) {
+            this.video.mozIsOrientationLocked = window.screen.mozLockOrientation("landscape");
+          } else if (dimenDiff < 0) {
+            this.video.mozIsOrientationLocked = window.screen.mozLockOrientation("portrait");
+          } else {
+            this.video.mozIsOrientationLocked = window.screen.mozLockOrientation(window.screen.orientation);
+          }
+        } else {
+          if (this.video.mozIsOrientationLocked) {
+            window.screen.mozUnlockOrientation();
+            this.video.mozIsOrientationLocked = false;
+          }
+        }
+      },
+
       clickToPlayClickHandler(e) {
         if (e.button != 0) {
           return;
         }
         if (this.hasError() && !this.suppressError) {
           // Errors that can be dismissed should be placed here as we discover them.
           if (this.video.error.code != this.video.error.MEDIA_ERR_ABORTED) {
             return;
@@ -1831,16 +1856,17 @@
     };
 
     this.Utils.init(this);
     ]]>
   </constructor>
   <destructor>
     <![CDATA[
     this.Utils.terminateEventListeners();
+    this.Utils.updateOrientationState(false);
     // randomID used to be a <field>, which meant that the XBL machinery
     // undefined the property when the element was unbound. The code in
     // this file actually depends on this, so now that randomID is an
     // expando, we need to make sure to explicitly delete it.
     delete this.randomID;
     ]]>
   </destructor>