| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 * @fileoverview ChromeVox keyboard handler. | 6 * @fileoverview ChromeVox keyboard handler. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 goog.provide('BackgroundKeyboardHandler'); | 9 goog.provide('BackgroundKeyboardHandler'); |
| 10 | 10 |
| 11 goog.require('cvox.ChromeVoxKbHandler'); | 11 goog.require('cvox.ChromeVoxKbHandler'); |
| 12 | 12 |
| 13 /** @constructor */ | 13 /** @constructor */ |
| 14 BackgroundKeyboardHandler = function() { | 14 BackgroundKeyboardHandler = function() { |
| 15 // Classic keymap. | 15 // Classic keymap. |
| 16 cvox.ChromeVoxKbHandler.handlerKeyMap = cvox.KeyMap.fromDefaults(); | 16 cvox.ChromeVoxKbHandler.handlerKeyMap = cvox.KeyMap.fromDefaults(); |
| 17 | 17 |
| 18 /** @type {number} @private */ | 18 /** @type {number} @private */ |
| 19 this.passThroughKeyUpCount_ = 0; | 19 this.passThroughKeyUpCount_ = 0; |
| 20 | 20 |
| 21 /** @type {Set} @private */ |
| 22 this.eatenKeyDowns_ = new Set(); |
| 23 |
| 21 document.addEventListener('keydown', this.onKeyDown.bind(this), false); | 24 document.addEventListener('keydown', this.onKeyDown.bind(this), false); |
| 22 document.addEventListener('keyup', this.onKeyUp.bind(this), false); | 25 document.addEventListener('keyup', this.onKeyUp.bind(this), false); |
| 23 }; | 26 }; |
| 24 | 27 |
| 25 BackgroundKeyboardHandler.prototype = { | 28 BackgroundKeyboardHandler.prototype = { |
| 26 /** | 29 /** |
| 27 * Handles key down events. | 30 * Handles key down events. |
| 28 * @param {Event} evt The key down event to process. | 31 * @param {Event} evt The key down event to process. |
| 29 * @return {boolean} True if the default action should be performed. | 32 * @return {boolean} True if the default action should be performed. |
| 30 */ | 33 */ |
| 31 onKeyDown: function(evt) { | 34 onKeyDown: function(evt) { |
| 32 evt.stickyMode = cvox.ChromeVox.isStickyModeOn() && cvox.ChromeVox.isActive; | 35 evt.stickyMode = cvox.ChromeVox.isStickyModeOn() && cvox.ChromeVox.isActive; |
| 33 if (cvox.ChromeVox.passThroughMode) | 36 if (cvox.ChromeVox.passThroughMode) |
| 34 return false; | 37 return false; |
| 35 | 38 |
| 36 if (ChromeVoxState.instance.mode != ChromeVoxMode.CLASSIC && | 39 if (ChromeVoxState.instance.mode != ChromeVoxMode.CLASSIC && |
| 37 ChromeVoxState.instance.mode != ChromeVoxMode.NEXT_COMPAT && | 40 ChromeVoxState.instance.mode != ChromeVoxMode.NEXT_COMPAT && |
| 38 !cvox.ChromeVoxKbHandler.basicKeyDownActionsListener(evt)) { | 41 !cvox.ChromeVoxKbHandler.basicKeyDownActionsListener(evt)) { |
| 39 evt.preventDefault(); | 42 evt.preventDefault(); |
| 40 evt.stopPropagation(); | 43 evt.stopPropagation(); |
| 44 this.eatenKeyDowns_.add(evt.keyCode); |
| 41 } | 45 } |
| 42 Output.forceModeForNextSpeechUtterance(cvox.QueueMode.FLUSH); | 46 Output.forceModeForNextSpeechUtterance(cvox.QueueMode.FLUSH); |
| 43 return false; | 47 return false; |
| 44 }, | 48 }, |
| 45 | 49 |
| 46 /** | 50 /** |
| 47 * Handles key up events. | 51 * Handles key up events. |
| 48 * @param {Event} evt The key down event to process. | 52 * @param {Event} evt The key down event to process. |
| 49 * @return {boolean} True if the default action should be performed. | 53 * @return {boolean} True if the default action should be performed. |
| 50 */ | 54 */ |
| 51 onKeyUp: function(evt) { | 55 onKeyUp: function(evt) { |
| 52 // Reset pass through mode once a keyup (not involving the pass through key) | 56 // Reset pass through mode once a keyup (not involving the pass through key) |
| 53 // is seen. The pass through command involves three keys. | 57 // is seen. The pass through command involves three keys. |
| 54 if (cvox.ChromeVox.passThroughMode) { | 58 if (cvox.ChromeVox.passThroughMode) { |
| 55 if (this.passThroughKeyUpCount_ >= 3) { | 59 if (this.passThroughKeyUpCount_ >= 3) { |
| 56 cvox.ChromeVox.passThroughMode = false; | 60 cvox.ChromeVox.passThroughMode = false; |
| 57 this.passThroughKeyUpCount_ = 0; | 61 this.passThroughKeyUpCount_ = 0; |
| 58 } else { | 62 } else { |
| 59 this.passThroughKeyUpCount_++; | 63 this.passThroughKeyUpCount_++; |
| 60 } | 64 } |
| 61 } | 65 } |
| 66 |
| 67 if (this.eatenKeyDowns_.has(evt.keyCode)) { |
| 68 evt.preventDefault(); |
| 69 evt.stopPropagation(); |
| 70 this.eatenKeyDowns_.delete(evt.keyCode); |
| 71 } |
| 72 |
| 62 return false; | 73 return false; |
| 63 }, | 74 }, |
| 64 | 75 |
| 65 /** | 76 /** |
| 66 * React to mode changes. | 77 * React to mode changes. |
| 67 * @param {ChromeVoxMode} newMode | 78 * @param {ChromeVoxMode} newMode |
| 68 * @param {ChromeVoxMode?} oldMode | 79 * @param {ChromeVoxMode?} oldMode |
| 69 */ | 80 */ |
| 70 onModeChanged: function(newMode, oldMode) { | 81 onModeChanged: function(newMode, oldMode) { |
| 71 if (newMode == ChromeVoxMode.CLASSIC || | 82 if (newMode == ChromeVoxMode.CLASSIC || |
| (...skipping 12 matching lines...) Expand all Loading... |
| 84 window['prefs'].switchToKeyMap('keymap_next'); | 95 window['prefs'].switchToKeyMap('keymap_next'); |
| 85 } else if (oldMode && | 96 } else if (oldMode && |
| 86 oldMode != ChromeVoxMode.CLASSIC && | 97 oldMode != ChromeVoxMode.CLASSIC && |
| 87 oldMode != ChromeVoxMode.CLASSIC_COMPAT) { | 98 oldMode != ChromeVoxMode.CLASSIC_COMPAT) { |
| 88 // Switching out of next. Intentionally do nothing when switching out of | 99 // Switching out of next. Intentionally do nothing when switching out of |
| 89 // an uninitialized |oldMode|. | 100 // an uninitialized |oldMode|. |
| 90 window['prefs'].switchToKeyMap('keymap_classic'); | 101 window['prefs'].switchToKeyMap('keymap_classic'); |
| 91 } | 102 } |
| 92 } | 103 } |
| 93 }; | 104 }; |
| OLD | NEW |