summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/chromeos/chromevox/host/interface/abstract_host.js
blob: c4e1e2fcf1ff8993368fcc8c0a98b51c86cb5193 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright 2014 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 Abstract interface to methods that differ depending on the
 * host platform.
 *
 */

goog.provide('cvox.AbstractHost');


/**
 * @constructor
 */
cvox.AbstractHost = function() {
};


/**
 * @enum {number}
 */
cvox.AbstractHost.State = {
  ACTIVE: 0,
  INACTIVE: 1,
  KILLED: 2
};


/**
 * Do all host-platform-specific initialization.
 */
cvox.AbstractHost.prototype.init = function() {
};


/**
 * Used to reinitialize ChromeVox if initialization fails.
 */
cvox.AbstractHost.prototype.reinit = function() {
};


/**
 * Executed on page load.
 */
cvox.AbstractHost.prototype.onPageLoad = function() {
};


/**
 * Sends a message to the background page (if it exists) for this host.
 * @param {Object} message The message to pass to the background page.
 */
cvox.AbstractHost.prototype.sendToBackgroundPage = function(message) {
};


/**
 * Returns the absolute URL to the API source.
 * @return {string} The URL.
 */
cvox.AbstractHost.prototype.getApiSrc = function() {
  return '';
};


/**
 * Return the absolute URL to the given file.
 * @param {string} path The URL suffix.
 * @return {string} The full URL.
 */
cvox.AbstractHost.prototype.getFileSrc = function(path) {
  return '';
};


/**
 * @return {boolean} True if the host has a Tts callback.
 */
cvox.AbstractHost.prototype.hasTtsCallback = function() {
  return true;
};


/**
 * @return {boolean} True if the TTS has been loaded.
 */
cvox.AbstractHost.prototype.ttsLoaded = function() {
  return true;
};


/**
 * @return {boolean} True if the ChromeVox is supposed to intercept and handle
 * mouse clicks for the platform, instead of just letting the clicks fall
 * through.
 *
 * Note: This behavior is only needed for Android because of the way touch
 * exploration and double-tap to click is implemented by the platform.
 */
cvox.AbstractHost.prototype.mustRedispatchClickEvent = function() {
  return false;
};

/**
 * Activate or deactivate ChromeVox on this host.
 * @param {boolean} active The desired state; true for active, false for
 * inactive.
 */
cvox.AbstractHost.prototype.activateOrDeactivateChromeVox = function(active) {
  this.onStateChanged_(active ? cvox.AbstractHost.State.ACTIVE :
      cvox.AbstractHost.State.INACTIVE);
};


/**
 * Kills ChromeVox on this host.
 */
cvox.AbstractHost.prototype.killChromeVox = function() {
  this.onStateChanged_(cvox.AbstractHost.State.KILLED);
};


/**
 * Helper managing the three states of ChromeVox --
 * active: all event listeners registered
 * inactive: only key down listener registered
 * killed: no listeners registered
 * @param {cvox.AbstractHost.State} state The new state.
 * @private
 */
cvox.AbstractHost.prototype.onStateChanged_ = function(state) {
  var active = state == cvox.AbstractHost.State.ACTIVE;
  if (active == cvox.ChromeVox.isActive) {
    return;
  }
  cvox.ChromeVoxEventWatcher.cleanup(window);
  switch (state) {
    case cvox.AbstractHost.State.ACTIVE:
      cvox.ChromeVox.isActive = true;
      cvox.ChromeVox.navigationManager.showOrHideIndicator(true);
      cvox.ChromeVoxEventWatcher.init(window);
      if (document.activeElement) {
        var speakNodeAlso = cvox.ChromeVox.documentHasFocus();
        cvox.ApiImplementation.syncToNode(
            document.activeElement, speakNodeAlso);
      } else {
        cvox.ChromeVox.navigationManager.updateIndicator();
      }
      break;
    case cvox.AbstractHost.State.INACTIVE:
      cvox.ChromeVox.isActive = false;
      cvox.ChromeVox.navigationManager.showOrHideIndicator(false);
      // If ChromeVox is inactive, the event watcher will only listen for key
      // down events.
      cvox.ChromeVoxEventWatcher.init(window);
      break;
    case cvox.AbstractHost.State.KILLED:
      cvox.ChromeVox.isActive = false;
      cvox.ChromeVox.navigationManager.showOrHideIndicator(false);
      break;
  }
};