Bug 848502 - Add a contextMenu option to SideMenuWidget. r=vporof

This commit is contained in:
Mike Taylor 2015-04-03 09:12:00 -04:00
parent f2c4532dfe
commit ec24053f6c

View File

@ -22,6 +22,7 @@ this.EXPORTED_SYMBOLS = ["SideMenuWidget"];
* @param nsIDOMNode aNode
* The element associated with the widget.
* @param Object aOptions
* - contextMenu: optional element or element ID that serves as a context menu.
* - showArrows: specifies if items should display horizontal arrows.
* - showItemCheckboxes: specifies if items should display checkboxes.
* - showGroupCheckboxes: specifies if groups should display checkboxes.
@ -31,7 +32,8 @@ this.SideMenuWidget = function SideMenuWidget(aNode, aOptions={}) {
this.window = this.document.defaultView;
this._parent = aNode;
let { showArrows, showItemCheckboxes, showGroupCheckboxes } = aOptions;
let { contextMenu, showArrows, showItemCheckboxes, showGroupCheckboxes } = aOptions;
this._contextMenu = contextMenu || null;
this._showArrows = showArrows || false;
this._showItemCheckboxes = showItemCheckboxes || false;
this._showGroupCheckboxes = showGroupCheckboxes || false;
@ -45,6 +47,7 @@ this.SideMenuWidget = function SideMenuWidget(aNode, aOptions={}) {
this._list.setAttribute("with-item-checkboxes", this._showItemCheckboxes);
this._list.setAttribute("with-group-checkboxes", this._showGroupCheckboxes);
this._list.setAttribute("tabindex", "0");
this._list.addEventListener("contextmenu", e => this._showContextMenu(e), false);
this._list.addEventListener("keypress", e => this.emit("keyPress", e), false);
this._list.addEventListener("mousedown", e => this.emit("mousePress", e), false);
this._parent.appendChild(this._list);
@ -389,6 +392,17 @@ SideMenuWidget.prototype = {
}
},
/**
* Shows the contextMenu element.
*/
_showContextMenu: function(e) {
if (!this._contextMenu) {
return;
}
this._contextMenu.openPopupAtScreen(e.screenX, e.screenY, true);
},
window: null,
document: null,
_showArrows: false,