Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(501)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/braille_command_handler.js

Issue 2486293002: Add keyboard explorer improvements for braille (Closed)
Patch Set: Indents and braille cap cond Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.require('ChromeVoxState');
12 goog.require('CommandHandler');
13
14
15 goog.scope(function() { 11 goog.scope(function() {
16 /** 12 /**
17 * Maps a dot pattern to a command. 13 * Maps a dot pattern to a command.
18 * @type {!Object<number, string>} 14 * @type {!Object<number, string>}
19 */ 15 */
20 BrailleCommandHandler.DOT_PATTERN_TO_COMMAND = { 16 BrailleCommandHandler.DOT_PATTERN_TO_COMMAND = {
21 }; 17 };
22 18
23 /** 19 /**
24 * Makes a dot pattern given a list of dots numbered from 1 to 8 arranged in a 20 * Makes a dot pattern given a list of dots numbered from 1 to 8 arranged in a
25 * braille cell (a 2 x 4 dot grid). 21 * braille cell (a 2 x 4 dot grid).
26 * @param {Array<number>} dots The dots to be set in the returned pattern. 22 * @param {Array<number>} dots The dots to be set in the returned pattern.
27 * @return {number} 23 * @return {number}
28 */ 24 */
29 BrailleCommandHandler.makeDotPattern = function(dots) { 25 BrailleCommandHandler.makeDotPattern = function(dots) {
30 return dots.reduce(function(p, c) { 26 return dots.reduce(function(p, c) {
31 return p | (1 << c - 1); 27 return p | (1 << c - 1);
32 }, 0); 28 }, 0);
33 }; 29 };
34 30
35 /** 31 /**
36 * Perform a braille command based on a dot pattern from a chord. 32 * Gets a braille command based on a dot pattern from a chord.
37 * @param {number} dots Braille dot pattern 33 * @param {number} dots
34 * @return {string?}
38 */ 35 */
39 BrailleCommandHandler.onBrailleCommand = function(dots) { 36 BrailleCommandHandler.getCommand = function(dots) {
40 var command = BrailleCommandHandler.DOT_PATTERN_TO_COMMAND[dots]; 37 var command = BrailleCommandHandler.DOT_PATTERN_TO_COMMAND[dots];
41 if (command) 38 return command;
42 CommandHandler.onCommand(command);
43 }; 39 };
44 40
45 /** 41 /**
42 * Gets a dot shortcut for a command.
43 * @param {string} command
44 * @param {boolean=} opt_chord True if the pattern comes from a chord.
45 * @return {string} The shortcut.
46 */
47 BrailleCommandHandler.getDotShortcut = function(command, opt_chord) {
48 var commandDots = BrailleCommandHandler.getDots(command);
49 return BrailleCommandHandler.makeShortcutText(commandDots, opt_chord);
50 };
51
52 /**
53 * @param {number} pattern
54 * @param {boolean=} opt_chord
55 * @return {string}
56 */
57 BrailleCommandHandler.makeShortcutText = function(pattern, opt_chord) {
58 var dots = [];
59 for (var shifter = 0; shifter <= 7; shifter++) {
60 if ((1 << shifter) & pattern)
61 dots.push(shifter + 1);
62 }
63 var msgid;
64 if (dots.length > 1)
65 msgid = 'braille_dots';
66 else if (dots.length == 1)
67 msgid = 'braille_dot';
68
69 if (msgid) {
70 var dotText = Msgs.getMsg(msgid, [dots.join('-')]);
71 if (opt_chord)
72 dotText = Msgs.getMsg('braille_chord', [dotText]);
73 return dotText;
74 }
75 return '';
76 };
77
78 /**
79 * @param {string} command
80 * @return {number} The dot pattern for |command|.
81 */
82 BrailleCommandHandler.getDots = function(command) {
83 for (var key in BrailleCommandHandler.DOT_PATTERN_TO_COMMAND) {
84 key = parseInt(key, 10);
85 if (command == BrailleCommandHandler.DOT_PATTERN_TO_COMMAND[key])
86 return key;
87 }
88 return 0;
89 };
90
91 /**
46 * @private 92 * @private
47 */ 93 */
48 BrailleCommandHandler.init_ = function() { 94 BrailleCommandHandler.init_ = function() {
49 var map = function(dots, command) { 95 var map = function(dots, command) {
50 BrailleCommandHandler.DOT_PATTERN_TO_COMMAND[ 96 BrailleCommandHandler.DOT_PATTERN_TO_COMMAND[
51 BrailleCommandHandler.makeDotPattern(dots)] = command; 97 BrailleCommandHandler.makeDotPattern(dots)] = command;
52 }; 98 };
53 99
54 map([2, 3], 'previousGroup'); 100 map([2, 3], 'previousGroup');
55 map([5, 6], 'nextGroup'); 101 map([5, 6], 'nextGroup');
(...skipping 30 matching lines...) Expand all
86 map([8], 'forceClickOnCurrentItem'); 132 map([8], 'forceClickOnCurrentItem');
87 map([3, 4], 'toggleSearchWidget'); 133 map([3, 4], 'toggleSearchWidget');
88 134
89 // Question. 135 // Question.
90 map([1, 4, 5, 6], 'toggleKeyboardHelp'); 136 map([1, 4, 5, 6], 'toggleKeyboardHelp');
91 }; 137 };
92 138
93 BrailleCommandHandler.init_(); 139 BrailleCommandHandler.init_();
94 140
95 }); // goog.scope 141 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698