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 |
11 */ | 11 */ |
12 const IME_HEIGHT = 48; | 12 const IME_HEIGHT = 48; |
13 const IME_VMARGIN = 12; | 13 const IME_VMARGIN = 12; |
14 const IME_HMARGIN = 16; | 14 const IME_HMARGIN = 16; |
15 const IME_FONTSIZE = IME_HEIGHT - IME_VMARGIN * 2; | 15 const IME_FONTSIZE = IME_HEIGHT - IME_VMARGIN * 2; |
16 const IME_MAX_CANDIDATES = 20; | 16 const IME_MAX_CANDIDATES = 20; |
17 | 17 |
18 /** | 18 /** |
19 * global variables | |
20 */ | |
21 var imeEnabled = true; | |
22 | |
23 /** | |
19 * Creates a new button element. | 24 * Creates a new button element. |
20 * @param {Object=} opt_propertyBag Optional properties. | 25 * @param {Object=} opt_propertyBag Optional properties. |
21 * @constructor | 26 * @constructor |
22 * @extends {HTMLButtonElement} | 27 * @extends {HTMLButtonElement} |
23 */ | 28 */ |
24 var Button = cr.ui.define('button'); | 29 var Button = cr.ui.define('button'); |
25 | 30 |
26 Button.prototype = { | 31 Button.prototype = { |
27 __proto__: HTMLButtonElement.prototype, | 32 __proto__: HTMLButtonElement.prototype, |
28 /** | 33 /** |
(...skipping 153 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 | 187 // TODO(penghuang) Adjust the width of all items in ImeUi to fill the width |
183 // of keyboard. | 188 // of keyboard. |
184 }, | 189 }, |
185 | 190 |
186 /** | 191 /** |
187 * Candidate is clicked. | 192 * Candidate is clicked. |
188 * @param {number} index The index of the candidate. | 193 * @param {number} index The index of the candidate. |
189 * @return {void} | 194 * @return {void} |
190 */ | 195 */ |
191 candidateClicked: function(index) { | 196 candidateClicked: function(index) { |
192 if (!chrome.experimental) { | 197 if (!imeEnabled) { |
James Hawkins
2011/05/30 22:07:15
Why is this check necessary since ImeUi is not cre
Peng
2011/05/31 14:55:34
Done.
Remove all check code
| |
193 console.log('candidateClicked(' + index + '): experimental is disabled.'); | 198 console.log('candidateClicked(' + index + '): experimental is disabled.'); |
194 return; | 199 return; |
195 } | 200 } |
196 chrome.experimental.inputUI.candidateClicked(index, 1); | 201 chrome.experimental.inputUI.candidateClicked(index, 1); |
197 }, | 202 }, |
198 | 203 |
199 /** | 204 /** |
200 * Go to the previous page of the lookup table. | 205 * Go to the previous page of the lookup table. |
201 * @return {void} | 206 * @return {void} |
202 */ | 207 */ |
203 pageUp: function() { | 208 pageUp: function() { |
204 if (!chrome.experimental) { | 209 if (!imeEnabled) { |
205 console.log('pageUp: experimental is disabled.'); | 210 console.log('pageUp: experimental is disabled.'); |
206 return; | 211 return; |
207 } | 212 } |
208 chrome.experimental.inputUI.pageUp(); | 213 chrome.experimental.inputUI.pageUp(); |
209 }, | 214 }, |
210 | 215 |
211 /** | 216 /** |
212 * Go to the next page of the lookup table. | 217 * Go to the next page of the lookup table. |
213 * @return {void} | 218 * @return {void} |
214 */ | 219 */ |
215 pageDown: function() { | 220 pageDown: function() { |
216 if (!chrome.experimental) { | 221 if (!imeEnabled) { |
217 console.log('pageDown: experimental is diabled.'); | 222 console.log('pageDown: experimental is diabled.'); |
218 return; | 223 return; |
219 } | 224 } |
220 chrome.experimental.inputUI.pageDown(); | 225 chrome.experimental.inputUI.pageDown(); |
221 }, | 226 }, |
222 }; | 227 }; |
223 | 228 |
224 var imeui = null; | 229 var imeui = null; |
225 | 230 |
226 /** | 231 /** |
227 * Initialize Ime Ui | 232 * Initialize Ime Ui |
228 * @param {Element} element The html element which will contain the ImeUi. | 233 * @param {Element} element The html element which will contain the ImeUi. |
229 * @return {void} | 234 * @return {void} |
230 */ | 235 */ |
231 function initIme(element) { | 236 function initIme(element) { |
232 // imeui has been initialized. | 237 if (!imeEnabled || imeui) { |
233 if (imeui) { | 238 // ime is not enabled in chromium or ime ui has been initialized. |
234 return; | 239 return; |
235 } | 240 } |
236 | 241 |
242 try { | |
243 // Register self to receive input method UI events. | |
244 chrome.experimental.inputUI.register(); | |
245 } catch (e) { | |
246 // The ime is not enabled in chromium. | |
247 imeEnabled = false; | |
248 return; | |
249 } | |
250 | |
237 imeui = new ImeUi(); | 251 imeui = new ImeUi(); |
238 | 252 |
239 element.appendChild(imeui); | 253 element.appendChild(imeui); |
240 | 254 |
241 // new row | 255 // new row |
242 var clearingDiv = document.createElement('div'); | 256 var clearingDiv = document.createElement('div'); |
243 clearingDiv.style.clear = 'both'; | 257 clearingDiv.style.clear = 'both'; |
244 element.appendChild(clearingDiv); | 258 element.appendChild(clearingDiv); |
245 | 259 |
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. | 260 // Install events handlers. |
253 chrome.experimental.inputUI.onSetCursorLocation.addListener( | 261 chrome.experimental.inputUI.onSetCursorLocation.addListener( |
254 function(x, y, w, h) { | 262 function(x, y, w, h) { |
255 imeui.setCursorLocation(x, y, w, h); | 263 imeui.setCursorLocation(x, y, w, h); |
256 }); | 264 }); |
257 chrome.experimental.inputUI.onUpdateAuxiliaryText.addListener( | 265 chrome.experimental.inputUI.onUpdateAuxiliaryText.addListener( |
258 function(text) { | 266 function(text) { |
259 imeui.updateAuxiliaryText(text); | 267 imeui.updateAuxiliaryText(text); |
260 }); | 268 }); |
261 chrome.experimental.inputUI.onUpdateLookupTable.addListener( | 269 chrome.experimental.inputUI.onUpdateLookupTable.addListener( |
262 function(table) { | 270 function(table) { |
263 imeui.updateLookupTable(table); | 271 imeui.updateLookupTable(table); |
264 }); | 272 }); |
265 } | 273 } |
266 | 274 |
267 /** | 275 /** |
268 * Updates Ime Ui. It should be called when window is resized. | 276 * Updates Ime Ui. It should be called when window is resized. |
269 * @return {void} | 277 * @return {void} |
270 */ | 278 */ |
271 function updateIme() { | 279 function updateIme() { |
272 if (imeui) { | 280 if (imeEnabled && imeui) { |
273 imeui.update(); | 281 imeui.update(); |
274 } | 282 } |
275 } | 283 } |
OLD | NEW |