Chromium Code Reviews| Index: chrome/browser/resources/chromeos/chromevox/cvox2/background/braille_command_handler.js |
| diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/braille_command_handler.js b/chrome/browser/resources/chromeos/chromevox/cvox2/background/braille_command_handler.js |
| index 8ae609f0a0d6f4c8d99fa94c00fd6caa2b0a62be..ae2850c179d0eb8d47b630cf99971871fa07cf5d 100644 |
| --- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/braille_command_handler.js |
| +++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/braille_command_handler.js |
| @@ -8,10 +8,6 @@ |
| goog.provide('BrailleCommandHandler'); |
| -goog.require('ChromeVoxState'); |
| -goog.require('CommandHandler'); |
| - |
| - |
| goog.scope(function() { |
| /** |
| * Maps a dot pattern to a command. |
| @@ -33,13 +29,66 @@ BrailleCommandHandler.makeDotPattern = function(dots) { |
| }; |
| /** |
| - * Perform a braille command based on a dot pattern from a chord. |
| - * @param {number} dots Braille dot pattern |
| + * Gets a braille command based on a dot pattern from a chord. |
| + * @param {number} dots |
| + * @return {string?} |
| */ |
| -BrailleCommandHandler.onBrailleCommand = function(dots) { |
| +BrailleCommandHandler.getCommand = function(dots) { |
| var command = BrailleCommandHandler.DOT_PATTERN_TO_COMMAND[dots]; |
| - if (command) |
| - CommandHandler.onCommand(command); |
| + return command; |
| +}; |
| + |
| +/** |
| + * Gets a dot shortcut for a command. |
| + * @param {string} command |
| + * @param {boolean=} opt_chord True if the pattern comes from a chord. |
| + * @return {string} The shortcut. |
| + */ |
| +BrailleCommandHandler.getDotShortcut = function(command, opt_chord) { |
| + var commandDots = BrailleCommandHandler.getDots(command); |
| + return BrailleCommandHandler.makeShortcutText(commandDots, opt_chord); |
| +}; |
| + |
| +/** |
| + * @param {number} pattern |
| + * @param {boolean=} opt_chord |
| + * @return {string} |
| + */ |
| +BrailleCommandHandler.makeShortcutText = function(pattern, opt_chord) { |
| + var shifter = 0; |
| + var dots = []; |
| + 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.
|
| + if ((1 << shifter) & pattern) |
| + dots.push(shifter + 1); |
|
dmazzoni
2016/11/10 01:22:04
indent
David Tseng
2016/11/10 04:56:58
Done.
|
| + shifter++; |
| + } |
| + var msgid; |
| + if (dots.length > 1) |
| + msgid = 'braille_dots'; |
| + else if (dots.length == 1) |
| + msgid = 'braille_dot'; |
| + |
| + if (msgid) { |
| + 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.
|
| + if (opt_chord) |
| + dotText = Msgs.getMsg('braille_chord', [dotText]); |
| + return dotText; |
| + } |
| + |
| +return ''; |
|
dmazzoni
2016/11/10 01:22:05
indent
|
| +}; |
| + |
| +/** |
| + * @param {string} command |
| + * @return {number} The dot pattern for |command|. |
| + */ |
| +BrailleCommandHandler.getDots = function(command) { |
| + for (var key in BrailleCommandHandler.DOT_PATTERN_TO_COMMAND) { |
| + key = parseInt(key, 10); |
| + if (command == BrailleCommandHandler.DOT_PATTERN_TO_COMMAND[key]) |
| + return key; |
| + } |
| + return 0; |
| }; |
| /** |