1 // Copyright 2014 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.DataSource');
16 goog.require('goog.events');
17 goog.require('goog.events.Event');
18 goog.require('goog.events.EventTarget');
19 goog.require('goog.functions');
22 goog.scope(function() {
23 var Event = goog.events.Event;
24 var EventTarget = goog.events.EventTarget;
31 * @param {number} numOfCanddiate The number of canddiate to fetch.
32 * @param {function(string, !Array.<!Object>)} callback .
34 * @extends {EventTarget}
36 i18n.input.chrome.DataSource = function(numOfCanddiate, callback) {
40 * The number of candidates to fetch.
44 this.numOfCandidate = numOfCanddiate;
46 /** @protected {function(string, !Array.<!Object>)} */
47 this.callback = callback;
49 var DataSource = i18n.input.chrome.DataSource;
50 goog.inherits(DataSource, EventTarget);
58 DataSource.EventType = {
59 CANDIDATES_BACK: goog.events.getUniqueId('cb'),
60 READY: goog.events.getUniqueId('r')
64 /** @type {boolean} */
65 DataSource.prototype.ready = false;
69 * The correction level.
73 DataSource.prototype.correctionLevel = 0;
77 * Whether user dict is enabled.
79 * @protected {boolean}
81 DataSource.prototype.enableUserDict = false;
90 DataSource.prototype.language;
94 * Sets the langauge code.
96 * @param {string} language The language code.
98 DataSource.prototype.setLanguage = function(language) {
99 this.language = language;
104 * True if the datasource is ready.
106 * @return {boolean} .
108 DataSource.prototype.isReady = function() {
114 * Creates the common payload for completion or prediction request.
116 * @return {!Object} The payload.
119 DataSource.prototype.createCommonPayload = function() {
121 'itc': this.getInputToolCode(),
122 'num': this.numOfCandidate
128 * Gets the input tool code.
132 DataSource.prototype.getInputToolCode = function() {
133 return this.language + '-t-i0-und';
138 * Sends completion request for a word.
140 * @param {string} word The word.
141 * @param {string} context The context.
143 DataSource.prototype.sendCompletionRequestForWord = goog.functions.NULL;
147 * Sends completion request.
149 * @param {string} query The query .
150 * @param {string} context The context .
151 * @param {!Object=} opt_spatialData .
153 DataSource.prototype.sendCompletionRequest = goog.functions.NULL;
157 * Enables/disables user dictionary.
159 * @param {boolean} enabled
161 DataSource.prototype.setEnableUserDict = function(enabled) {
162 this.enableUserDict = enabled;
167 * Sends prediciton request.
169 * @param {string} context The context.
171 DataSource.prototype.sendPredictionRequest = goog.functions.NULL;
175 * Sets the correction level.
177 * @param {number} level .
179 DataSource.prototype.setCorrectionLevel = function(level) {
180 this.correctionLevel = level;
185 * Changes frequency of word in the data source.
187 * @param {string} word The word to commit/change.
188 * @param {number} frequency The change in frequency.
190 DataSource.prototype.changeWordFrequency = goog.functions.NULL;
194 * Clears the data source.
196 DataSource.prototype.clear = goog.functions.NULL;
201 * The candidates is fetched back.
203 * @param {string} source The source.
204 * @param {!Array.<!Object>} candidates The candidates.
208 DataSource.CandidatesBackEvent = function(source, candidates) {
209 DataSource.CandidatesBackEvent.base(
210 this, 'constructor', DataSource.EventType.CANDIDATES_BACK);
217 this.source = source;
220 * The candidate list.
222 * @type {!Array.<!Object>}
224 this.candidates = candidates;
226 goog.inherits(DataSource.CandidatesBackEvent, Event);