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

Side by Side Diff: Source/devtools/front_end/ui/ShortcutRegistry.js

Issue 377253002: DevTools: Add support for showing shortcuts based on shortcuts registry and use it for pause/resume… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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/ui/KeyboardShortcut.js ('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 // 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 * @param {!WebInspector.ActionRegistry} actionRegistry 7 * @param {!WebInspector.ActionRegistry} actionRegistry
8 */ 8 */
9 WebInspector.ShortcutRegistry = function(actionRegistry) 9 WebInspector.ShortcutRegistry = function(actionRegistry)
10 { 10 {
11 this._actionRegistry = actionRegistry; 11 this._actionRegistry = actionRegistry;
12 /** @type {!StringMultimap.<string>} */ 12 /** @type {!StringMultimap.<string>} */
13 this._defaultKeyToActions = new StringMultimap(); 13 this._defaultKeyToActions = new StringMultimap();
14 /** @type {!StringMultimap.<!WebInspector.KeyboardShortcut.Descriptor>} */
15 this._defaultActionToShortcut = new StringMultimap();
14 this._registerBindings(); 16 this._registerBindings();
15 } 17 }
16 18
17 WebInspector.ShortcutRegistry.prototype = { 19 WebInspector.ShortcutRegistry.prototype = {
18 /** 20 /**
19 * @param {number} key 21 * @param {number} key
20 * @return {!Array.<string>} 22 * @return {!Array.<string>}
21 */ 23 */
22 applicableActions: function(key) 24 applicableActions: function(key)
23 { 25 {
(...skipping 18 matching lines...) Expand all
42 /** 44 /**
43 * @param {number} key 45 * @param {number} key
44 * @return {!Set.<string>} 46 * @return {!Set.<string>}
45 */ 47 */
46 _defaultActionsForKey: function(key) 48 _defaultActionsForKey: function(key)
47 { 49 {
48 return this._defaultKeyToActions.get(String(key)); 50 return this._defaultKeyToActions.get(String(key));
49 }, 51 },
50 52
51 /** 53 /**
54 * @param {string} actionId
55 * @return {!Array.<!WebInspector.KeyboardShortcut.Descriptor>}
56 */
57 shortcutDescriptorsForAction: function(actionId)
58 {
59 return this._defaultActionToShortcut.get(actionId).values();
60 },
61
62 /**
52 * @param {!Array.<string>} actionIds 63 * @param {!Array.<string>} actionIds
53 * @return {!Array.<number>} 64 * @return {!Array.<number>}
54 */ 65 */
55 keysForActions: function(actionIds) 66 keysForActions: function(actionIds)
56 { 67 {
57 var actionIdSet = actionIds.keySet();
58 var result = []; 68 var result = [];
59 this._defaultKeyToActions.keys().forEach(function(key) { 69 for (var i = 0; i < actionIds.length; ++i) {
60 var actionIdsForKey = this._defaultKeyToActions.get(key); 70 var descriptors = this.shortcutDescriptorsForAction(actionIds[i]);
61 actionIdsForKey.values().some(function(actionId) { 71 for (var j = 0; j < descriptors.length; ++j)
62 if (actionIdSet.hasOwnProperty(actionId)) { 72 result.push(descriptors[j]);
63 result.push(key); 73 }
64 return true;
65 }
66 });
67 }, this);
68 return result; 74 return result;
69 }, 75 },
70 76
71 /** 77 /**
72 * @param {!KeyboardEvent} event 78 * @param {!KeyboardEvent} event
73 */ 79 */
74 handleShortcut: function(event) 80 handleShortcut: function(event)
75 { 81 {
76 this.handleKey(WebInspector.KeyboardShortcut.makeKeyFromEvent(event), ev ent.keyIdentifier, event); 82 this.handleKey(WebInspector.KeyboardShortcut.makeKeyFromEvent(event), ev ent.keyIdentifier, event);
77 }, 83 },
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 return result; 148 return result;
143 } 149 }
144 }, 150 },
145 151
146 /** 152 /**
147 * @param {string} actionId 153 * @param {string} actionId
148 * @param {string} shortcut 154 * @param {string} shortcut
149 */ 155 */
150 registerShortcut: function(actionId, shortcut) 156 registerShortcut: function(actionId, shortcut)
151 { 157 {
152 var key = WebInspector.KeyboardShortcut.makeKeyFromBindingShortcut(short cut); 158 var descriptor = WebInspector.KeyboardShortcut.makeDescriptorFromBinding Shortcut(shortcut);
153 if (!key) 159 if (!descriptor)
154 return; 160 return;
155 this._defaultKeyToActions.put(String(key), actionId); 161 this._defaultActionToShortcut.put(actionId, descriptor);
162 this._defaultKeyToActions.put(String(descriptor.key), actionId);
156 }, 163 },
157 164
158 /** 165 /**
159 * @param {?Event} event 166 * @param {?Event} event
160 */ 167 */
161 _onInput: function(event) 168 _onInput: function(event)
162 { 169 {
163 if (this._pendingActionTimer) { 170 if (this._pendingActionTimer) {
164 clearTimeout(this._pendingActionTimer); 171 clearTimeout(this._pendingActionTimer);
165 delete this._pendingActionTimer; 172 delete this._pendingActionTimer;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 * @constructor 217 * @constructor
211 */ 218 */
212 WebInspector.ShortcutRegistry.ForwardedShortcut = function() 219 WebInspector.ShortcutRegistry.ForwardedShortcut = function()
213 { 220 {
214 } 221 }
215 222
216 WebInspector.ShortcutRegistry.ForwardedShortcut.instance = new WebInspector.Shor tcutRegistry.ForwardedShortcut(); 223 WebInspector.ShortcutRegistry.ForwardedShortcut.instance = new WebInspector.Shor tcutRegistry.ForwardedShortcut();
217 224
218 /** @type {!WebInspector.ShortcutRegistry} */ 225 /** @type {!WebInspector.ShortcutRegistry} */
219 WebInspector.shortcutRegistry; 226 WebInspector.shortcutRegistry;
OLDNEW
« no previous file with comments | « Source/devtools/front_end/ui/KeyboardShortcut.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698