1 // Copyright 2015 The ChromeOS IME Authors. All Rights Reserved.
2 // limitations under the License.
3 // See the License for the specific language governing permissions and
4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5 // distributed under the License is distributed on an "AS-IS" BASIS,
6 // Unless required by applicable law or agreed to in writing, software
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // You may obtain a copy of the License at
11 // you may not use this file except in compliance with the License.
12 // Licensed under the Apache License, Version 2.0 (the "License");
14 goog.provide('i18n.input.chrome.Env');
16 goog.require('goog.array');
17 goog.require('i18n.input.chrome.Constant');
18 goog.require('i18n.input.chrome.inputview.FeatureTracker');
19 goog.require('i18n.input.lang.InputTool');
20 goog.require('i18n.input.lang.InputToolType');
22 goog.scope(function() {
23 var Constant = i18n.input.chrome.Constant;
24 var FeatureTracker = i18n.input.chrome.inputview.FeatureTracker;
25 var InputTool = i18n.input.lang.InputTool;
26 var InputToolType = i18n.input.lang.InputToolType;
31 * The Environment class which holds some status' of ChromeOS for input methods.
32 * e.g. the current input field context, the current input method engine ID,
37 i18n.input.chrome.Env = function() {
40 * Tracker for which FeatureName are enabled.
42 * @type {!FeatureTracker};
44 this.featureTracker = new FeatureTracker();
46 /** @private {!Function} */
47 this.compositionBoundsChangedHandler_ =
48 this.onBoundsChanged_.bind(this);
51 * The current initial bounds.
54 this.currentBounds = /** @type {!BoundSize} */ ({x: 0, y: 0, w: 0, h: 0});
58 * The current bounds list.
59 * @type {!Array.<!BoundSize>}
61 this.currentBoundsList = [
62 /** @type {!BoundSize} */ ({x: 0, y: 0, w: 0, h: 0})];
65 if (chrome.accessibilityFeatures &&
66 chrome.accessibilityFeatures.spokenFeedback) {
67 chrome.accessibilityFeatures.spokenFeedback.get({}, (function(details) {
68 this.isChromeVoxOn = details['value'];
71 chrome.accessibilityFeatures.spokenFeedback.onChange.addListener(
73 this.isChromeVoxOn = details['value'];
77 if (window.inputview && window.inputview.getKeyboardConfig) {
78 window.inputview.getKeyboardConfig((function(config) {
79 this.featureTracker.initialize(config);
83 var Env = i18n.input.chrome.Env;
84 goog.addSingletonGetter(Env);
88 Env.prototype.engineId = '';
91 /** @type {InputContext} */
92 Env.prototype.context = null;
96 Env.prototype.screenType = 'normal';
99 /** @type {boolean} */
100 Env.prototype.isPhysicalKeyboardAutocorrectEnabled = false;
103 /** @type {string} */
104 Env.prototype.textBeforeCursor = '';
107 /** @type {Object.<{text: string, focus: number, anchor: number}>} */
108 Env.prototype.surroundingInfo = null;
111 /** @type {boolean} */
112 Env.prototype.isChromeVoxOn = false;
115 /** @type {boolean} */
116 Env.prototype.isOnScreenKeyboardShown = false;
120 * Handler for onCompositionBoundsChanged event.
122 * @param {!BoundSize} bounds The bounds of the composition text.
123 * @param {!Array.<!BoundSize>} boundsList The list of bounds of each
124 * composition character.
127 Env.prototype.onBoundsChanged_ = function(bounds, boundsList) {
128 this.currentBounds = bounds;
129 this.currentBoundsList = boundsList;
134 * Let Env listen "onCompositionBoundsChanged" event.
136 Env.prototype.listenCompositionBoundsChanged = function() {
137 if (chrome.inputMethodPrivate &&
138 chrome.inputMethodPrivate.onCompositionBoundsChanged) {
139 chrome.inputMethodPrivate.onCompositionBoundsChanged.addListener(
140 this.compositionBoundsChangedHandler_);
146 * Let Env unlisten "onCompositionBoundsChanged" event.
148 Env.prototype.unlistenCompositionBoundsChanged = function() {
149 if (chrome.inputMethodPrivate &&
150 chrome.inputMethodPrivate.onCompositionBoundsChanged) {
151 chrome.inputMethodPrivate.onCompositionBoundsChanged.removeListener(
152 this.compositionBoundsChangedHandler_);
158 * Returns whether the XKB engine id supports NACL.
160 * @param {string} xkbEngineId The XKB engine Id.
161 * @return {boolean} supported or not.
163 Env.isXkbAndNaclEnabled = function(xkbEngineId) {
164 var inputTool = InputTool.get(xkbEngineId);
165 return !!inputTool && inputTool.type == InputToolType.XKB &&
166 goog.array.contains(Constant.NACL_LANGUAGES, inputTool.languageCode);