Bug 1543940 - menu.popup() should take a document argument instead of toolbox r=ochameau

Depends on D27693

Menu::popup and popupAtZoom are expecting a toolbox argument as last argument.
However, half of the callsites do not have access to the toolbox and just pass
a { doc } object. This is misleading when trying to work on menu.js because you
cannot rely on toolbox APIs.

Differential Revision: https://phabricator.services.mozilla.com/D28036

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Julian Descottes 2019-05-08 21:35:36 +00:00
Родитель d66a731d54
Коммит 039d3e7c13
11 изменённых файлов: 19 добавлений и 21 удалений

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

@ -203,7 +203,7 @@ class AccessibilityRow extends Component {
})); }));
} }
menu.popup(e.screenX, e.screenY, gToolbox); menu.popup(e.screenX, e.screenY, gToolbox.doc);
if (gTelemetry) { if (gTelemetry) {
gTelemetry.scalarAdd(TELEMETRY_ACCESSIBLE_CONTEXT_MENU_OPENED, 1); gTelemetry.scalarAdd(TELEMETRY_ACCESSIBLE_CONTEXT_MENU_OPENED, 1);

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

@ -59,11 +59,11 @@ Menu.prototype.insert = function(pos, menuItem) {
* *
* @param {int} x * @param {int} x
* @param {int} y * @param {int} y
* @param Toolbox toolbox * @param {Document} doc
*/ */
Menu.prototype.popupWithZoom = function(x, y, toolbox) { Menu.prototype.popupWithZoom = function(x, y, doc) {
const zoom = getCurrentZoom(toolbox.doc); const zoom = getCurrentZoom(doc);
this.popup(x * zoom, y * zoom, toolbox); this.popup(x * zoom, y * zoom, doc);
}; };
/** /**
@ -75,12 +75,10 @@ Menu.prototype.popupWithZoom = function(x, y, toolbox) {
* *
* @param {int} screenX * @param {int} screenX
* @param {int} screenY * @param {int} screenY
* @param Toolbox toolbox (non standard) * @param {Document} doc
* Needed so we in which window to inject XUL * The document that should own the context menu.
*/ */
Menu.prototype.popup = function(screenX, screenY, toolbox) { Menu.prototype.popup = function(screenX, screenY, doc) {
const doc = toolbox.doc;
let popupset = doc.querySelector("popupset"); let popupset = doc.querySelector("popupset");
if (!popupset) { if (!popupset) {
popupset = doc.createXULElement("popupset"); popupset = doc.createXULElement("popupset");

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

@ -80,7 +80,7 @@ async function testMenuPopup(toolbox) {
visible: false, visible: false,
})); }));
menu.popup(0, 0, toolbox); menu.popup(0, 0, toolbox.doc);
ok(toolbox.doc.querySelector("#menu-popup"), "A popup is in the DOM"); ok(toolbox.doc.querySelector("#menu-popup"), "A popup is in the DOM");
@ -143,7 +143,7 @@ async function testSubmenu(toolbox) {
disabled: true, disabled: true,
})); }));
menu.popup(0, 0, toolbox); menu.popup(0, 0, toolbox.doc);
ok(toolbox.doc.querySelector("#menu-popup"), "A popup is in the DOM"); ok(toolbox.doc.querySelector("#menu-popup"), "A popup is in the DOM");
is(toolbox.doc.querySelectorAll("#menu-popup > menuitem").length, 0, is(toolbox.doc.querySelectorAll("#menu-popup > menuitem").length, 0,
"No menuitem children"); "No menuitem children");

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

@ -3253,7 +3253,7 @@ Toolbox.prototype = {
menu.once("open", () => this.emit("menu-open")); menu.once("open", () => this.emit("menu-open"));
menu.once("close", () => this.emit("menu-close")); menu.once("close", () => this.emit("menu-close"));
menu.popup(x, y, { doc: this.doc }); menu.popup(x, y, this.doc);
}, },
/** /**

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

@ -87,7 +87,7 @@ class ChangesContextMenu {
}); });
menu.append(menuitemSelectAll); menu.append(menuitemSelectAll);
menu.popup(screenX, screenY, this.inspector.toolbox); menu.popup(screenX, screenY, this.inspector.toolbox.doc);
return menu; return menu;
} }

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

@ -752,7 +752,7 @@ class MarkupContextMenu {
menu.append(menuitem); menu.append(menuitem);
} }
menu.popup(screenX, screenY, this.toolbox); menu.popup(screenX, screenY, this.toolbox.doc);
return menu; return menu;
} }

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

@ -238,7 +238,7 @@ StyleInspectorMenu.prototype = {
}); });
menu.append(menuitemSources); menu.append(menuitemSources);
menu.popup(screenX, screenY, this.inspector._toolbox); menu.popup(screenX, screenY, this.inspector.toolbox.doc);
return menu; return menu;
}, },

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

@ -71,7 +71,7 @@ function showMenu(items, options) {
doc = window.parent.document; doc = window.parent.document;
} }
menu.popup(screenX, screenY, { doc }); menu.popup(screenX, screenY, doc);
} }
module.exports = { module.exports = {

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

@ -300,7 +300,7 @@ class Tabbar extends Component {
const screenX = target.ownerDocument.defaultView.mozInnerScreenX; const screenX = target.ownerDocument.defaultView.mozInnerScreenX;
const screenY = target.ownerDocument.defaultView.mozInnerScreenY; const screenY = target.ownerDocument.defaultView.mozInnerScreenY;
menu.popupWithZoom(rect.left + screenX, rect.bottom + screenY, menu.popupWithZoom(rect.left + screenX, rect.bottom + screenY,
{ doc: this.props.menuDocument }); this.props.menuDocument);
return menu; return menu;
} }

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

@ -201,7 +201,7 @@ StyleEditorUI.prototype = {
this._optionsButton.removeAttribute("open"); this._optionsButton.removeAttribute("open");
}); });
this._optionsMenu.popup(screenX, screenY, this._toolbox); this._optionsMenu.popup(screenX, screenY, this._toolbox.doc);
}, },
/** /**

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

@ -256,7 +256,7 @@ class WebConsoleWrapper {
// Emit the "menu-open" event for testing. // Emit the "menu-open" event for testing.
menu.once("open", () => this.emit("menu-open")); menu.once("open", () => this.emit("menu-open"));
menu.popup(screenX, screenY, { doc: this.hud.chromeWindow.document }); menu.popup(screenX, screenY, this.hud.chromeWindow.document);
return menu; return menu;
}; };
@ -266,7 +266,7 @@ class WebConsoleWrapper {
const menu = createEditContextMenu(window, "webconsole-menu"); const menu = createEditContextMenu(window, "webconsole-menu");
// Emit the "menu-open" event for testing. // Emit the "menu-open" event for testing.
menu.once("open", () => this.emit("menu-open")); menu.once("open", () => this.emit("menu-open"));
menu.popup(screenX, screenY, { doc: this.hud.chromeWindow.document }); menu.popup(screenX, screenY, this.hud.chromeWindow.document);
return menu; return menu;
}; };