| Index: chrome/browser/resources/access_chromevox/common/key_util.js
|
| ===================================================================
|
| --- chrome/browser/resources/access_chromevox/common/key_util.js (revision 0)
|
| +++ chrome/browser/resources/access_chromevox/common/key_util.js (revision 0)
|
| @@ -0,0 +1,84 @@
|
| +// 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.
|
| +
|
| +/**
|
| + * @fileoverview A collection of JavaScript utilities used to simplify working
|
| + * with keyboard events.
|
| + */
|
| +
|
| +
|
| +goog.provide('cvox.KeyUtil');
|
| +
|
| +
|
| +/**
|
| + * Create the namespace
|
| + * @constructor
|
| + */
|
| +cvox.KeyUtil = function() {
|
| +};
|
| +
|
| +/**
|
| + * Convert a key event into an unambiguous string representation that's
|
| + * unique but also human-readable enough for debugging.
|
| + *
|
| + * A key event with a keyCode of 76 ('L') and the control and alt keys down
|
| + * would return the string 'Ctrl+Alt+L', for example. A key code that doesn't
|
| + * correspond to a letter or number will return a string with a pound and
|
| + * then its keyCode, like 'Ctrl+Alt+#39' for Right Arrow.
|
| + *
|
| + * The modifiers always come in this order:
|
| + *
|
| + * Ctrl
|
| + * Alt
|
| + * Shift
|
| + * Meta
|
| + *
|
| + * @param {Object} keyEvent The keyEvent to convert.
|
| + * @return {string} A string representation of the key event.
|
| + */
|
| +cvox.KeyUtil.keyEventToString = function(keyEvent) {
|
| + var str = '';
|
| +
|
| + if (keyEvent.ctrlKey) {
|
| + if (str) {
|
| + str += '+';
|
| + }
|
| + str += 'Ctrl';
|
| + }
|
| + if (keyEvent.altKey) {
|
| + if (str) {
|
| + str += '+';
|
| + }
|
| + str += 'Alt';
|
| + }
|
| + if (keyEvent.shiftKey) {
|
| + if (str) {
|
| + str += '+';
|
| + }
|
| + str += 'Shift';
|
| + }
|
| + if (keyEvent.metaKey) {
|
| + if (str) {
|
| + str += '+';
|
| + }
|
| + str += 'Meta';
|
| + }
|
| +
|
| + if (str) {
|
| + str += '+';
|
| + }
|
| +
|
| + if (keyEvent.keyCode >= 65 && keyEvent.keyCode <= 90) {
|
| + // A - Z
|
| + str += String.fromCharCode(keyEvent.keyCode);
|
| + } else if (keyEvent.keyCode >= 48 && keyEvent.keyCode <= 57) {
|
| + // 0 - 9
|
| + str += String.fromCharCode(keyEvent.keyCode);
|
| + } else {
|
| + // Anything else
|
| + str += '#' + keyEvent.keyCode;
|
| + }
|
| +
|
| + return str;
|
| +};
|
|
|
| Property changes on: chrome/browser/resources/access_chromevox/common/key_util.js
|
| ___________________________________________________________________
|
| Added: svn:executable
|
| + *
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|