Index: chrome/browser/resources/access_chromevox/chromevox/injected/keyboard_handler.js |
=================================================================== |
--- chrome/browser/resources/access_chromevox/chromevox/injected/keyboard_handler.js (revision 0) |
+++ chrome/browser/resources/access_chromevox/chromevox/injected/keyboard_handler.js (revision 0) |
@@ -0,0 +1,89 @@ |
+// Copyright (c) 2011 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. |
+ |
+goog.provide('cvox.ChromeVoxKbHandler'); |
+ |
+goog.require('cvox.ChromeVox'); |
+goog.require('cvox.ChromeVoxJSON'); |
+goog.require('cvox.ChromeVoxSearch'); |
+goog.require('cvox.ChromeVoxUserCommands'); |
+goog.require('cvox.KeyUtil'); |
+ |
+/** |
+ * @fileoverview Handles user keyboard input events. |
+ */ |
+cvox.ChromeVoxKbHandler = {}; |
+ |
+/** |
+ * Maps a key string in the form generated by KeyUtil.keyEventToString |
+ * (like "Ctrl+Alt+X") into the name of a command to execute. |
+ * |
+ * @type {Object} |
+ */ |
+cvox.ChromeVoxKbHandler.keyToFunctionsTable = {}; |
+ |
+/** |
+ * Loads the key bindings into the keyToFunctionsTable. |
+ * |
+ * @param {Object} keyToFunctionsTable The key bindings table. |
+ */ |
+cvox.ChromeVoxKbHandler.loadKeyToFunctionsTable = function( |
+ keyToFunctionsTable) { |
+ console.log('Got keyToFunctionsTable: ' + |
+ JSON.stringify(keyToFunctionsTable)); |
+ cvox.ChromeVoxKbHandler.keyToFunctionsTable = keyToFunctionsTable; |
+}; |
+ |
+/** |
+ * Checks if ChromeVox must pass the enter key to the browser. |
+ * For example, if the user has focus on an input field, link, button, |
+ * etc., then that takes precedence over anything else ChromeVox |
+ * might be doing and so it must pass the enter key to the browser. |
+ * |
+ * @return {boolean} True if an Enter key event must be passed to the browser. |
+ */ |
+cvox.ChromeVoxKbHandler.mustPassEnterKey = function() { |
+ return (document.activeElement && |
+ ((document.activeElement.tagName == 'INPUT') || |
+ (document.activeElement.tagName == 'A') || |
+ (document.activeElement.tagName == 'SELECT') || |
+ (document.activeElement.tagName == 'BUTTON') || |
+ (document.activeElement.tagName == 'TEXTAREA'))); |
+}; |
+ |
+/** |
+ * Handles key down events. |
+ * |
+ * @param {Object} evt The key down event to process. |
+ * @return {boolean} True if the default action should be performed. |
+ */ |
+cvox.ChromeVoxKbHandler.basicKeyDownActionsListener = function(evt) { |
+ // The enter key can be handled either by ChromeVox or by the browser. |
+ if (evt.keyCode == 13) { |
+ // If the user is focused on something that explicitly takes the |
+ // enter key, that has precedence. Always let the key through. |
+ if (cvox.ChromeVoxKbHandler.mustPassEnterKey()) { |
+ return true; |
+ } |
+ // The only time ChromeVox should consider handling the enter |
+ // key is if the navigation manager is able to act on the current item. |
+ if (!cvox.ChromeVox.navigationManager.canActOnCurrentItem()) { |
+ return true; |
+ } |
+ } |
+ |
+ var keyStr = cvox.KeyUtil.keyEventToString(evt); |
+ var functionName = cvox.ChromeVoxKbHandler.keyToFunctionsTable[keyStr]; |
+ var func = cvox.ChromeVoxUserCommands.commands[functionName]; |
+ |
+ if (func) { |
+ if (cvox.ChromeVoxSearch.isActive()) { |
+ cvox.ChromeVoxSearch.hide(); |
+ cvox.ChromeVox.navigationManager.syncToSelection(); |
+ } |
+ return func(); |
+ } |
+ |
+ return true; |
+}; |
Property changes on: chrome/browser/resources/access_chromevox/chromevox/injected/keyboard_handler.js |
___________________________________________________________________ |
Added: svn:executable |
+ * |
Added: svn:eol-style |
+ LF |