this._disabled = !enabled;
},
+ /**
+ * @return {!InspectorFrontendHostAPI.ContextMenuDescriptor}
+ */
_buildDescriptor: function()
{
switch (this._type) {
case "checkbox":
return { type: "checkbox", id: this._id, label: this._label, checked: !!this._checked, enabled: !this._disabled };
}
+ throw new Error("Invalid item type:" + this._type);
}
}
return !this._items.length;
},
+ /**
+ * @return {!InspectorFrontendHostAPI.ContextMenuDescriptor}
+ */
_buildDescriptor: function()
{
var result = { type: "subMenu", label: this._label, enabled: !this._disabled, subItems: [] };
/**
* @constructor
* @extends {WebInspector.ContextSubMenuItem}
- * @param {?Event} event
+ * @param {!Event} event
*/
WebInspector.ContextMenu = function(event)
{
WebInspector.ContextSubMenuItem.call(this, this, "");
- this._event = /** @type {!Event} */ (event);
+ this._event = event;
this._handlers = {};
this._id = 0;
}
-/**
- * @param {boolean} useSoftMenu
- */
-WebInspector.ContextMenu.setUseSoftMenu = function(useSoftMenu)
+WebInspector.ContextMenu.initialize = function()
{
- WebInspector.ContextMenu._useSoftMenu = useSoftMenu;
+ InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.SetUseSoftMenu, setUseSoftMenu);
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ function setUseSoftMenu(event)
+ {
+ WebInspector.ContextMenu._useSoftMenu = /** @type {boolean} */ (event.data);
+ }
}
WebInspector.ContextMenu.prototype = {
if (menuObject.length) {
WebInspector._contextMenu = this;
- if (WebInspector.ContextMenu._useSoftMenu) {
- var softMenu = new WebInspector.SoftContextMenu(menuObject);
- softMenu.show(this._event);
+ if (WebInspector.ContextMenu._useSoftMenu || InspectorFrontendHost.isHostedMode()) {
+ var softMenu = new WebInspector.SoftContextMenu(menuObject, this._itemSelected.bind(this));
+ softMenu.show(this._event.x, this._event.y);
} else {
- InspectorFrontendHost.showContextMenu(this._event, menuObject);
+ InspectorFrontendHost.showContextMenuAtPoint(this._event.x, this._event.y, menuObject);
+ InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.ContextMenuCleared, this._menuCleared, this);
+ InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.ContextMenuItemSelected, this._onItemSelected, this);
}
this._event.consume(true);
}
this._handlers[id] = handler;
},
+ /**
+ * @return {!Array.<!InspectorFrontendHostAPI.ContextMenuDescriptor>}
+ */
_buildDescriptor: function()
{
var result = [];
return result;
},
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _onItemSelected: function(event)
+ {
+ this._itemSelected(/** @type {string} */ (event.data));
+ },
+
+ /**
+ * @param {string} id
+ */
_itemSelected: function(id)
{
if (this._handlers[id])
this._handlers[id].call(this);
+ this._menuCleared();
+ },
+
+ _menuCleared: function()
+ {
+ InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAPI.Events.ContextMenuCleared, this._menuCleared, this);
+ InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAPI.Events.ContextMenuItemSelected, this._onItemSelected, this);
},
/**
*/
appendApplicableItems: function(target)
{
- WebInspector.moduleManager.extensions(WebInspector.ContextMenu.Provider, target).forEach(processProviders.bind(this));
+ self.runtime.extensions(WebInspector.ContextMenu.Provider, target).forEach(processProviders.bind(this));
/**
- * @param {!WebInspector.ModuleManager.Extension} extension
+ * @param {!Runtime.Extension} extension
* @this {WebInspector.ContextMenu}
*/
function processProviders(extension)
*/
appendApplicableItems: function(event, contextMenu, target) { }
}
-
-WebInspector.contextMenuItemSelected = function(id)
-{
- if (WebInspector._contextMenu)
- WebInspector._contextMenu._itemSelected(id);
-}
-
-WebInspector.contextMenuCleared = function()
-{
- // FIXME: Unfortunately, contextMenuCleared is invoked between show and item selected
- // so we can't delete last menu object from WebInspector. Fix the contract.
-}