Bug 1268749 followup - Avoid querying :fullscreen selector for context menu. r=margaret a=lizzard
authorXidorn Quan <me@upsuper.org>
Fri, 13 May 2016 21:07:58 +1000
changeset 332845 8f26c5435bb14e6da2f48a00738a38b290b78013
parent 332844 898a985fd269aab39ba07cb56ce402ccacd52ee2
child 332846 ac470f026c69f90c82798f15dbf9d538fc99b68e
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret, lizzard
bugs1268749
milestone48.0a2
Bug 1268749 followup - Avoid querying :fullscreen selector for context menu. r=margaret a=lizzard MozReview-Commit-ID: A2Tn7I6h81Y
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -782,17 +782,18 @@ var BrowserApp = {
       function(aTarget) {
         UITelemetry.addEvent("action.1", "contextmenu", null, "web_controls_media");
         aTarget.setAttribute("controls", true);
       });
 
     NativeWindow.contextmenus.add({
       label: stringGetter("contextmenu.shareMedia"),
       order: NativeWindow.contextmenus.DEFAULT_HTML5_ORDER - 1,
-      selector: NativeWindow.contextmenus._disableRestricted("SHARE", NativeWindow.contextmenus.SelectorContext("video")),
+      selector: NativeWindow.contextmenus._disableRestricted(
+        "SHARE", NativeWindow.contextmenus.videoContext()),
       showAsActions: function(aElement) {
         let url = (aElement.currentSrc || aElement.src);
         let title = aElement.textContent || aElement.title;
         return {
           title: title,
           uri: url,
           type: "video/*",
         };
@@ -800,17 +801,17 @@ var BrowserApp = {
       icon: "drawable://ic_menu_share",
       callback: function(aTarget) {
         // share.1 telemetry is handled in Java via PromptList
         UITelemetry.addEvent("action.1", "contextmenu", null, "web_share_media");
       }
     });
 
     NativeWindow.contextmenus.add(stringGetter("contextmenu.fullScreen"),
-      NativeWindow.contextmenus.SelectorContext("video:not(:fullscreen)"),
+      NativeWindow.contextmenus.videoContext("not-fullscreen"),
       function(aTarget) {
         UITelemetry.addEvent("action.1", "contextmenu", null, "web_fullscreen");
         aTarget.requestFullscreen();
       });
 
     NativeWindow.contextmenus.add(stringGetter("contextmenu.mute"),
       NativeWindow.contextmenus.mediaContext("media-unmuted"),
       function(aTarget) {
@@ -2280,16 +2281,18 @@ var NativeWindow = {
       this.items[cmItem.id] = cmItem;
       return cmItem.id;
     },
 
     remove: function(aId) {
       delete this.items[aId];
     },
 
+    // Although we do not use this ourselves anymore, add-ons may still
+    // need it as it has been documented, so we shouldn't remove it.
     SelectorContext: function(aSelector) {
       return {
         matches: function(aElt) {
           if (aElt.matches)
             return aElt.matches(aSelector);
           return false;
         }
       };
@@ -2444,16 +2447,36 @@ var NativeWindow = {
             else if (!muted && aMode == "media-unmuted")
               return true;
           }
           return false;
         }
       };
     },
 
+    videoContext: function(aMode) {
+      return {
+        matches: function(aElt) {
+          if (aElt instanceof HTMLVideoElement) {
+            if (!aMode) {
+              return true;
+            }
+            var isFullscreen = aElt.ownerDocument.fullscreenElement == aElt;
+            if (aMode == "not-fullscreen") {
+              return !isFullscreen;
+            }
+            if (aMode == "fullscreen") {
+              return isFullscreen;
+            }
+          }
+          return false;
+        }
+      };
+    },
+
     /* Holds a WeakRef to the original target element this context menu was shown for.
      * Most API's will have to walk up the tree from this node to find the correct element
      * to act on
      */
     get _target() {
       if (this._targetRef)
         return this._targetRef.get();
       return null;