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

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: Add stuff to panel.. 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 shifter = 0;
59 var dots = [];
60 while (shifter <= 7) {
dmazzoni 2016/11/10 01:22:04 This might be more clear as a for loop
David Tseng 2016/11/10 04:56:58 Done.
61 if ((1 << shifter) & pattern)
62 dots.push(shifter + 1);
dmazzoni 2016/11/10 01:22:04 indent
David Tseng 2016/11/10 04:56:58 Done.
63 shifter++;
64 }
65 var msgid;
66 if (dots.length > 1)
67 msgid = 'braille_dots';
68 else if (dots.length == 1)
69 msgid = 'braille_dot';
70
71 if (msgid) {
72 var dotText = Msgs.getMsg(msgid, [dots.join(' ')]);
dmazzoni 2016/11/10 01:22:04 Would it work to join with hyphens or anything els
David Tseng 2016/11/10 04:56:58 Done.
73 if (opt_chord)
74 dotText = Msgs.getMsg('braille_chord', [dotText]);
75 return dotText;
76 }
77
78 return '';
dmazzoni 2016/11/10 01:22:05 indent
79 };
80
81 /**
82 * @param {string} command
83 * @return {number} The dot pattern for |command|.
84 */
85 BrailleCommandHandler.getDots = function(command) {
86 for (var key in BrailleCommandHandler.DOT_PATTERN_TO_COMMAND) {
87 key = parseInt(key, 10);
88 if (command == BrailleCommandHandler.DOT_PATTERN_TO_COMMAND[key])
89 return key;
90 }
91 return 0;
92 };
93
94 /**
46 * @private 95 * @private
47 */ 96 */
48 BrailleCommandHandler.init_ = function() { 97 BrailleCommandHandler.init_ = function() {
49 var map = function(dots, command) { 98 var map = function(dots, command) {
50 BrailleCommandHandler.DOT_PATTERN_TO_COMMAND[ 99 BrailleCommandHandler.DOT_PATTERN_TO_COMMAND[
51 BrailleCommandHandler.makeDotPattern(dots)] = command; 100 BrailleCommandHandler.makeDotPattern(dots)] = command;
52 }; 101 };
53 102
54 map([2, 3], 'previousGroup'); 103 map([2, 3], 'previousGroup');
55 map([5, 6], 'nextGroup'); 104 map([5, 6], 'nextGroup');
(...skipping 30 matching lines...) Expand all
86 map([8], 'forceClickOnCurrentItem'); 135 map([8], 'forceClickOnCurrentItem');
87 map([3, 4], 'toggleSearchWidget'); 136 map([3, 4], 'toggleSearchWidget');
88 137
89 // Question. 138 // Question.
90 map([1, 4, 5, 6], 'toggleKeyboardHelp'); 139 map([1, 4, 5, 6], 'toggleKeyboardHelp');
91 }; 140 };
92 141
93 BrailleCommandHandler.init_(); 142 BrailleCommandHandler.init_();
94 143
95 }); // goog.scope 144 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698