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

Unified Diff: chrome/browser/resources/access_chromevox/common/key_util.js

Issue 6254007: Adding ChromeVox as a component extensions (enabled only for ChromeOS, for no... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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/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

Powered by Google App Engine
This is Rietveld 408576698