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 : 4f0863ec40cdb33be577671ee7f130b125101a74
This commit is contained in:
Brendan Dahl 2018-06-06 14:55:23 -07:00
Родитель cc9fecba49
Коммит 0cb38e81f6
1 изменённых файлов: 12 добавлений и 6 удалений

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

@ -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();