Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // TODO(kochi): Generalize the notification as a component and put it | 5 // TODO(kochi): Generalize the notification as a component and put it |
| 6 // in js/cr/ui/notification.js . | 6 // in js/cr/ui/notification.js . |
| 7 | 7 |
| 8 cr.define('options', function() { | 8 cr.define('options', function() { |
| 9 /** @const */ var Page = cr.ui.pageManager.Page; | 9 /** @const */ var Page = cr.ui.pageManager.Page; |
| 10 /** @const */ var PageManager = cr.ui.pageManager.PageManager; | 10 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
| 11 /** @const */ var LanguageList = options.LanguageList; | 11 /** @const */ var LanguageList = options.LanguageList; |
| 12 /** @const */ var ThirdPartyImeConfirmOverlay = | 12 /** @const */ var ThirdPartyImeConfirmOverlay = |
| 13 options.ThirdPartyImeConfirmOverlay; | 13 options.ThirdPartyImeConfirmOverlay; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Spell check dictionary download status. | 16 * Spell check dictionary download status. |
| 17 * @type {Enum} | 17 * @type {Enum} |
| 18 */ | 18 */ |
| 19 /** @const*/ var DOWNLOAD_STATUS = { | 19 /** @const*/ var DOWNLOAD_STATUS = { |
| 20 IN_PROGRESS: 1, | 20 IN_PROGRESS: 1, |
| 21 FAILED: 2 | 21 FAILED: 2 |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * The preference is a boolean that enables/disables spell checking. | 25 * The preference is a boolean that enables/disables spell checking. |
| 26 * @type {string} | 26 * @const {string} |
| 27 * @const | |
| 28 */ | 27 */ |
| 29 var ENABLE_SPELL_CHECK_PREF = 'browser.enable_spellchecking'; | 28 var ENABLE_SPELL_CHECK_PREF = 'browser.enable_spellchecking'; |
| 30 | 29 |
| 31 /** | 30 /** |
| 32 * The preference is a CSV string that describes preload engines | 31 * The preference is a CSV string that describes preload engines |
| 33 * (i.e. active input methods). | 32 * (i.e. active input methods). |
| 34 * @type {string} | 33 * @const {string} |
| 35 * @const | |
| 36 */ | 34 */ |
| 37 var PRELOAD_ENGINES_PREF = 'settings.language.preload_engines'; | 35 var PRELOAD_ENGINES_PREF = 'settings.language.preload_engines'; |
| 38 | 36 |
| 39 /** | 37 /** |
| 40 * The preference that lists the extension IMEs that are enabled in the | 38 * The preference that lists the extension IMEs that are enabled in the |
| 41 * language menu. | 39 * language menu. |
| 42 * @type {string} | 40 * @const {string} |
| 43 * @const | |
| 44 */ | 41 */ |
| 45 var ENABLED_EXTENSION_IME_PREF = 'settings.language.enabled_extension_imes'; | 42 var ENABLED_EXTENSION_IME_PREF = 'settings.language.enabled_extension_imes'; |
| 46 | 43 |
| 47 /** | 44 /** |
| 48 * The preference that lists the languages which are not translated. | 45 * The preference that lists the languages which are not translated. |
| 49 * @type {string} | 46 * @const {string} |
| 50 * @const | |
| 51 */ | 47 */ |
| 52 var TRANSLATE_BLOCKED_LANGUAGES_PREF = 'translate_blocked_languages'; | 48 var TRANSLATE_BLOCKED_LANGUAGES_PREF = 'translate_blocked_languages'; |
| 53 | 49 |
| 54 /** | 50 /** |
| 55 * The preference key that is a string that describes the spell check | 51 * The preference key that is a string that describes the spell check |
| 56 * dictionary language, like "en-US". | 52 * dictionary language, like "en-US". |
| 57 * @type {string} | 53 * @const {string} |
|
Dan Beam
2015/06/25 02:25:59
try to minimize the amount of changes you make in
Julius
2015/07/06 22:38:52
I'll undo these @const changes. They're unnecessar
| |
| 58 * @const | |
| 59 */ | 54 */ |
| 60 var SPELL_CHECK_DICTIONARY_PREF = 'spellcheck.dictionary'; | 55 var SPELL_CHECK_DICTIONARY_PREF = 'spellcheck.dictionary'; |
| 61 | 56 |
| 62 /** | 57 /** |
| 58 * The preference key that describes the spell check dictionary languages | |
| 59 * currently selected (as a comma separated string, like "en-US,sl-SI"). | |
| 60 * @const {string} | |
| 61 */ | |
| 62 var SPELL_CHECK_DICTIONARIES_PREF = 'spellcheck.dictionaries'; | |
| 63 | |
| 64 /** | |
| 63 * The preference that indicates if the Translate feature is enabled. | 65 * The preference that indicates if the Translate feature is enabled. |
| 64 * @type {string} | 66 * @const {string} |
| 65 * @const | |
| 66 */ | 67 */ |
| 67 var ENABLE_TRANSLATE = 'translate.enabled'; | 68 var ENABLE_TRANSLATE = 'translate.enabled'; |
| 68 | 69 |
| 69 ///////////////////////////////////////////////////////////////////////////// | 70 ///////////////////////////////////////////////////////////////////////////// |
| 70 // LanguageOptions class: | 71 // LanguageOptions class: |
| 71 | 72 |
| 72 /** | 73 /** |
| 73 * Encapsulated handling of ChromeOS language options page. | 74 * Encapsulated handling of ChromeOS language options page. |
| 74 * @constructor | 75 * @constructor |
| 75 * @extends {cr.ui.pageManager.Page} | 76 * @extends {cr.ui.pageManager.Page} |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 * @private | 135 * @private |
| 135 */ | 136 */ |
| 136 translateSupportedLanguages_: [], | 137 translateSupportedLanguages_: [], |
| 137 | 138 |
| 138 /** | 139 /** |
| 139 * The preference is a string that describes the spell check dictionary | 140 * The preference is a string that describes the spell check dictionary |
| 140 * language, like "en-US". | 141 * language, like "en-US". |
| 141 * @type {string} | 142 * @type {string} |
| 142 * @private | 143 * @private |
| 143 */ | 144 */ |
| 144 spellCheckDictionary_: '', | 145 spellCheckLanguage_: '', |
| 146 | |
| 147 /** | |
| 148 * The dictionary of currently selected spell check dictionary languages, | |
| 149 * like {"en-US": true, "sl-SI": true}. | |
| 150 * @type {Object} | |
| 151 * @private | |
| 152 */ | |
| 153 spellCheckLanguages_: {}, | |
| 145 | 154 |
| 146 /** | 155 /** |
| 147 * The map of language code to input method IDs, like: | 156 * The map of language code to input method IDs, like: |
| 148 * {'ja': ['mozc', 'mozc-jp'], 'zh-CN': ['pinyin'], ...} | 157 * {'ja': ['mozc', 'mozc-jp'], 'zh-CN': ['pinyin'], ...} |
| 149 * @type {Object} | 158 * @type {Object} |
| 150 * @private | 159 * @private |
| 151 */ | 160 */ |
| 152 languageCodeToInputMethodIdsMap_: {}, | 161 languageCodeToInputMethodIdsMap_: {}, |
| 153 | 162 |
| 154 /** | 163 /** |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 180 this.initializeLanguageCodeToInputMethodIdsMap_(); | 189 this.initializeLanguageCodeToInputMethodIdsMap_(); |
| 181 } | 190 } |
| 182 | 191 |
| 183 var checkbox = $('offer-to-translate-in-this-language'); | 192 var checkbox = $('offer-to-translate-in-this-language'); |
| 184 checkbox.addEventListener('click', | 193 checkbox.addEventListener('click', |
| 185 this.handleOfferToTranslateCheckboxClick_.bind(this)); | 194 this.handleOfferToTranslateCheckboxClick_.bind(this)); |
| 186 | 195 |
| 187 Preferences.getInstance().addEventListener( | 196 Preferences.getInstance().addEventListener( |
| 188 TRANSLATE_BLOCKED_LANGUAGES_PREF, | 197 TRANSLATE_BLOCKED_LANGUAGES_PREF, |
| 189 this.handleTranslateBlockedLanguagesPrefChange_.bind(this)); | 198 this.handleTranslateBlockedLanguagesPrefChange_.bind(this)); |
| 190 Preferences.getInstance().addEventListener(SPELL_CHECK_DICTIONARY_PREF, | 199 |
| 200 if (loadTimeData.getBoolean('enableMultilingualSpellChecker')) { | |
| 201 Preferences.getInstance().addEventListener( | |
| 202 SPELL_CHECK_DICTIONARIES_PREF, | |
| 203 this.handleSpellCheckDictionariesPrefChange_.bind(this)); | |
| 204 } else { | |
| 205 Preferences.getInstance().addEventListener(SPELL_CHECK_DICTIONARY_PREF, | |
| 191 this.handleSpellCheckDictionaryPrefChange_.bind(this)); | 206 this.handleSpellCheckDictionaryPrefChange_.bind(this)); |
| 207 } | |
| 208 | |
| 192 Preferences.getInstance().addEventListener(ENABLE_TRANSLATE, | 209 Preferences.getInstance().addEventListener(ENABLE_TRANSLATE, |
| 193 this.handleEnableTranslatePrefChange_.bind(this)); | 210 this.handleEnableTranslatePrefChange_.bind(this)); |
| 194 this.translateSupportedLanguages_ = | 211 this.translateSupportedLanguages_ = |
| 195 loadTimeData.getValue('translateSupportedLanguages'); | 212 loadTimeData.getValue('translateSupportedLanguages'); |
| 196 | 213 |
| 197 // Set up add button. | 214 // Set up add button. |
| 198 var onclick = function(e) { | 215 var onclick = function(e) { |
| 199 // Add the language without showing the overlay if it's specified in | 216 // Add the language without showing the overlay if it's specified in |
| 200 // the URL hash (ex. lang_add=ja). Used for automated testing. | 217 // the URL hash (ex. lang_add=ja). Used for automated testing. |
| 201 var match = document.location.hash.match(/\blang_add=([\w-]+)/); | 218 var match = document.location.hash.match(/\blang_add=([\w-]+)/); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 // Handle spell check enable/disable. | 250 // Handle spell check enable/disable. |
| 234 if (!cr.isMac) { | 251 if (!cr.isMac) { |
| 235 Preferences.getInstance().addEventListener( | 252 Preferences.getInstance().addEventListener( |
| 236 ENABLE_SPELL_CHECK_PREF, | 253 ENABLE_SPELL_CHECK_PREF, |
| 237 this.updateEnableSpellCheck_.bind(this)); | 254 this.updateEnableSpellCheck_.bind(this)); |
| 238 } | 255 } |
| 239 } | 256 } |
| 240 | 257 |
| 241 // Handle clicks on "Use this language for spell checking" button. | 258 // Handle clicks on "Use this language for spell checking" button. |
| 242 if (!cr.isMac) { | 259 if (!cr.isMac) { |
| 243 var spellCheckLanguageButton = getRequiredElement( | 260 if (loadTimeData.getBoolean('enableMultilingualSpellChecker')) { |
| 244 'language-options-spell-check-language-button'); | 261 $('spellcheck-language-checkbox').addEventListener( |
| 245 spellCheckLanguageButton.addEventListener( | 262 'change', |
| 246 'click', | 263 this.handleSpellCheckLanguageCheckboxClick_.bind(this)); |
| 247 this.handleSpellCheckLanguageButtonClick_.bind(this)); | 264 } else { |
| 265 var spellCheckLanguageButton = getRequiredElement( | |
| 266 'spellcheck-language-button'); | |
| 267 spellCheckLanguageButton.addEventListener( | |
| 268 'click', | |
| 269 this.handleSpellCheckLanguageButtonClick_.bind(this)); | |
| 270 } | |
| 248 } | 271 } |
| 249 | 272 |
| 250 if (cr.isChromeOS) { | 273 if (cr.isChromeOS) { |
| 251 $('language-options-ui-restart-button').onclick = function() { | 274 $('language-options-ui-restart-button').onclick = function() { |
| 252 chrome.send('uiLanguageRestart'); | 275 chrome.send('uiLanguageRestart'); |
| 253 }; | 276 }; |
| 254 } | 277 } |
| 255 | 278 |
| 256 $('language-confirm').onclick = | 279 $('language-confirm').onclick = |
| 257 PageManager.closeOverlay.bind(PageManager); | 280 PageManager.closeOverlay.bind(PageManager); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 } | 443 } |
| 421 | 444 |
| 422 this.updateOfferToTranslateCheckbox_(languageCode); | 445 this.updateOfferToTranslateCheckbox_(languageCode); |
| 423 | 446 |
| 424 if (cr.isWindows || cr.isChromeOS) | 447 if (cr.isWindows || cr.isChromeOS) |
| 425 this.updateUiLanguageButton_(languageCode); | 448 this.updateUiLanguageButton_(languageCode); |
| 426 | 449 |
| 427 this.updateSelectedLanguageName_(languageCode); | 450 this.updateSelectedLanguageName_(languageCode); |
| 428 | 451 |
| 429 if (!cr.isMac) | 452 if (!cr.isMac) |
| 430 this.updateSpellCheckLanguageButton_(languageCode); | 453 this.updateSpellCheckLanguageControls_(languageCode); |
| 431 | 454 |
| 432 if (cr.isChromeOS) | 455 if (cr.isChromeOS) |
| 433 this.updateInputMethodList_(languageCode); | 456 this.updateInputMethodList_(languageCode); |
| 434 | 457 |
| 435 this.updateLanguageListInAddLanguageOverlay_(); | 458 this.updateLanguageListInAddLanguageOverlay_(); |
| 436 }, | 459 }, |
| 437 | 460 |
| 438 /** | 461 /** |
| 439 * Handles languageOptionsList's save event. | 462 * Handles languageOptionsList's save event. |
| 440 * @param {Event} e Save event. | 463 * @param {Event} e Save event. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 showMutuallyExclusiveNodes( | 620 showMutuallyExclusiveNodes( |
| 598 [uiLanguageButton, uiLanguageMessage, uiLanguageNotification], 1); | 621 [uiLanguageButton, uiLanguageMessage, uiLanguageNotification], 1); |
| 599 } | 622 } |
| 600 }, | 623 }, |
| 601 | 624 |
| 602 /** | 625 /** |
| 603 * Updates the spell check language button. | 626 * Updates the spell check language button. |
| 604 * @param {string} languageCode Language code (ex. "fr"). | 627 * @param {string} languageCode Language code (ex. "fr"). |
| 605 * @private | 628 * @private |
| 606 */ | 629 */ |
| 607 updateSpellCheckLanguageButton_: function(languageCode) { | 630 updateSpellCheckLanguageControls_: function(languageCode) { |
|
Dan Beam
2015/06/25 02:25:59
assert(languageCode);
Julius
2015/07/06 22:38:52
Done.
| |
| 608 var spellCheckLanguageSection = $('language-options-spellcheck'); | 631 var spellCheckLanguageSection = $('language-options-spellcheck'); |
| 609 var spellCheckLanguageButton = | 632 var spellCheckLanguageButton = |
| 610 $('language-options-spell-check-language-button'); | 633 $('spellcheck-language-button'); |
| 634 var spellCheckLanguageCheckboxDiv = | |
| 635 $('spellcheck-language-checkbox-container'); | |
| 636 var spellCheckLanguageCheckbox = | |
| 637 $('spellcheck-language-checkbox'); | |
| 611 var spellCheckLanguageMessage = | 638 var spellCheckLanguageMessage = |
| 612 $('language-options-spell-check-language-message'); | 639 $('spellcheck-language-message'); |
| 613 var dictionaryDownloadInProgress = | 640 var dictionaryDownloadInProgress = |
| 614 $('language-options-dictionary-downloading-message'); | 641 $('language-options-dictionary-downloading-message'); |
| 615 var dictionaryDownloadFailed = | 642 var dictionaryDownloadFailed = |
| 616 $('language-options-dictionary-download-failed-message'); | 643 $('language-options-dictionary-download-failed-message'); |
| 617 var dictionaryDownloadFailHelp = | 644 var dictionaryDownloadFailHelp = |
| 618 $('language-options-dictionary-download-fail-help-message'); | 645 $('language-options-dictionary-download-fail-help-message'); |
| 646 | |
| 619 spellCheckLanguageSection.hidden = false; | 647 spellCheckLanguageSection.hidden = false; |
| 620 spellCheckLanguageMessage.hidden = true; | 648 spellCheckLanguageMessage.hidden = true; |
| 621 spellCheckLanguageButton.hidden = true; | 649 spellCheckLanguageButton.hidden = true; |
| 650 spellCheckLanguageCheckboxDiv.hidden = true; | |
| 622 dictionaryDownloadInProgress.hidden = true; | 651 dictionaryDownloadInProgress.hidden = true; |
| 623 dictionaryDownloadFailed.hidden = true; | 652 dictionaryDownloadFailed.hidden = true; |
| 624 dictionaryDownloadFailHelp.hidden = true; | 653 dictionaryDownloadFailHelp.hidden = true; |
| 654 spellCheckLanguageCheckbox.checked = false; | |
| 625 | 655 |
| 626 if (languageCode == this.spellCheckDictionary_) { | 656 if (languageCode in loadTimeData.getValue('spellCheckLanguageCodeSet')) { |
| 627 if (!(languageCode in this.spellcheckDictionaryDownloadStatus_)) { | 657 if (loadTimeData.getBoolean('enableMultilingualSpellChecker')) { |
| 628 spellCheckLanguageMessage.textContent = | 658 spellCheckLanguageCheckbox.languageCode = languageCode; |
| 629 loadTimeData.getString('isUsedForSpellChecking'); | 659 spellCheckLanguageCheckbox.checked = |
| 630 showMutuallyExclusiveNodes( | 660 this.spellCheckLanguages_.hasOwnProperty(languageCode); |
| 631 [spellCheckLanguageButton, spellCheckLanguageMessage], 1); | 661 spellCheckLanguageCheckboxDiv.hidden = false; |
| 632 } else if (this.spellcheckDictionaryDownloadStatus_[languageCode] == | 662 } else if (languageCode == this.spellCheckLanguage_) { |
| 633 DOWNLOAD_STATUS.IN_PROGRESS) { | 663 if (!(languageCode in this.spellcheckDictionaryDownloadStatus_)) { |
| 634 dictionaryDownloadInProgress.hidden = false; | 664 spellCheckLanguageMessage.textContent = |
| 635 } else if (this.spellcheckDictionaryDownloadStatus_[languageCode] == | 665 loadTimeData.getString('isUsedForSpellChecking'); |
| 636 DOWNLOAD_STATUS.FAILED) { | 666 spellCheckLanguageMessage.hidden = false; |
| 637 spellCheckLanguageSection.hidden = true; | 667 } |
| 638 dictionaryDownloadFailed.hidden = false; | 668 } else { |
| 639 if (this.spellcheckDictionaryDownloadFailures_ > 1) | 669 spellCheckLanguageButton.textContent = |
| 640 dictionaryDownloadFailHelp.hidden = false; | 670 loadTimeData.getString('useThisForSpellChecking'); |
| 671 spellCheckLanguageButton.hidden = false; | |
| 672 spellCheckLanguageButton.languageCode = languageCode; | |
| 641 } | 673 } |
| 642 } else if (languageCode in | 674 |
| 643 loadTimeData.getValue('spellCheckLanguageCodeSet')) { | 675 switch (this.spellcheckDictionaryDownloadStatus_[languageCode]) { |
| 644 spellCheckLanguageButton.textContent = | 676 case DOWNLOAD_STATUS.IN_PROGRESS: |
| 645 loadTimeData.getString('useThisForSpellChecking'); | 677 dictionaryDownloadInProgress.hidden = false; |
| 646 showMutuallyExclusiveNodes( | 678 break; |
| 647 [spellCheckLanguageButton, spellCheckLanguageMessage], 0); | 679 case DOWNLOAD_STATUS.FAILED: |
| 648 spellCheckLanguageButton.languageCode = languageCode; | 680 showMutuallyExclusiveNodes( |
| 649 } else if (!languageCode) { | 681 [spellCheckLanguageSection, dictionaryDownloadFailed], 1); |
| 650 spellCheckLanguageButton.hidden = true; | 682 if (this.spellcheckDictionaryDownloadFailures_ > 1) |
| 651 spellCheckLanguageMessage.hidden = true; | 683 dictionaryDownloadFailHelp.hidden = false; |
| 684 break; | |
| 685 } | |
| 652 } else { | 686 } else { |
| 653 spellCheckLanguageMessage.textContent = | 687 spellCheckLanguageMessage.textContent = |
| 654 loadTimeData.getString('cannotBeUsedForSpellChecking'); | 688 loadTimeData.getString('cannotBeUsedForSpellChecking'); |
| 655 showMutuallyExclusiveNodes( | 689 spellCheckLanguageMessage.hidden = false; |
| 656 [spellCheckLanguageButton, spellCheckLanguageMessage], 1); | |
| 657 } | 690 } |
| 658 }, | 691 }, |
| 659 | 692 |
| 660 /** | 693 /** |
| 661 * Updates the checkbox for stopping translation. | 694 * Updates the checkbox for stopping translation. |
| 662 * @param {string} languageCode Language code (ex. "fr"). | 695 * @param {string} languageCode Language code (ex. "fr"). |
| 663 * @private | 696 * @private |
| 664 */ | 697 */ |
| 665 updateOfferToTranslateCheckbox_: function(languageCode) { | 698 updateOfferToTranslateCheckbox_: function(languageCode) { |
| 666 var div = $('language-options-offer-to-translate'); | 699 var div = $('language-options-offer-to-translate'); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 912 return (!cr.isChromeOS || | 945 return (!cr.isChromeOS || |
| 913 this.canDeleteLanguage_(languageCode)); | 946 this.canDeleteLanguage_(languageCode)); |
| 914 }, | 947 }, |
| 915 | 948 |
| 916 /** | 949 /** |
| 917 * Handles browse.enable_spellchecking change. | 950 * Handles browse.enable_spellchecking change. |
| 918 * @param {Event} e Change event. | 951 * @param {Event} e Change event. |
| 919 * @private | 952 * @private |
| 920 */ | 953 */ |
| 921 updateEnableSpellCheck_: function(e) { | 954 updateEnableSpellCheck_: function(e) { |
| 922 var value = !$('enable-spell-check').checked; | 955 var value = !$('enable-spellcheck').checked; |
| 923 $('language-options-spell-check-language-button').disabled = value; | 956 $('spellcheck-language-button').disabled = value; |
| 924 if (!cr.isMac) | 957 if (!cr.isMac) |
| 925 $('edit-dictionary-button').hidden = value; | 958 $('edit-dictionary-button').hidden = value; |
| 926 }, | 959 }, |
| 927 | 960 |
| 928 /** | 961 /** |
| 929 * Handles translateBlockedLanguagesPref change. | 962 * Handles translateBlockedLanguagesPref change. |
| 930 * @param {Event} e Change event. | 963 * @param {Event} e Change event. |
| 931 * @private | 964 * @private |
| 932 */ | 965 */ |
| 933 handleTranslateBlockedLanguagesPrefChange_: function(e) { | 966 handleTranslateBlockedLanguagesPrefChange_: function(e) { |
| 934 this.translateBlockedLanguages_ = e.value.value; | 967 this.translateBlockedLanguages_ = e.value.value; |
| 935 this.updateOfferToTranslateCheckbox_( | 968 this.updateOfferToTranslateCheckbox_( |
| 936 $('language-options-list').getSelectedLanguageCode()); | 969 $('language-options-list').getSelectedLanguageCode()); |
| 937 }, | 970 }, |
| 938 | 971 |
| 939 /** | 972 /** |
| 940 * Handles spellCheckDictionaryPref change. | 973 * Handles spellCheckDictionaryPref change. |
| 941 * @param {Event} e Change event. | 974 * @param {Event} e Change event. |
| 942 * @private | 975 * @private |
| 943 */ | 976 */ |
| 944 handleSpellCheckDictionaryPrefChange_: function(e) { | 977 handleSpellCheckDictionaryPrefChange_: function(e) { |
| 945 var languageCode = e.value.value; | 978 this.spellCheckLanguage_ = e.value.value; |
| 946 this.spellCheckDictionary_ = languageCode; | |
| 947 if (!cr.isMac) { | 979 if (!cr.isMac) { |
| 948 this.updateSpellCheckLanguageButton_( | 980 this.updateSpellCheckLanguageControls_( |
| 949 $('language-options-list').getSelectedLanguageCode()); | 981 $('language-options-list').getSelectedLanguageCode()); |
| 950 } | 982 } |
| 951 }, | 983 }, |
| 952 | 984 |
| 953 /** | 985 /** |
| 986 * Updates spellcheck dictionary UI (checkboxes, buttons, and labels) when | |
| 987 * preferences change. | |
| 988 * @param {Event} e Preference change event where e.value.value is the | |
| 989 * comma separated list of languages currently used for spellchecking. | |
| 990 * @private | |
| 991 */ | |
| 992 handleSpellCheckDictionariesPrefChange_: function(e) { | |
| 993 assert(!cr.isMac); | |
| 994 | |
| 995 // e.value.value can be an empty string. If it is, then splitting it will | |
|
Dan Beam
2015/06/25 02:26:00
"e.value.value can be an empty string." -> why?
Julius
2015/07/06 22:38:52
Since we're using a ListPref now this doesn't appl
| |
| 996 // return [''] and we do not want to add an empty language to the | |
| 997 // spellCheckLanguages_ object. | |
| 998 if (e.value.value === '') { | |
| 999 this.spellCheckLanguages_ = {}; | |
| 1000 } else { | |
| 1001 var languages = e.value.value.split(','); | |
| 1002 this.spellCheckLanguages_ = {}; | |
| 1003 for (var i = 0; i < languages.length; i++) | |
| 1004 this.spellCheckLanguages_[languages[i]] = true; | |
|
Dan Beam
2015/06/25 02:26:00
wrong indent
Julius
2015/07/06 22:38:52
Done.
| |
| 1005 } | |
| 1006 this.updateSpellCheckLanguageControls_( | |
| 1007 $('language-options-list').getSelectedLanguageCode()); | |
| 1008 }, | |
| 1009 | |
| 1010 /** | |
| 954 * Handles translate.enabled change. | 1011 * Handles translate.enabled change. |
| 955 * @param {Event} e Change event. | 1012 * @param {Event} e Change event. |
| 956 * @private | 1013 * @private |
| 957 */ | 1014 */ |
| 958 handleEnableTranslatePrefChange_: function(e) { | 1015 handleEnableTranslatePrefChange_: function(e) { |
| 959 var enabled = e.value.value; | 1016 var enabled = e.value.value; |
| 960 this.enableTranslate_ = enabled; | 1017 this.enableTranslate_ = enabled; |
| 961 this.updateOfferToTranslateCheckbox_( | 1018 this.updateOfferToTranslateCheckbox_( |
| 962 $('language-options-list').getSelectedLanguageCode()); | 1019 $('language-options-list').getSelectedLanguageCode()); |
| 963 }, | 1020 }, |
| 964 | 1021 |
| 965 /** | 1022 /** |
| 966 * Handles spellCheckLanguageButton click. | 1023 * Handles spellCheckLanguageButton click. |
| 967 * @param {Event} e Click event. | 1024 * @param {Event} e Click event. |
| 968 * @private | 1025 * @private |
| 969 */ | 1026 */ |
| 970 handleSpellCheckLanguageButtonClick_: function(e) { | 1027 handleSpellCheckLanguageButtonClick_: function(e) { |
| 971 var languageCode = e.target.languageCode; | 1028 var languageCode = e.target.languageCode; |
| 972 // Save the preference. | 1029 // Save the preference. |
| 973 Preferences.setStringPref(SPELL_CHECK_DICTIONARY_PREF, | 1030 Preferences.setStringPref(SPELL_CHECK_DICTIONARY_PREF, |
| 974 languageCode, true); | 1031 languageCode, true); |
| 975 chrome.send('spellCheckLanguageChange', [languageCode]); | 1032 chrome.send('spellCheckLanguageChange', [languageCode]); |
| 976 chrome.send('coreOptionsUserMetricsAction', | 1033 chrome.send('coreOptionsUserMetricsAction', |
| 977 ['Options_Languages_SpellCheck']); | 1034 ['Options_Languages_SpellCheck']); |
| 978 }, | 1035 }, |
| 979 | 1036 |
| 980 /** | 1037 /** |
| 1038 * Updates the spellcheck.dictionaries preference with the currently | |
| 1039 * selected language codes. | |
| 1040 * @param {Event} e Click event. e.target represents the "Use this language | |
| 1041 * for spellchecking" | |
| 1042 * @private | |
| 1043 */ | |
| 1044 handleSpellCheckLanguageCheckboxClick_: function(e) { | |
| 1045 var languageCode = e.target.languageCode; | |
| 1046 | |
| 1047 if (e.target.checked) | |
| 1048 this.spellCheckLanguages_[languageCode] = true; | |
| 1049 else | |
| 1050 delete this.spellCheckLanguages_[languageCode]; | |
| 1051 | |
| 1052 var languageCodes = Object.keys(this.spellCheckLanguages_); | |
| 1053 Preferences.setStringPref(SPELL_CHECK_DICTIONARIES_PREF, | |
| 1054 languageCodes.join(','), true); | |
| 1055 }, | |
| 1056 | |
| 1057 /** | |
| 981 * Checks whether it's possible to remove the language specified by | 1058 * Checks whether it's possible to remove the language specified by |
| 982 * languageCode and returns true if possible. This function returns false | 1059 * languageCode and returns true if possible. This function returns false |
| 983 * if the removal causes the number of preload engines to be zero. | 1060 * if the removal causes the number of preload engines to be zero. |
| 984 * | 1061 * |
| 985 * @param {string} languageCode Language code (ex. "fr"). | 1062 * @param {string} languageCode Language code (ex. "fr"). |
| 986 * @return {boolean} Returns true on success. | 1063 * @return {boolean} Returns true on success. |
| 987 * @private | 1064 * @private |
| 988 */ | 1065 */ |
| 989 canDeleteLanguage_: function(languageCode) { | 1066 canDeleteLanguage_: function(languageCode) { |
| 990 // First create the set of engines to be removed from input methods | 1067 // First create the set of engines to be removed from input methods |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1269 * @param {string} languageCode The language of the dictionary that just | 1346 * @param {string} languageCode The language of the dictionary that just |
| 1270 * began downloading. | 1347 * began downloading. |
| 1271 * @private | 1348 * @private |
| 1272 */ | 1349 */ |
| 1273 onDictionaryDownloadBegin_: function(languageCode) { | 1350 onDictionaryDownloadBegin_: function(languageCode) { |
| 1274 this.spellcheckDictionaryDownloadStatus_[languageCode] = | 1351 this.spellcheckDictionaryDownloadStatus_[languageCode] = |
| 1275 DOWNLOAD_STATUS.IN_PROGRESS; | 1352 DOWNLOAD_STATUS.IN_PROGRESS; |
| 1276 if (!cr.isMac && | 1353 if (!cr.isMac && |
| 1277 languageCode == | 1354 languageCode == |
| 1278 $('language-options-list').getSelectedLanguageCode()) { | 1355 $('language-options-list').getSelectedLanguageCode()) { |
| 1279 this.updateSpellCheckLanguageButton_(languageCode); | 1356 this.updateSpellCheckLanguageControls_(languageCode); |
| 1280 } | 1357 } |
| 1281 }, | 1358 }, |
| 1282 | 1359 |
| 1283 /** | 1360 /** |
| 1284 * A handler for when dictionary for |languageCode| successfully downloaded. | 1361 * A handler for when dictionary for |languageCode| successfully downloaded. |
| 1285 * @param {string} languageCode The language of the dictionary that | 1362 * @param {string} languageCode The language of the dictionary that |
| 1286 * succeeded downloading. | 1363 * succeeded downloading. |
| 1287 * @private | 1364 * @private |
| 1288 */ | 1365 */ |
| 1289 onDictionaryDownloadSuccess_: function(languageCode) { | 1366 onDictionaryDownloadSuccess_: function(languageCode) { |
| 1290 delete this.spellcheckDictionaryDownloadStatus_[languageCode]; | 1367 delete this.spellcheckDictionaryDownloadStatus_[languageCode]; |
| 1291 this.spellcheckDictionaryDownloadFailures_ = 0; | 1368 this.spellcheckDictionaryDownloadFailures_ = 0; |
| 1292 if (!cr.isMac && | 1369 if (!cr.isMac && |
| 1293 languageCode == | 1370 languageCode == |
| 1294 $('language-options-list').getSelectedLanguageCode()) { | 1371 $('language-options-list').getSelectedLanguageCode()) { |
| 1295 this.updateSpellCheckLanguageButton_(languageCode); | 1372 this.updateSpellCheckLanguageControls_(languageCode); |
| 1296 } | 1373 } |
| 1297 }, | 1374 }, |
| 1298 | 1375 |
| 1299 /** | 1376 /** |
| 1300 * A handler for when dictionary for |languageCode| fails to download. | 1377 * A handler for when dictionary for |languageCode| fails to download. |
| 1301 * @param {string} languageCode The language of the dictionary that failed | 1378 * @param {string} languageCode The language of the dictionary that failed |
| 1302 * to download. | 1379 * to download. |
| 1303 * @private | 1380 * @private |
| 1304 */ | 1381 */ |
| 1305 onDictionaryDownloadFailure_: function(languageCode) { | 1382 onDictionaryDownloadFailure_: function(languageCode) { |
| 1306 this.spellcheckDictionaryDownloadStatus_[languageCode] = | 1383 this.spellcheckDictionaryDownloadStatus_[languageCode] = |
| 1307 DOWNLOAD_STATUS.FAILED; | 1384 DOWNLOAD_STATUS.FAILED; |
| 1308 this.spellcheckDictionaryDownloadFailures_++; | 1385 this.spellcheckDictionaryDownloadFailures_++; |
| 1309 if (!cr.isMac && | 1386 if (!cr.isMac && |
| 1310 languageCode == | 1387 languageCode == |
| 1311 $('language-options-list').getSelectedLanguageCode()) { | 1388 $('language-options-list').getSelectedLanguageCode()) { |
| 1312 this.updateSpellCheckLanguageButton_(languageCode); | 1389 this.updateSpellCheckLanguageControls_(languageCode); |
| 1313 } | 1390 } |
| 1314 }, | 1391 }, |
| 1315 | 1392 |
| 1316 /** | 1393 /** |
| 1317 * Converts the language code for Translation. There are some differences | 1394 * Converts the language code for Translation. There are some differences |
| 1318 * between the language set for Translation and that for Accept-Language. | 1395 * between the language set for Translation and that for Accept-Language. |
| 1319 * @param {string} languageCode The language code like 'fr'. | 1396 * @param {string} languageCode The language code like 'fr'. |
| 1320 * @return {string} The converted language code. | 1397 * @return {string} The converted language code. |
| 1321 * @private | 1398 * @private |
| 1322 */ | 1399 */ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1354 */ | 1431 */ |
| 1355 function showMutuallyExclusiveNodes(nodes, index) { | 1432 function showMutuallyExclusiveNodes(nodes, index) { |
| 1356 assert(index >= 0 && index < nodes.length); | 1433 assert(index >= 0 && index < nodes.length); |
| 1357 for (var i = 0; i < nodes.length; ++i) { | 1434 for (var i = 0; i < nodes.length; ++i) { |
| 1358 assert(nodes[i] instanceof HTMLElement); // TODO(dbeam): Ignore null? | 1435 assert(nodes[i] instanceof HTMLElement); // TODO(dbeam): Ignore null? |
| 1359 nodes[i].hidden = i != index; | 1436 nodes[i].hidden = i != index; |
| 1360 } | 1437 } |
| 1361 } | 1438 } |
| 1362 | 1439 |
| 1363 LanguageOptions.uiLanguageSaved = function(languageCode) { | 1440 LanguageOptions.uiLanguageSaved = function(languageCode) { |
| 1364 LanguageOptions.getInstance().uiLanguageSaved_(languageCode); | 1441 var instance = LanguageOptions.getInstance(); |
| 1442 instance.uiLanguageSaved_(languageCode); | |
|
Dan Beam
2015/06/25 02:26:00
i meant `var instance` only when you need to wrap
Julius
2015/07/06 22:38:52
Done.
| |
| 1365 }; | 1443 }; |
| 1366 | 1444 |
| 1367 LanguageOptions.onDictionaryDownloadBegin = function(languageCode) { | 1445 LanguageOptions.onDictionaryDownloadBegin = function(languageCode) { |
| 1368 LanguageOptions.getInstance().onDictionaryDownloadBegin_(languageCode); | 1446 var instance = LanguageOptions.getInstance(); |
| 1447 instance.onDictionaryDownloadBegin_(languageCode); | |
| 1369 }; | 1448 }; |
| 1370 | 1449 |
| 1371 LanguageOptions.onDictionaryDownloadSuccess = function(languageCode) { | 1450 LanguageOptions.onDictionaryDownloadSuccess = function(languageCode) { |
| 1372 LanguageOptions.getInstance().onDictionaryDownloadSuccess_(languageCode); | 1451 var instance = LanguageOptions.getInstance(); |
| 1452 instance.onDictionaryDownloadSuccess_(languageCode); | |
| 1373 }; | 1453 }; |
| 1374 | 1454 |
| 1375 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { | 1455 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { |
| 1376 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); | 1456 var instance = LanguageOptions.getInstance(); |
| 1457 instance.onDictionaryDownloadFailure_(languageCode); | |
| 1377 }; | 1458 }; |
| 1378 | 1459 |
| 1460 LanguageOptions.updateSpellCheckLanguageControls = function(languageCode) { | |
| 1461 var instance = LanguageOptions.getInstance(); | |
| 1462 instance.updateSpellCheckLanguageControls_(languageCode); | |
| 1463 }; | |
| 1379 // Export | 1464 // Export |
| 1380 return { | 1465 return { |
| 1381 LanguageOptions: LanguageOptions | 1466 LanguageOptions: LanguageOptions |
| 1382 }; | 1467 }; |
| 1383 }); | 1468 }); |
| OLD | NEW |