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

Unified Diff: chrome/browser/resources/chromeos/switch_access/keyboard_handler.js

Issue 2939133004: Added to options page to let users change keyboard mappings. (Closed)
Patch Set: Missing semicolon Created 3 years, 6 months 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/switch_access/keyboard_handler.js
diff --git a/chrome/browser/resources/chromeos/switch_access/keyboard_handler.js b/chrome/browser/resources/chromeos/switch_access/keyboard_handler.js
index 7231a6b6dc21641371c1d8709cff4c6de7828ff8..7162a6d97b0f164324befe81b36ba08bc79d8cdd 100644
--- a/chrome/browser/resources/chromeos/switch_access/keyboard_handler.js
+++ b/chrome/browser/resources/chromeos/switch_access/keyboard_handler.js
@@ -18,6 +18,13 @@ function KeyboardHandler(switchAccess) {
*/
this.switchAccess_ = switchAccess;
+ /**
+ * User preferences.
+ *
+ * @private {SwitchAccessPrefs}
+ */
+ this.prefs_ = switchAccess.switchAccessPrefs;
+
this.init_();
}
@@ -28,13 +35,31 @@ KeyboardHandler.prototype = {
* @private
*/
init_: function() {
- // Capture keycodes for keys 1 through 4, and 6 through 9.
- let keyCodes = ['1', '2', '3', '4', '6', '7', '8', '9'].map(
- key => key.charCodeAt(0));
- chrome.accessibilityPrivate.setSwitchAccessKeys(keyCodes);
+ this.updateSwitchAccessKeys();
document.addEventListener('keyup', this.handleKeyEvent_.bind(this));
},
+ /**
+ * Update the keyboard keys captured by Switch Access to those stored in
+ * prefs.
+ */
+ updateSwitchAccessKeys: function() {
+ let keyCodes = [];
+ for (let command of this.prefs_.getCommands())
+ keyCodes.push(this.keyCodeFor_(command));
+ chrome.accessibilityPrivate.setSwitchAccessKeys(keyCodes);
+ },
+
+ /**
+ * Return the key code that |command| maps to.
+ *
+ * @param {string} command
+ * @return {number}
+ */
+ keyCodeFor_: function(command) {
+ return this.prefs_.getNumberPref(command);
+ },
+
/**
* Handle a keyboard event by calling the appropriate SwitchAccess functions.
*
@@ -42,39 +67,40 @@ KeyboardHandler.prototype = {
* @private
*/
handleKeyEvent_: function(event) {
- switch (event.key) {
- case '1':
- console.log('1 = go to next element');
+ let key = event.key.toUpperCase();
+ switch (event.keyCode) {
dmazzoni 2017/06/15 22:37:39 One possibility here would be a map from command n
elichtenberg 2017/06/20 01:02:30 Done. Put command map in commands.js
+ case this.keyCodeFor_('next'):
+ console.log(key + ' = go to next element');
this.switchAccess_.moveToNode(true);
break;
- case '2':
- console.log('2 = go to previous element');
+ case this.keyCodeFor_('previous'):
+ console.log(key + ' = go to previous element');
this.switchAccess_.moveToNode(false);
break;
- case '3':
- console.log('3 = select element');
+ case this.keyCodeFor_('select'):
+ console.log(key + ' = select element');
this.switchAccess_.selectCurrentNode();
break;
- case '4':
+ case this.keyCodeFor_('options'):
this.switchAccess_.showOptionsPage();
break;
}
if (debuggingEnabled) {
- switch (event.key) {
- case '6':
- console.log('6 = go to next element (debug mode)');
+ switch (event.keyCode) {
+ case this.keyCodeFor_('debugNext'):
+ console.log(key + ' = go to next element (debug mode)');
this.switchAccess_.debugMoveToNext();
break;
- case '7':
- console.log('7 = go to previous element (debug mode)');
+ case this.keyCodeFor_('debugPrevious'):
+ console.log(key + ' = go to previous element (debug mode)');
this.switchAccess_.debugMoveToPrevious();
break;
- case '8':
- console.log('8 = go to child element (debug mode)');
+ case this.keyCodeFor_('debugChild'):
+ console.log(key + ' = go to child element (debug mode)');
this.switchAccess_.debugMoveToFirstChild();
break;
- case '9':
- console.log('9 = go to parent element (debug mode)');
+ case this.keyCodeFor_('debugParent'):
+ console.log(key + ' = go to parent element (debug mode)');
this.switchAccess_.debugMoveToParent();
break;
}

Powered by Google App Engine
This is Rietveld 408576698