diff --git a/devtools/client/framework/menu.js b/devtools/client/framework/menu.js index b5eb337daff2..e9bb3dcf382d 100644 --- a/devtools/client/framework/menu.js +++ b/devtools/client/framework/menu.js @@ -6,6 +6,7 @@ "use strict"; +const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; const Services = require("Services"); const EventEmitter = require("devtools/shared/event-emitter"); @@ -83,7 +84,12 @@ Menu.prototype.popupWithZoom = function(x, y, toolbox) { */ Menu.prototype.popup = function(screenX, screenY, toolbox) { const doc = toolbox.doc; - const popupset = doc.querySelector("popupset"); + + let popupset = doc.querySelector("popupset"); + if (!popupset) { + popupset = doc.createElementNS(XUL_NS, "popupset"); + doc.documentElement.appendChild(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 @@ -93,7 +99,7 @@ Menu.prototype.popup = function(screenX, screenY, toolbox) { popup.hidePopup(); } - popup = doc.createElement("menupopup"); + popup = doc.createElementNS(XUL_NS, "menupopup"); popup.setAttribute("menu-api", "true"); popup.setAttribute("consumeoutsideclicks", "true"); @@ -128,10 +134,10 @@ Menu.prototype._createMenuItems = function(parent) { } if (item.submenu) { - const menupopup = doc.createElement("menupopup"); + const menupopup = doc.createElementNS(XUL_NS, "menupopup"); item.submenu._createMenuItems(menupopup); - const menu = doc.createElement("menu"); + const menu = doc.createElementNS(XUL_NS, "menu"); menu.appendChild(menupopup); menu.setAttribute("label", item.label); if (item.disabled) { @@ -148,10 +154,10 @@ Menu.prototype._createMenuItems = function(parent) { } parent.appendChild(menu); } else if (item.type === "separator") { - const menusep = doc.createElement("menuseparator"); + const menusep = doc.createElementNS(XUL_NS, "menuseparator"); parent.appendChild(menusep); } else { - const menuitem = doc.createElement("menuitem"); + const menuitem = doc.createElementNS(XUL_NS, "menuitem"); menuitem.setAttribute("label", item.label); menuitem.addEventListener("command", () => { item.click();