OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Creates a new list of extension commands. | 9 * Creates a new list of extension commands. |
10 * @param {Object=} opt_propertyBag Optional properties. | 10 * @param {Object=} opt_propertyBag Optional properties. |
(...skipping 15 matching lines...) Expand all Loading... | |
26 } | 26 } |
27 | 27 |
28 /** | 28 /** |
29 * Convert a keystroke event to string form, while taking into account | 29 * Convert a keystroke event to string form, while taking into account |
30 * (ignoring) invalid extension commands. | 30 * (ignoring) invalid extension commands. |
31 * @param {Event} event The keyboard event to convert. | 31 * @param {Event} event The keyboard event to convert. |
32 * @return {string} The keystroke as a string. | 32 * @return {string} The keystroke as a string. |
33 */ | 33 */ |
34 function keystrokeToString(event) { | 34 function keystrokeToString(event) { |
35 var output = ''; | 35 var output = ''; |
36 if (cr.isMac && event.metaKey) | |
Nico
2012/08/22 14:30:49
Do you need the cr.isMac here?
| |
37 output = 'Command+'; | |
36 if (event.ctrlKey) | 38 if (event.ctrlKey) |
37 output = 'Ctrl+'; | 39 output = 'Ctrl+'; |
38 if (!event.ctrlKey && event.altKey) | 40 if (!event.ctrlKey && event.altKey) |
39 output += 'Alt+'; | 41 output += 'Alt+'; |
40 if (event.shiftKey) | 42 if (event.shiftKey) |
41 output += 'Shift+'; | 43 output += 'Shift+'; |
42 if (validChar(event.keyCode)) | 44 if (validChar(event.keyCode)) |
43 output += String.fromCharCode('A'.charCodeAt(0) + event.keyCode - 65); | 45 output += String.fromCharCode('A'.charCodeAt(0) + event.keyCode - 65); |
44 return output; | 46 return output; |
45 } | 47 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 * @param {Event} event The keyboard event to consider. | 227 * @param {Event} event The keyboard event to consider. |
226 * @private | 228 * @private |
227 */ | 229 */ |
228 handleKey_: function(event) { | 230 handleKey_: function(event) { |
229 // While capturing, we prevent all events from bubbling, to prevent | 231 // While capturing, we prevent all events from bubbling, to prevent |
230 // shortcuts lacking the right modifier (F3 for example) from activating | 232 // shortcuts lacking the right modifier (F3 for example) from activating |
231 // and ending capture prematurely. | 233 // and ending capture prematurely. |
232 event.preventDefault(); | 234 event.preventDefault(); |
233 event.stopPropagation(); | 235 event.stopPropagation(); |
234 | 236 |
235 if (!event.ctrlKey && !event.altKey) | 237 if (!event.ctrlKey && !event.altKey && (!cr.isMac || !event.metaKey)) |
236 return; // Ctrl or Alt is a must. | 238 return; // Ctrl or Alt is a must (or Cmd on Mac). |
237 | 239 |
238 var keystroke = keystrokeToString(event); | 240 var keystroke = keystrokeToString(event); |
239 event.target.textContent = keystroke; | 241 event.target.textContent = keystroke; |
240 event.target.classList.add('contains-chars'); | 242 event.target.classList.add('contains-chars'); |
241 | 243 |
242 if (validChar(event.keyCode)) { | 244 if (validChar(event.keyCode)) { |
243 var node = event.target; | 245 var node = event.target; |
244 while (node && !node.id) | 246 while (node && !node.id) |
245 node = node.parentElement; | 247 node = node.parentElement; |
246 // The id is set to namespacePrefix-extensionId-commandName. We don't | 248 // The id is set to namespacePrefix-extensionId-commandName. We don't |
247 // care about the namespacePrefix (but we care about the other two). | 249 // care about the namespacePrefix (but we care about the other two). |
248 var id = node.id.substring(8, 40); | 250 var id = node.id.substring(8, 40); |
249 var command_name = node.id.substring(41); | 251 var command_name = node.id.substring(41); |
250 | 252 |
251 this.oldValue_ = keystroke; // Forget what the old value was. | 253 this.oldValue_ = keystroke; // Forget what the old value was. |
252 chrome.send('setExtensionCommandShortcut', | 254 chrome.send('setExtensionCommandShortcut', |
253 [id, command_name, keystroke]); | 255 [id, command_name, keystroke]); |
254 this.endCapture_(event); | 256 this.endCapture_(event); |
255 } | 257 } |
256 | 258 |
257 this.currentKeyEvent_ = event; | 259 this.currentKeyEvent_ = event; |
258 }, | 260 }, |
259 }; | 261 }; |
260 | 262 |
261 return { | 263 return { |
262 ExtensionCommandList: ExtensionCommandList | 264 ExtensionCommandList: ExtensionCommandList |
263 }; | 265 }; |
264 }); | 266 }); |
OLD | NEW |