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 braille commands. | 6 * @fileoverview ChromeVox braille commands. |
7 */ | 7 */ |
8 | 8 |
9 goog.provide('BrailleCommandHandler'); | 9 goog.provide('BrailleCommandHandler'); |
10 | 10 |
11 goog.scope(function() { | 11 goog.scope(function() { |
12 /** | 12 /** |
13 * Maps a dot pattern to a command. | 13 * Maps a dot pattern to a command. |
14 * @type {!Object<number, string>} | 14 * @type {!Object<number, string>} |
15 */ | 15 */ |
16 BrailleCommandHandler.DOT_PATTERN_TO_COMMAND = { | 16 BrailleCommandHandler.DOT_PATTERN_TO_COMMAND = {}; |
17 }; | |
18 | 17 |
19 /** | 18 /** |
20 * Makes a dot pattern given a list of dots numbered from 1 to 8 arranged in a | 19 * Makes a dot pattern given a list of dots numbered from 1 to 8 arranged in a |
21 * braille cell (a 2 x 4 dot grid). | 20 * braille cell (a 2 x 4 dot grid). |
22 * @param {Array<number>} dots The dots to be set in the returned pattern. | 21 * @param {Array<number>} dots The dots to be set in the returned pattern. |
23 * @return {number} | 22 * @return {number} |
24 */ | 23 */ |
25 BrailleCommandHandler.makeDotPattern = function(dots) { | 24 BrailleCommandHandler.makeDotPattern = function(dots) { |
26 return dots.reduce(function(p, c) { | 25 return dots.reduce(function(p, c) { |
27 return p | (1 << c - 1); | 26 return p | (1 << c - 1); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 return key; | 85 return key; |
87 } | 86 } |
88 return 0; | 87 return 0; |
89 }; | 88 }; |
90 | 89 |
91 /** | 90 /** |
92 * @private | 91 * @private |
93 */ | 92 */ |
94 BrailleCommandHandler.init_ = function() { | 93 BrailleCommandHandler.init_ = function() { |
95 var map = function(dots, command) { | 94 var map = function(dots, command) { |
96 BrailleCommandHandler.DOT_PATTERN_TO_COMMAND[ | 95 BrailleCommandHandler |
97 BrailleCommandHandler.makeDotPattern(dots)] = command; | 96 .DOT_PATTERN_TO_COMMAND[BrailleCommandHandler.makeDotPattern(dots)] = |
| 97 command; |
98 }; | 98 }; |
99 | 99 |
100 map([2, 3], 'previousGroup'); | 100 map([2, 3], 'previousGroup'); |
101 map([5, 6], 'nextGroup'); | 101 map([5, 6], 'nextGroup'); |
102 map([1], 'previousObject'); | 102 map([1], 'previousObject'); |
103 map([4], 'nextObject'); | 103 map([4], 'nextObject'); |
104 map([2], 'previousWord'); | 104 map([2], 'previousWord'); |
105 map([5], 'nextWord'); | 105 map([5], 'nextWord'); |
106 map([3], 'previousCharacter'); | 106 map([3], 'previousCharacter'); |
107 map([6], 'nextCharacter'); | 107 map([6], 'nextCharacter'); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 // s. | 142 // s. |
143 map([2, 3, 4], 'toggleSpeechOnOrOff'); | 143 map([2, 3, 4], 'toggleSpeechOnOrOff'); |
144 | 144 |
145 // g. | 145 // g. |
146 map([1, 2, 4, 5], 'toggleBrailleTable'); | 146 map([1, 2, 4, 5], 'toggleBrailleTable'); |
147 }; | 147 }; |
148 | 148 |
149 BrailleCommandHandler.init_(); | 149 BrailleCommandHandler.init_(); |
150 | 150 |
151 }); // goog.scope | 151 }); // goog.scope |
OLD | NEW |