Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(539)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/ContextMenu.js

Issue 1413593008: DevTools: straw man adaptable implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/sdk/module.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 * @param {!Event} event 294 * @param {!Event} event
295 * @param {boolean=} useSoftMenu 295 * @param {boolean=} useSoftMenu
296 * @param {number=} x 296 * @param {number=} x
297 * @param {number=} y 297 * @param {number=} y
298 */ 298 */
299 WebInspector.ContextMenu = function(event, useSoftMenu, x, y) 299 WebInspector.ContextMenu = function(event, useSoftMenu, x, y)
300 { 300 {
301 WebInspector.ContextSubMenuItem.call(this, this, ""); 301 WebInspector.ContextSubMenuItem.call(this, this, "");
302 /** @type {!Array.<!Promise.<!Array.<!WebInspector.ContextMenu.Provider>>>} */ 302 /** @type {!Array.<!Promise.<!Array.<!WebInspector.ContextMenu.Provider>>>} */
303 this._pendingPromises = []; 303 this._pendingPromises = [];
304 this._adapterPromises = [];
304 /** @type {!Array.<!Promise.<!Object>>} */ 305 /** @type {!Array.<!Promise.<!Object>>} */
305 this._pendingTargets = []; 306 this._pendingTargets = [];
306 this._event = event; 307 this._event = event;
307 this._useSoftMenu = !!useSoftMenu; 308 this._useSoftMenu = !!useSoftMenu;
308 this._x = x === undefined ? event.x : x; 309 this._x = x === undefined ? event.x : x;
309 this._y = y === undefined ? event.y : y; 310 this._y = y === undefined ? event.y : y;
310 this._handlers = {}; 311 this._handlers = {};
311 this._id = 0; 312 this._id = 0;
312 } 313 }
313 314
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 /** 346 /**
346 * @return {number} 347 * @return {number}
347 */ 348 */
348 _nextId: function() 349 _nextId: function()
349 { 350 {
350 return this._id++; 351 return this._id++;
351 }, 352 },
352 353
353 show: function() 354 show: function()
354 { 355 {
356 Promise.all(this._adapterPromises).then(this._showWithProviders.bind(thi s));
357 WebInspector.ContextMenu._pendingMenu = this;
358 this._event.consume(true);
359 },
360
361 _showWithProviders: function()
362 {
355 Promise.all(this._pendingPromises).then(populateAndShow.bind(this)); 363 Promise.all(this._pendingPromises).then(populateAndShow.bind(this));
356 WebInspector.ContextMenu._pendingMenu = this;
357 364
358 /** 365 /**
359 * @param {!Array.<!Array.<!WebInspector.ContextMenu.Provider>>} appendC allResults 366 * @param {!Array.<!Array.<!WebInspector.ContextMenu.Provider>>} appendC allResults
360 * @this {WebInspector.ContextMenu} 367 * @this {WebInspector.ContextMenu}
361 */ 368 */
362 function populateAndShow(appendCallResults) 369 function populateAndShow(appendCallResults)
363 { 370 {
364 if (WebInspector.ContextMenu._pendingMenu !== this) 371 if (WebInspector.ContextMenu._pendingMenu !== this)
365 return; 372 return;
366 delete WebInspector.ContextMenu._pendingMenu; 373 delete WebInspector.ContextMenu._pendingMenu;
367 374
368 for (var i = 0; i < appendCallResults.length; ++i) { 375 for (var i = 0; i < appendCallResults.length; ++i) {
369 var providers = appendCallResults[i]; 376 var providers = appendCallResults[i];
370 var target = this._pendingTargets[i]; 377 var target = this._pendingTargets[i];
371 378
372 for (var j = 0; j < providers.length; ++j) { 379 for (var j = 0; j < providers.length; ++j) {
373 var provider = /** @type {!WebInspector.ContextMenu.Provider } */ (providers[j]); 380 var provider = /** @type {!WebInspector.ContextMenu.Provider } */ (providers[j]);
374 this.appendSeparator(); 381 this.appendSeparator();
375 provider.appendApplicableItems(this._event, this, target); 382 provider.appendApplicableItems(this._event, this, target);
376 this.appendSeparator(); 383 this.appendSeparator();
377 } 384 }
378 } 385 }
379 386
380 this._pendingPromises = []; 387 this._pendingPromises = [];
381 this._pendingTargets = []; 388 this._pendingTargets = [];
382 this._innerShow(); 389 this._innerShow();
383 } 390 }
384
385 this._event.consume(true);
386 }, 391 },
387 392
388 discard: function() 393 discard: function()
389 { 394 {
390 if (this._softMenu) 395 if (this._softMenu)
391 this._softMenu.discard(); 396 this._softMenu.discard();
392 }, 397 },
393 398
394 _innerShow: function() 399 _innerShow: function()
395 { 400 {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP I.Events.ContextMenuItemSelected, this._onItemSelected, this); 456 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP I.Events.ContextMenuItemSelected, this._onItemSelected, this);
452 }, 457 },
453 458
454 /** 459 /**
455 * @param {!Object} target 460 * @param {!Object} target
456 */ 461 */
457 appendApplicableItems: function(target) 462 appendApplicableItems: function(target)
458 { 463 {
459 this._pendingPromises.push(self.runtime.instancesPromise(WebInspector.Co ntextMenu.Provider, target)); 464 this._pendingPromises.push(self.runtime.instancesPromise(WebInspector.Co ntextMenu.Provider, target));
460 this._pendingTargets.push(target); 465 this._pendingTargets.push(target);
466
467 this._adapterPromises.push(self.runtime.adapt(target).then(appendForAdap ted.bind(this)));
468 /**
469 * @param {!Array<!Object>} adapted
470 * @this {WebInspector.ContextSubMenuItem}
471 */
472 function appendForAdapted(adapted)
473 {
474 for (var object of adapted) {
475 this._pendingPromises.push(self.runtime.instancesPromise(WebInsp ector.ContextMenu.Provider, object));
476 this._pendingTargets.push(object);
477 }
478 }
461 }, 479 },
462 480
463 __proto__: WebInspector.ContextSubMenuItem.prototype 481 __proto__: WebInspector.ContextSubMenuItem.prototype
464 } 482 }
465 483
466 /** 484 /**
467 * @interface 485 * @interface
468 */ 486 */
469 WebInspector.ContextMenu.Provider = function() { 487 WebInspector.ContextMenu.Provider = function() {
470 } 488 }
471 489
472 WebInspector.ContextMenu.Provider.prototype = { 490 WebInspector.ContextMenu.Provider.prototype = {
473 /** 491 /**
474 * @param {!Event} event 492 * @param {!Event} event
475 * @param {!WebInspector.ContextMenu} contextMenu 493 * @param {!WebInspector.ContextMenu} contextMenu
476 * @param {!Object} target 494 * @param {!Object} target
477 */ 495 */
478 appendApplicableItems: function(event, contextMenu, target) { } 496 appendApplicableItems: function(event, contextMenu, target) { }
479 } 497 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/sdk/module.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698