From 0cb38e81f6f401c76b3342184c130be65f1ecac5 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Wed, 6 Jun 2018 14:55:23 -0700 Subject: [PATCH] Bug 1466897 - Support devtools context menus in top level HTML pages. r=bgrins Create a popugroup element to setup the context menu behind the scenes. Create all the menu related elements with the XUL namespace. MozReview-Commit-ID: DI24aNHHFON Signed-off-by: Brendan Dahl --HG-- extra : rebase_source : 4f0863ec40cdb33be577671ee7f130b125101a74 --- devtools/client/framework/menu.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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();