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

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

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 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
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 * @unrestricted 5 * @unrestricted
6 */ 6 */
7 WebInspector.ShortcutRegistry = class { 7 UI.ShortcutRegistry = class {
8 /** 8 /**
9 * @param {!WebInspector.ActionRegistry} actionRegistry 9 * @param {!UI.ActionRegistry} actionRegistry
10 * @param {!Document} document 10 * @param {!Document} document
11 */ 11 */
12 constructor(actionRegistry, document) { 12 constructor(actionRegistry, document) {
13 this._actionRegistry = actionRegistry; 13 this._actionRegistry = actionRegistry;
14 /** @type {!Multimap.<string, string>} */ 14 /** @type {!Multimap.<string, string>} */
15 this._defaultKeyToActions = new Multimap(); 15 this._defaultKeyToActions = new Multimap();
16 /** @type {!Multimap.<string, !WebInspector.KeyboardShortcut.Descriptor>} */ 16 /** @type {!Multimap.<string, !UI.KeyboardShortcut.Descriptor>} */
17 this._defaultActionToShortcut = new Multimap(); 17 this._defaultActionToShortcut = new Multimap();
18 this._registerBindings(document); 18 this._registerBindings(document);
19 } 19 }
20 20
21 /** 21 /**
22 * @param {number} key 22 * @param {number} key
23 * @return {!Array.<!WebInspector.Action>} 23 * @return {!Array.<!UI.Action>}
24 */ 24 */
25 _applicableActions(key) { 25 _applicableActions(key) {
26 return this._actionRegistry.applicableActions(this._defaultActionsForKey(key ).valuesArray(), WebInspector.context); 26 return this._actionRegistry.applicableActions(this._defaultActionsForKey(key ).valuesArray(), UI.context);
27 } 27 }
28 28
29 /** 29 /**
30 * @param {number} key 30 * @param {number} key
31 * @return {!Set.<string>} 31 * @return {!Set.<string>}
32 */ 32 */
33 _defaultActionsForKey(key) { 33 _defaultActionsForKey(key) {
34 return this._defaultKeyToActions.get(String(key)); 34 return this._defaultKeyToActions.get(String(key));
35 } 35 }
36 36
37 /** 37 /**
38 * @param {string} actionId 38 * @param {string} actionId
39 * @return {!Array.<!WebInspector.KeyboardShortcut.Descriptor>} 39 * @return {!Array.<!UI.KeyboardShortcut.Descriptor>}
40 */ 40 */
41 shortcutDescriptorsForAction(actionId) { 41 shortcutDescriptorsForAction(actionId) {
42 return this._defaultActionToShortcut.get(actionId).valuesArray(); 42 return this._defaultActionToShortcut.get(actionId).valuesArray();
43 } 43 }
44 44
45 /** 45 /**
46 * @param {!Array.<string>} actionIds 46 * @param {!Array.<string>} actionIds
47 * @return {!Array.<number>} 47 * @return {!Array.<number>}
48 */ 48 */
49 keysForActions(actionIds) { 49 keysForActions(actionIds) {
(...skipping 13 matching lines...) Expand all
63 shortcutTitleForAction(actionId) { 63 shortcutTitleForAction(actionId) {
64 var descriptors = this.shortcutDescriptorsForAction(actionId); 64 var descriptors = this.shortcutDescriptorsForAction(actionId);
65 if (descriptors.length) 65 if (descriptors.length)
66 return descriptors[0].name; 66 return descriptors[0].name;
67 } 67 }
68 68
69 /** 69 /**
70 * @param {!KeyboardEvent} event 70 * @param {!KeyboardEvent} event
71 */ 71 */
72 handleShortcut(event) { 72 handleShortcut(event) {
73 this.handleKey(WebInspector.KeyboardShortcut.makeKeyFromEvent(event), event. key, event); 73 this.handleKey(UI.KeyboardShortcut.makeKeyFromEvent(event), event.key, event );
74 } 74 }
75 75
76 /** 76 /**
77 * @param {number} key 77 * @param {number} key
78 * @param {string} domKey 78 * @param {string} domKey
79 * @param {!KeyboardEvent=} event 79 * @param {!KeyboardEvent=} event
80 */ 80 */
81 handleKey(key, domKey, event) { 81 handleKey(key, domKey, event) {
82 var keyModifiers = key >> 8; 82 var keyModifiers = key >> 8;
83 var actions = this._applicableActions(key); 83 var actions = this._applicableActions(key);
84 if (!actions.length) 84 if (!actions.length)
85 return; 85 return;
86 if (WebInspector.Dialog.hasInstance()) { 86 if (UI.Dialog.hasInstance()) {
87 if (event && !isPossiblyInputKey()) 87 if (event && !isPossiblyInputKey())
88 event.consume(true); 88 event.consume(true);
89 return; 89 return;
90 } 90 }
91 91
92 if (!isPossiblyInputKey()) { 92 if (!isPossiblyInputKey()) {
93 if (event) 93 if (event)
94 event.consume(true); 94 event.consume(true);
95 processNextAction.call(this, false); 95 processNextAction.call(this, false);
96 } else { 96 } else {
97 this._pendingActionTimer = setTimeout(processNextAction.bind(this, false), 0); 97 this._pendingActionTimer = setTimeout(processNextAction.bind(this, false), 0);
98 } 98 }
99 99
100 /** 100 /**
101 * @param {boolean} handled 101 * @param {boolean} handled
102 * @this {WebInspector.ShortcutRegistry} 102 * @this {UI.ShortcutRegistry}
103 */ 103 */
104 function processNextAction(handled) { 104 function processNextAction(handled) {
105 delete this._pendingActionTimer; 105 delete this._pendingActionTimer;
106 var action = actions.shift(); 106 var action = actions.shift();
107 if (!action || handled) 107 if (!action || handled)
108 return; 108 return;
109 109
110 action.execute().then(processNextAction.bind(this)); 110 action.execute().then(processNextAction.bind(this));
111 } 111 }
112 112
113 /** 113 /**
114 * @return {boolean} 114 * @return {boolean}
115 */ 115 */
116 function isPossiblyInputKey() { 116 function isPossiblyInputKey() {
117 if (!event || !WebInspector.isEditing() || /^F\d+|Control|Shift|Alt|Meta|E scape|Win|U\+001B$/.test(domKey)) 117 if (!event || !UI.isEditing() || /^F\d+|Control|Shift|Alt|Meta|Escape|Win| U\+001B$/.test(domKey))
118 return false; 118 return false;
119 119
120 if (!keyModifiers) 120 if (!keyModifiers)
121 return true; 121 return true;
122 122
123 var modifiers = WebInspector.KeyboardShortcut.Modifiers; 123 var modifiers = UI.KeyboardShortcut.Modifiers;
124 if ((keyModifiers & (modifiers.Ctrl | modifiers.Alt)) === (modifiers.Ctrl | modifiers.Alt)) 124 if ((keyModifiers & (modifiers.Ctrl | modifiers.Alt)) === (modifiers.Ctrl | modifiers.Alt))
125 return WebInspector.isWin(); 125 return Host.isWin();
126 126
127 return !hasModifier(modifiers.Ctrl) && !hasModifier(modifiers.Alt) && !has Modifier(modifiers.Meta); 127 return !hasModifier(modifiers.Ctrl) && !hasModifier(modifiers.Alt) && !has Modifier(modifiers.Meta);
128 } 128 }
129 129
130 /** 130 /**
131 * @param {number} mod 131 * @param {number} mod
132 * @return {boolean} 132 * @return {boolean}
133 */ 133 */
134 function hasModifier(mod) { 134 function hasModifier(mod) {
135 return !!(keyModifiers & mod); 135 return !!(keyModifiers & mod);
136 } 136 }
137 } 137 }
138 138
139 /** 139 /**
140 * @param {string} actionId 140 * @param {string} actionId
141 * @param {string} shortcut 141 * @param {string} shortcut
142 */ 142 */
143 registerShortcut(actionId, shortcut) { 143 registerShortcut(actionId, shortcut) {
144 var descriptor = WebInspector.KeyboardShortcut.makeDescriptorFromBindingShor tcut(shortcut); 144 var descriptor = UI.KeyboardShortcut.makeDescriptorFromBindingShortcut(short cut);
145 if (!descriptor) 145 if (!descriptor)
146 return; 146 return;
147 this._defaultActionToShortcut.set(actionId, descriptor); 147 this._defaultActionToShortcut.set(actionId, descriptor);
148 this._defaultKeyToActions.set(String(descriptor.key), actionId); 148 this._defaultKeyToActions.set(String(descriptor.key), actionId);
149 } 149 }
150 150
151 dismissPendingShortcutAction() { 151 dismissPendingShortcutAction() {
152 if (this._pendingActionTimer) { 152 if (this._pendingActionTimer) {
153 clearTimeout(this._pendingActionTimer); 153 clearTimeout(this._pendingActionTimer);
154 delete this._pendingActionTimer; 154 delete this._pendingActionTimer;
155 } 155 }
156 } 156 }
157 157
158 /** 158 /**
159 * @param {!Document} document 159 * @param {!Document} document
160 */ 160 */
161 _registerBindings(document) { 161 _registerBindings(document) {
162 document.addEventListener('input', this.dismissPendingShortcutAction.bind(th is), true); 162 document.addEventListener('input', this.dismissPendingShortcutAction.bind(th is), true);
163 var extensions = self.runtime.extensions(WebInspector.ActionDelegate); 163 var extensions = self.runtime.extensions(UI.ActionDelegate);
164 extensions.forEach(registerExtension, this); 164 extensions.forEach(registerExtension, this);
165 165
166 /** 166 /**
167 * @param {!Runtime.Extension} extension 167 * @param {!Runtime.Extension} extension
168 * @this {WebInspector.ShortcutRegistry} 168 * @this {UI.ShortcutRegistry}
169 */ 169 */
170 function registerExtension(extension) { 170 function registerExtension(extension) {
171 var descriptor = extension.descriptor(); 171 var descriptor = extension.descriptor();
172 var bindings = descriptor['bindings']; 172 var bindings = descriptor['bindings'];
173 for (var i = 0; bindings && i < bindings.length; ++i) { 173 for (var i = 0; bindings && i < bindings.length; ++i) {
174 if (!platformMatches(bindings[i].platform)) 174 if (!platformMatches(bindings[i].platform))
175 continue; 175 continue;
176 var shortcuts = bindings[i]['shortcut'].split(/\s+/); 176 var shortcuts = bindings[i]['shortcut'].split(/\s+/);
177 shortcuts.forEach(this.registerShortcut.bind(this, descriptor['actionId' ])); 177 shortcuts.forEach(this.registerShortcut.bind(this, descriptor['actionId' ]));
178 } 178 }
179 } 179 }
180 180
181 /** 181 /**
182 * @param {string=} platformsString 182 * @param {string=} platformsString
183 * @return {boolean} 183 * @return {boolean}
184 */ 184 */
185 function platformMatches(platformsString) { 185 function platformMatches(platformsString) {
186 if (!platformsString) 186 if (!platformsString)
187 return true; 187 return true;
188 var platforms = platformsString.split(','); 188 var platforms = platformsString.split(',');
189 var isMatch = false; 189 var isMatch = false;
190 var currentPlatform = WebInspector.platform(); 190 var currentPlatform = Host.platform();
191 for (var i = 0; !isMatch && i < platforms.length; ++i) 191 for (var i = 0; !isMatch && i < platforms.length; ++i)
192 isMatch = platforms[i] === currentPlatform; 192 isMatch = platforms[i] === currentPlatform;
193 return isMatch; 193 return isMatch;
194 } 194 }
195 } 195 }
196 }; 196 };
197 197
198 /** 198 /**
199 * @unrestricted 199 * @unrestricted
200 */ 200 */
201 WebInspector.ShortcutRegistry.ForwardedShortcut = class {}; 201 UI.ShortcutRegistry.ForwardedShortcut = class {};
202 202
203 WebInspector.ShortcutRegistry.ForwardedShortcut.instance = new WebInspector.Shor tcutRegistry.ForwardedShortcut(); 203 UI.ShortcutRegistry.ForwardedShortcut.instance = new UI.ShortcutRegistry.Forward edShortcut();
204 204
205 /** @type {!WebInspector.ShortcutRegistry} */ 205 /** @type {!UI.ShortcutRegistry} */
206 WebInspector.shortcutRegistry; 206 UI.shortcutRegistry;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698