| OLD | NEW |
| 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 {Event} 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); | 16 event = /** @type {KeyboardEvent} */(event); |
| 17 | 17 |
| 18 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) | 18 if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) |
| 19 return; | 19 return; |
| 20 | 20 |
| 21 if (event.keyIdentifier == 'Left' || | 21 if (event.key == 'ArrowLeft' || |
| 22 event.keyIdentifier == 'Right' || | 22 event.key == 'ArrowRight' || |
| 23 event.keyIdentifier == 'Up' || | 23 event.key == 'ArrowUp' || |
| 24 event.keyIdentifier == 'Down') { | 24 event.key == 'ArrowDown') { |
| 25 event.stopPropagation(); | 25 event.stopPropagation(); |
| 26 event.preventDefault(); | 26 event.preventDefault(); |
| 27 } | 27 } |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * Converts arrow keys into tab/shift-tab key events. | 31 * Converts arrow keys into tab/shift-tab key events. |
| 32 * @param {Event} event Raised event. | 32 * @param {Event} event Raised event. |
| 33 * @private | 33 * @private |
| 34 */ | 34 */ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 46 // $ is defined differently depending on how this file gets executed; we have | 46 // $ is defined differently depending on how this file gets executed; we have |
| 47 // to use document.getElementById to get consistent behavior. | 47 // to use document.getElementById to get consistent behavior. |
| 48 // | 48 // |
| 49 // See crbug.com/543865. | 49 // See crbug.com/543865. |
| 50 if (document.activeElement === | 50 if (document.activeElement === |
| 51 document.getElementById('oauth-enroll-auth-view')) | 51 document.getElementById('oauth-enroll-auth-view')) |
| 52 return; | 52 return; |
| 53 | 53 |
| 54 var needsUpDownKeys = event.target.classList.contains('needs-up-down-keys'); | 54 var needsUpDownKeys = event.target.classList.contains('needs-up-down-keys'); |
| 55 | 55 |
| 56 if (event.keyIdentifier == 'Left' || | 56 if (event.key == 'ArrowLeft' || |
| 57 (!needsUpDownKeys && event.keyIdentifier == 'Up')) { | 57 (!needsUpDownKeys && event.key == 'ArrowUp')) { |
| 58 keyboard.raiseKeyFocusPrevious(document.activeElement); | 58 keyboard.raiseKeyFocusPrevious(document.activeElement); |
| 59 event.stopPropagation(); | 59 event.stopPropagation(); |
| 60 event.preventDefault(); | 60 event.preventDefault(); |
| 61 } else if (event.keyIdentifier == 'Right' || | 61 } else if (event.key == 'ArrowRight' || |
| 62 (!needsUpDownKeys && event.keyIdentifier == 'Down')) { | 62 (!needsUpDownKeys && event.key == 'ArrowDown')) { |
| 63 keyboard.raiseKeyFocusNext(document.activeElement); | 63 keyboard.raiseKeyFocusNext(document.activeElement); |
| 64 event.stopPropagation(); | 64 event.stopPropagation(); |
| 65 event.preventDefault(); | 65 event.preventDefault(); |
| 66 } | 66 } |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * Raises tab/shift-tab keyboard events. | 70 * Raises tab/shift-tab keyboard events. |
| 71 * @param {HTMLElement} element Element that should receive the event. | 71 * @param {HTMLElement} element Element that should receive the event. |
| 72 * @param {string} eventType Keyboard event type. | 72 * @param {string} eventType Keyboard event type. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 * Initializes event handling for arrow keys driven focus flow. | 113 * Initializes event handling for arrow keys driven focus flow. |
| 114 */ | 114 */ |
| 115 keyboard.initializeKeyboardFlow = function() { | 115 keyboard.initializeKeyboardFlow = function() { |
| 116 document.addEventListener('keydown', | 116 document.addEventListener('keydown', |
| 117 keyboard.onKeyDown_, true); | 117 keyboard.onKeyDown_, true); |
| 118 document.addEventListener('keypress', | 118 document.addEventListener('keypress', |
| 119 keyboard.onKeyIgnore_, true); | 119 keyboard.onKeyIgnore_, true); |
| 120 document.addEventListener('keyup', | 120 document.addEventListener('keyup', |
| 121 keyboard.onKeyIgnore_, true); | 121 keyboard.onKeyIgnore_, true); |
| 122 }; | 122 }; |
| OLD | NEW |