kbexplorer.js revision cedac228d2dd51db4b79ea1e72c7f249408ee061
1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5/**
6 * @fileoverview Script for ChromeOS keyboard explorer.
7 *
8 */
9
10goog.provide('cvox.KbExplorer');
11
12goog.require('cvox.KeyUtil');
13
14
15/**
16 * Class to manage the keyboard explorer.
17 * @constructor
18 */
19cvox.KbExplorer = function() { };
20
21
22/**
23 * Initialize keyboard explorer.
24 */
25cvox.KbExplorer.init = function() {
26  document.addEventListener('keydown', cvox.KbExplorer.onKeyDown, false);
27  document.addEventListener('keyup', cvox.KbExplorer.onKeyUp, false);
28  document.addEventListener('keypress', cvox.KbExplorer.onKeyPress, false);
29};
30
31
32/**
33 * Handles keydown events by speaking the human understandable name of the key.
34 * @param {Event} evt key event.
35 */
36cvox.KbExplorer.onKeyDown = function(evt) {
37  chrome.extension.getBackgroundPage()['speak'](
38      cvox.KeyUtil.getReadableNameForKeyCode(evt.keyCode), false, {});
39  evt.preventDefault();
40  evt.stopPropagation();
41};
42
43
44/**
45 * Handles keyup events.
46 * @param {Event} evt key event.
47 */
48cvox.KbExplorer.onKeyUp = function(evt) {
49  evt.preventDefault();
50  evt.stopPropagation();
51};
52
53
54/**
55 * Handles keypress events.
56 * @param {Event} evt key event.
57 */
58cvox.KbExplorer.onKeyPress = function(evt) {
59  evt.preventDefault();
60  evt.stopPropagation();
61};
62