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) { | |
193 console.log('candidateClicked(' + index + '): experimental is disabled.'); | |
194 return; | |
195 } | |
196 chrome.experimental.inputUI.candidateClicked(index, 1); | 197 chrome.experimental.inputUI.candidateClicked(index, 1); |
197 }, | 198 }, |
198 | 199 |
199 /** | 200 /** |
200 * Go to the previous page of the lookup table. | 201 * Go to the previous page of the lookup table. |
201 * @return {void} | 202 * @return {void} |
202 */ | 203 */ |
203 pageUp: function() { | 204 pageUp: function() { |
204 if (!chrome.experimental) { | |
205 console.log('pageUp: experimental is disabled.'); | |
206 return; | |
207 } | |
208 chrome.experimental.inputUI.pageUp(); | 205 chrome.experimental.inputUI.pageUp(); |
209 }, | 206 }, |
210 | 207 |
211 /** | 208 /** |
212 * Go to the next page of the lookup table. | 209 * Go to the next page of the lookup table. |
213 * @return {void} | 210 * @return {void} |
214 */ | 211 */ |
215 pageDown: function() { | 212 pageDown: function() { |
216 if (!chrome.experimental) { | |
217 console.log('pageDown: experimental is diabled.'); | |
218 return; | |
219 } | |
220 chrome.experimental.inputUI.pageDown(); | 213 chrome.experimental.inputUI.pageDown(); |
221 }, | 214 }, |
222 }; | 215 }; |
223 | 216 |
224 var imeui = null; | 217 var imeui = null; |
225 | 218 |
226 /** | 219 /** |
227 * Initialize Ime Ui | 220 * Initialize Ime Ui |
228 * @param {Element} element The html element which will contain the ImeUi. | 221 * @param {Element} element The html element which will contain the ImeUi. |
229 * @return {void} | 222 * @return {void} |
230 */ | 223 */ |
231 function initIme(element) { | 224 function initIme(element) { |
232 // imeui has been initialized. | 225 if (!imeEnabled || imeui) { |
233 if (imeui) { | 226 // ime is not enabled in chromium or ime ui has been initialized. |
234 return; | 227 return; |
235 } | 228 } |
236 | 229 |
230 try { | |
231 // Register self to receive input method UI events. | |
232 chrome.experimental.inputUI.register(); | |
233 } catch (e) { | |
234 // The ime is not enabled in chromium. | |
235 imeEnabled = false; | |
James Hawkins
2011/05/31 16:38:16
I really agree that using a separate global var fo
| |
236 return; | |
237 } | |
238 | |
237 imeui = new ImeUi(); | 239 imeui = new ImeUi(); |
238 | 240 |
239 element.appendChild(imeui); | 241 element.appendChild(imeui); |
240 | 242 |
241 // new row | 243 // new row |
242 var clearingDiv = document.createElement('div'); | 244 var clearingDiv = document.createElement('div'); |
243 clearingDiv.style.clear = 'both'; | 245 clearingDiv.style.clear = 'both'; |
244 element.appendChild(clearingDiv); | 246 element.appendChild(clearingDiv); |
245 | 247 |
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. | 248 // Install events handlers. |
253 chrome.experimental.inputUI.onSetCursorLocation.addListener( | 249 chrome.experimental.inputUI.onSetCursorLocation.addListener( |
254 function(x, y, w, h) { | 250 function(x, y, w, h) { |
255 imeui.setCursorLocation(x, y, w, h); | 251 imeui.setCursorLocation(x, y, w, h); |
256 }); | 252 }); |
257 chrome.experimental.inputUI.onUpdateAuxiliaryText.addListener( | 253 chrome.experimental.inputUI.onUpdateAuxiliaryText.addListener( |
258 function(text) { | 254 function(text) { |
259 imeui.updateAuxiliaryText(text); | 255 imeui.updateAuxiliaryText(text); |
260 }); | 256 }); |
261 chrome.experimental.inputUI.onUpdateLookupTable.addListener( | 257 chrome.experimental.inputUI.onUpdateLookupTable.addListener( |
262 function(table) { | 258 function(table) { |
263 imeui.updateLookupTable(table); | 259 imeui.updateLookupTable(table); |
264 }); | 260 }); |
265 } | 261 } |
266 | 262 |
267 /** | 263 /** |
268 * Updates Ime Ui. It should be called when window is resized. | 264 * Updates Ime Ui. It should be called when window is resized. |
269 * @return {void} | 265 * @return {void} |
270 */ | 266 */ |
271 function updateIme() { | 267 function updateIme() { |
272 if (imeui) { | 268 if (imeEnabled && imeui) { |
273 imeui.update(); | 269 imeui.update(); |
274 } | 270 } |
275 } | 271 } |
OLD | NEW |