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

Side by Side Diff: chrome/browser/resources/extensions/extension_command_list.js

Issue 23523019: Enable user assign media keys in chrome://extensions page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 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
« no previous file with comments | « no previous file | 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 (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.
11 * @constructor 11 * @constructor
12 * @extends {cr.ui.div} 12 * @extends {cr.ui.div}
13 */ 13 */
14 var ExtensionCommandList = cr.ui.define('div'); 14 var ExtensionCommandList = cr.ui.define('div');
15 15
16 /** @const */ var keyComma = 188; 16 /** @const */ var keyComma = 188;
17 /** @const */ var keyDel = 46; 17 /** @const */ var keyDel = 46;
18 /** @const */ var keyDown = 40; 18 /** @const */ var keyDown = 40;
19 /** @const */ var keyEnd = 35; 19 /** @const */ var keyEnd = 35;
20 /** @const */ var keyHome = 36; 20 /** @const */ var keyHome = 36;
21 /** @const */ var keyIns = 45; 21 /** @const */ var keyIns = 45;
22 /** @const */ var keyLeft = 37; 22 /** @const */ var keyLeft = 37;
23 /** @const */ var keyPageDown = 34; 23 /** @const */ var keyPageDown = 34;
24 /** @const */ var keyPageUp = 33; 24 /** @const */ var keyPageUp = 33;
25 /** @const */ var keyPeriod = 190; 25 /** @const */ var keyPeriod = 190;
26 /** @const */ var keyRight = 39; 26 /** @const */ var keyRight = 39;
27 /** @const */ var keyTab = 9; 27 /** @const */ var keyTab = 9;
28 /** @const */ var keyUp = 38; 28 /** @const */ var keyUp = 38;
29 /** @const */ var keyMediaNextTrack = 176;
30 /** @const */ var keyMediaPrevTrack = 177;
31 /** @const */ var keyMediaStop = 178;
32 /** @const */ var keyMediaPlayPause = 179;
Finnur 2013/09/04 11:28:12 The list is alphabetical so this should not be at
zhchbin 2013/09/04 12:50:03 Done.
29 33
30 /** 34 /**
31 * Returns whether the passed in |keyCode| is a valid extension command 35 * Returns whether the passed in |keyCode| is a valid extension command
32 * char or not. This is restricted to A-Z and 0-9 (ignoring modifiers) at 36 * char or not. This is restricted to A-Z and 0-9 (ignoring modifiers) at
33 * the moment. 37 * the moment.
34 * @param {int} keyCode The keycode to consider. 38 * @param {int} keyCode The keycode to consider.
35 * @return {boolean} Returns whether the char is valid. 39 * @return {boolean} Returns whether the char is valid.
36 */ 40 */
37 function validChar(keyCode) { 41 function validChar(keyCode) {
38 return keyCode == keyComma || 42 return keyCode == keyComma ||
39 keyCode == keyDel || 43 keyCode == keyDel ||
40 keyCode == keyDown || 44 keyCode == keyDown ||
41 keyCode == keyEnd || 45 keyCode == keyEnd ||
42 keyCode == keyHome || 46 keyCode == keyHome ||
43 keyCode == keyIns || 47 keyCode == keyIns ||
44 keyCode == keyLeft || 48 keyCode == keyLeft ||
45 keyCode == keyPageDown || 49 keyCode == keyPageDown ||
46 keyCode == keyPageUp || 50 keyCode == keyPageUp ||
47 keyCode == keyPeriod || 51 keyCode == keyPeriod ||
48 keyCode == keyRight || 52 keyCode == keyRight ||
49 keyCode == keyTab || 53 keyCode == keyTab ||
50 keyCode == keyUp || 54 keyCode == keyUp ||
55 keyCode == keyMediaNextTrack ||
56 keyCode == keyMediaPrevTrack ||
57 keyCode == keyMediaStop ||
58 keyCode == keyMediaPlayPause ||
Finnur 2013/09/04 11:28:12 Same here.
zhchbin 2013/09/04 12:50:03 Done.
51 (keyCode >= 'A'.charCodeAt(0) && keyCode <= 'Z'.charCodeAt(0)) || 59 (keyCode >= 'A'.charCodeAt(0) && keyCode <= 'Z'.charCodeAt(0)) ||
52 (keyCode >= '0'.charCodeAt(0) && keyCode <= '9'.charCodeAt(0)); 60 (keyCode >= '0'.charCodeAt(0) && keyCode <= '9'.charCodeAt(0));
53 } 61 }
54 62
55 /** 63 /**
56 * Convert a keystroke event to string form, while taking into account 64 * Convert a keystroke event to string form, while taking into account
57 * (ignoring) invalid extension commands. 65 * (ignoring) invalid extension commands.
58 * @param {Event} event The keyboard event to convert. 66 * @param {Event} event The keyboard event to convert.
59 * @return {string} The keystroke as a string. 67 * @return {string} The keystroke as a string.
60 */ 68 */
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 case keyPageUp: 103 case keyPageUp:
96 output += 'PageUp'; break; 104 output += 'PageUp'; break;
97 case keyPeriod: 105 case keyPeriod:
98 output += 'Period'; break; 106 output += 'Period'; break;
99 case keyRight: 107 case keyRight:
100 output += 'Right'; break; 108 output += 'Right'; break;
101 case keyTab: 109 case keyTab:
102 output += 'Tab'; break; 110 output += 'Tab'; break;
103 case keyUp: 111 case keyUp:
104 output += 'Up'; break; 112 output += 'Up'; break;
113 case keyMediaNextTrack:
114 output += 'MediaNextTrack'; break;
115 case keyMediaPrevTrack:
116 output += 'MediaPrevTrack'; break;
117 case keyMediaStop:
118 output += 'MediaStop'; break;
119 case keyMediaPlayPause:
120 output += 'MediaPlayPause'; break;
Finnur 2013/09/04 11:28:12 Same here.
zhchbin 2013/09/04 12:50:03 Done.
105 } 121 }
106 } 122 }
107 } 123 }
108 124
109 return output; 125 return output;
110 } 126 }
111 127
128 /**
129 * Returns whether the passed in |keyCode| is a keycode of media key. This is
130 * restricted to 'MediaNextTrack', 'MediaPrevTrack', 'MediaStop',
131 * 'MediaPlayPause' at the moment.
132 * @param {int} keyCode The keycode to consider.
133 * @return {boolean} Returns whether the keycode is media key.
134 */
135 function isMediaKey(keyCode) {
Finnur 2013/09/04 11:28:12 I'd like to make this function a bit more general,
zhchbin 2013/09/04 12:50:03 Done with using a enum: /** * Enum for wheth
136 return keyCode == keyMediaNextTrack ||
137 keyCode == keyMediaPrevTrack ||
138 keyCode == keyMediaStop ||
139 keyCode == keyMediaPlayPause;
140 }
141
112 ExtensionCommandList.prototype = { 142 ExtensionCommandList.prototype = {
113 __proto__: HTMLDivElement.prototype, 143 __proto__: HTMLDivElement.prototype,
114 144
115 /** 145 /**
116 * While capturing, this records the current (last) keyboard event generated 146 * While capturing, this records the current (last) keyboard event generated
117 * by the user. Will be |null| after capture and during capture when no 147 * by the user. Will be |null| after capture and during capture when no
118 * keyboard event has been generated. 148 * keyboard event has been generated.
119 * @type: {keyboard event}. 149 * @type: {keyboard event}.
120 * @private 150 * @private
121 */ 151 */
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 * @param {Event} event The keyboard event to consider. 346 * @param {Event} event The keyboard event to consider.
317 * @private 347 * @private
318 */ 348 */
319 handleKey_: function(event) { 349 handleKey_: function(event) {
320 // While capturing, we prevent all events from bubbling, to prevent 350 // While capturing, we prevent all events from bubbling, to prevent
321 // shortcuts lacking the right modifier (F3 for example) from activating 351 // shortcuts lacking the right modifier (F3 for example) from activating
322 // and ending capture prematurely. 352 // and ending capture prematurely.
323 event.preventDefault(); 353 event.preventDefault();
324 event.stopPropagation(); 354 event.stopPropagation();
325 355
326 if (!event.ctrlKey && !event.altKey && (!cr.isMac || !event.metaKey)) 356 if (!event.ctrlKey && !event.altKey && (!cr.isMac || !event.metaKey) &&
327 return; // Ctrl or Alt is a must (or Cmd on Mac). 357 !isMediaKey(event.keyCode)) {
358 // Ctrl or Alt is a must (or Cmd on Mac), except for Media Keys.
359 return;
360 }
361
362 // Modifiers can not be used in combination with the Media Keys.
363 if (isMediaKey(event.keyCode)) {
364 if (event.ctrlKey || event.altKey || (cr.isMac && event.metaKey) ||
365 event.shiftKey)
366 return;
367 }
Finnur 2013/09/04 11:28:12 I think this is a bit more readable: function has
zhchbin 2013/09/04 12:50:03 Done with still using a boolean for countShiftAsMo
328 368
329 var shortcutNode = this.capturingElement_; 369 var shortcutNode = this.capturingElement_;
330 var keystroke = keystrokeToString(event); 370 var keystroke = keystrokeToString(event);
331 shortcutNode.textContent = keystroke; 371 shortcutNode.textContent = keystroke;
332 event.target.classList.add('contains-chars'); 372 event.target.classList.add('contains-chars');
333 373
334 if (validChar(event.keyCode)) { 374 if (validChar(event.keyCode)) {
335 var node = event.target; 375 var node = event.target;
336 while (node && !node.id) 376 while (node && !node.id)
337 node = node.parentElement; 377 node = node.parentElement;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 namespace.length + 1 + kExtensionIdLength), 425 namespace.length + 1 + kExtensionIdLength),
386 commandName: id.substring(namespace.length + 1 + kExtensionIdLength + 1) 426 commandName: id.substring(namespace.length + 1 + kExtensionIdLength + 1)
387 }; 427 };
388 }, 428 },
389 }; 429 };
390 430
391 return { 431 return {
392 ExtensionCommandList: ExtensionCommandList 432 ExtensionCommandList: ExtensionCommandList
393 }; 433 };
394 }); 434 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698