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

Unified 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 side-by-side diff with in-line comments
Download patch
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;
};
/**

Powered by Google App Engine
This is Rietveld 408576698