| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 }.bind(this))); | 197 }.bind(this))); |
| 198 } | 198 } |
| 199 | 199 |
| 200 Promise.all(promises).then(function(results) { | 200 Promise.all(promises).then(function(results) { |
| 201 if (!this.isConnected) { | 201 if (!this.isConnected) { |
| 202 // Return early if this element was detached from the DOM before this | 202 // Return early if this element was detached from the DOM before this |
| 203 // async callback executes (can happen during testing). | 203 // async callback executes (can happen during testing). |
| 204 return; | 204 return; |
| 205 } | 205 } |
| 206 | 206 |
| 207 // TODO(dpapad): Cleanup this code. It uses results[3] and results[4] |
| 208 // which only exist for ChromeOS. |
| 207 this.createModel_(results[1], results[2], results[3], results[4]); | 209 this.createModel_(results[1], results[2], results[3], results[4]); |
| 208 this.resolver_.resolve(); | 210 this.resolver_.resolve(); |
| 209 }.bind(this)); | 211 }.bind(this)); |
| 210 | 212 |
| 211 if (cr.isChromeOS) { | 213 if (cr.isChromeOS) { |
| 212 this.boundOnInputMethodChanged_ = this.onInputMethodChanged_.bind(this); | 214 this.boundOnInputMethodChanged_ = this.onInputMethodChanged_.bind(this); |
| 213 this.inputMethodPrivate.onChanged.addListener( | 215 this.inputMethodPrivate.onChanged.addListener( |
| 214 assert(this.boundOnInputMethodChanged_)); | 216 assert(this.boundOnInputMethodChanged_)); |
| 215 } | 217 } |
| 216 }, | 218 }, |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 478 |
| 477 // LanguageHelper implementation. | 479 // LanguageHelper implementation. |
| 478 // TODO(michaelpg): replace duplicate docs with @override once b/24294625 | 480 // TODO(michaelpg): replace duplicate docs with @override once b/24294625 |
| 479 // is fixed. | 481 // is fixed. |
| 480 | 482 |
| 481 /** @return {!Promise} */ | 483 /** @return {!Promise} */ |
| 482 whenReady: function() { | 484 whenReady: function() { |
| 483 return this.resolver_.promise; | 485 return this.resolver_.promise; |
| 484 }, | 486 }, |
| 485 | 487 |
| 488 // <if expr="chromeos or is_win"> |
| 486 /** | 489 /** |
| 487 * Sets the prospective UI language to the chosen language. This won't affect | 490 * Sets the prospective UI language to the chosen language. This won't affect |
| 488 * the actual UI language until a restart. | 491 * the actual UI language until a restart. |
| 489 * @param {string} languageCode | 492 * @param {string} languageCode |
| 490 */ | 493 */ |
| 491 setProspectiveUILanguage: function(languageCode) { | 494 setProspectiveUILanguage: function(languageCode) { |
| 492 assert(cr.isChromeOS || cr.isWindows); | |
| 493 chrome.send('setProspectiveUILanguage', [languageCode]); | 495 chrome.send('setProspectiveUILanguage', [languageCode]); |
| 494 }, | 496 }, |
| 495 | 497 |
| 496 /** | 498 /** |
| 497 * True if the prospective UI language was changed from its starting value. | 499 * True if the prospective UI language was changed from its starting value. |
| 498 * @return {boolean} | 500 * @return {boolean} |
| 499 */ | 501 */ |
| 500 requiresRestart: function() { | 502 requiresRestart: function() { |
| 501 return this.originalProspectiveUILanguage_ != | 503 return this.originalProspectiveUILanguage_ != |
| 502 this.languages.prospectiveUILanguage; | 504 this.languages.prospectiveUILanguage; |
| 503 }, | 505 }, |
| 506 // </if> |
| 504 | 507 |
| 505 /** | 508 /** |
| 506 * @param {string} languageCode | 509 * @param {string} languageCode |
| 507 * @return {boolean} True if the language is enabled. | 510 * @return {boolean} True if the language is enabled. |
| 508 */ | 511 */ |
| 509 isLanguageEnabled: function(languageCode) { | 512 isLanguageEnabled: function(languageCode) { |
| 510 return this.enabledLanguageSet_.has(languageCode); | 513 return this.enabledLanguageSet_.has(languageCode); |
| 511 }, | 514 }, |
| 512 | 515 |
| 513 /** | 516 /** |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 }, | 722 }, |
| 720 | 723 |
| 721 /** | 724 /** |
| 722 * @param {string} languageCode | 725 * @param {string} languageCode |
| 723 * @return {!chrome.languageSettingsPrivate.Language|undefined} | 726 * @return {!chrome.languageSettingsPrivate.Language|undefined} |
| 724 */ | 727 */ |
| 725 getLanguage: function(languageCode) { | 728 getLanguage: function(languageCode) { |
| 726 return this.supportedLanguageMap_.get(languageCode); | 729 return this.supportedLanguageMap_.get(languageCode); |
| 727 }, | 730 }, |
| 728 | 731 |
| 729 /** | 732 // <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 */ | 733 /** @param {string} id */ |
| 739 addInputMethod: function(id) { | 734 addInputMethod: function(id) { |
| 740 assert(cr.isChromeOS); | |
| 741 if (!this.supportedInputMethodMap_.has(id)) | 735 if (!this.supportedInputMethodMap_.has(id)) |
| 742 return; | 736 return; |
| 743 this.languageSettingsPrivate.addInputMethod(id); | 737 this.languageSettingsPrivate.addInputMethod(id); |
| 744 }, | 738 }, |
| 745 | 739 |
| 746 /** @param {string} id */ | 740 /** @param {string} id */ |
| 747 removeInputMethod: function(id) { | 741 removeInputMethod: function(id) { |
| 748 assert(cr.isChromeOS); | |
| 749 if (!this.supportedInputMethodMap_.has(id)) | 742 if (!this.supportedInputMethodMap_.has(id)) |
| 750 return; | 743 return; |
| 751 this.languageSettingsPrivate.removeInputMethod(id); | 744 this.languageSettingsPrivate.removeInputMethod(id); |
| 752 }, | 745 }, |
| 753 | 746 |
| 754 /** @param {string} id */ | 747 /** @param {string} id */ |
| 755 setCurrentInputMethod: function(id) { | 748 setCurrentInputMethod: function(id) { |
| 756 assert(cr.isChromeOS); | |
| 757 this.inputMethodPrivate.setCurrentInputMethod(id); | 749 this.inputMethodPrivate.setCurrentInputMethod(id); |
| 758 }, | 750 }, |
| 759 | 751 |
| 760 /** | 752 /** |
| 761 * @param {string} languageCode | 753 * @param {string} languageCode |
| 762 * @return {!Array<!chrome.languageSettingsPrivate.InputMethod>} | 754 * @return {!Array<!chrome.languageSettingsPrivate.InputMethod>} |
| 763 */ | 755 */ |
| 764 getInputMethodsForLanguage: function(languageCode) { | 756 getInputMethodsForLanguage: function(languageCode) { |
| 765 return this.languageInputMethods_.get(languageCode) || []; | 757 return this.languageInputMethods_.get(languageCode) || []; |
| 766 }, | 758 }, |
| 767 | 759 |
| 768 /** | 760 /** |
| 769 * @param {!chrome.languageSettingsPrivate.InputMethod} inputMethod | 761 * @param {!chrome.languageSettingsPrivate.InputMethod} inputMethod |
| 770 * @return {boolean} | 762 * @return {boolean} |
| 771 */ | 763 */ |
| 772 isComponentIme: function(inputMethod) { | 764 isComponentIme: function(inputMethod) { |
| 773 assert(cr.isChromeOS); | |
| 774 return inputMethod.id.startsWith('_comp_'); | 765 return inputMethod.id.startsWith('_comp_'); |
| 775 }, | 766 }, |
| 776 | 767 |
| 777 /** @param {string} id Input method ID. */ | 768 /** @param {string} id Input method ID. */ |
| 778 openInputMethodOptions: function(id) { | 769 openInputMethodOptions: function(id) { |
| 779 assert(cr.isChromeOS); | |
| 780 this.inputMethodPrivate.openOptionsPage(id); | 770 this.inputMethodPrivate.openOptionsPage(id); |
| 781 }, | 771 }, |
| 782 | 772 |
| 783 /** @param {string} id New current input method ID. */ | 773 /** @param {string} id New current input method ID. */ |
| 784 onInputMethodChanged_: function(id) { | 774 onInputMethodChanged_: function(id) { |
| 785 assert(cr.isChromeOS); | |
| 786 this.set('languages.inputMethods.currentId', id); | 775 this.set('languages.inputMethods.currentId', id); |
| 787 }, | 776 }, |
| 788 | 777 |
| 789 /** @param {string} id Added input method ID. */ | 778 /** @param {string} id Added input method ID. */ |
| 790 onInputMethodAdded_: function(id) { | 779 onInputMethodAdded_: function(id) { |
| 791 assert(cr.isChromeOS); | |
| 792 this.updateEnabledInputMethods_(); | 780 this.updateEnabledInputMethods_(); |
| 793 }, | 781 }, |
| 794 | 782 |
| 795 /** @param {string} id Removed input method ID. */ | 783 /** @param {string} id Removed input method ID. */ |
| 796 onInputMethodRemoved_: function(id) { | 784 onInputMethodRemoved_: function(id) { |
| 797 assert(cr.isChromeOS); | |
| 798 this.updateEnabledInputMethods_(); | 785 this.updateEnabledInputMethods_(); |
| 799 }, | 786 }, |
| 787 // </if> |
| 800 }); | 788 }); |
| 801 })(); | 789 })(); |
| OLD | NEW |