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

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: Fixed merge conflict and formatting error 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 644f6235fdf578a856c8ca1120031145afaebcac..23bf3f6e4cd4d20da46be23c00588e363d35be21 100644
--- a/chrome/browser/resources/chromeos/switch_access/keyboard_handler.js
+++ b/chrome/browser/resources/chromeos/switch_access/keyboard_handler.js
@@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// TODO(elichtenberg): Move into custom logger class or somewhere else.
-let debuggingEnabled = true;
-
/**
* Class to handle keyboard input.
*
@@ -14,6 +11,7 @@ let debuggingEnabled = true;
function KeyboardHandler(switchAccess) {
/**
* SwitchAccess reference.
+ *
* @private {SwitchAccessInterface}
*/
this.switchAccess_ = switchAccess;
@@ -28,57 +26,50 @@ 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));
},
/**
- * Handle a keyboard event by calling the appropriate SwitchAccess functions.
+ * Update the keyboard keys captured by Switch Access to those stored in
+ * prefs.
+ */
+ updateSwitchAccessKeys: function() {
+ let keyCodes = [];
+ for (let command of this.switchAccess_.getCommands()) {
+ let keyCode = this.keyCodeFor_(command);
+ if ((keyCode >= '0'.charCodeAt(0) && keyCode <= '9'.charCodeAt(0)) ||
+ (keyCode >= 'A'.charCodeAt(0) && keyCode <= 'Z'.charCodeAt(0)))
+ keyCodes.push(keyCode);
+ }
+ chrome.accessibilityPrivate.setSwitchAccessKeys(keyCodes);
+ },
+
+ /**
+ * Return the key code that |command| maps to.
+ *
+ * @param {string} command
+ * @return {number}
+ */
+ keyCodeFor_: function(command) {
+ return this.switchAccess_.getNumberPref(command);
+ },
+
+ /**
+ * Run the command associated with the passed keyboard event.
*
* @param {!Event} event
* @private
*/
handleKeyEvent_: function(event) {
- switch (event.key) {
- case '1':
- console.log('1 = go to next element');
- this.switchAccess_.moveToNode(true);
- break;
- case '2':
- console.log('2 = go to previous element');
- this.switchAccess_.moveToNode(false);
- break;
- case '3':
- console.log('3 = select element');
- this.switchAccess_.selectCurrentNode();
- break;
- case '4':
- this.switchAccess_.showOptionsPage();
- break;
- }
- if (debuggingEnabled) {
- switch (event.key) {
- case '6':
- console.log('6 = go to next element (debug mode)');
- this.switchAccess_.debugMoveToNext();
- break;
- case '7':
- console.log('7 = go to previous element (debug mode)');
- this.switchAccess_.debugMoveToPrevious();
- break;
- case '8':
- console.log('8 = go to child element (debug mode)');
- this.switchAccess_.debugMoveToFirstChild();
- break;
- case '9':
- console.log('9 = go to parent element (debug mode)');
- this.switchAccess_.debugMoveToParent();
- break;
+ for (let command of this.switchAccess_.getCommands()) {
+ if (this.keyCodeFor_(command) === event.keyCode) {
+ let key = event.key.toUpperCase();
+ console.log('\'' + key + '\' pressed for command: ' + command);
+ this.switchAccess_.runCommand(command);
+ this.switchAccess_.performedUserAction();
+ return;
}
}
- this.switchAccess_.performedUserAction();
- }
+ },
};

Powered by Google App Engine
This is Rietveld 408576698