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

Side by Side Diff: Source/devtools/front_end/ModuleManager.js

Issue 218613013: DevTools: Decouple shortcuts from actions, introduce shortcut contexts (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comments - take 1 Created 6 years, 8 months 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 this._cachedTypeClasses = {}; 53 this._cachedTypeClasses = {};
54 54
55 /** 55 /**
56 * @type {!Object.<string, !WebInspector.ModuleManager.ModuleDescriptor>} 56 * @type {!Object.<string, !WebInspector.ModuleManager.ModuleDescriptor>}
57 */ 57 */
58 this._descriptorsMap = {}; 58 this._descriptorsMap = {};
59 for (var i = 0; i < descriptors.length; ++i) 59 for (var i = 0; i < descriptors.length; ++i)
60 this._descriptorsMap[descriptors[i]["name"]] = descriptors[i]; 60 this._descriptorsMap[descriptors[i]["name"]] = descriptors[i];
61 } 61 }
62 62
63 /**
64 * @param {!WebInspector.ModuleManager.Extension} extension
65 * @param {?function(!Function):boolean} predicate
66 */
67 WebInspector.ModuleManager._checkExtensionApplicability = function(extension, pr edicate)
68 {
69 if (!predicate)
70 return false;
71 var contextTypes = /** @type {!Array.<string>|undefined} */ (extension.descr iptor().contextTypes);
72 if (!contextTypes)
73 return true;
74 var conjunction = !!extension.descriptor()["contextTypeConjunction"];
pfeldman 2014/04/17 10:40:25 I don't see it used. Lets not add it for now.
apavlov 2014/04/17 12:42:22 Done.
75 for (var i = 0; i < contextTypes.length; ++i) {
76 var contextType = /** @type {!Function} */ (window.eval(contextTypes[i]) );
77 var isMatching = predicate(contextType);
78 if (conjunction && !isMatching)
79 return false;
80 if (!conjunction && isMatching)
81 return true;
82 }
83 return conjunction;
84 }
85
86 /**
87 * @param {!WebInspector.ModuleManager.Extension} extension
88 * @param {?Object} context
89 * @return {boolean}
90 */
91 WebInspector.ModuleManager.isExtensionApplicableToContext = function(extension, context)
92 {
93 if (!context)
94 return true;
95 return WebInspector.ModuleManager._checkExtensionApplicability(extension, is InstanceOf);
96
97 /**
98 * @param {!Function} targetType
99 * @return {boolean}
100 */
101 function isInstanceOf(targetType)
102 {
103 return context instanceof targetType;
104 }
105 }
106
107 /**
108 * @param {!WebInspector.ModuleManager.Extension} extension
109 * @param {!Set.<!Function>=} currentContextTypes
110 * @return {boolean}
111 */
112 WebInspector.ModuleManager.isExtensionApplicableToContextTypes = function(extens ion, currentContextTypes)
113 {
114 if (!extension.descriptor().contextTypes)
115 return true;
116
117 return WebInspector.ModuleManager._checkExtensionApplicability(extension, cu rrentContextTypes ? isContextTypeKnown : null);
118
119 /**
120 * @param {!Function} targetType
121 * @return {boolean}
122 */
123 function isContextTypeKnown(targetType)
124 {
125 return currentContextTypes.contains(targetType);
126 }
127 }
128
63 WebInspector.ModuleManager.prototype = { 129 WebInspector.ModuleManager.prototype = {
64 /** 130 /**
65 * @param {!Array.<string>} configuration 131 * @param {!Array.<string>} configuration
66 */ 132 */
67 registerModules: function(configuration) 133 registerModules: function(configuration)
68 { 134 {
69 for (var i = 0; i < configuration.length; ++i) 135 for (var i = 0; i < configuration.length; ++i)
70 this.registerModule(configuration[i]); 136 this.registerModule(configuration[i]);
71 }, 137 },
72 138
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 return null; 397 return null;
332 return this._module._manager.resolve(this._type); 398 return this._module._manager.resolve(this._type);
333 }, 399 },
334 400
335 /** 401 /**
336 * @param {?Object} context 402 * @param {?Object} context
337 * @return {boolean} 403 * @return {boolean}
338 */ 404 */
339 isApplicable: function(context) 405 isApplicable: function(context)
340 { 406 {
341 var contextTypes = /** @type {!Array.<string>|undefined} */ (this._descr iptor.contextTypes); 407 return WebInspector.ModuleManager.isExtensionApplicableToContext(this, c ontext);
342 if (!contextTypes)
343 return true;
344 for (var i = 0; i < contextTypes.length; ++i) {
345 var contextType = /** @type {!Function} */ (window.eval(contextTypes [i]));
346 if (context instanceof contextType)
347 return true;
348 }
349 return false;
350 }, 408 },
351 409
352 /** 410 /**
353 * @return {?Object} 411 * @return {?Object}
354 */ 412 */
355 instance: function() 413 instance: function()
356 { 414 {
357 if (!this._className) 415 if (!this._className)
358 return null; 416 return null;
359 417
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 revealer.reveal(revealable, lineNumber); 463 revealer.reveal(revealable, lineNumber);
406 } 464 }
407 465
408 WebInspector.Revealer.prototype = { 466 WebInspector.Revealer.prototype = {
409 /** 467 /**
410 * @param {!Object} object 468 * @param {!Object} object
411 */ 469 */
412 reveal: function(object) {} 470 reveal: function(object) {}
413 } 471 }
414 472
415 /**
416 * @interface
417 */
418 WebInspector.ActionDelegate = function()
419 {
420 }
421
422 WebInspector.ActionDelegate.prototype = {
423 /**
424 * @param {!Event} event
425 * @return {boolean}
426 */
427 handleAction: function(event) {}
428 }
429
430 WebInspector.moduleManager = new WebInspector.ModuleManager(allDescriptors); 473 WebInspector.moduleManager = new WebInspector.ModuleManager(allDescriptors);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698