Bug 1444489 - Part VII, nit: Improve naming consistency in videocontrols.xml draft
authorTimothy Guan-tin Chien <timdream@gmail.com>
Wed, 14 Mar 2018 13:41:20 +0800
changeset 770606 365b6076f7ff697cac7d950fe61d506671db43f1
parent 770605 b9b48bccf1128227005cbed42c658e24ee6a71e7
child 770607 93e4192d67d48d97e4577cf189c4e8d4372629ce
push id103447
push usertimdream@gmail.com
push dateWed, 21 Mar 2018 15:57:15 +0000
bugs1444489
milestone61.0a1
Bug 1444489 - Part VII, nit: Improve naming consistency in videocontrols.xml Convert all is* methods to getter or rename them if they take arguments. MozReview-Commit-ID: GOJzz0JYGnq
toolkit/content/widgets/videocontrols.xml
--- a/toolkit/content/widgets/videocontrols.xml
+++ b/toolkit/content/widgets/videocontrols.xml
@@ -227,17 +227,17 @@
           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());
+        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;
@@ -935,17 +935,17 @@
 
         clearTimeout(this._hideControlsTimeout);
 
         // Ignore events caused by transitions between child nodes.
         // Note that the videocontrols element is the same
         // size as the *content area* of the video element,
         // but this is not the same as the video element's
         // border area if the video has border or padding.
-        if (this.isEventWithin(event, this.videocontrols)) {
+        if (this.checkEventWithin(event, this.videocontrols)) {
           return;
         }
 
         var isMouseOver = (event.type == "mouseover");
 
         var controlRect = this.controlBar.getBoundingClientRect();
         var isMouseInControls = event.clientY > controlRect.top &&
         event.clientY < controlRect.bottom &&
@@ -1051,60 +1051,60 @@
           this.video.pause();
         }
 
         // We'll handle style changes in the event listener for
         // the "play" and "pause" events, same as if content
         // script was controlling video playback.
       },
 
