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

Side by Side Diff: chrome/browser/resources/chromeos/keyboard/keyboard_utils.js

Issue 570503002: Compile chrome://settings, part 6 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@H_options_errors_4
Patch Set: fix asserts, rebase Created 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 * Namespace for keyboard utility functions. 6 * Namespace for keyboard utility functions.
7 */ 7 */
8 var keyboard = {}; 8 var keyboard = {};
9 9
10 /** 10 /**
11 * Swallows keypress and keyup events of arrow keys. 11 * Swallows keypress and keyup events of arrow keys.
12 * @param {KeyboardEvent} event Raised event. 12 * @param {Event} event Raised event.
13 * @private 13 * @private
14 */ 14 */
15 keyboard.onKeyIgnore_ = function(event) { 15 keyboard.onKeyIgnore_ = function(event) {
16 event = /** @type {KeyboardEvent} */(event);
17
16 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) 18 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey)
17 return; 19 return;
18 20
19 if (event.keyIdentifier == 'Left' || 21 if (event.keyIdentifier == 'Left' ||
20 event.keyIdentifier == 'Right' || 22 event.keyIdentifier == 'Right' ||
21 event.keyIdentifier == 'Up' || 23 event.keyIdentifier == 'Up' ||
22 event.keyIdentifier == 'Down') { 24 event.keyIdentifier == 'Down') {
23 event.stopPropagation(); 25 event.stopPropagation();
24 event.preventDefault(); 26 event.preventDefault();
25 } 27 }
26 }; 28 };
27 29
28 /** 30 /**
29 * Converts arrow keys into tab/shift-tab key events. 31 * Converts arrow keys into tab/shift-tab key events.
30 * @param {KeyboardEvent} event Raised event. 32 * @param {Event} event Raised event.
31 * @private 33 * @private
32 */ 34 */
33 keyboard.onKeyDown_ = function(event) { 35 keyboard.onKeyDown_ = function(event) {
34 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) 36 event = /** @type {KeyboardEvent} */(event);
35 return;
36 37
37 var needsUpDownKeys = event.target.classList.contains('needs-up-down-keys'); 38 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey)
39 return;
38 40
39 if (event.keyIdentifier == 'Left' || 41 var needsUpDownKeys = event.target.classList.contains('needs-up-down-keys');
40 (!needsUpDownKeys && event.keyIdentifier == 'Up')) { 42
41 keyboard.raiseKeyFocusPrevious(document.activeElement); 43 if (event.keyIdentifier == 'Left' ||
42 event.stopPropagation(); 44 (!needsUpDownKeys && event.keyIdentifier == 'Up')) {
43 event.preventDefault(); 45 keyboard.raiseKeyFocusPrevious(document.activeElement);
44 } else if (event.keyIdentifier == 'Right' || 46 event.stopPropagation();
45 (!needsUpDownKeys && event.keyIdentifier == 'Down')) { 47 event.preventDefault();
46 keyboard.raiseKeyFocusNext(document.activeElement); 48 } else if (event.keyIdentifier == 'Right' ||
47 event.stopPropagation(); 49 (!needsUpDownKeys && event.keyIdentifier == 'Down')) {
48 event.preventDefault(); 50 keyboard.raiseKeyFocusNext(document.activeElement);
49 } 51 event.stopPropagation();
52 event.preventDefault();
53 }
50 }; 54 };
51 55
52 /** 56 /**
53 * Raises tab/shift-tab keyboard events. 57 * Raises tab/shift-tab keyboard events.
54 * @param {HTMLElement} element Element that should receive the event. 58 * @param {HTMLElement} element Element that should receive the event.
55 * @param {string} eventType Keyboard event type. 59 * @param {string} eventType Keyboard event type.
56 * @param {boolean} shift True if shift should be on. 60 * @param {boolean} shift True if shift should be on.
57 * @private 61 * @private
58 */ 62 */
59 keyboard.raiseTabKeyEvent_ = function(element, eventType, shift) { 63 keyboard.raiseTabKeyEvent_ = function(element, eventType, shift) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 * Initializes event handling for arrow keys driven focus flow. 100 * Initializes event handling for arrow keys driven focus flow.
97 */ 101 */
98 keyboard.initializeKeyboardFlow = function() { 102 keyboard.initializeKeyboardFlow = function() {
99 document.addEventListener('keydown', 103 document.addEventListener('keydown',
100 keyboard.onKeyDown_, true); 104 keyboard.onKeyDown_, true);
101 document.addEventListener('keypress', 105 document.addEventListener('keypress',
102 keyboard.onKeyIgnore_, true); 106 keyboard.onKeyIgnore_, true);
103 document.addEventListener('keyup', 107 document.addEventListener('keyup',
104 keyboard.onKeyIgnore_, true); 108 keyboard.onKeyIgnore_, true);
105 }; 109 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698