gecko-dev/dom/html/htmlMenuBuilder.js
Andrew McCreight 5dec0e0beb Bug 1432992, part 1 - Remove definitions of Ci, Cr, Cc, and Cu. r=florian
This patch was autogenerated by my decomponents.py

It covers almost every file with the extension js, jsm, html, py,
xhtml, or xul.

It removes blank lines after removed lines, when the removed lines are
preceded by either blank lines or the start of a new block. The "start
of a new block" is defined fairly hackily: either the line starts with
//, ends with */, ends with {, <![CDATA[, """ or '''. The first two
cover comments, the third one covers JS, the fourth covers JS embedded
in XUL, and the final two cover JS embedded in Python. This also
applies if the removed line was the first line of the file.

It covers the pattern matching cases like "var {classes: Cc,
interfaces: Ci, utils: Cu, results: Cr} = Components;". It'll remove
the entire thing if they are all either Ci, Cr, Cc or Cu, or it will
remove the appropriate ones and leave the residue behind. If there's
only one behind, then it will turn it into a normal, non-pattern
matching variable definition. (For instance, "const { classes: Cc,
Constructor: CC, interfaces: Ci, utils: Cu } = Components" becomes
"const CC = Components.Constructor".)

MozReview-Commit-ID: DeSHcClQ7cG

--HG--
extra : rebase_source : d9c41878036c1ef7766ef5e91a7005025bc1d72b
2018-02-06 09:36:57 -08:00

135 lines
3.3 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This component is used to build the menus for the HTML contextmenu attribute.
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
// A global value that is used to identify each menu item. It is
// incremented with each one that is found.
var gGeneratedId = 1;
function HTMLMenuBuilder() {
this.currentNode = null;
this.root = null;
this.items = {};
this.nestedStack = [];
};
// Building is done in two steps:
// The first generates a hierarchical JS object that contains the menu structure.
// This object is returned by toJSONString.
//
// The second step can take this structure and generate a XUL menu hierarchy or
// other UI from this object. The default UI is done in PageMenu.jsm.
//
// When a multi-process browser is used, the first step is performed by the child
// process and the second step is performed by the parent process.
HTMLMenuBuilder.prototype =
{
classID: Components.ID("{51c65f5d-0de5-4edc-9058-60e50cef77f8}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIMenuBuilder]),
currentNode: null,
root: null,
items: {},
nestedStack: [],
toJSONString: function() {
return JSON.stringify(this.root);
},
openContainer: function(aLabel) {
if (!this.currentNode) {
this.root = {
type: "menu",
children: []
};
this.currentNode = this.root;
}
else {
let parent = this.currentNode;
this.currentNode = {
type: "menu",
label: aLabel,
children: []
};
parent.children.push(this.currentNode);
this.nestedStack.push(parent);
}
},
addItemFor: function(aElement, aCanLoadIcon) {
// Since we no longer type check this at the IDL level, make sure we've got
// the right element type here.
if (ChromeUtils.getClassName(aElement) !== "HTMLMenuItemElement") {
return;
}
if (!("children" in this.currentNode)) {
return;
}
let item = {
type: "menuitem",
label: aElement.label
};
let elementType = aElement.type;
if (elementType == "checkbox" || elementType == "radio") {
item.checkbox = true;
if (aElement.checked) {
item.checked = true;
}
}
let icon = aElement.icon;
if (icon.length > 0 && aCanLoadIcon) {
item.icon = icon;
}
if (aElement.disabled) {
item.disabled = true;
}
item.id = gGeneratedId++;
this.currentNode.children.push(item);
this.items[item.id] = aElement;
},
addSeparator: function() {
if (!("children" in this.currentNode)) {
return;
}
this.currentNode.children.push({ type: "separator"});
},
undoAddSeparator: function() {
if (!("children" in this.currentNode)) {
return;
}
let children = this.currentNode.children;
if (children.length && children[children.length - 1].type == "separator") {
children.pop();
}
},
closeContainer: function() {
this.currentNode = this.nestedStack.length ? this.nestedStack.pop() : this.root;
},
click: function(id) {
let item = this.items[id];
if (item) {
item.click();
}
}
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([HTMLMenuBuilder]);