OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 'settings-languages' handles Chrome's language and input | 6 * @fileoverview 'settings-languages' handles Chrome's language and input |
7 * method settings. The 'languages' property, which reflects the current | 7 * method settings. The 'languages' property, which reflects the current |
8 * language settings, must not be changed directly. Instead, changes to | 8 * language settings, must not be changed directly. Instead, changes to |
9 * language settings should be made using the LanguageHelper APIs provided by | 9 * language settings should be made using the LanguageHelper APIs provided by |
10 * this class via languageHelper. | 10 * this class via languageHelper. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 type: Object, | 75 type: Object, |
76 value: function() { | 76 value: function() { |
77 return new PromiseResolver(); | 77 return new PromiseResolver(); |
78 }, | 78 }, |
79 }, | 79 }, |
80 | 80 |
81 /** @type {!LanguageSettingsPrivate} */ | 81 /** @type {!LanguageSettingsPrivate} */ |
82 languageSettingsPrivate: Object, | 82 languageSettingsPrivate: Object, |
83 | 83 |
84 /** @type {!InputMethodPrivate} */ | 84 /** @type {!InputMethodPrivate} */ |
85 inputMethodPrivate: Object, | 85 inputMethodPrivate: Object, |
michaelpg
2017/04/18 05:03:35
Wondering if this and the input method properties
dpapad
2017/04/18 18:31:20
I am addressing those in my next CL, which hides t
| |
86 | 86 |
87 /** | 87 /** |
88 * Hash map of supported languages by language codes for fast lookup. | 88 * Hash map of supported languages by language codes for fast lookup. |
89 * @private {!Map<string, !chrome.languageSettingsPrivate.Language>} | 89 * @private {!Map<string, !chrome.languageSettingsPrivate.Language>} |
90 */ | 90 */ |
91 supportedLanguageMap_: { | 91 supportedLanguageMap_: { |
92 type: Object, | 92 type: Object, |
93 value: function() { return new Map(); }, | 93 value: function() { return new Map(); }, |
94 }, | 94 }, |
95 | 95 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 // Get the language list. | 167 // Get the language list. |
168 promises[1] = new Promise(function(resolve) { | 168 promises[1] = new Promise(function(resolve) { |
169 this.languageSettingsPrivate.getLanguageList(resolve); | 169 this.languageSettingsPrivate.getLanguageList(resolve); |
170 }.bind(this)); | 170 }.bind(this)); |
171 | 171 |
172 // Get the translate target language. | 172 // Get the translate target language. |
173 promises[2] = new Promise(function(resolve) { | 173 promises[2] = new Promise(function(resolve) { |
174 this.languageSettingsPrivate.getTranslateTargetLanguage(resolve); | 174 this.languageSettingsPrivate.getTranslateTargetLanguage(resolve); |
175 }.bind(this)); | 175 }.bind(this)); |
176 | 176 |
177 if (cr.isChromeOS) { | 177 if (cr.isChromeOS) { |
michaelpg
2017/04/18 05:03:35
this stuff is platform specific for the same reaso
dpapad
2017/04/18 18:31:20
The platform specific code and the generic code ar
michaelpg
2017/04/18 22:47:58
Oof, you're right, and to make things worse the co
| |
178 promises[3] = new Promise(function(resolve) { | 178 promises[3] = new Promise(function(resolve) { |
179 this.languageSettingsPrivate.getInputMethodLists(function(lists) { | 179 this.languageSettingsPrivate.getInputMethodLists(function(lists) { |
180 resolve(lists.componentExtensionImes.concat( | 180 resolve(lists.componentExtensionImes.concat( |
181 lists.thirdPartyExtensionImes)); | 181 lists.thirdPartyExtensionImes)); |
182 }); | 182 }); |
183 }.bind(this)); | 183 }.bind(this)); |
184 | 184 |
185 promises[4] = new Promise(function(resolve) { | 185 promises[4] = new Promise(function(resolve) { |
186 this.inputMethodPrivate.getCurrentInputMethod(resolve); | 186 this.inputMethodPrivate.getCurrentInputMethod(resolve); |
187 }.bind(this)); | 187 }.bind(this)); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 | 476 |
477 // LanguageHelper implementation. | 477 // LanguageHelper implementation. |
478 // TODO(michaelpg): replace duplicate docs with @override once b/24294625 | 478 // TODO(michaelpg): replace duplicate docs with @override once b/24294625 |
479 // is fixed. | 479 // is fixed. |
480 | 480 |
481 /** @return {!Promise} */ | 481 /** @return {!Promise} */ |
482 whenReady: function() { | 482 whenReady: function() { |
483 return this.resolver_.promise; | 483 return this.resolver_.promise; |
484 }, | 484 }, |
485 | 485 |
486 // <if expr="chromeos or is_win"> | |
486 /** | 487 /** |
487 * Sets the prospective UI language to the chosen language. This won't affect | 488 * Sets the prospective UI language to the chosen language. This won't affect |
488 * the actual UI language until a restart. | 489 * the actual UI language until a restart. |
489 * @param {string} languageCode | 490 * @param {string} languageCode |
490 */ | 491 */ |
491 setProspectiveUILanguage: function(languageCode) { | 492 setProspectiveUILanguage: function(languageCode) { |
492 assert(cr.isChromeOS || cr.isWindows); | |
michaelpg
2017/04/18 05:03:35
I used runtime checks instead of grit because that
dpapad
2017/04/18 18:31:20
AFAIK, GRIT is preferred. This guarantees for exam
| |
493 chrome.send('setProspectiveUILanguage', [languageCode]); | 493 chrome.send('setProspectiveUILanguage', [languageCode]); |
michaelpg
2017/04/18 05:03:35
Does it makes sense to #ifdef these handlers in C+
dpapad
2017/04/18 18:31:20
Done.
| |
494 }, | 494 }, |
495 | 495 |
496 /** | 496 /** |
497 * True if the prospective UI language was changed from its starting value. | 497 * True if the prospective UI language was changed from its starting value. |
498 * @return {boolean} | 498 * @return {boolean} |
499 */ | 499 */ |
500 requiresRestart: function() { | 500 requiresRestart: function() { |
501 return this.originalProspectiveUILanguage_ != | 501 return this.originalProspectiveUILanguage_ != |
502 this.languages.prospectiveUILanguage; | 502 this.languages.prospectiveUILanguage; |
503 }, | 503 }, |
504 // </if> | |
504 | 505 |
505 /** | 506 /** |
506 * @param {string} languageCode | 507 * @param {string} languageCode |
507 * @return {boolean} True if the language is enabled. | 508 * @return {boolean} True if the language is enabled. |
508 */ | 509 */ |
509 isLanguageEnabled: function(languageCode) { | 510 isLanguageEnabled: function(languageCode) { |
510 return this.enabledLanguageSet_.has(languageCode); | 511 return this.enabledLanguageSet_.has(languageCode); |
511 }, | 512 }, |
512 | 513 |
513 /** | 514 /** |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 }, | 720 }, |
720 | 721 |
721 /** | 722 /** |
722 * @param {string} languageCode | 723 * @param {string} languageCode |
723 * @return {!chrome.languageSettingsPrivate.Language|undefined} | 724 * @return {!chrome.languageSettingsPrivate.Language|undefined} |
724 */ | 725 */ |
725 getLanguage: function(languageCode) { | 726 getLanguage: function(languageCode) { |
726 return this.supportedLanguageMap_.get(languageCode); | 727 return this.supportedLanguageMap_.get(languageCode); |
727 }, | 728 }, |
728 | 729 |
729 /** | 730 // <if expr="chromeos"> |
730 * @param {string} id | |
731 * @return {!chrome.languageSettingsPrivate.InputMethod|undefined} | |
732 */ | |
733 getInputMethod: function(id) { | |
734 assert(cr.isChromeOS); | |
735 return this.supportedInputMethodMap_.get(id); | |
736 }, | |
737 | |
738 /** @param {string} id */ | 731 /** @param {string} id */ |
739 addInputMethod: function(id) { | 732 addInputMethod: function(id) { |
740 assert(cr.isChromeOS); | |
741 if (!this.supportedInputMethodMap_.has(id)) | 733 if (!this.supportedInputMethodMap_.has(id)) |
742 return; | 734 return; |
743 this.languageSettingsPrivate.addInputMethod(id); | 735 this.languageSettingsPrivate.addInputMethod(id); |
744 }, | 736 }, |
745 | 737 |
746 /** @param {string} id */ | 738 /** @param {string} id */ |
747 removeInputMethod: function(id) { | 739 removeInputMethod: function(id) { |
748 assert(cr.isChromeOS); | |
749 if (!this.supportedInputMethodMap_.has(id)) | 740 if (!this.supportedInputMethodMap_.has(id)) |
750 return; | 741 return; |
751 this.languageSettingsPrivate.removeInputMethod(id); | 742 this.languageSettingsPrivate.removeInputMethod(id); |
752 }, | 743 }, |
753 | 744 |
754 /** @param {string} id */ | 745 /** @param {string} id */ |
755 setCurrentInputMethod: function(id) { | 746 setCurrentInputMethod: function(id) { |
756 assert(cr.isChromeOS); | |
757 this.inputMethodPrivate.setCurrentInputMethod(id); | 747 this.inputMethodPrivate.setCurrentInputMethod(id); |
758 }, | 748 }, |
759 | 749 |
760 /** | 750 /** |
761 * @param {string} languageCode | 751 * @param {string} languageCode |
762 * @return {!Array<!chrome.languageSettingsPrivate.InputMethod>} | 752 * @return {!Array<!chrome.languageSettingsPrivate.InputMethod>} |
763 */ | 753 */ |
764 getInputMethodsForLanguage: function(languageCode) { | 754 getInputMethodsForLanguage: function(languageCode) { |
765 return this.languageInputMethods_.get(languageCode) || []; | 755 return this.languageInputMethods_.get(languageCode) || []; |
766 }, | 756 }, |
767 | 757 |
768 /** | 758 /** |
769 * @param {!chrome.languageSettingsPrivate.InputMethod} inputMethod | 759 * @param {!chrome.languageSettingsPrivate.InputMethod} inputMethod |
770 * @return {boolean} | 760 * @return {boolean} |
771 */ | 761 */ |
772 isComponentIme: function(inputMethod) { | 762 isComponentIme: function(inputMethod) { |
773 assert(cr.isChromeOS); | |
774 return inputMethod.id.startsWith('_comp_'); | 763 return inputMethod.id.startsWith('_comp_'); |
775 }, | 764 }, |
776 | 765 |
777 /** @param {string} id Input method ID. */ | 766 /** @param {string} id Input method ID. */ |
778 openInputMethodOptions: function(id) { | 767 openInputMethodOptions: function(id) { |
779 assert(cr.isChromeOS); | |
780 this.inputMethodPrivate.openOptionsPage(id); | 768 this.inputMethodPrivate.openOptionsPage(id); |
781 }, | 769 }, |
782 | 770 |
783 /** @param {string} id New current input method ID. */ | 771 /** @param {string} id New current input method ID. */ |
784 onInputMethodChanged_: function(id) { | 772 onInputMethodChanged_: function(id) { |
785 assert(cr.isChromeOS); | |
786 this.set('languages.inputMethods.currentId', id); | 773 this.set('languages.inputMethods.currentId', id); |
787 }, | 774 }, |
788 | 775 |
789 /** @param {string} id Added input method ID. */ | 776 /** @param {string} id Added input method ID. */ |
790 onInputMethodAdded_: function(id) { | 777 onInputMethodAdded_: function(id) { |
791 assert(cr.isChromeOS); | |
792 this.updateEnabledInputMethods_(); | 778 this.updateEnabledInputMethods_(); |
793 }, | 779 }, |
794 | 780 |
795 /** @param {string} id Removed input method ID. */ | 781 /** @param {string} id Removed input method ID. */ |
796 onInputMethodRemoved_: function(id) { | 782 onInputMethodRemoved_: function(id) { |
797 assert(cr.isChromeOS); | |
798 this.updateEnabledInputMethods_(); | 783 this.updateEnabledInputMethods_(); |
799 }, | 784 }, |
785 // </if> | |
800 }); | 786 }); |
801 })(); | 787 })(); |
OLD | NEW |