Bug 856267 - Hide menu popups when the appbar shows with a listener for MozContentShowing. r=jimm
authorSam Foster <sfoster@mozilla.com>
Tue, 30 Apr 2013 16:36:26 +0100
changeset 130463 e562e90b820f464f6137a8a7587449f424617121
parent 130462 da9dc0f5752f058a2400191c2c406d916714d846
child 130464 87fafdf157700c7d1f077ef25de93454d89b8e61
push id24618
push userryanvm@gmail.com
push dateWed, 01 May 2013 14:49:43 +0000
treeherdermozilla-central@4ff1e574e509 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs856267
milestone23.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 856267 - Hide menu popups when the appbar shows with a listener for MozContentShowing. r=jimm
browser/metro/base/content/helperui/MenuUI.js
--- a/browser/metro/base/content/helperui/MenuUI.js
+++ b/browser/metro/base/content/helperui/MenuUI.js
@@ -10,20 +10,21 @@ var AutofillMenuUI = {
   _popupState: null,
   __menuPopup: null,
 
   get _panel() { return document.getElementById("autofill-container"); },
   get _popup() { return document.getElementById("autofill-popup"); },
   get _commands() { return this._popup.childNodes[0]; },
 
   get _menuPopup() {
-    if (!this.__menuPopup)
+    if (!this.__menuPopup) {
       this.__menuPopup = new MenuPopup(this._panel, this._popup);
       this.__menuPopup._wantTypeBehind = true;
-
+      this.__menuPopup.controller = this;
+    }
     return this.__menuPopup;
   },
 
   _firePopupEvent: function _firePopupEvent(aEventName) {
     let menupopup = this._currentControl.menupopup;
     if (menupopup.hasAttribute(aEventName)) {
       let func = new Function("event", menupopup.getAttribute(aEventName));
       func.call(this);
@@ -82,36 +83,37 @@ var ContextMenuUI = {
     moveBelowToFit: true
   },
 
   get _panel() { return document.getElementById("context-container"); },
   get _popup() { return document.getElementById("context-popup"); },
   get _commands() { return this._popup.childNodes[0]; },
 
   get _menuPopup() {
-    if (!this.__menuPopup)
+    if (!this.__menuPopup) {
       this.__menuPopup = new MenuPopup(this._panel, this._popup);
-
+      this.__menuPopup.controller = this;
+    }
     return this.__menuPopup;
   },
 
   /*******************************************
    * External api
    */
 
   /*
    * popupState - return the json object for this context. Called
    * by context command to invoke actions on the target.
    */
   get popupState() {
     return this._popupState;
   },
 
   /*
-   * showContextMenu - display a context sensitive menu based 
+   * showContextMenu - display a context sensitive menu based
    * on the data provided in a json data structure.
    *
    * @param aMessage data structure containing information about
    * the context.
    *  aMessage.json - json data structure described below.
    *  aMessage.target - target element on which to evoke
    *
    * @returns true if the context menu was displayed,
@@ -162,17 +164,17 @@ var ContextMenuUI = {
         command.getAttribute("priority") == "low");
       let searchTextItem = (command.id == "context-search");
 
       // filter low priority items if we have more than one media type.
       if (multipleMediaTypes && lowPriority)
         continue;
 
       for (let i = 0; i < types.length; i++) {
-        // If one of the item's types has '!' before it, treat it as an exclusion rule. 
+        // If one of the item's types has '!' before it, treat it as an exclusion rule.
         if (types[i].charAt(0) == '!' && contentTypes.indexOf(types[i].substring(1)) != -1) {
           break;
         }
         if (contentTypes.indexOf(types[i]) != -1) {
           // If this is the special search text item, we need to set its label dynamically.
           if (searchTextItem && !ContextCommands.searchTextSetup(command, this._popupState.string)) {
             break;
           }
@@ -217,19 +219,20 @@ var MenuControlUI = {
   _currentControl: null,
   __menuPopup: null,
 
   get _panel() { return document.getElementById("menucontrol-container"); },
   get _popup() { return document.getElementById("menucontrol-popup"); },
   get _commands() { return this._popup.childNodes[0]; },
 
   get _menuPopup() {
-    if (!this.__menuPopup)
+    if (!this.__menuPopup) {
       this.__menuPopup = new MenuPopup(this._panel, this._popup);
-
+      this.__menuPopup.controller = this;
+    }
     return this.__menuPopup;
   },
 
   _firePopupEvent: function _firePopupEvent(aEventName) {
     let menupopup = this._currentControl.menupopup;
     if (menupopup.hasAttribute(aEventName)) {
       let func = new Function("event", menupopup.getAttribute(aEventName));
       func.call(this);
@@ -330,18 +333,19 @@ var MenuControlUI = {
     this._menuPopup.hide();
   }
 };
 
 function MenuPopup(aPanel, aPopup) {
   this._panel = aPanel;
   this._popup = aPopup;
   this._wantTypeBehind = false;
+
+  window.addEventListener('MozAppbarShowing', this, false);
 }
-
 MenuPopup.prototype = {
   get _visible() { return !this._panel.hidden; },
   get _commands() { return this._popup.childNodes[0]; },
 
   show: function (aPositionOptions) {
     if (this._visible)
       return;
 
@@ -471,11 +475,18 @@ MenuPopup.prototype = {
           this.hide();
         }
         break;
       case "PopupChanged":
         if (aEvent.detail) {
           this.hide();
         }
         break;
+      case "MozAppbarShowing":
+        if (this.controller && this.controller.hide) {
+          this.controller.hide()
+        } else {
+          this.hide();
+        }
+        break;
     }
   }
 };