OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview An input method UI implementation | 6 * @fileoverview An input method UI implementation |
7 */ | 7 */ |
8 | 8 |
9 /** | 9 /** |
10 * Const variables | 10 * Const variables |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // TODO(penghuang) Adjust the width of all items in ImeUi to fill the width | 182 // TODO(penghuang) Adjust the width of all items in ImeUi to fill the width |
183 // of keyboard. | 183 // of keyboard. |
184 }, | 184 }, |
185 | 185 |
186 /** | 186 /** |
187 * Candidate is clicked. | 187 * Candidate is clicked. |
188 * @param {number} index The index of the candidate. | 188 * @param {number} index The index of the candidate. |
189 * @return {void} | 189 * @return {void} |
190 */ | 190 */ |
191 candidateClicked: function(index) { | 191 candidateClicked: function(index) { |
192 if (!chrome.experimental) { | |
193 console.log('candidateClicked(' + index + '): experimental is disabled.'); | |
194 return; | |
195 } | |
196 chrome.experimental.inputUI.candidateClicked(index, 1); | 192 chrome.experimental.inputUI.candidateClicked(index, 1); |
197 }, | 193 }, |
198 | 194 |
199 /** | 195 /** |
200 * Go to the previous page of the lookup table. | 196 * Go to the previous page of the lookup table. |
201 * @return {void} | 197 * @return {void} |
202 */ | 198 */ |
203 pageUp: function() { | 199 pageUp: function() { |
204 if (!chrome.experimental) { | |
205 console.log('pageUp: experimental is disabled.'); | |
206 return; | |
207 } | |
208 chrome.experimental.inputUI.pageUp(); | 200 chrome.experimental.inputUI.pageUp(); |
209 }, | 201 }, |
210 | 202 |
211 /** | 203 /** |
212 * Go to the next page of the lookup table. | 204 * Go to the next page of the lookup table. |
213 * @return {void} | 205 * @return {void} |
214 */ | 206 */ |
215 pageDown: function() { | 207 pageDown: function() { |
216 if (!chrome.experimental) { | |
217 console.log('pageDown: experimental is diabled.'); | |
218 return; | |
219 } | |
220 chrome.experimental.inputUI.pageDown(); | 208 chrome.experimental.inputUI.pageDown(); |
221 }, | 209 }, |
222 }; | 210 }; |
223 | 211 |
224 var imeui = null; | 212 var imeui = null; |
225 | 213 |
226 /** | 214 /** |
227 * Initialize Ime Ui | 215 * Initialize Ime Ui |
228 * @param {Element} element The html element which will contain the ImeUi. | 216 * @param {Element} element The html element which will contain the ImeUi. |
229 * @return {void} | 217 * @return {void} |
230 */ | 218 */ |
231 function initIme(element) { | 219 function initIme(element) { |
232 // imeui has been initialized. | |
233 if (imeui) { | 220 if (imeui) { |
| 221 // ime ui has been initialized. |
234 return; | 222 return; |
235 } | 223 } |
236 | 224 |
| 225 try { |
| 226 // Register self to receive input method UI events. |
| 227 chrome.experimental.inputUI.register(); |
| 228 } catch (e) { |
| 229 // The ime is not enabled in chromium. |
| 230 return; |
| 231 } |
| 232 |
237 imeui = new ImeUi(); | 233 imeui = new ImeUi(); |
238 | 234 |
239 element.appendChild(imeui); | 235 element.appendChild(imeui); |
240 | 236 |
241 // new row | 237 // new row |
242 var clearingDiv = document.createElement('div'); | 238 var clearingDiv = document.createElement('div'); |
243 clearingDiv.style.clear = 'both'; | 239 clearingDiv.style.clear = 'both'; |
244 element.appendChild(clearingDiv); | 240 element.appendChild(clearingDiv); |
245 | 241 |
246 if (!chrome.experimental) | |
247 return; | |
248 | |
249 // Register self to receive input method UI events. | |
250 chrome.experimental.inputUI.register(); | |
251 | |
252 // Install events handlers. | 242 // Install events handlers. |
253 chrome.experimental.inputUI.onSetCursorLocation.addListener( | 243 chrome.experimental.inputUI.onSetCursorLocation.addListener( |
254 function(x, y, w, h) { | 244 function(x, y, w, h) { |
255 imeui.setCursorLocation(x, y, w, h); | 245 imeui.setCursorLocation(x, y, w, h); |
256 }); | 246 }); |
257 chrome.experimental.inputUI.onUpdateAuxiliaryText.addListener( | 247 chrome.experimental.inputUI.onUpdateAuxiliaryText.addListener( |
258 function(text) { | 248 function(text) { |
259 imeui.updateAuxiliaryText(text); | 249 imeui.updateAuxiliaryText(text); |
260 }); | 250 }); |
261 chrome.experimental.inputUI.onUpdateLookupTable.addListener( | 251 chrome.experimental.inputUI.onUpdateLookupTable.addListener( |
262 function(table) { | 252 function(table) { |
263 imeui.updateLookupTable(table); | 253 imeui.updateLookupTable(table); |
264 }); | 254 }); |
265 } | 255 } |
266 | 256 |
267 /** | 257 /** |
268 * Updates Ime Ui. It should be called when window is resized. | 258 * Updates Ime Ui. It should be called when window is resized. |
269 * @return {void} | 259 * @return {void} |
270 */ | 260 */ |
271 function updateIme() { | 261 function updateIme() { |
272 if (imeui) { | 262 if (imeui) { |
273 imeui.update(); | 263 imeui.update(); |
274 } | 264 } |
275 } | 265 } |
OLD | NEW |