Chromium Code Reviews| 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 /** | |
| 6 * @fileoverview Manages a sequence of braille key events. | |
| 7 */ | |
| 8 | |
| 9 goog.provide('BrailleKeyEventSequenceReducer'); | |
| 10 | |
| 11 goog.require('Output'); | |
| 12 goog.require('cvox.BrailleKeyEvent'); | |
| 13 | |
| 14 /** | |
| 15 * A class that transforms a sequence of braille key events into a standard key | |
| 16 * event. | |
| 17 * @constructor | |
| 18 */ | |
| 19 BrailleKeyEventSequenceReducer = function() { | |
| 20 /** @private {Object} */ | |
|
dmazzoni
2017/04/17 04:53:25
Use a more specific type. Looks like a nullable re
| |
| 21 this.incrementalKey_ = null; | |
| 22 }; | |
| 23 | |
| 24 BrailleKeyEventSequenceReducer.prototype = { | |
| 25 /** | |
| 26 * Accumulates and optionally modifies in-coming braille key events. | |
| 27 * @param {cvox.BrailleKeyEvent} evt | |
| 28 * @return {boolean} False to continue event propagation. | |
| 29 */ | |
| 30 onBrailleKeyEvent: function(evt) { | |
| 31 var standardKeyCode; | |
| 32 var dots = evt.brailleDots; | |
| 33 if (!dots) { | |
| 34 this.incrementalKey_ = {}; | |
| 35 return false; | |
| 36 } | |
| 37 | |
| 38 if (evt.command == cvox.BrailleKeyCommand.CHORD) { | |
| 39 Output.forceModeForNextSpeechUtterance(cvox.QueueMode.CATEGORY_FLUSH); | |
| 40 var modifiers = cvox.BrailleKeyEvent.brailleDotsToModifiers[dots]; | |
| 41 | |
| 42 // Check for a modifier mapping. | |
| 43 if (modifiers) { | |
| 44 this.incrementalKey_ = this.incrementalKey_ || {}; | |
| 45 for (var key in modifiers) { | |
| 46 this.incrementalKey_[key] = true; | |
| 47 } | |
| 48 | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 // Check for a chord to standard key mapping. | |
| 53 standardKeyCode = | |
| 54 cvox.BrailleKeyEvent.brailleChordsToStandardKeyCode[dots]; | |
| 55 } | |
| 56 | |
| 57 // Check for a 'dots' command, which is typed on the keyboard with a | |
| 58 // previous incremental key press. | |
| 59 if (evt.command == cvox.BrailleKeyCommand.DOTS && this.incrementalKey_) { | |
| 60 // Check if this braille pattern has a standard key mapping. | |
| 61 standardKeyCode = | |
| 62 cvox.BrailleKeyEvent.brailleDotsToStandardKeyCode[dots]; | |
| 63 } | |
| 64 | |
| 65 if (standardKeyCode) { | |
| 66 evt.command = cvox.BrailleKeyCommand.STANDARD_KEY; | |
| 67 evt.standardKeyCode = standardKeyCode; | |
| 68 if (this.incrementalKey_) { | |
| 69 // Apply all modifiers seen so far to the outgoing event as a standard | |
| 70 // keyboard command. | |
| 71 evt.altKey = this.incrementalKey_.altKey; | |
| 72 evt.ctrlKey = this.incrementalKey_.ctrlKey; | |
| 73 evt.shiftKey = this.incrementalKey_.shiftKey; | |
|
dmazzoni
2017/04/17 04:53:24
Would be nice to support Search too in a future ch
| |
| 74 this.incrementalKey_ = null; | |
|
dmazzoni
2017/04/17 04:53:25
Why not just set it to {} here and then you don't
David Tseng
2017/04/17 16:10:51
Actually, the null state is important.
I've:
- re
| |
| 75 } | |
| 76 return false; | |
| 77 } | |
| 78 | |
| 79 this.incrementalKey_ = null; | |
| 80 return false; | |
| 81 } | |
| 82 }; | |
| OLD | NEW |