goog.provide('i18n.input.chrome.Env');
goog.require('goog.array');
goog.require('i18n.input.chrome.Constant');
goog.require('i18n.input.chrome.FeatureTracker');
goog.require('i18n.input.lang.InputTool');
goog.require('i18n.input.lang.InputToolType');
goog.scope(function() {
var Constant = i18n.input.chrome.Constant;
var FeatureTracker = i18n.input.chrome.FeatureTracker;
var InputTool = i18n.input.lang.InputTool;
var InputToolType = i18n.input.lang.InputToolType;
* The Environment class which holds some status' of ChromeOS for input methods.
* e.g. the current input field context, the current input method engine ID,
* the flags, etc.
*
* @constructor
*/
i18n.input.chrome.Env = function() {
* Tracker for which FeatureName are enabled.
*
* @type {!FeatureTracker};
*/
this.featureTracker = new FeatureTracker();
this.compositionBoundsChangedHandler_ =
this.onBoundsChanged_.bind(this);
* The current initial bounds.
* @type {!BoundSize}
*/
this.currentBounds = ({x: 0, y: 0, w: 0, h: 0});
* The current bounds list.
* @type {!Array.<!BoundSize>}
*/
this.currentBoundsList = [
({x: 0, y: 0, w: 0, h: 0})];
if (chrome.accessibilityFeatures &&
chrome.accessibilityFeatures.spokenFeedback) {
chrome.accessibilityFeatures.spokenFeedback.get({}, (function(details) {
this.isChromeVoxOn = details['value'];
}).bind(this));
chrome.accessibilityFeatures.spokenFeedback.onChange.addListener(
function(details) {
this.isChromeVoxOn = details['value'];
}.bind(this));
}
if (window.inputview && window.inputview.getKeyboardConfig) {
window.inputview.getKeyboardConfig((function(config) {
this.featureTracker.initialize(config);
}).bind(this));
}
};
var Env = i18n.input.chrome.Env;
goog.addSingletonGetter(Env);
Env.prototype.engineId = '';
Env.prototype.context = null;
Env.prototype.screenType = 'normal';
Env.prototype.isPhysicalKeyboardAutocorrectEnabled = false;
Env.prototype.textBeforeCursor = '';
* @type {Object.<{text: string, focus: number, anchor: number,
* offset: number}>}
*/
Env.prototype.surroundingInfo = null;
Env.prototype.isChromeVoxOn = false;
Env.prototype.isOnScreenKeyboardShown = false;
* Handler for onCompositionBoundsChanged event.
*
* @param {!BoundSize} bounds The bounds of the composition text.
* @param {!Array.<!BoundSize>} boundsList The list of bounds of each
* composition character.
* @private
*/
Env.prototype.onBoundsChanged_ = function(bounds, boundsList) {
this.currentBounds = bounds;
this.currentBoundsList = boundsList;
};
* Let Env listen "onCompositionBoundsChanged" event.
*/
Env.prototype.listenCompositionBoundsChanged = function() {
if (chrome.inputMethodPrivate &&
chrome.inputMethodPrivate.onCompositionBoundsChanged) {
chrome.inputMethodPrivate.onCompositionBoundsChanged.addListener(
this.compositionBoundsChangedHandler_);
}
};
* Let Env unlisten "onCompositionBoundsChanged" event.
*/
Env.prototype.unlistenCompositionBoundsChanged = function() {
if (chrome.inputMethodPrivate &&
chrome.inputMethodPrivate.onCompositionBoundsChanged) {
chrome.inputMethodPrivate.onCompositionBoundsChanged.removeListener(
this.compositionBoundsChangedHandler_);
}
};
* Returns whether the XKB engine id supports NACL.
*
* @param {string} xkbEngineId The XKB engine Id.
* @return {boolean} supported or not.
*/
Env.isXkbAndNaclEnabled = function(xkbEngineId) {
var inputTool = InputTool.get(xkbEngineId);
return !!inputTool && inputTool.type == InputToolType.XKB &&
goog.array.contains(Constant.NACL_LANGUAGES, inputTool.languageCode);
};
});