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

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

Issue 218613013: DevTools: Decouple shortcuts from actions, introduce shortcut contexts (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased patch 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
« no previous file with comments | « Source/devtools/front_end/AdvancedSearchView.js ('k') | Source/devtools/front_end/Dialog.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 */ 7 */
8 WebInspector.Context = function() 8 WebInspector.Context = function()
9 { 9 {
10 this._flavors = new Map(); 10 this._flavors = new Map();
11 this._eventDispatchers = new Map(); 11 this._eventDispatchers = new Map();
12 } 12 }
13 13
14 /** 14 /**
15 * @enum {string} 15 * @enum {string}
16 */ 16 */
17 WebInspector.Context.Events = { 17 WebInspector.Context.Events = {
18 FlavorChanged: "FlavorChanged" 18 FlavorChanged: "FlavorChanged"
19 } 19 }
20 20
21 WebInspector.Context.prototype = { 21 WebInspector.Context.prototype = {
22 /** 22 /**
23 * @param {function(new:T)} flavorType 23 * @param {function(new:T, ...)} flavorType
24 * @param {?T} flavorValue 24 * @param {?T} flavorValue
25 * @template T 25 * @template T
26 */ 26 */
27 setFlavor: function(flavorType, flavorValue) 27 setFlavor: function(flavorType, flavorValue)
28 { 28 {
29 var value = this._flavors.get(flavorType) || null; 29 var value = this._flavors.get(flavorType) || null;
30 if (value === flavorValue) 30 if (value === flavorValue)
31 return; 31 return;
32 if (flavorValue) 32 if (flavorValue)
33 this._flavors.put(flavorType, flavorValue); 33 this._flavors.put(flavorType, flavorValue);
34 else 34 else
35 this._flavors.remove(flavorType); 35 this._flavors.remove(flavorType);
36 36
37 this._dispatchFlavorChange(flavorType, flavorValue); 37 this._dispatchFlavorChange(flavorType, flavorValue);
38 }, 38 },
39 39
40 /** 40 /**
41 * @param {function(new:T)} flavorType 41 * @param {function(new:T, ...)} flavorType
42 * @param {?T} flavorValue 42 * @param {?T} flavorValue
43 * @template T 43 * @template T
44 */ 44 */
45 _dispatchFlavorChange: function(flavorType, flavorValue) 45 _dispatchFlavorChange: function(flavorType, flavorValue)
46 { 46 {
47 var dispatcher = this._eventDispatchers.get(flavorType); 47 var dispatcher = this._eventDispatchers.get(flavorType);
48 if (!dispatcher) 48 if (!dispatcher)
49 return; 49 return;
50 dispatcher.dispatchEventToListeners(WebInspector.Context.Events.FlavorCh anged, flavorValue); 50 dispatcher.dispatchEventToListeners(WebInspector.Context.Events.FlavorCh anged, flavorValue);
51 }, 51 },
52 52
53 /** 53 /**
54 * @param {function(new:Object)} flavorType 54 * @param {function(new:Object, ...)} flavorType
55 * @param {function(!WebInspector.Event)} listener 55 * @param {function(!WebInspector.Event)} listener
56 * @param {!Object=} thisObject 56 * @param {!Object=} thisObject
57 */ 57 */
58 addFlavorChangeListener: function(flavorType, listener, thisObject) 58 addFlavorChangeListener: function(flavorType, listener, thisObject)
59 { 59 {
60 var dispatcher = this._eventDispatchers.get(flavorType); 60 var dispatcher = this._eventDispatchers.get(flavorType);
61 if (!dispatcher) { 61 if (!dispatcher) {
62 dispatcher = new WebInspector.Object(); 62 dispatcher = new WebInspector.Object();
63 this._eventDispatchers.put(flavorType, dispatcher); 63 this._eventDispatchers.put(flavorType, dispatcher);
64 } 64 }
65 dispatcher.addEventListener(WebInspector.Context.Events.FlavorChanged, l istener, thisObject); 65 dispatcher.addEventListener(WebInspector.Context.Events.FlavorChanged, l istener, thisObject);
66 }, 66 },
67 67
68 /** 68 /**
69 * @param {function(new:Object)} flavorType 69 * @param {function(new:Object, ...)} flavorType
70 * @param {function(!WebInspector.Event)} listener 70 * @param {function(!WebInspector.Event)} listener
71 * @param {!Object=} thisObject 71 * @param {!Object=} thisObject
72 */ 72 */
73 removeFlavorChangeListener: function(flavorType, listener, thisObject) 73 removeFlavorChangeListener: function(flavorType, listener, thisObject)
74 { 74 {
75 var dispatcher = this._eventDispatchers.get(flavorType); 75 var dispatcher = this._eventDispatchers.get(flavorType);
76 if (!dispatcher) 76 if (!dispatcher)
77 return; 77 return;
78 dispatcher.removeEventListener(WebInspector.Context.Events.FlavorChanged , listener, thisObject); 78 dispatcher.removeEventListener(WebInspector.Context.Events.FlavorChanged , listener, thisObject);
79 if (!dispatcher.hasEventListeners(WebInspector.Context.Events.FlavorChan ged)) 79 if (!dispatcher.hasEventListeners(WebInspector.Context.Events.FlavorChan ged))
80 this._eventDispatchers.remove(flavorType); 80 this._eventDispatchers.remove(flavorType);
81 }, 81 },
82 82
83 /** 83 /**
84 * @param {function(new:T)} flavorType 84 * @param {function(new:T, ...)} flavorType
85 * @return {?T} 85 * @return {?T}
86 * @template T 86 * @template T
87 */ 87 */
88 flavor: function(flavorType) 88 flavor: function(flavorType)
89 { 89 {
90 return this._flavors.get(flavorType) || null; 90 return this._flavors.get(flavorType) || null;
91 }, 91 },
92 92
93 /** 93 /**
94 * @return {!Array.<function(new:Object)>} 94 * @return {!Array.<function(new:Object, ...)>}
95 */ 95 */
96 flavors: function() 96 flavors: function()
97 { 97 {
98 return this._flavors.keys(); 98 return this._flavors.keys();
99 },
100
101 /**
102 * @param {!Array.<!WebInspector.ModuleManager.Extension>} extensions
103 * @return {!Set.<!WebInspector.ModuleManager.Extension>}
104 */
105 applicableExtensions: function(extensions)
106 {
107 var targetExtensionSet = new Set();
108
109 var availableFlavors = Set.fromArray(this.flavors());
110 extensions.forEach(function(extension) {
111 if (WebInspector.ModuleManager.isExtensionApplicableToContextTypes(e xtension, availableFlavors))
112 targetExtensionSet.add(extension);
113 });
114
115 return targetExtensionSet;
99 } 116 }
100 } 117 }
101 118
102 WebInspector.context = new WebInspector.Context(); 119 WebInspector.context = new WebInspector.Context();
OLDNEW
« no previous file with comments | « Source/devtools/front_end/AdvancedSearchView.js ('k') | Source/devtools/front_end/Dialog.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698