Chromium Code Reviews| 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 {Array<number>} @private */ | |
| 22 this.preventedKeys_ = []; | |
| 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.preventedKeys_.push(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 var wasDown = false; | |
| 68 var updatedKeys = []; | |
| 69 for (var i = 0; i < this.preventedKeys_.length; i++) { | |
|
dmazzoni
2016/12/06 07:25:22
If you make preventedKeys_ a Set(), I think you ca
David Tseng
2016/12/06 16:55:53
Sure. Was storing the entire event before. Changed
| |
| 70 var otherKeyCode = this.preventedKeys_[i]; | |
| 71 if (otherKeyCode == evt.keyCode) | |
| 72 wasDown = true; | |
| 73 else | |
| 74 updatedKeys.push(otherKeyCode); | |
| 75 } | |
| 76 this.preventedKeys_ = updatedKeys; | |
| 77 | |
| 78 if (wasDown) { | |
| 79 evt.preventDefault(); | |
| 80 evt.stopPropagation(); | |
| 81 } | |
| 62 return false; | 82 return false; |
| 63 }, | 83 }, |
| 64 | 84 |
| 65 /** | 85 /** |
| 66 * React to mode changes. | 86 * React to mode changes. |
| 67 * @param {ChromeVoxMode} newMode | 87 * @param {ChromeVoxMode} newMode |
| 68 * @param {ChromeVoxMode?} oldMode | 88 * @param {ChromeVoxMode?} oldMode |
| 69 */ | 89 */ |
| 70 onModeChanged: function(newMode, oldMode) { | 90 onModeChanged: function(newMode, oldMode) { |
| 71 if (newMode == ChromeVoxMode.CLASSIC || | 91 if (newMode == ChromeVoxMode.CLASSIC || |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 84 window['prefs'].switchToKeyMap('keymap_next'); | 104 window['prefs'].switchToKeyMap('keymap_next'); |
| 85 } else if (oldMode && | 105 } else if (oldMode && |
| 86 oldMode != ChromeVoxMode.CLASSIC && | 106 oldMode != ChromeVoxMode.CLASSIC && |
| 87 oldMode != ChromeVoxMode.CLASSIC_COMPAT) { | 107 oldMode != ChromeVoxMode.CLASSIC_COMPAT) { |
| 88 // Switching out of next. Intentionally do nothing when switching out of | 108 // Switching out of next. Intentionally do nothing when switching out of |
| 89 // an uninitialized |oldMode|. | 109 // an uninitialized |oldMode|. |
| 90 window['prefs'].switchToKeyMap('keymap_classic'); | 110 window['prefs'].switchToKeyMap('keymap_classic'); |
| 91 } | 111 } |
| 92 } | 112 } |
| 93 }; | 113 }; |
| OLD | NEW |