OLD | NEW |
1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. | 1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. |
2 // limitations under the License. | 2 // limitations under the License. |
3 // See the License for the specific language governing permissions and | 3 // See the License for the specific language governing permissions and |
4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
5 // distributed under the License is distributed on an "AS-IS" BASIS, | 5 // distributed under the License is distributed on an "AS-IS" BASIS, |
6 // Unless required by applicable law or agreed to in writing, software | 6 // Unless required by applicable law or agreed to in writing, software |
7 // | 7 // |
8 // http://www.apache.org/licenses/LICENSE-2.0 | 8 // http://www.apache.org/licenses/LICENSE-2.0 |
9 // | 9 // |
10 // You may obtain a copy of the License at | 10 // You may obtain a copy of the License at |
(...skipping 16 matching lines...) Expand all Loading... |
27 goog.require('i18n.input.chrome.message.ContextType'); | 27 goog.require('i18n.input.chrome.message.ContextType'); |
28 goog.require('i18n.input.chrome.message.Event'); | 28 goog.require('i18n.input.chrome.message.Event'); |
29 goog.require('i18n.input.chrome.message.Name'); | 29 goog.require('i18n.input.chrome.message.Name'); |
30 goog.require('i18n.input.chrome.message.Type'); | 30 goog.require('i18n.input.chrome.message.Type'); |
31 | 31 |
32 goog.scope(function() { | 32 goog.scope(function() { |
33 var CandidatesBackEvent = i18n.input.chrome.DataSource.CandidatesBackEvent; | 33 var CandidatesBackEvent = i18n.input.chrome.DataSource.CandidatesBackEvent; |
34 var ContextType = i18n.input.chrome.message.ContextType; | 34 var ContextType = i18n.input.chrome.message.ContextType; |
35 var Type = i18n.input.chrome.message.Type; | 35 var Type = i18n.input.chrome.message.Type; |
36 var Name = i18n.input.chrome.message.Name; | 36 var Name = i18n.input.chrome.message.Name; |
| 37 var SizeSpec = i18n.input.chrome.inputview.SizeSpec; |
37 | 38 |
38 | 39 |
39 | 40 |
40 /** | 41 /** |
41 * The adapter for interview. | 42 * The adapter for interview. |
42 * | 43 * |
43 * @param {!i18n.input.chrome.inputview.ReadyState} readyState . | 44 * @param {!i18n.input.chrome.inputview.ReadyState} readyState . |
44 * @extends {goog.events.EventTarget} | 45 * @extends {goog.events.EventTarget} |
45 * @constructor | 46 * @constructor |
46 */ | 47 */ |
(...skipping 19 matching lines...) Expand all Loading... |
66 * The system ready state. | 67 * The system ready state. |
67 * | 68 * |
68 * @private {!i18n.input.chrome.inputview.ReadyState} | 69 * @private {!i18n.input.chrome.inputview.ReadyState} |
69 */ | 70 */ |
70 this.readyState_ = readyState; | 71 this.readyState_ = readyState; |
71 | 72 |
72 chrome.runtime.onMessage.addListener(this.onMessage_.bind(this)); | 73 chrome.runtime.onMessage.addListener(this.onMessage_.bind(this)); |
73 | 74 |
74 /** @private {!goog.events.EventHandler} */ | 75 /** @private {!goog.events.EventHandler} */ |
75 this.handler_ = new goog.events.EventHandler(this); | 76 this.handler_ = new goog.events.EventHandler(this); |
76 this.handler_.listen(document, 'webkitvisibilitychange', | 77 this.handler_. |
77 this.onVisibilityChange_); | 78 listen(document, 'webkitvisibilitychange', this.onVisibilityChange_). |
| 79 // When screen rotate, will trigger resize event. |
| 80 listen(window, goog.events.EventType.RESIZE, this.onVisibilityChange_); |
| 81 |
| 82 // Notifies the initial visibility change message to background. |
| 83 this.onVisibilityChange_(); |
78 }; | 84 }; |
79 goog.inherits(i18n.input.chrome.inputview.Adapter, | 85 goog.inherits(i18n.input.chrome.inputview.Adapter, |
80 goog.events.EventTarget); | 86 goog.events.EventTarget); |
81 var Adapter = i18n.input.chrome.inputview.Adapter; | 87 var Adapter = i18n.input.chrome.inputview.Adapter; |
82 | 88 |
83 | 89 |
84 /** @type {boolean} */ | 90 /** @type {boolean} */ |
85 Adapter.prototype.isA11yMode = false; | 91 Adapter.prototype.isA11yMode = false; |
86 | 92 |
87 | 93 |
(...skipping 14 matching lines...) Expand all Loading... |
102 | 108 |
103 | 109 |
104 /** @type {boolean} */ | 110 /** @type {boolean} */ |
105 Adapter.prototype.isChromeVoxOn = false; | 111 Adapter.prototype.isChromeVoxOn = false; |
106 | 112 |
107 | 113 |
108 /** @type {string} */ | 114 /** @type {string} */ |
109 Adapter.prototype.textBeforeCursor = ''; | 115 Adapter.prototype.textBeforeCursor = ''; |
110 | 116 |
111 | 117 |
| 118 /** @type {boolean} */ |
| 119 Adapter.prototype.isQPInputView = false; |
| 120 |
| 121 |
112 /** | 122 /** |
113 * Whether the background controller is on switching. | 123 * Whether the background controller is on switching. |
114 * | 124 * |
115 * @private {boolean} | 125 * @private {boolean} |
116 */ | 126 */ |
117 Adapter.prototype.isBgControllerSwitching_ = false; | 127 Adapter.prototype.isBgControllerSwitching_ = false; |
118 | 128 |
119 | 129 |
120 /** | 130 /** |
121 * Callback for updating settings. | 131 * Callback for updating settings. |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 * @private | 329 * @private |
320 */ | 330 */ |
321 Adapter.prototype.onContextFocus_ = function(message) { | 331 Adapter.prototype.onContextFocus_ = function(message) { |
322 this.contextType = /** @type {string} */ (message[Name.CONTEXT_TYPE]); | 332 this.contextType = /** @type {string} */ (message[Name.CONTEXT_TYPE]); |
323 this.dispatchEvent(new goog.events.Event( | 333 this.dispatchEvent(new goog.events.Event( |
324 i18n.input.chrome.inputview.events.EventType.CONTEXT_FOCUS)); | 334 i18n.input.chrome.inputview.events.EventType.CONTEXT_FOCUS)); |
325 }; | 335 }; |
326 | 336 |
327 | 337 |
328 /** | 338 /** |
329 * Intializes the communication to background page. | 339 * Initializes the communication to background page. |
330 * | 340 * |
331 * @param {string} languageCode The language code. | |
332 * @private | 341 * @private |
333 */ | 342 */ |
334 Adapter.prototype.initBackground_ = function(languageCode) { | 343 Adapter.prototype.initBackground_ = function() { |
335 chrome.runtime.getBackgroundPage((function() { | 344 chrome.runtime.getBackgroundPage((function() { |
336 this.isBgControllerSwitching_ = true; | 345 this.isBgControllerSwitching_ = true; |
337 chrome.runtime.sendMessage( | 346 chrome.runtime.sendMessage( |
338 goog.object.create(Name.TYPE, Type.CONNECT)); | 347 goog.object.create(Name.TYPE, Type.CONNECT)); |
339 chrome.runtime.sendMessage(goog.object.create(Name.TYPE, | |
340 Type.VISIBILITY_CHANGE, Name.VISIBILITY, !document.webkitHidden)); | |
341 if (languageCode) { | |
342 this.setLanguage(languageCode); | |
343 } | |
344 }).bind(this)); | 348 }).bind(this)); |
345 }; | 349 }; |
346 | 350 |
347 | 351 |
348 /** | 352 /** |
349 * Loads the keyboard settings. | 353 * Loads the keyboard settings. |
350 * | 354 * |
351 * @param {string} languageCode The language code. | 355 * @param {string} languageCode The language code. |
352 */ | 356 */ |
353 Adapter.prototype.initialize = function(languageCode) { | 357 Adapter.prototype.initialize = function(languageCode) { |
354 if (chrome.accessibilityFeatures && | 358 if (chrome.accessibilityFeatures && |
355 chrome.accessibilityFeatures.spokenFeedback) { | 359 chrome.accessibilityFeatures.spokenFeedback) { |
356 chrome.accessibilityFeatures.spokenFeedback.get({}, (function(details) { | 360 chrome.accessibilityFeatures.spokenFeedback.get({}, (function(details) { |
357 this.isChromeVoxOn = details['value']; | 361 this.isChromeVoxOn = details['value']; |
358 }).bind(this)); | 362 }).bind(this)); |
359 chrome.accessibilityFeatures.spokenFeedback.onChange.addListener((function( | 363 chrome.accessibilityFeatures.spokenFeedback.onChange.addListener((function( |
360 details) { | 364 details) { |
361 this.isChromeVoxOn = details['value']; | 365 this.isChromeVoxOn = details['value']; |
362 }).bind(this)); | 366 }).bind(this)); |
363 } | 367 } |
364 | 368 |
365 this.initBackground_(languageCode); | 369 this.initBackground_(); |
366 | 370 |
367 var StateType = i18n.input.chrome.inputview.ReadyState.StateType; | 371 var StateType = i18n.input.chrome.inputview.ReadyState.StateType; |
368 if (window.inputview) { | 372 if (window.inputview) { |
369 if (inputview.getKeyboardConfig) { | 373 inputview.getKeyboardConfig((function(config) { |
370 inputview.getKeyboardConfig((function(config) { | 374 this.isA11yMode = !!config['a11ymode']; |
371 this.isA11yMode = !!config['a11ymode']; | 375 this.isExperimental = !!config['experimental']; |
372 this.isExperimental = !!config['experimental']; | |
373 this.readyState_.markStateReady(StateType.KEYBOARD_CONFIG_READY); | |
374 if (this.readyState_.isReady(StateType.IME_LIST_READY)) { | |
375 this.dispatchEvent(new goog.events.Event( | |
376 i18n.input.chrome.inputview.events.EventType.SETTINGS_READY)); | |
377 } | |
378 }).bind(this)); | |
379 } else { | |
380 this.readyState_.markStateReady(StateType.KEYBOARD_CONFIG_READY); | 376 this.readyState_.markStateReady(StateType.KEYBOARD_CONFIG_READY); |
381 } | 377 this.maybeDispatchSettingsReadyEvent_(); |
382 if (inputview.getInputMethods) { | 378 }).bind(this)); |
383 inputview.getInputMethods((function(inputMethods) { | 379 inputview.getInputMethods((function(inputMethods) { |
384 // Only show globe key to switching between IMEs when there are more | 380 // Only show globe key to switching between IMEs when there are more |
385 // than one IME. | 381 // than one IME. |
386 this.showGlobeKey = inputMethods.length > 1; | 382 this.showGlobeKey = inputMethods.length > 1; |
387 this.readyState_.markStateReady(StateType.IME_LIST_READY); | |
388 if (this.readyState_.isReady(StateType.KEYBOARD_CONFIG_READY)) { | |
389 this.dispatchEvent(new goog.events.Event( | |
390 i18n.input.chrome.inputview.events.EventType.SETTINGS_READY)); | |
391 } | |
392 }).bind(this)); | |
393 } else { | |
394 this.readyState_.markStateReady(StateType.IME_LIST_READY); | 383 this.readyState_.markStateReady(StateType.IME_LIST_READY); |
395 } | 384 this.maybeDispatchSettingsReadyEvent_(); |
| 385 }).bind(this)); |
| 386 inputview.getInputMethodConfig((function(config) { |
| 387 this.isQPInputView = !!config['isNewQPInputViewEnabled']; |
| 388 this.readyState_.markStateReady(StateType.INPUT_METHOD_CONFIG_READY); |
| 389 this.maybeDispatchSettingsReadyEvent_(); |
| 390 }).bind(this)); |
396 } else { | 391 } else { |
397 this.readyState_.markStateReady(StateType.IME_LIST_READY); | 392 this.readyState_.markStateReady(StateType.IME_LIST_READY); |
398 this.readyState_.markStateReady(StateType.KEYBOARD_CONFIG_READY); | 393 this.readyState_.markStateReady(StateType.KEYBOARD_CONFIG_READY); |
| 394 this.readyState_.markStateReady(StateType.INPUT_METHOD_CONFIG_READY); |
399 } | 395 } |
400 | 396 |
401 if (this.readyState_.isReady(StateType.KEYBOARD_CONFIG_READY) && | 397 this.maybeDispatchSettingsReadyEvent_(); |
402 this.readyState_.isReady(StateType.IME_LIST_READY)) { | 398 }; |
| 399 |
| 400 |
| 401 /** |
| 402 * Dispatch event SETTINGS_READY if all required bits are flipped. |
| 403 * |
| 404 * @private |
| 405 */ |
| 406 Adapter.prototype.maybeDispatchSettingsReadyEvent_ = function() { |
| 407 var StateType = i18n.input.chrome.inputview.ReadyState.StateType; |
| 408 var states = [ |
| 409 StateType.KEYBOARD_CONFIG_READY, |
| 410 StateType.IME_LIST_READY, |
| 411 StateType.INPUT_METHOD_CONFIG_READY]; |
| 412 var ready = true; |
| 413 for (var i = 0; i < states.length; i++) { |
| 414 ready = ready && this.readyState_.isReady(states[i]); |
| 415 } |
| 416 if (ready) { |
403 window.setTimeout((function() { | 417 window.setTimeout((function() { |
404 this.dispatchEvent(new goog.events.Event( | 418 this.dispatchEvent(new goog.events.Event( |
405 i18n.input.chrome.inputview.events.EventType.SETTINGS_READY)); | 419 i18n.input.chrome.inputview.events.EventType.SETTINGS_READY)); |
406 }).bind(this), 0); | 420 }).bind(this), 0); |
407 } | 421 } |
408 }; | 422 }; |
409 | 423 |
410 | 424 |
411 /** | 425 /** |
412 * Gets the currently activated input method. | 426 * Gets the currently activated input method. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 | 466 |
453 /** | 467 /** |
454 * Callback for visibility change on the input view window. | 468 * Callback for visibility change on the input view window. |
455 * | 469 * |
456 * @private | 470 * @private |
457 */ | 471 */ |
458 Adapter.prototype.onVisibilityChange_ = function() { | 472 Adapter.prototype.onVisibilityChange_ = function() { |
459 this.isVisible = !document.webkitHidden; | 473 this.isVisible = !document.webkitHidden; |
460 this.dispatchEvent(new goog.events.Event(i18n.input.chrome.inputview. | 474 this.dispatchEvent(new goog.events.Event(i18n.input.chrome.inputview. |
461 events.EventType.VISIBILITY_CHANGE)); | 475 events.EventType.VISIBILITY_CHANGE)); |
462 chrome.runtime.sendMessage(goog.object.create(Name.TYPE, | 476 chrome.runtime.sendMessage(goog.object.create( |
463 Type.VISIBILITY_CHANGE, Name.VISIBILITY, !document.webkitHidden)); | 477 Name.TYPE, Type.VISIBILITY_CHANGE, |
| 478 Name.VISIBILITY, !document.webkitHidden, |
| 479 Name.IS_EXPERIMENTAL, this.isExperimental, |
| 480 Name.WORKSPACE_HEIGHT, screen.height - window.innerHeight)); |
464 }; | 481 }; |
465 | 482 |
466 | 483 |
467 /** | 484 /** |
468 * Sends request for completion. | 485 * Sends request for completion. |
469 * | 486 * |
470 * @param {string} query . | 487 * @param {string} query . |
471 * @param {!Object=} opt_spatialData . | 488 * @param {!Object=} opt_spatialData . |
472 */ | 489 */ |
473 Adapter.prototype.sendCompletionRequest = function(query, opt_spatialData) { | 490 Adapter.prototype.sendCompletionRequest = function(query, opt_spatialData) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 break; | 604 break; |
588 case Type.CONTEXT_BLUR: | 605 case Type.CONTEXT_BLUR: |
589 this.onContextBlur_(); | 606 this.onContextBlur_(); |
590 break; | 607 break; |
591 case Type.SURROUNDING_TEXT_CHANGED: | 608 case Type.SURROUNDING_TEXT_CHANGED: |
592 this.onSurroundingTextChanged_(request[Name.TEXT]); | 609 this.onSurroundingTextChanged_(request[Name.TEXT]); |
593 break; | 610 break; |
594 case Type.UPDATE_SETTINGS: | 611 case Type.UPDATE_SETTINGS: |
595 this.onUpdateSettings_(msg); | 612 this.onUpdateSettings_(msg); |
596 break; | 613 break; |
| 614 case Type.VOICE_STATE_CHANGE: |
597 case Type.HWT_NETWORK_ERROR: | 615 case Type.HWT_NETWORK_ERROR: |
598 case Type.HWT_PRIVACY_INFO: | |
599 case Type.FRONT_TOGGLE_LANGUAGE_STATE: | 616 case Type.FRONT_TOGGLE_LANGUAGE_STATE: |
600 this.dispatchEvent(new i18n.input.chrome.message.Event(type, msg)); | 617 this.dispatchEvent(new i18n.input.chrome.message.Event(type, msg)); |
601 break; | 618 break; |
602 } | 619 } |
603 }; | 620 }; |
604 | 621 |
605 | 622 |
606 /** | 623 /** |
607 * Sends the privacy confirmed message to background and broadcasts it. | 624 * Sends the voice state to background. |
| 625 * |
| 626 * @param {boolean} state . |
608 */ | 627 */ |
609 Adapter.prototype.sendHwtPrivacyConfirmMessage = function() { | 628 Adapter.prototype.sendVoiceViewStateChange = function(state) { |
610 chrome.runtime.sendMessage( | 629 chrome.runtime.sendMessage(goog.object.create( |
611 goog.object.create(Name.TYPE, Type.HWT_PRIVACY_GOT_IT)); | 630 Name.TYPE, Type.VOICE_VIEW_STATE_CHANGE, Name.MSG, state)); |
612 this.dispatchEvent( | |
613 new goog.events.Event(Type.HWT_PRIVACY_GOT_IT)); | |
614 }; | 631 }; |
615 | 632 |
616 | 633 |
617 /** @override */ | 634 /** @override */ |
618 Adapter.prototype.disposeInternal = function() { | 635 Adapter.prototype.disposeInternal = function() { |
619 goog.dispose(this.handler_); | 636 goog.dispose(this.handler_); |
620 | 637 |
621 goog.base(this, 'disposeInternal'); | 638 goog.base(this, 'disposeInternal'); |
622 }; | 639 }; |
623 | 640 |
(...skipping 28 matching lines...) Expand all Loading... |
652 * Unset the inputtool | 669 * Unset the inputtool |
653 */ | 670 */ |
654 Adapter.prototype.unsetController = function() { | 671 Adapter.prototype.unsetController = function() { |
655 chrome.runtime.sendMessage( | 672 chrome.runtime.sendMessage( |
656 goog.object.create( | 673 goog.object.create( |
657 Name.TYPE, | 674 Name.TYPE, |
658 Type.UNSET_CONTROLLER)); | 675 Type.UNSET_CONTROLLER)); |
659 }; | 676 }; |
660 }); // goog.scope | 677 }); // goog.scope |
661 | 678 |
OLD | NEW |