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>)} candidatesCallback .
33 * @param {function(!Array.<string>)} gestureCallback .
35 * @extends {EventTarget}
37 i18n
.input
.chrome
.DataSource = function(numOfCanddiate
, candidatesCallback
,
42 * The number of candidates to fetch.
46 this.numOfCandidate
= numOfCanddiate
;
48 /** @protected {function(string, !Array.<!Object>)} */
49 this.candidatesCallback
= candidatesCallback
;
51 /** @protected {function(!Array.<string>)} */
52 this.gestureCallback
= gestureCallback
;
54 var DataSource
= i18n
.input
.chrome
.DataSource
;
55 goog
.inherits(DataSource
, EventTarget
);
63 DataSource
.EventType
= {
64 CANDIDATES_BACK
: goog
.events
.getUniqueId('cb'),
65 GESTURES_BACK
: goog
.events
.getUniqueId('gb'),
66 READY
: goog
.events
.getUniqueId('r')
70 /** @type {boolean} */
71 DataSource
.prototype.ready
= false;
75 * The correction level.
79 DataSource
.prototype.correctionLevel
= 0;
83 * Whether user dict is enabled.
85 * @protected {boolean}
87 DataSource
.prototype.enableUserDict
= false;
96 DataSource
.prototype.language
;
100 * Sets the langauge code.
102 * @param {string} language The language code.
104 DataSource
.prototype.setLanguage = function(language
) {
105 this.language
= language
;
110 * True if the datasource is ready.
112 * @return {boolean} .
114 DataSource
.prototype.isReady = function() {
120 * Creates the common payload for completion or prediction request.
122 * @return {!Object} The payload.
125 DataSource
.prototype.createCommonPayload = function() {
127 'itc': this.getInputToolCode(),
128 'num': this.numOfCandidate
134 * Gets the input tool code.
138 DataSource
.prototype.getInputToolCode = function() {
139 return this.language
+ '-t-i0-und';
144 * Sends completion request for a word.
146 * @param {string} word The word.
147 * @param {string} context The context.
149 DataSource
.prototype.sendCompletionRequestForWord
= goog
.functions
.NULL
;
153 * Sends completion request.
155 * @param {string} query The query .
156 * @param {string} context The context .
157 * @param {!Object=} opt_spatialData .
159 DataSource
.prototype.sendCompletionRequest
= goog
.functions
.NULL
;
163 * Enables/disables user dictionary.
165 * @param {boolean} enabled
167 DataSource
.prototype.setEnableUserDict = function(enabled
) {
168 this.enableUserDict
= enabled
;
173 * Sends prediciton request.
175 * @param {string} context The context.
177 DataSource
.prototype.sendPredictionRequest
= goog
.functions
.NULL
;
181 * Sets the correction level.
183 * @param {number} level .
185 DataSource
.prototype.setCorrectionLevel = function(level
) {
186 this.correctionLevel
= level
;
191 * Changes frequency of word in the data source.
193 * @param {string} word The word to commit/change.
194 * @param {number} frequency The change in frequency.
196 DataSource
.prototype.changeWordFrequency
= goog
.functions
.NULL
;
200 * Clears the data source.
202 DataSource
.prototype.clear
= goog
.functions
.NULL
;
207 * The candidates are fetched back.
209 * @param {string} source The source.
210 * @param {!Array.<!Object>} candidates The candidates.
214 DataSource
.CandidatesBackEvent = function(source
, candidates
) {
215 DataSource
.CandidatesBackEvent
.base(
216 this, 'constructor', DataSource
.EventType
.CANDIDATES_BACK
);
223 this.source
= source
;
226 * The candidate list.
228 * @type {!Array.<!Object>}
230 this.candidates
= candidates
;
232 goog
.inherits(DataSource
.CandidatesBackEvent
, Event
);
237 * The gesture results are fetched back.
239 * @param {!Array.<!string>} results The gesture results.
243 DataSource
.GesturesBackEvent = function(results
) {
244 DataSource
.GesturesBackEvent
.base(
245 this, 'constructor', DataSource
.EventType
.GESTURES_BACK
);
248 * The gesture results list.
250 * @type {!Array.<!string>}
252 this.results
= results
;
254 goog
.inherits(DataSource
.GesturesBackEvent
, Event
);