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.
6 * @fileoverview Abstract interface to methods that differ depending on the
11 goog.provide('cvox.AbstractHost');
17 cvox.AbstractHost = function() {
24 cvox.AbstractHost.State = {
32 * Do all host-platform-specific initialization.
34 cvox.AbstractHost.prototype.init = function() {
39 * Used to reinitialize ChromeVox if initialization fails.
41 cvox.AbstractHost.prototype.reinit = function() {
46 * Executed on page load.
48 cvox.AbstractHost.prototype.onPageLoad = function() {
53 * Sends a message to the background page (if it exists) for this host.
54 * @param {Object} message The message to pass to the background page.
56 cvox.AbstractHost.prototype.sendToBackgroundPage = function(message) {
61 * Returns the absolute URL to the API source.
62 * @return {string} The URL.
64 cvox.AbstractHost.prototype.getApiSrc = function() {
70 * Return the absolute URL to the given file.
71 * @param {string} path The URL suffix.
72 * @return {string} The full URL.
74 cvox.AbstractHost.prototype.getFileSrc = function(path) {
80 * @return {boolean} True if the host has a Tts callback.
82 cvox.AbstractHost.prototype.hasTtsCallback = function() {
88 * @return {boolean} True if the TTS has been loaded.
90 cvox.AbstractHost.prototype.ttsLoaded = function() {
96 * @return {boolean} True if the ChromeVox is supposed to intercept and handle
97 * mouse clicks for the platform, instead of just letting the clicks fall
100 * Note: This behavior is only needed for Android because of the way touch
101 * exploration and double-tap to click is implemented by the platform.
103 cvox.AbstractHost.prototype.mustRedispatchClickEvent = function() {
108 * Activate or deactivate ChromeVox on this host.
109 * @param {boolean} active The desired state; true for active, false for
112 cvox.AbstractHost.prototype.activateOrDeactivateChromeVox = function(active) {
113 this.onStateChanged_(active ? cvox.AbstractHost.State.ACTIVE :
114 cvox.AbstractHost.State.INACTIVE);
119 * Kills ChromeVox on this host.
121 cvox.AbstractHost.prototype.killChromeVox = function() {
122 this.onStateChanged_(cvox.AbstractHost.State.KILLED);
127 * Helper managing the three states of ChromeVox --
128 * active: all event listeners registered
129 * inactive: only key down listener registered
130 * killed: no listeners registered
131 * @param {cvox.AbstractHost.State} state The new state.
134 cvox.AbstractHost.prototype.onStateChanged_ = function(state) {
135 var active = state == cvox.AbstractHost.State.ACTIVE;
136 if (active == cvox.ChromeVox.isActive) {
139 cvox.ChromeVoxEventWatcher.cleanup(window);
141 case cvox.AbstractHost.State.ACTIVE:
142 cvox.ChromeVox.isActive = true;
143 cvox.ChromeVox.navigationManager.showOrHideIndicator(true);
144 cvox.ChromeVoxEventWatcher.init(window);
145 if (document.activeElement) {
146 var speakNodeAlso = cvox.ChromeVox.documentHasFocus();
147 cvox.ApiImplementation.syncToNode(
148 document.activeElement, speakNodeAlso);
150 cvox.ChromeVox.navigationManager.updateIndicator();
153 case cvox.AbstractHost.State.INACTIVE:
154 cvox.ChromeVox.isActive = false;
155 cvox.ChromeVox.navigationManager.showOrHideIndicator(false);
156 // If ChromeVox is inactive, the event watcher will only listen for key
158 cvox.ChromeVoxEventWatcher.init(window);
160 case cvox.AbstractHost.State.KILLED:
161 cvox.ChromeVox.isActive = false;
162 cvox.ChromeVox.navigationManager.showOrHideIndicator(false);