summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/chromeos/chromevox/common/chromevox.js
blob: db20382a06ab570fa42197ec1f4209f701e5b685 (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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
// 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 Defines a global object. The initialization of this
 *   object happens in init.js.
 *
 */

goog.provide('cvox.ChromeVox');

// Forward declarations.
// TODO (stoarca): Put these in a separate file and pass that
// into the build system instead of having it here. This will allow
// us to group all of the forward declarations for each file without
// having them overwrite the mapping in deps.js
goog.addDependency(
    '../host/interface/abstract_host.js',
    ['cvox.AbstractHost'],
    []);

goog.addDependency(
    '../host/interface/tts_interface.js',
    ['cvox.TtsInterface'],
    []);

goog.addDependency(
    '../host/interface/braille_interface.js',
    ['cvox.BrailleInterface'],
    []);

goog.addDependency(
    '../host/interface/mathjax_interface.js',
    ['cvox.MathJaxInterface'],
    []);

goog.addDependency(
    '../chromevox/messages/msgs.js',
    ['cvox.Msgs'],
    []);

goog.addDependency(
    '../host/interface/abstract_earcons.js',
    ['cvox.AbstractEarcons'],
    []);

goog.addDependency(
    '../chromevox/common/key_sequence.js',
    ['cvox.KeySequence'],
    []);

goog.addDependency(
    '../chromevox/injected/navigation_manager.js',
    ['cvox.NavigationManager'],
    []);

goog.addDependency(
    '../chromevox/injected/serializer.js',
    ['cvox.Serializer'],
    []);

// Constants
/**
 * Constant for verbosity setting (cvox.ChromeVox.verbosity).
 * @const
 * @type {number}
 */
cvox.VERBOSITY_VERBOSE = 0;
/**
 * Constant for verbosity setting (cvox.ChromeVox.verbosity).
 * @const
 * @type {number}
 */
cvox.VERBOSITY_BRIEF = 1;


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

/**
 * @type {cvox.AbstractHost}
 */
cvox.ChromeVox.host = null;
/**
 * @type {cvox.TtsInterface}
 */
cvox.ChromeVox.tts;
/**
 * @type {cvox.BrailleInterface}
 */
cvox.ChromeVox.braille;
/**
 * @type {cvox.MathJaxInterface}
 */
cvox.ChromeVox.mathJax;
/**
 * @type {cvox.Msgs}
 */
cvox.ChromeVox.msgs = null;
/**
 * @type {boolean}
 */
cvox.ChromeVox.isActive = true;
/**
 * @type {?string}
 */
cvox.ChromeVox.version = null;
/**
 * @type {cvox.AbstractEarcons}
 */
cvox.ChromeVox.earcons = null;
/**
 * @type {cvox.NavigationManager}
 */
cvox.ChromeVox.navigationManager = null;
/**
 * @type {cvox.Serializer}
 */
cvox.ChromeVox.serializer = null;
/**
 * This indicates whether or not the sticky mode pref is toggled on.
 * Use cvox.ChromeVox.isStickyModeOn() to test if sticky mode is enabled
 * either through the pref or due to being temporarily toggled on.
 * @type {boolean}
 */
cvox.ChromeVox.isStickyPrefOn = false;
/**
 * If set to true or false, this value overrides cvox.ChromeVox.isStickyPrefOn
 * temporarily - in order to temporarily enable sticky mode while doing
 * 'read from here' or to temporarily disable it while using a widget.
 * @type {?boolean}
 */
cvox.ChromeVox.stickyOverride = null;
/**
 * @type {boolean}
 */
cvox.ChromeVox.keyPrefixOn = false;
/**
 * Verbosity setting.
 * See: cvox.VERBOSITY_VERBOSE and cvox.VERBOSITY_BRIEF
 * @type {number}
 */
cvox.ChromeVox.verbosity = cvox.VERBOSITY_VERBOSE;
/**
 * @type {number}
 */
cvox.ChromeVox.typingEcho = 0;
/**
 * Echoing on key press events.
 * @type {Object<string, boolean>}
 */
cvox.ChromeVox.keyEcho = {};
/**
 * @type {Object<string, {x:number, y:number}>}
 */
cvox.ChromeVox.position = {};
/**
 * @type {boolean}
 */
cvox.ChromeVox.isChromeOS = navigator.userAgent.indexOf('CrOS') != -1;
/**
 * @type {boolean}
 */
cvox.ChromeVox.isMac = navigator.platform.indexOf('Mac') != -1;
/**
 * @type {string}
 */
cvox.ChromeVox.modKeyStr;
if (cvox.ChromeVox.isChromeOS) {
  cvox.ChromeVox.modKeyStr = 'Shift+Search';
} else if (cvox.ChromeVox.isMac) {
  cvox.ChromeVox.modKeyStr = 'Ctrl+Cmd';
} else {
  cvox.ChromeVox.modKeyStr = 'Shift+Alt';
}
/**
 * If any of these keys is pressed with the modifier key, we go in sequence mode
 * where the subsequent independent key downs (while modifier keys are down)
 * are a part of the same shortcut. This array is populated in
 * cvox.ChromeVoxKbHandler.loadKeyToFunctionsTable().
 * @type {!Array<cvox.KeySequence>}
 */
cvox.ChromeVox.sequenceSwitchKeyCodes = [];
/** @type {Object<string, boolean>} */
cvox.ChromeVox.visitedUrls = {};
/**
 * This function can be called before doing an operation that may trigger
 * focus events and other events that would normally be announced. This
 * tells the event manager that these events should be ignored, they're
 * a result of another command that's already announced them. This is
 * a temporary state that's automatically reverted after a few milliseconds,
 * there's no way to explicitly "un-mark".
 * @type {Function}
 */
cvox.ChromeVox.markInUserCommand = function() {};
/**
 * Synchronizes ChromeVox's internal cursor to the targetNode.
 * @param {Node} targetNode The node that ChromeVox should be synced to.
 * @param {boolean=} speakNode If true, speaks out the node.
 * @param {number=} opt_queueMode The queue mode to use for speaking.
 */
cvox.ChromeVox.syncToNode = function(
    targetNode, speakNode, opt_queueMode) {};

/**
 * Speaks the given node.
 * @param {Node} targetNode The node that ChromeVox should be synced to.
 * @param {number=} queueMode The queue mode to use for speaking.
 * @param {Object=} properties Speech properties to use for this utterance.
 */
cvox.ChromeVox.speakNode = function(targetNode, queueMode, properties) {};

/**
 * Provide a way for modules that can't depend on cvox.ChromeVoxUserCommands
 * to execute commands.
 *
 * @param {string} commandName The command name as a string.
 */
cvox.ChromeVox.executeUserCommand = function(commandName) {};

/**
 * True if the document body has aria-hidden='true' when we first load.
 * ChromeVox will disallow any navigation and not eat any keystrokes.
 * @type {boolean}
 */
cvox.ChromeVox.entireDocumentIsHidden = false;

/**
 * Stores state variables in a provided object.
 *
 * @param {Object} store The object.
 */
cvox.ChromeVox.storeOn = function(store) {
  store['isStickyPrefOn'] = cvox.ChromeVox.isStickyPrefOn;
  cvox.ChromeVox.navigationManager.storeOn(store);
};

/**
 * Updates the object with state variables from an earlier storeOn call.
 *
 * @param {Object} store The object.
 */
cvox.ChromeVox.readFrom = function(store) {
  cvox.ChromeVox.isStickyPrefOn = store['isStickyPrefOn'];
  cvox.ChromeVox.navigationManager.readFrom(store);
};

/**
 * Returns whether sticky mode is on, taking both the global sticky mode
 * pref and the temporary sticky mode override into account.
 *
 * @return {boolean} Whether sticky mode is on.
 */
cvox.ChromeVox.isStickyModeOn = function() {
  if (cvox.ChromeVox.stickyOverride !== null) {
    return cvox.ChromeVox.stickyOverride;
  } else {
    return cvox.ChromeVox.isStickyPrefOn;
  }
};

/**
 * Shortcut for document.getElementById.
 * @param {string} id of the element.
 * @return {HTMLElement} with the id.
 */
function $(id) {
  return document.getElementById(id);
}

/**
 * @param {Array} tabs
 */
cvox.ChromeVox.injectChromeVoxIntoTabs = function(tabs) {};

/**
 * Returns whether the document has focus, taking into account whether
 * it's hidden and also that if an iframe or webview element has focus,
 * the focus is really inside that frame and not in this document.
 * @return {boolean} True if the document has focus.
 */
cvox.ChromeVox.documentHasFocus = function() {
  if (!document.hasFocus() || document.hidden) {
    return false;
  }
  if (document.activeElement.tagName == 'IFRAME' ||
      document.activeElement.tagName == 'WEBVIEW') {
    return false;
  }
  return true;
};