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 Rewrites a braille key event. |
| 7 */ |
| 8 |
| 9 goog.provide('BrailleKeyEventRewriter'); |
| 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 BrailleKeyEventRewriter = function() { |
| 20 /** @private {Object} */ |
| 21 this.incrementalKey_ = null; |
| 22 }; |
| 23 |
| 24 BrailleKeyEventRewriter.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_ = null; |
| 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; |
| 74 this.incrementalKey_ = null; |
| 75 } |
| 76 return false; |
| 77 } |
| 78 |
| 79 this.incrementalKey_ = null; |
| 80 return false; |
| 81 } |
| 82 }; |
OLD | NEW |