summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/keyboard_overlay_accessibility_helper.js
blob: c28a5001c2ceede9fae96f14d36943ae1c472a20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 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.

// An object to implement keyboard overlay accessiblity.
var KeyboardOverlayAccessibilityHelper = {
  // Returns true when ChromeVox is loaded and active, false otherwise.
  cvoxIsActive: function() {
    return window.cvox && window.cvox.Api.isChromeVoxActive();
  },
  // Speaks all the shortcut with the given modifiers.
  maybeSpeakAllShortcuts: function(modifiers) {
    if (!this.cvoxIsActive())
      return;
    cvox.Api.stop();
    var keyboardGlyphData = getKeyboardGlyphData();
    var shortcutData = getShortcutData();
    var layout = getLayouts()[keyboardGlyphData.layoutName];
    var keysToShortcutText = {};
    for (var i = 0; i < layout.length; ++i) {
      var identifier = remapIdentifier(layout[i][0]);
      var keyData = keyboardGlyphData.keys[identifier];
      var keyLabel = getKeyLabel(keyData, modifiers);
      var shortcutId = shortcutData[getAction(keyLabel, modifiers)];
      var shortcutText = templateData[shortcutId];
      var keysText = modifiers.concat(keyLabel).join(' + ');
      if (shortcutText)
        keysToShortcutText[keysText] = shortcutText;
    }
    for (var keysText in keysToShortcutText) {
      this.speakShortcut_(keysText, keysToShortcutText[keysText]);
    }
  },
  // Speaks given shortcut description.
  speakShortcut_: function(keysText, shortcutText) {
    keysText = keysText.toLowerCase();  // For correct pronunciation.
    cvox.Api.speak(keysText, 1, {});
    cvox.Api.speak(shortcutText, 1, {});
  },
};