-      isVideoWithoutAudioTrack() {
+      get isVideoWithoutAudioTrack() {
         return this.video.readyState >= this.video.HAVE_METADATA &&
                !this.isAudioOnly &&
                !this.video.mozHasAudio;
       },
 
       toggleMute() {
-        if (this.isVideoWithoutAudioTrack()) {
+        if (this.isVideoWithoutAudioTrack) {
           return;
         }
-        this.video.muted = !this.isEffectivelyMuted();
+        this.video.muted = !this.isEffectivelyMuted;
         if (this.video.volume === 0) {
           this.video.volume = 0.5;
         }
 
         // We'll handle style changes in the event listener for
         // the "volumechange" event, same as if content script was
         // controlling volume.
       },
 
-      isVideoInFullScreen() {
+      get isVideoInFullScreen() {
         return document.mozFullScreenElement == this.video;
       },
 
       toggleFullscreen() {
-        this.isVideoInFullScreen() ?
+        this.isVideoInFullScreen ?
           document.mozCancelFullScreen() :
           this.video.mozRequestFullScreen();
       },
 
       setFullscreenButtonState() {
         if (this.isAudioOnly || !document.mozFullScreenEnabled) {
           this.controlBar.setAttribute("fullscreen-unavailable", true);
           this.adjustControlSize();
           return;
         }
         this.controlBar.removeAttribute("fullscreen-unavailable");
         this.adjustControlSize();
 
-        var attrName = this.isVideoInFullScreen() ? "exitfullscreenlabel" : "enterfullscreenlabel";
+        var attrName = this.isVideoInFullScreen ? "exitfullscreenlabel" : "enterfullscreenlabel";
         var value = this.fullscreenButton.getAttribute(attrName);
         this.fullscreenButton.setAttribute("aria-label", value);
 
-        if (this.isVideoInFullScreen()) {
+        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.
@@ -1112,24 +1112,24 @@
       // 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.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()) {
+        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();
       },
       */
@@ -1209,22 +1209,22 @@
           this.playButton.removeAttribute("paused");
         }
 
         var attrName = aPaused ? "playlabel" : "pauselabel";
         var value = this.playButton.getAttribute(attrName);
         this.playButton.setAttribute("aria-label", value);
       },
 
-      isEffectivelyMuted() {
+      get isEffectivelyMuted() {
         return this.video.muted || !this.video.volume;
       },
 
       updateMuteButtonState() {
-        var muted = this.isEffectivelyMuted();
+        var muted = this.isEffectivelyMuted;
 
         if (muted) {
           this.muteButton.setAttribute("muted", "true");
         } else {
           this.muteButton.removeAttribute("muted");
         }
 
         var attrName = muted ? "unmutelabel" : "mutelabel";
@@ -1351,46 +1351,46 @@
             default:
               return;
           }
         } catch (e) { /* ignore any exception from setting .currentTime */ }
 
         event.preventDefault(); // Prevent page scrolling
       },
 
-      isSupportedTextTrack(textTrack) {
+      checkTextTrackSupport(textTrack) {
         return textTrack.kind == "subtitles" ||
                textTrack.kind == "captions";
       },
 
       get isCastingAvailable() {
         return !this.isAudioOnly && this.video.mozAllowCasting;
       },
 
       get isClosedCaptionAvailable() {
         return this.overlayableTextTracks.length;
       },
 
       get overlayableTextTracks() {
-        return Array.prototype.filter.call(this.video.textTracks, this.isSupportedTextTrack);
+        return Array.prototype.filter.call(this.video.textTracks, this.checkTextTrackSupport);
       },
 
       get currentTextTrackIndex() {
         const showingTT = this.overlayableTextTracks.find(tt => tt.mode == "showing");
 
         // fallback to off button if there's no showing track.
         return showingTT ? showingTT.index : 0;
       },
 
-      isCastingOn() {
+      get isCastingOn() {
         return this.isCastingAvailable && this.video.mozIsCasting;
       },
 
       setCastingButtonState() {
-        if (this.isCastingOn()) {
+        if (this.isCastingOn) {
           this.castingButton.setAttribute("enabled", "true");
         } else {
           this.castingButton.removeAttribute("enabled");
         }
 
         this.adjustControlSize();
       },
 
@@ -1401,28 +1401,28 @@
         }
 
         if ("active" in castingData) {
           this.video.mozIsCasting = !!castingData.active;
         }
         this.setCastingButtonState();
       },
 
-      isClosedCaptionOn() {
+      get isClosedCaptionOn() {
         for (let tt of this.overlayableTextTracks) {
           if (tt.mode === "showing") {
             return true;
           }
         }
 
         return false;
       },
 
       setClosedCaptionButtonState() {
-        if (this.isClosedCaptionOn()) {
+        if (this.isClosedCaptionOn) {
           this.closedCaptionButton.setAttribute("enabled", "true");
         } else {
           this.closedCaptionButton.removeAttribute("enabled");
         }
 
         let ttItems = this.textTrackList.childNodes;
 
         for (let tti of ttItems) {
@@ -1434,17 +1434,17 @@
             tti.removeAttribute("on");
           }
         }
 
         this.adjustControlSize();
       },
 
       addNewTextTrack(tt) {
-        if (!this.isSupportedTextTrack(tt)) {
+        if (!this.checkTextTrackSupport(tt)) {
           return;
         }
 
         if (tt.index && tt.index < this.textTracksCount) {
           // Don't create items for initialized tracks. However, we
           // still need to care about mode since TextTrackManager would
           // turn on the first available track automatically.
           if (tt.mode === "showing") {
@@ -1545,17 +1545,17 @@
 
         for (let tt of this.overlayableTextTracks) {
           this.addNewTextTrack(tt);
         }
 
         this.setClosedCaptionButtonState();
       },
 
-      isEventWithin(event, parent1, parent2) {
+      checkEventWithin(event, parent1, parent2) {
         function isDescendant(node) {
           while (node) {
             if (node == parent1 || node == parent2) {
               return true;
             }
             node = node.parentNode;
           }
           return false;