Bug 1285229 - Prevent duplicated context menu in the Inspector on Windows. r=jdescottes
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 13 Jul 2016 15:44:20 -0700
changeset 304920 31cab0ba8bbf1d88b08abeae45bcdf317645355a
parent 304919 c492812c7932a78769ae2ddad321b725e09fd9ea
child 304921 cd9da00ffcc3f37ae32b9401dfbeaa892e314ab3
child 304960 e8071e322140e6ec07a1dc2b2f4ae121b9ae74c4
push id30446
push usercbook@mozilla.com
push dateThu, 14 Jul 2016 09:44:34 +0000
treeherdermozilla-central@cd9da00ffcc3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1285229
milestone50.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 1285229 - Prevent duplicated context menu in the Inspector on Windows. r=jdescottes
devtools/client/framework/menu.js
--- a/devtools/client/framework/menu.js
+++ b/devtools/client/framework/menu.js
@@ -59,17 +59,27 @@ Menu.prototype.insert = function (pos, m
  *
  * @param {int} screenX
  * @param {int} screenY
  * @param Toolbox toolbox (non standard)
  *        Needed so we in which window to inject XUL
  */
 Menu.prototype.popup = function (screenX, screenY, toolbox) {
   let doc = toolbox.doc;
-  let popup = doc.createElement("menupopup");
+  let popupset = doc.querySelector("popupset");
+  // See bug 1285229, on Windows, opening the same popup multiple times in a
+  // row ends up duplicating the popup. The newly inserted popup doesn't
+  // dismiss the old one. So remove any previously displayed popup before
+  // opening a new one.
+  let popup = popupset.querySelector("menupopup[menu-api=\"true\"]");
+  if (popup) {
+    popup.hidePopup();
+  }
+
+  popup = doc.createElement("menupopup");
   popup.setAttribute("menu-api", "true");
 
   if (this.id) {
     popup.id = this.id;
   }
   this._createMenuItems(popup);
 
   // Remove the menu from the DOM once it's hidden.
@@ -81,17 +91,17 @@ Menu.prototype.popup = function (screenX
   });
 
   popup.addEventListener("popupshown", (e) => {
     if (e.target === popup) {
       this.emit("open");
     }
   });
 
-  doc.querySelector("popupset").appendChild(popup);
+  popupset.appendChild(popup);
   popup.openPopupAtScreen(screenX, screenY, true);
 };
 
 Menu.prototype._createMenuItems = function (parent) {
   let doc = parent.ownerDocument;
   this.menuitems.forEach(item => {
     if (!item.visible) {
       return;