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

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

Issue 2777203006: Added auto-scan, made some small changes to how prefs are stored, refactored. (Closed)
Patch Set: Responding to comments. Refactored tree_walker. Removed testable_tree_walker. Created 3 years, 9 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
new file mode 100644
index 0000000000000000000000000000000000000000..ce3078bff94a4203f4fe5d2dfd2c5d35d4808fa8
--- /dev/null
+++ b/chrome/browser/resources/chromeos/switch_access/keyboard_handler.js
@@ -0,0 +1,80 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// 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.
+ *
+ * @constructor
+ * @param {SwitchAccessInterface} switchAccess
+ */
+function KeyboardHandler(switchAccess) {
+ /**
+ * SwitchAccess reference.
+ * @private {SwitchAccessInterface}
+ */
+ this.switchAccess_ = switchAccess;
+
+ this.init_();
+};
+
+KeyboardHandler.prototype = {
+ /**
+ * Set up key listener.
+ *
+ * @private
+ */
+ init_: function() {
+ document.addEventListener('keyup', this.handleKeyEvent_.bind(this));
+ },
+
+ /**
+ * Handle a keyboard event by calling the appropriate SwitchAccess functions.
+ *
+ * @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 = do default on element');
+ this.switchAccess_.doDefault();
+ 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;
+ }
+ }
+ this.switchAccess_.performedUserAction();
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698