зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
cd53e83d34
Коммит
4dc9578aa6
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||||
const EventEmitter = require("devtools/shared/event-emitter");
|
const EventEmitter = require("devtools/shared/event-emitter");
|
||||||
const { getCurrentZoom } = require("devtools/shared/layout/utils");
|
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) {
|
Menu.prototype.popup = function(screenX, screenY, toolbox) {
|
||||||
const doc = toolbox.doc;
|
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
|
// 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
|
// row ends up duplicating the popup. The newly inserted popup doesn't
|
||||||
// dismiss the old one. So remove any previously displayed popup before
|
// 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.hidePopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
popup = doc.createElement("menupopup");
|
popup = doc.createElementNS(XUL_NS, "menupopup");
|
||||||
popup.setAttribute("menu-api", "true");
|
popup.setAttribute("menu-api", "true");
|
||||||
popup.setAttribute("consumeoutsideclicks", "true");
|
popup.setAttribute("consumeoutsideclicks", "true");
|
||||||
|
|
||||||
|
@ -125,10 +131,10 @@ Menu.prototype._createMenuItems = function(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.submenu) {
|
if (item.submenu) {
|
||||||
const menupopup = doc.createElement("menupopup");
|
const menupopup = doc.createElementNS(XUL_NS, "menupopup");
|
||||||
item.submenu._createMenuItems(menupopup);
|
item.submenu._createMenuItems(menupopup);
|
||||||
|
|
||||||
const menu = doc.createElement("menu");
|
const menu = doc.createElementNS(XUL_NS, "menu");
|
||||||
menu.appendChild(menupopup);
|
menu.appendChild(menupopup);
|
||||||
menu.setAttribute("label", item.label);
|
menu.setAttribute("label", item.label);
|
||||||
if (item.disabled) {
|
if (item.disabled) {
|
||||||
|
@ -145,10 +151,10 @@ Menu.prototype._createMenuItems = function(parent) {
|
||||||
}
|
}
|
||||||
parent.appendChild(menu);
|
parent.appendChild(menu);
|
||||||
} else if (item.type === "separator") {
|
} else if (item.type === "separator") {
|
||||||
const menusep = doc.createElement("menuseparator");
|
const menusep = doc.createElementNS(XUL_NS, "menuseparator");
|
||||||
parent.appendChild(menusep);
|
parent.appendChild(menusep);
|
||||||
} else {
|
} else {
|
||||||
const menuitem = doc.createElement("menuitem");
|
const menuitem = doc.createElementNS(XUL_NS, "menuitem");
|
||||||
menuitem.setAttribute("label", item.label);
|
menuitem.setAttribute("label", item.label);
|
||||||
menuitem.addEventListener("command", () => {
|
menuitem.addEventListener("command", () => {
|
||||||
item.click();
|
item.click();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче