| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 WebInspector.ContextMenuItem = class { | 34 UI.ContextMenuItem = class { |
| 35 /** | 35 /** |
| 36 * @param {?WebInspector.ContextMenu} topLevelMenu | 36 * @param {?UI.ContextMenu} topLevelMenu |
| 37 * @param {string} type | 37 * @param {string} type |
| 38 * @param {string=} label | 38 * @param {string=} label |
| 39 * @param {boolean=} disabled | 39 * @param {boolean=} disabled |
| 40 * @param {boolean=} checked | 40 * @param {boolean=} checked |
| 41 */ | 41 */ |
| 42 constructor(topLevelMenu, type, label, disabled, checked) { | 42 constructor(topLevelMenu, type, label, disabled, checked) { |
| 43 this._type = type; | 43 this._type = type; |
| 44 this._label = label; | 44 this._label = label; |
| 45 this._disabled = disabled; | 45 this._disabled = disabled; |
| 46 this._checked = checked; | 46 this._checked = checked; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 * @param {string} shortcut | 101 * @param {string} shortcut |
| 102 */ | 102 */ |
| 103 setShortcut(shortcut) { | 103 setShortcut(shortcut) { |
| 104 this._shortcut = shortcut; | 104 this._shortcut = shortcut; |
| 105 } | 105 } |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 /** | 108 /** |
| 109 * @unrestricted | 109 * @unrestricted |
| 110 */ | 110 */ |
| 111 WebInspector.ContextSubMenuItem = class extends WebInspector.ContextMenuItem { | 111 UI.ContextSubMenuItem = class extends UI.ContextMenuItem { |
| 112 /** | 112 /** |
| 113 * @param {?WebInspector.ContextMenu} topLevelMenu | 113 * @param {?UI.ContextMenu} topLevelMenu |
| 114 * @param {string=} label | 114 * @param {string=} label |
| 115 * @param {boolean=} disabled | 115 * @param {boolean=} disabled |
| 116 */ | 116 */ |
| 117 constructor(topLevelMenu, label, disabled) { | 117 constructor(topLevelMenu, label, disabled) { |
| 118 super(topLevelMenu, 'subMenu', label, disabled); | 118 super(topLevelMenu, 'subMenu', label, disabled); |
| 119 /** @type {!Array.<!WebInspector.ContextMenuItem>} */ | 119 /** @type {!Array.<!UI.ContextMenuItem>} */ |
| 120 this._items = []; | 120 this._items = []; |
| 121 } | 121 } |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * @param {string} label | 124 * @param {string} label |
| 125 * @param {function(?)} handler | 125 * @param {function(?)} handler |
| 126 * @param {boolean=} disabled | 126 * @param {boolean=} disabled |
| 127 * @return {!WebInspector.ContextMenuItem} | 127 * @return {!UI.ContextMenuItem} |
| 128 */ | 128 */ |
| 129 appendItem(label, handler, disabled) { | 129 appendItem(label, handler, disabled) { |
| 130 var item = new WebInspector.ContextMenuItem(this._contextMenu, 'item', label
, disabled); | 130 var item = new UI.ContextMenuItem(this._contextMenu, 'item', label, disabled
); |
| 131 this._pushItem(item); | 131 this._pushItem(item); |
| 132 this._contextMenu._setHandler(item.id(), handler); | 132 this._contextMenu._setHandler(item.id(), handler); |
| 133 return item; | 133 return item; |
| 134 } | 134 } |
| 135 | 135 |
| 136 /** | 136 /** |
| 137 * @param {!Element} element | 137 * @param {!Element} element |
| 138 * @return {!WebInspector.ContextMenuItem} | 138 * @return {!UI.ContextMenuItem} |
| 139 */ | 139 */ |
| 140 appendCustomItem(element) { | 140 appendCustomItem(element) { |
| 141 var item = new WebInspector.ContextMenuItem(this._contextMenu, 'item', '<cus
tom>'); | 141 var item = new UI.ContextMenuItem(this._contextMenu, 'item', '<custom>'); |
| 142 item._customElement = element; | 142 item._customElement = element; |
| 143 this._pushItem(item); | 143 this._pushItem(item); |
| 144 return item; | 144 return item; |
| 145 } | 145 } |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * @param {string} actionId | 148 * @param {string} actionId |
| 149 * @param {string=} label | 149 * @param {string=} label |
| 150 * @return {!WebInspector.ContextMenuItem} | 150 * @return {!UI.ContextMenuItem} |
| 151 */ | 151 */ |
| 152 appendAction(actionId, label) { | 152 appendAction(actionId, label) { |
| 153 var action = WebInspector.actionRegistry.action(actionId); | 153 var action = UI.actionRegistry.action(actionId); |
| 154 if (!label) | 154 if (!label) |
| 155 label = action.title(); | 155 label = action.title(); |
| 156 var result = this.appendItem(label, action.execute.bind(action)); | 156 var result = this.appendItem(label, action.execute.bind(action)); |
| 157 var shortcut = WebInspector.shortcutRegistry.shortcutTitleForAction(actionId
); | 157 var shortcut = UI.shortcutRegistry.shortcutTitleForAction(actionId); |
| 158 if (shortcut) | 158 if (shortcut) |
| 159 result.setShortcut(shortcut); | 159 result.setShortcut(shortcut); |
| 160 return result; | 160 return result; |
| 161 } | 161 } |
| 162 | 162 |
| 163 /** | 163 /** |
| 164 * @param {string} label | 164 * @param {string} label |
| 165 * @param {boolean=} disabled | 165 * @param {boolean=} disabled |
| 166 * @param {string=} subMenuId | 166 * @param {string=} subMenuId |
| 167 * @return {!WebInspector.ContextSubMenuItem} | 167 * @return {!UI.ContextSubMenuItem} |
| 168 */ | 168 */ |
| 169 appendSubMenuItem(label, disabled, subMenuId) { | 169 appendSubMenuItem(label, disabled, subMenuId) { |
| 170 var item = new WebInspector.ContextSubMenuItem(this._contextMenu, label, dis
abled); | 170 var item = new UI.ContextSubMenuItem(this._contextMenu, label, disabled); |
| 171 if (subMenuId) | 171 if (subMenuId) |
| 172 this._contextMenu._namedSubMenus.set(subMenuId, item); | 172 this._contextMenu._namedSubMenus.set(subMenuId, item); |
| 173 this._pushItem(item); | 173 this._pushItem(item); |
| 174 return item; | 174 return item; |
| 175 } | 175 } |
| 176 | 176 |
| 177 /** | 177 /** |
| 178 * @param {string} label | 178 * @param {string} label |
| 179 * @param {function()} handler | 179 * @param {function()} handler |
| 180 * @param {boolean=} checked | 180 * @param {boolean=} checked |
| 181 * @param {boolean=} disabled | 181 * @param {boolean=} disabled |
| 182 * @return {!WebInspector.ContextMenuItem} | 182 * @return {!UI.ContextMenuItem} |
| 183 */ | 183 */ |
| 184 appendCheckboxItem(label, handler, checked, disabled) { | 184 appendCheckboxItem(label, handler, checked, disabled) { |
| 185 var item = new WebInspector.ContextMenuItem(this._contextMenu, 'checkbox', l
abel, disabled, checked); | 185 var item = new UI.ContextMenuItem(this._contextMenu, 'checkbox', label, disa
bled, checked); |
| 186 this._pushItem(item); | 186 this._pushItem(item); |
| 187 this._contextMenu._setHandler(item.id(), handler); | 187 this._contextMenu._setHandler(item.id(), handler); |
| 188 return item; | 188 return item; |
| 189 } | 189 } |
| 190 | 190 |
| 191 appendSeparator() { | 191 appendSeparator() { |
| 192 if (this._items.length) | 192 if (this._items.length) |
| 193 this._pendingSeparator = true; | 193 this._pendingSeparator = true; |
| 194 } | 194 } |
| 195 | 195 |
| 196 /** | 196 /** |
| 197 * @param {!WebInspector.ContextMenuItem} item | 197 * @param {!UI.ContextMenuItem} item |
| 198 */ | 198 */ |
| 199 _pushItem(item) { | 199 _pushItem(item) { |
| 200 if (this._pendingSeparator) { | 200 if (this._pendingSeparator) { |
| 201 this._items.push(new WebInspector.ContextMenuItem(this._contextMenu, 'sepa
rator')); | 201 this._items.push(new UI.ContextMenuItem(this._contextMenu, 'separator')); |
| 202 delete this._pendingSeparator; | 202 delete this._pendingSeparator; |
| 203 } | 203 } |
| 204 this._items.push(item); | 204 this._items.push(item); |
| 205 } | 205 } |
| 206 | 206 |
| 207 /** | 207 /** |
| 208 * @return {boolean} | 208 * @return {boolean} |
| 209 */ | 209 */ |
| 210 isEmpty() { | 210 isEmpty() { |
| 211 return !this._items.length; | 211 return !this._items.length; |
| 212 } | 212 } |
| 213 | 213 |
| 214 /** | 214 /** |
| 215 * @override | 215 * @override |
| 216 * @return {!InspectorFrontendHostAPI.ContextMenuDescriptor} | 216 * @return {!InspectorFrontendHostAPI.ContextMenuDescriptor} |
| 217 */ | 217 */ |
| 218 _buildDescriptor() { | 218 _buildDescriptor() { |
| 219 var result = {type: 'subMenu', label: this._label, enabled: !this._disabled,
subItems: []}; | 219 var result = {type: 'subMenu', label: this._label, enabled: !this._disabled,
subItems: []}; |
| 220 for (var i = 0; i < this._items.length; ++i) | 220 for (var i = 0; i < this._items.length; ++i) |
| 221 result.subItems.push(this._items[i]._buildDescriptor()); | 221 result.subItems.push(this._items[i]._buildDescriptor()); |
| 222 return result; | 222 return result; |
| 223 } | 223 } |
| 224 | 224 |
| 225 /** | 225 /** |
| 226 * @param {string} location | 226 * @param {string} location |
| 227 */ | 227 */ |
| 228 appendItemsAtLocation(location) { | 228 appendItemsAtLocation(location) { |
| 229 /** | 229 /** |
| 230 * @param {!WebInspector.ContextSubMenuItem} menu | 230 * @param {!UI.ContextSubMenuItem} menu |
| 231 * @param {!Runtime.Extension} extension | 231 * @param {!Runtime.Extension} extension |
| 232 */ | 232 */ |
| 233 function appendExtension(menu, extension) { | 233 function appendExtension(menu, extension) { |
| 234 var subMenuId = extension.descriptor()['subMenuId']; | 234 var subMenuId = extension.descriptor()['subMenuId']; |
| 235 if (subMenuId) { | 235 if (subMenuId) { |
| 236 var subMenuItem = menu.appendSubMenuItem(extension.title(), false, subMe
nuId); | 236 var subMenuItem = menu.appendSubMenuItem(extension.title(), false, subMe
nuId); |
| 237 subMenuItem.appendItemsAtLocation(subMenuId); | 237 subMenuItem.appendItemsAtLocation(subMenuId); |
| 238 } else { | 238 } else { |
| 239 menu.appendAction(extension.descriptor()['actionId']); | 239 menu.appendAction(extension.descriptor()['actionId']); |
| 240 } | 240 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 269 continue; | 269 continue; |
| 270 group.forEach(appendExtension.bind(null, this)); | 270 group.forEach(appendExtension.bind(null, this)); |
| 271 this.appendSeparator(); | 271 this.appendSeparator(); |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 }; | 274 }; |
| 275 | 275 |
| 276 /** | 276 /** |
| 277 * @unrestricted | 277 * @unrestricted |
| 278 */ | 278 */ |
| 279 WebInspector.ContextMenu = class extends WebInspector.ContextSubMenuItem { | 279 UI.ContextMenu = class extends UI.ContextSubMenuItem { |
| 280 /** | 280 /** |
| 281 * @param {!Event} event | 281 * @param {!Event} event |
| 282 * @param {boolean=} useSoftMenu | 282 * @param {boolean=} useSoftMenu |
| 283 * @param {number=} x | 283 * @param {number=} x |
| 284 * @param {number=} y | 284 * @param {number=} y |
| 285 */ | 285 */ |
| 286 constructor(event, useSoftMenu, x, y) { | 286 constructor(event, useSoftMenu, x, y) { |
| 287 super(null, ''); | 287 super(null, ''); |
| 288 this._contextMenu = this; | 288 this._contextMenu = this; |
| 289 /** @type {!Array.<!Promise.<!Array.<!WebInspector.ContextMenu.Provider>>>}
*/ | 289 /** @type {!Array.<!Promise.<!Array.<!UI.ContextMenu.Provider>>>} */ |
| 290 this._pendingPromises = []; | 290 this._pendingPromises = []; |
| 291 /** @type {!Array<!Object>} */ | 291 /** @type {!Array<!Object>} */ |
| 292 this._pendingTargets = []; | 292 this._pendingTargets = []; |
| 293 this._event = event; | 293 this._event = event; |
| 294 this._useSoftMenu = !!useSoftMenu; | 294 this._useSoftMenu = !!useSoftMenu; |
| 295 this._x = x === undefined ? event.x : x; | 295 this._x = x === undefined ? event.x : x; |
| 296 this._y = y === undefined ? event.y : y; | 296 this._y = y === undefined ? event.y : y; |
| 297 this._handlers = {}; | 297 this._handlers = {}; |
| 298 this._id = 0; | 298 this._id = 0; |
| 299 /** @type {!Map<string, !WebInspector.ContextSubMenuItem>} */ | 299 /** @type {!Map<string, !UI.ContextSubMenuItem>} */ |
| 300 this._namedSubMenus = new Map(); | 300 this._namedSubMenus = new Map(); |
| 301 } | 301 } |
| 302 | 302 |
| 303 static initialize() { | 303 static initialize() { |
| 304 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.SetUseSoftMenu, setUseSoftMenu); | 304 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.SetUseSoftMenu, setUseSoftMenu); |
| 305 /** | 305 /** |
| 306 * @param {!WebInspector.Event} event | 306 * @param {!Common.Event} event |
| 307 */ | 307 */ |
| 308 function setUseSoftMenu(event) { | 308 function setUseSoftMenu(event) { |
| 309 WebInspector.ContextMenu._useSoftMenu = /** @type {boolean} */ (event.data
); | 309 UI.ContextMenu._useSoftMenu = /** @type {boolean} */ (event.data); |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 | 312 |
| 313 /** | 313 /** |
| 314 * @param {!Document} doc | 314 * @param {!Document} doc |
| 315 */ | 315 */ |
| 316 static installHandler(doc) { | 316 static installHandler(doc) { |
| 317 doc.body.addEventListener('contextmenu', handler, false); | 317 doc.body.addEventListener('contextmenu', handler, false); |
| 318 | 318 |
| 319 /** | 319 /** |
| 320 * @param {!Event} event | 320 * @param {!Event} event |
| 321 */ | 321 */ |
| 322 function handler(event) { | 322 function handler(event) { |
| 323 var contextMenu = new WebInspector.ContextMenu(event); | 323 var contextMenu = new UI.ContextMenu(event); |
| 324 contextMenu.appendApplicableItems(/** @type {!Object} */ (event.deepElemen
tFromPoint())); | 324 contextMenu.appendApplicableItems(/** @type {!Object} */ (event.deepElemen
tFromPoint())); |
| 325 contextMenu.show(); | 325 contextMenu.show(); |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 | 328 |
| 329 /** | 329 /** |
| 330 * @return {number} | 330 * @return {number} |
| 331 */ | 331 */ |
| 332 _nextId() { | 332 _nextId() { |
| 333 return this._id++; | 333 return this._id++; |
| 334 } | 334 } |
| 335 | 335 |
| 336 /** | 336 /** |
| 337 * @param {function()} callback | 337 * @param {function()} callback |
| 338 */ | 338 */ |
| 339 beforeShow(callback) { | 339 beforeShow(callback) { |
| 340 this._beforeShow = callback; | 340 this._beforeShow = callback; |
| 341 } | 341 } |
| 342 | 342 |
| 343 show() { | 343 show() { |
| 344 Promise.all(this._pendingPromises).then(populate.bind(this)).then(this._inne
rShow.bind(this)); | 344 Promise.all(this._pendingPromises).then(populate.bind(this)).then(this._inne
rShow.bind(this)); |
| 345 WebInspector.ContextMenu._pendingMenu = this; | 345 UI.ContextMenu._pendingMenu = this; |
| 346 | 346 |
| 347 /** | 347 /** |
| 348 * @param {!Array.<!Array.<!WebInspector.ContextMenu.Provider>>} appendCallR
esults | 348 * @param {!Array.<!Array.<!UI.ContextMenu.Provider>>} appendCallResults |
| 349 * @this {WebInspector.ContextMenu} | 349 * @this {UI.ContextMenu} |
| 350 */ | 350 */ |
| 351 function populate(appendCallResults) { | 351 function populate(appendCallResults) { |
| 352 if (WebInspector.ContextMenu._pendingMenu !== this) | 352 if (UI.ContextMenu._pendingMenu !== this) |
| 353 return; | 353 return; |
| 354 delete WebInspector.ContextMenu._pendingMenu; | 354 delete UI.ContextMenu._pendingMenu; |
| 355 | 355 |
| 356 for (var i = 0; i < appendCallResults.length; ++i) { | 356 for (var i = 0; i < appendCallResults.length; ++i) { |
| 357 var providers = appendCallResults[i]; | 357 var providers = appendCallResults[i]; |
| 358 var target = this._pendingTargets[i]; | 358 var target = this._pendingTargets[i]; |
| 359 | 359 |
| 360 for (var j = 0; j < providers.length; ++j) { | 360 for (var j = 0; j < providers.length; ++j) { |
| 361 var provider = /** @type {!WebInspector.ContextMenu.Provider} */ (prov
iders[j]); | 361 var provider = /** @type {!UI.ContextMenu.Provider} */ (providers[j]); |
| 362 this.appendSeparator(); | 362 this.appendSeparator(); |
| 363 provider.appendApplicableItems(this._event, this, target); | 363 provider.appendApplicableItems(this._event, this, target); |
| 364 this.appendSeparator(); | 364 this.appendSeparator(); |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 | 367 |
| 368 this._pendingPromises = []; | 368 this._pendingPromises = []; |
| 369 this._pendingTargets = []; | 369 this._pendingTargets = []; |
| 370 } | 370 } |
| 371 | 371 |
| 372 this._event.consume(true); | 372 this._event.consume(true); |
| 373 } | 373 } |
| 374 | 374 |
| 375 discard() { | 375 discard() { |
| 376 if (this._softMenu) | 376 if (this._softMenu) |
| 377 this._softMenu.discard(); | 377 this._softMenu.discard(); |
| 378 } | 378 } |
| 379 | 379 |
| 380 _innerShow() { | 380 _innerShow() { |
| 381 if (typeof this._beforeShow === 'function') { | 381 if (typeof this._beforeShow === 'function') { |
| 382 this._beforeShow(); | 382 this._beforeShow(); |
| 383 delete this._beforeShow; | 383 delete this._beforeShow; |
| 384 } | 384 } |
| 385 | 385 |
| 386 var menuObject = this._buildDescriptors(); | 386 var menuObject = this._buildDescriptors(); |
| 387 | 387 |
| 388 WebInspector._contextMenu = this; | 388 UI._contextMenu = this; |
| 389 if (this._useSoftMenu || WebInspector.ContextMenu._useSoftMenu || InspectorF
rontendHost.isHostedMode()) { | 389 if (this._useSoftMenu || UI.ContextMenu._useSoftMenu || InspectorFrontendHos
t.isHostedMode()) { |
| 390 this._softMenu = new WebInspector.SoftContextMenu(menuObject, this._itemSe
lected.bind(this)); | 390 this._softMenu = new UI.SoftContextMenu(menuObject, this._itemSelected.bin
d(this)); |
| 391 this._softMenu.show(this._event.target.ownerDocument, this._x, this._y); | 391 this._softMenu.show(this._event.target.ownerDocument, this._x, this._y); |
| 392 } else { | 392 } else { |
| 393 InspectorFrontendHost.showContextMenuAtPoint(this._x, this._y, menuObject,
this._event.target.ownerDocument); | 393 InspectorFrontendHost.showContextMenuAtPoint(this._x, this._y, menuObject,
this._event.target.ownerDocument); |
| 394 | 394 |
| 395 /** | 395 /** |
| 396 * @this {WebInspector.ContextMenu} | 396 * @this {UI.ContextMenu} |
| 397 */ | 397 */ |
| 398 function listenToEvents() { | 398 function listenToEvents() { |
| 399 InspectorFrontendHost.events.addEventListener( | 399 InspectorFrontendHost.events.addEventListener( |
| 400 InspectorFrontendHostAPI.Events.ContextMenuCleared, this._menuCleare
d, this); | 400 InspectorFrontendHostAPI.Events.ContextMenuCleared, this._menuCleare
d, this); |
| 401 InspectorFrontendHost.events.addEventListener( | 401 InspectorFrontendHost.events.addEventListener( |
| 402 InspectorFrontendHostAPI.Events.ContextMenuItemSelected, this._onIte
mSelected, this); | 402 InspectorFrontendHostAPI.Events.ContextMenuItemSelected, this._onIte
mSelected, this); |
| 403 } | 403 } |
| 404 | 404 |
| 405 // showContextMenuAtPoint call above synchronously issues a clear event fo
r previous context menu (if any), | 405 // showContextMenuAtPoint call above synchronously issues a clear event fo
r previous context menu (if any), |
| 406 // so we skip it before subscribing to the clear event. | 406 // so we skip it before subscribing to the clear event. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 421 * @return {!Array.<!InspectorFrontendHostAPI.ContextMenuDescriptor>} | 421 * @return {!Array.<!InspectorFrontendHostAPI.ContextMenuDescriptor>} |
| 422 */ | 422 */ |
| 423 _buildDescriptors() { | 423 _buildDescriptors() { |
| 424 var result = []; | 424 var result = []; |
| 425 for (var i = 0; i < this._items.length; ++i) | 425 for (var i = 0; i < this._items.length; ++i) |
| 426 result.push(this._items[i]._buildDescriptor()); | 426 result.push(this._items[i]._buildDescriptor()); |
| 427 return result; | 427 return result; |
| 428 } | 428 } |
| 429 | 429 |
| 430 /** | 430 /** |
| 431 * @param {!WebInspector.Event} event | 431 * @param {!Common.Event} event |
| 432 */ | 432 */ |
| 433 _onItemSelected(event) { | 433 _onItemSelected(event) { |
| 434 this._itemSelected(/** @type {string} */ (event.data)); | 434 this._itemSelected(/** @type {string} */ (event.data)); |
| 435 } | 435 } |
| 436 | 436 |
| 437 /** | 437 /** |
| 438 * @param {string} id | 438 * @param {string} id |
| 439 */ | 439 */ |
| 440 _itemSelected(id) { | 440 _itemSelected(id) { |
| 441 if (this._handlers[id]) | 441 if (this._handlers[id]) |
| 442 this._handlers[id].call(this); | 442 this._handlers[id].call(this); |
| 443 this._menuCleared(); | 443 this._menuCleared(); |
| 444 } | 444 } |
| 445 | 445 |
| 446 _menuCleared() { | 446 _menuCleared() { |
| 447 InspectorFrontendHost.events.removeEventListener( | 447 InspectorFrontendHost.events.removeEventListener( |
| 448 InspectorFrontendHostAPI.Events.ContextMenuCleared, this._menuCleared, t
his); | 448 InspectorFrontendHostAPI.Events.ContextMenuCleared, this._menuCleared, t
his); |
| 449 InspectorFrontendHost.events.removeEventListener( | 449 InspectorFrontendHost.events.removeEventListener( |
| 450 InspectorFrontendHostAPI.Events.ContextMenuItemSelected, this._onItemSel
ected, this); | 450 InspectorFrontendHostAPI.Events.ContextMenuItemSelected, this._onItemSel
ected, this); |
| 451 } | 451 } |
| 452 | 452 |
| 453 /** | 453 /** |
| 454 * @param {!Object} target | 454 * @param {!Object} target |
| 455 */ | 455 */ |
| 456 appendApplicableItems(target) { | 456 appendApplicableItems(target) { |
| 457 this._pendingPromises.push(self.runtime.allInstances(WebInspector.ContextMen
u.Provider, target)); | 457 this._pendingPromises.push(self.runtime.allInstances(UI.ContextMenu.Provider
, target)); |
| 458 this._pendingTargets.push(target); | 458 this._pendingTargets.push(target); |
| 459 } | 459 } |
| 460 | 460 |
| 461 /** | 461 /** |
| 462 * @param {string} name | 462 * @param {string} name |
| 463 * @return {?WebInspector.ContextSubMenuItem} | 463 * @return {?UI.ContextSubMenuItem} |
| 464 */ | 464 */ |
| 465 namedSubMenu(name) { | 465 namedSubMenu(name) { |
| 466 return this._namedSubMenus.get(name) || null; | 466 return this._namedSubMenus.get(name) || null; |
| 467 } | 467 } |
| 468 }; | 468 }; |
| 469 | 469 |
| 470 | 470 |
| 471 /** | 471 /** |
| 472 * @interface | 472 * @interface |
| 473 */ | 473 */ |
| 474 WebInspector.ContextMenu.Provider = function() {}; | 474 UI.ContextMenu.Provider = function() {}; |
| 475 | 475 |
| 476 WebInspector.ContextMenu.Provider.prototype = { | 476 UI.ContextMenu.Provider.prototype = { |
| 477 /** | 477 /** |
| 478 * @param {!Event} event | 478 * @param {!Event} event |
| 479 * @param {!WebInspector.ContextMenu} contextMenu | 479 * @param {!UI.ContextMenu} contextMenu |
| 480 * @param {!Object} target | 480 * @param {!Object} target |
| 481 */ | 481 */ |
| 482 appendApplicableItems: function(event, contextMenu, target) {} | 482 appendApplicableItems: function(event, contextMenu, target) {} |
| 483 }; | 483 }; |
| OLD | NEW |