| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // TODO(elichtenberg): Move into custom logger class or somewhere else. |
| 6 let debuggingEnabled = true; |
| 7 |
| 8 /** |
| 9 * Class to handle keyboard input. |
| 10 * |
| 11 * @constructor |
| 12 * @param {SwitchAccessInterface} switchAccess |
| 13 */ |
| 14 function KeyboardHandler(switchAccess) { |
| 15 /** |
| 16 * SwitchAccess reference. |
| 17 * @private {SwitchAccessInterface} |
| 18 */ |
| 19 this.switchAccess_ = switchAccess; |
| 20 |
| 21 this.init_(); |
| 22 }; |
| 23 |
| 24 KeyboardHandler.prototype = { |
| 25 /** |
| 26 * Set up key listener. |
| 27 * |
| 28 * @private |
| 29 */ |
| 30 init_: function() { |
| 31 document.addEventListener('keyup', this.handleKeyEvent_.bind(this)); |
| 32 }, |
| 33 |
| 34 /** |
| 35 * Handle a keyboard event by calling the appropriate SwitchAccess functions. |
| 36 * |
| 37 * @param {!Event} event |
| 38 * @private |
| 39 */ |
| 40 handleKeyEvent_: function(event) { |
| 41 switch (event.key) { |
| 42 case '1': |
| 43 console.log('1 = go to next element'); |
| 44 this.switchAccess_.moveToNode(true); |
| 45 break; |
| 46 case '2': |
| 47 console.log('2 = go to previous element'); |
| 48 this.switchAccess_.moveToNode(false); |
| 49 break; |
| 50 case '3': |
| 51 console.log('3 = do default on element'); |
| 52 this.switchAccess_.doDefault(); |
| 53 break; |
| 54 case '4': |
| 55 this.switchAccess_.showOptionsPage(); |
| 56 break; |
| 57 } |
| 58 if (debuggingEnabled) { |
| 59 switch (event.key) { |
| 60 case '6': |
| 61 console.log('6 = go to next element (debug mode)'); |
| 62 this.switchAccess_.debugMoveToNext(); |
| 63 break; |
| 64 case '7': |
| 65 console.log('7 = go to previous element (debug mode)'); |
| 66 this.switchAccess_.debugMoveToPrevious(); |
| 67 break; |
| 68 case '8': |
| 69 console.log('8 = go to child element (debug mode)'); |
| 70 this.switchAccess_.debugMoveToFirstChild(); |
| 71 break; |
| 72 case '9': |
| 73 console.log('9 = go to parent element (debug mode)'); |
| 74 this.switchAccess_.debugMoveToParent(); |
| 75 break; |
| 76 } |
| 77 } |
| 78 this.switchAccess_.performedUserAction(); |
| 79 } |
| 80 }; |
| OLD | NEW |