Chromium Code Reviews| Index: chrome/browser/resources/chromeos/chromevox/braille/braille_key_event_sequence_reducer.js |
| diff --git a/chrome/browser/resources/chromeos/chromevox/braille/braille_key_event_sequence_reducer.js b/chrome/browser/resources/chromeos/chromevox/braille/braille_key_event_sequence_reducer.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e3595bf35a93dd12a1c4c9e8ea842aa627ab1cba |
| --- /dev/null |
| +++ b/chrome/browser/resources/chromeos/chromevox/braille/braille_key_event_sequence_reducer.js |
| @@ -0,0 +1,82 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview Manages a sequence of braille key events. |
| + */ |
| + |
| +goog.provide('BrailleKeyEventSequenceReducer'); |
| + |
| +goog.require('Output'); |
| +goog.require('cvox.BrailleKeyEvent'); |
| + |
| +/** |
| + * A class that transforms a sequence of braille key events into a standard key |
| + * event. |
| + * @constructor |
| + */ |
| +BrailleKeyEventSequenceReducer = function() { |
| + /** @private {Object} */ |
|
dmazzoni
2017/04/17 04:53:25
Use a more specific type. Looks like a nullable re
|
| + this.incrementalKey_ = null; |
| +}; |
| + |
| +BrailleKeyEventSequenceReducer.prototype = { |
| + /** |
| + * Accumulates and optionally modifies in-coming braille key events. |
| + * @param {cvox.BrailleKeyEvent} evt |
| + * @return {boolean} False to continue event propagation. |
| + */ |
| + onBrailleKeyEvent: function(evt) { |
| + var standardKeyCode; |
| + var dots = evt.brailleDots; |
| + if (!dots) { |
| + this.incrementalKey_ = {}; |
| + return false; |
| + } |
| + |
| + if (evt.command == cvox.BrailleKeyCommand.CHORD) { |
| + Output.forceModeForNextSpeechUtterance(cvox.QueueMode.CATEGORY_FLUSH); |
| + var modifiers = cvox.BrailleKeyEvent.brailleDotsToModifiers[dots]; |
| + |
| + // Check for a modifier mapping. |
| + if (modifiers) { |
| + this.incrementalKey_ = this.incrementalKey_ || {}; |
| + for (var key in modifiers) { |
| + this.incrementalKey_[key] = true; |
| + } |
| + |
| + return true; |
| + } |
| + |
| + // Check for a chord to standard key mapping. |
| + standardKeyCode = |
| + cvox.BrailleKeyEvent.brailleChordsToStandardKeyCode[dots]; |
| + } |
| + |
| + // Check for a 'dots' command, which is typed on the keyboard with a |
| + // previous incremental key press. |
| + if (evt.command == cvox.BrailleKeyCommand.DOTS && this.incrementalKey_) { |
| + // Check if this braille pattern has a standard key mapping. |
| + standardKeyCode = |
| + cvox.BrailleKeyEvent.brailleDotsToStandardKeyCode[dots]; |
| + } |
| + |
| + if (standardKeyCode) { |
| + evt.command = cvox.BrailleKeyCommand.STANDARD_KEY; |
| + evt.standardKeyCode = standardKeyCode; |
| + if (this.incrementalKey_) { |
| + // Apply all modifiers seen so far to the outgoing event as a standard |
| + // keyboard command. |
| + evt.altKey = this.incrementalKey_.altKey; |
| + evt.ctrlKey = this.incrementalKey_.ctrlKey; |
| + evt.shiftKey = this.incrementalKey_.shiftKey; |
|
dmazzoni
2017/04/17 04:53:24
Would be nice to support Search too in a future ch
|
| + 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
|
| + } |
| + return false; |
| + } |
| + |
| + this.incrementalKey_ = null; |
| + return false; |
| + } |
| +}; |