Bug 1444489 - Part III, Workaround bug 718107 draft
authorTimothy Guan-tin Chien <timdream@gmail.com>
Wed, 21 Mar 2018 15:19:00 +0800
changeset 770602 07ca36eb8c656d1b548e61d648a750a020fa5c99
parent 770601 c1abda11f158873222e85e48937b83d97b12b9c1
child 770603 51ab81f98e43ac9d8c2b0464a17cddf1ad3af0d9
push id103447
push usertimdream@gmail.com
push dateWed, 21 Mar 2018 15:57:15 +0000
bugs1444489, 718107
milestone61.0a1
Bug 1444489 - Part III, Workaround bug 718107 The videocontrols binding will be destroyed and reattached when the video enters/leaves fullscreen. This change accounts for that so that screen orientation is correctly set on mobile. MozReview-Commit-ID: 7D1gkiuXZtX
toolkit/content/widgets/videocontrols.xml
--- a/toolkit/content/widgets/videocontrols.xml
+++ b/toolkit/content/widgets/videocontrols.xml
@@ -223,16 +223,20 @@
           // cause the bindings to detach and reattach, hence
           // unsetting the attribute.
           if (!this.isAudioOnly && !this.video.mozHasAudio) {
             this.muteButton.setAttribute("noAudio", "true");
             this.muteButton.setAttribute("disabled", "true");
           }
         }
 
+        // We should lock the orientation if we are already in
+        // fullscreen and were reattached because of bug 718107.
+        this.updateOrientationState(this.isVideoInFullScreen());
+
         if (this.isAudioOnly) {
           this.clickToPlay.hidden = true;
         }
 
         // If the first frame hasn't loaded, kick off a throbber fade-in.
         if (this.video.readyState >= this.video.HAVE_CURRENT_DATA) {
           this.firstFrameShown = true;
         }
@@ -1095,23 +1099,43 @@
 
         if (this.isVideoInFullScreen()) {
           this.fullscreenButton.setAttribute("fullscreened", "true");
         } else {
           this.fullscreenButton.removeAttribute("fullscreened");
         }
       },
 
+      // XXX This should be the place where we update the control states and
+      // screen orientation upon entering/leaving fullscreen.
+      // Sadly because of bug 718107 as soon as this function exits
+      // the attached binding gets destructored and a new binding is then created.
+      // We therefore don't do anything here and leave it to the new binding to
+      // set state correctly from its constructor.
+      /*
       onFullscreenChange() {
+        // Constructor and destructor will lock/unlock the orientation exactly
+        // once. Doing so here again will cause the videocontrols to
+        // lock-unlock-lock the orientation when entering the fullscreen.
         this.updateOrientationState(this.isVideoInFullScreen());
+
+        // This is already broken by bug 718107 (controls will be hidden
+        // as soon as the video enters fullscreen).
+        // We can think about restoring the behavior here once the bug is
+        // fixed, or we could simply acknowledge the current behavior
+        // after-the-fact and try not to fix this.
         if (this.isVideoInFullScreen()) {
           Utils._hideControlsTimeout = setTimeout(this._hideControlsFn, this.HIDE_CONTROLS_TIMEOUT_MS);
         }
+
+        // Constructor will handle this correctly on the new DOM content in
+        // the new binding.
         this.setFullscreenButtonState();
       },
+      */
 
       updateOrientationState(lock) {
         if (!this.video.mozOrientationLockEnabled) {
           return;
         }
         if (lock) {
           if (this.video.mozIsOrientationLocked) {
             return;
@@ -1702,19 +1726,19 @@
         // the control bar, instead of playing the video or toggle fullscreen.
         if (!this.videocontrols.isTouchControls) {
           addListener(this.controlsSpacer, "click", this.clickToPlayClickHandler);
           addListener(this.controlsSpacer, "dblclick", this.toggleFullscreen);
         }
 
         addListener(this.videocontrols, "resizevideocontrols", this.adjustControlSize);
         addListener(this.videocontrols, "transitionend", this.onTransitionEnd);
-        addListener(this.video.ownerDocument, "mozfullscreenchange", this.onFullscreenChange);
         addListener(this.controlBar, "transitionend", this.onControlBarTransitioned);
-        addListener(this.video.ownerDocument, "fullscreenchange", this.onFullscreenChange);
+        // See comment at onFullscreenChange on bug 718107.
+        // addListener(this.video.ownerDocument, "fullscreenchange", this.onFullscreenChange);
         addListener(this.video, "keypress", this.keyHandler, {capture: true});
         // Prevent any click event within media controls from dispatching through to video.
         addListener(this.videocontrols, "click", function(event) {
           event.stopPropagation();
         }, {mozSystemGroup: false});
         addListener(this.videocontrols, "dragstart", function(event) {
           event.preventDefault(); // prevent dragging of controls image (bug 517114)
         });