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 <brendan.dahl@gmail.com>

--HG--
extra : rebase_source : cd2444bd8ce24e89c8aa6b78ecd203e41156a7fe
This commit is contained in:
Brendan Dahl 2018-07-05 10:56:15 -07:00
Родитель cd53e83d34
Коммит 4dc9578aa6
1 изменённых файлов: 12 добавлений и 6 удалений

Просмотреть файл

@ -6,6 +6,7 @@
"use strict";
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const EventEmitter = require("devtools/shared/event-emitter");
const { getCurrentZoom } = require("devtools/shared/layout/utils");
@ -80,7 +81,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
@ -90,7 +96,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");
@ -125,10 +131,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) {
@ -145,10 +151,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();