| 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 OptionsPage = options.OptionsPage; | 9 /** @const */ var OptionsPage = options.OptionsPage; |
| 10 /** @const */ var LanguageList = options.LanguageList; | 10 /** @const */ var LanguageList = options.LanguageList; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * Spell check dictionary download status. | 25 * Spell check dictionary download status. |
| 26 * @type {Enum} | 26 * @type {Enum} |
| 27 */ | 27 */ |
| 28 /** @const*/ var DOWNLOAD_STATUS = { | 28 /** @const*/ var DOWNLOAD_STATUS = { |
| 29 IN_PROGRESS: 1, | 29 IN_PROGRESS: 1, |
| 30 FAILED: 2 | 30 FAILED: 2 |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 /** |
| 34 * The preference is a boolean that enables/disables spell checking. |
| 35 * @type {string} |
| 36 * @const |
| 37 */ |
| 38 var ENABLE_SPELL_CHECK_PREF = 'browser.enable_spellchecking'; |
| 39 |
| 40 /** |
| 41 * The preference is a CSV string that describes preload engines |
| 42 * (i.e. active input methods). |
| 43 * @type {string} |
| 44 * @const |
| 45 */ |
| 46 var PRELOAD_ENGINES_PREF = 'settings.language.preload_engines'; |
| 47 |
| 48 /** |
| 49 * The preference that lists the extension IMEs that are enabled in the |
| 50 * language menu. |
| 51 * @type {string} |
| 52 * @const |
| 53 */ |
| 54 var ENABLED_EXTENSION_IME_PREF = 'settings.language.enabled_extension_imes'; |
| 55 |
| 56 /** |
| 57 * The preference that lists the languages which are not translated. |
| 58 * @type {string} |
| 59 * @const |
| 60 */ |
| 61 var TRANSLATE_LANGUAGE_BLACKLIST_PREF = 'translate_language_blacklist'; |
| 62 |
| 63 /** |
| 64 * The preference key that is a string that describes the spell check |
| 65 * dictionary language, like "en-US". |
| 66 * @type {string} |
| 67 * @const |
| 68 */ |
| 69 var SPELL_CHECK_DICTIONARY_PREF = 'spellcheck.dictionary'; |
| 70 |
| 33 ///////////////////////////////////////////////////////////////////////////// | 71 ///////////////////////////////////////////////////////////////////////////// |
| 34 // LanguageOptions class: | 72 // LanguageOptions class: |
| 35 | 73 |
| 36 /** | 74 /** |
| 37 * Encapsulated handling of ChromeOS language options page. | 75 * Encapsulated handling of ChromeOS language options page. |
| 38 * @constructor | 76 * @constructor |
| 39 */ | 77 */ |
| 40 function LanguageOptions(model) { | 78 function LanguageOptions(model) { |
| 41 OptionsPage.call(this, 'languages', | 79 OptionsPage.call(this, 'languages', |
| 42 loadTimeData.getString('languagePageTabTitle'), | 80 loadTimeData.getString('languagePageTabTitle'), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 64 spellcheckDictionaryDownloadStatus_: [], | 102 spellcheckDictionaryDownloadStatus_: [], |
| 65 | 103 |
| 66 /** | 104 /** |
| 67 * Number of times a spell check dictionary download failed. | 105 * Number of times a spell check dictionary download failed. |
| 68 * @type {int} | 106 * @type {int} |
| 69 * @private | 107 * @private |
| 70 */ | 108 */ |
| 71 spellcheckDictionaryDownloadFailures_: 0, | 109 spellcheckDictionaryDownloadFailures_: 0, |
| 72 | 110 |
| 73 /** | 111 /** |
| 74 * The preference is a boolean that enables/disables spell checking. | |
| 75 * @type {string} | |
| 76 * @private | |
| 77 * @const | |
| 78 */ | |
| 79 enableSpellCheckPref_: 'browser.enable_spellchecking', | |
| 80 | |
| 81 /** | |
| 82 * The preference is a CSV string that describes preload engines | |
| 83 * (i.e. active input methods). | |
| 84 * @type {string} | |
| 85 * @private | |
| 86 * @const | |
| 87 */ | |
| 88 preloadEnginesPref_: 'settings.language.preload_engines', | |
| 89 | |
| 90 /** | |
| 91 * The list of preload engines, like ['mozc', 'pinyin']. | 112 * The list of preload engines, like ['mozc', 'pinyin']. |
| 92 * @type {Array} | 113 * @type {Array} |
| 93 * @private | 114 * @private |
| 94 */ | 115 */ |
| 95 preloadEngines_: [], | 116 preloadEngines_: [], |
| 96 | 117 |
| 97 /** | 118 /** |
| 98 * The preference that lists the extension IMEs that are enabled in the | |
| 99 * language menu. | |
| 100 * @type {string} | |
| 101 * @private | |
| 102 * @const | |
| 103 */ | |
| 104 enabledExtensionImePref_: 'settings.language.enabled_extension_imes', | |
| 105 | |
| 106 /** | |
| 107 * The list of extension IMEs that are enabled out of the language menu. | 119 * The list of extension IMEs that are enabled out of the language menu. |
| 108 * @type {Array} | 120 * @type {Array} |
| 109 * @private | 121 * @private |
| 110 */ | 122 */ |
| 111 enabledExtensionImes_: [], | 123 enabledExtensionImes_: [], |
| 112 | 124 |
| 113 /** | 125 /** |
| 114 * The preference key that is a string that describes the spell check | 126 * The list of the languages which is not translated. |
| 115 * dictionary language, like "en-US". | 127 * @type {Array} |
| 116 * @type {string} | |
| 117 * @private | 128 * @private |
| 118 * @const | |
| 119 */ | 129 */ |
| 120 spellCheckDictionaryPref_: 'spellcheck.dictionary', | 130 translateLanguageBlacklist_: [], |
| 121 | 131 |
| 122 /** | 132 /** |
| 123 * The preference is a string that describes the spell check dictionary | 133 * The preference is a string that describes the spell check dictionary |
| 124 * language, like "en-US". | 134 * language, like "en-US". |
| 125 * @type {string} | 135 * @type {string} |
| 126 * @private | 136 * @private |
| 127 */ | 137 */ |
| 128 spellCheckDictionary_: '', | 138 spellCheckDictionary_: '', |
| 129 | 139 |
| 130 /** | 140 /** |
| (...skipping 25 matching lines...) Expand all Loading... |
| 156 this.handleVisibleChange_.bind(this)); | 166 this.handleVisibleChange_.bind(this)); |
| 157 | 167 |
| 158 if (cr.isChromeOS) { | 168 if (cr.isChromeOS) { |
| 159 $('chewing-confirm').onclick = $('hangul-confirm').onclick = | 169 $('chewing-confirm').onclick = $('hangul-confirm').onclick = |
| 160 $('mozc-confirm').onclick = $('pinyin-confirm').onclick = | 170 $('mozc-confirm').onclick = $('pinyin-confirm').onclick = |
| 161 OptionsPage.closeOverlay.bind(OptionsPage); | 171 OptionsPage.closeOverlay.bind(OptionsPage); |
| 162 | 172 |
| 163 this.initializeInputMethodList_(); | 173 this.initializeInputMethodList_(); |
| 164 this.initializeLanguageCodeToInputMethodIdsMap_(); | 174 this.initializeLanguageCodeToInputMethodIdsMap_(); |
| 165 } | 175 } |
| 166 Preferences.getInstance().addEventListener(this.spellCheckDictionaryPref_, | 176 |
| 177 var checkbox = |
| 178 $('language-options-dont-translate').querySelector('input'); |
| 179 checkbox.addEventListener('click', |
| 180 this.handleDontTranslateCheckboxClick_.bind(this)); |
| 181 |
| 182 Preferences.getInstance().addEventListener( |
| 183 TRANSLATE_LANGUAGE_BLACKLIST_PREF, |
| 184 this.handleTranslateLanguageBlacklistPrefChange_.bind(this)); |
| 185 Preferences.getInstance().addEventListener(SPELL_CHECK_DICTIONARY_PREF, |
| 167 this.handleSpellCheckDictionaryPrefChange_.bind(this)); | 186 this.handleSpellCheckDictionaryPrefChange_.bind(this)); |
| 168 | 187 |
| 169 // Set up add button. | 188 // Set up add button. |
| 170 $('language-options-add-button').onclick = function(e) { | 189 $('language-options-add-button').onclick = function(e) { |
| 171 // Add the language without showing the overlay if it's specified in | 190 // Add the language without showing the overlay if it's specified in |
| 172 // the URL hash (ex. lang_add=ja). Used for automated testing. | 191 // the URL hash (ex. lang_add=ja). Used for automated testing. |
| 173 var match = document.location.hash.match(/\blang_add=([\w-]+)/); | 192 var match = document.location.hash.match(/\blang_add=([\w-]+)/); |
| 174 if (match) { | 193 if (match) { |
| 175 var addLanguageCode = match[1]; | 194 var addLanguageCode = match[1]; |
| 176 $('language-options-list').addLanguage(addLanguageCode); | 195 $('language-options-list').addLanguage(addLanguageCode); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 194 'click', this.handleAddLanguageOkButtonClick_.bind(this)); | 213 'click', this.handleAddLanguageOkButtonClick_.bind(this)); |
| 195 | 214 |
| 196 if (!cr.isChromeOS) { | 215 if (!cr.isChromeOS) { |
| 197 // Show experimental features if enabled. | 216 // Show experimental features if enabled. |
| 198 if (loadTimeData.getBoolean('enableSpellingAutoCorrect')) | 217 if (loadTimeData.getBoolean('enableSpellingAutoCorrect')) |
| 199 $('auto-spell-correction-option').hidden = false; | 218 $('auto-spell-correction-option').hidden = false; |
| 200 | 219 |
| 201 // Handle spell check enable/disable. | 220 // Handle spell check enable/disable. |
| 202 if (!cr.isMac) { | 221 if (!cr.isMac) { |
| 203 Preferences.getInstance().addEventListener( | 222 Preferences.getInstance().addEventListener( |
| 204 this.enableSpellCheckPref_, | 223 ENABLE_SPELL_CHECK_PREF, |
| 205 this.updateEnableSpellCheck_.bind(this)); | 224 this.updateEnableSpellCheck_.bind(this)); |
| 206 } | 225 } |
| 207 } | 226 } |
| 208 | 227 |
| 209 // Handle clicks on "Use this language for spell checking" button. | 228 // Handle clicks on "Use this language for spell checking" button. |
| 210 if (!cr.isMac) { | 229 if (!cr.isMac) { |
| 211 var spellCheckLanguageButton = getRequiredElement( | 230 var spellCheckLanguageButton = getRequiredElement( |
| 212 'language-options-spell-check-language-button'); | 231 'language-options-spell-check-language-button'); |
| 213 spellCheckLanguageButton.addEventListener( | 232 spellCheckLanguageButton.addEventListener( |
| 214 'click', | 233 'click', |
| (...skipping 21 matching lines...) Expand all Loading... |
| 236 // change the visibility in handleLanguageOptionsListChange_() based | 255 // change the visibility in handleLanguageOptionsListChange_() based |
| 237 // on the selected language. Note that we only have less than 100 | 256 // on the selected language. Note that we only have less than 100 |
| 238 // input methods, so creating DOM nodes at once here should be ok. | 257 // input methods, so creating DOM nodes at once here should be ok. |
| 239 this.appendInputMethodElement_(loadTimeData.getValue('inputMethodList')); | 258 this.appendInputMethodElement_(loadTimeData.getValue('inputMethodList')); |
| 240 this.appendInputMethodElement_(loadTimeData.getValue('extensionImeList')); | 259 this.appendInputMethodElement_(loadTimeData.getValue('extensionImeList')); |
| 241 this.appendComponentExtensionIme_( | 260 this.appendComponentExtensionIme_( |
| 242 loadTimeData.getValue('componentExtensionImeList')); | 261 loadTimeData.getValue('componentExtensionImeList')); |
| 243 | 262 |
| 244 // Listen to pref change once the input method list is initialized. | 263 // Listen to pref change once the input method list is initialized. |
| 245 Preferences.getInstance().addEventListener( | 264 Preferences.getInstance().addEventListener( |
| 246 this.preloadEnginesPref_, | 265 PRELOAD_ENGINES_PREF, |
| 247 this.handlePreloadEnginesPrefChange_.bind(this)); | 266 this.handlePreloadEnginesPrefChange_.bind(this)); |
| 248 Preferences.getInstance().addEventListener( | 267 Preferences.getInstance().addEventListener( |
| 249 this.enabledExtensionImePref_, | 268 ENABLED_EXTENSION_IME_PREF, |
| 250 this.handleEnabledExtensionsPrefChange_.bind(this)); | 269 this.handleEnabledExtensionsPrefChange_.bind(this)); |
| 251 }, | 270 }, |
| 252 | 271 |
| 253 /** | 272 /** |
| 254 * Appends input method lists based on component extension ime list. | 273 * Appends input method lists based on component extension ime list. |
| 255 * @param {!Array} componentExtensionImeList A list of input method | 274 * @param {!Array} componentExtensionImeList A list of input method |
| 256 * descriptors. | 275 * descriptors. |
| 257 * @private | 276 * @private |
| 258 */ | 277 */ |
| 259 appendComponentExtensionIme_: function(componentExtensionImeList) { | 278 appendComponentExtensionIme_: function(componentExtensionImeList) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 // Select the language if it's specified in the URL hash (ex. lang=ja). | 385 // Select the language if it's specified in the URL hash (ex. lang=ja). |
| 367 // Used for automated testing. | 386 // Used for automated testing. |
| 368 var match = document.location.hash.match(/\blang=([\w-]+)/); | 387 var match = document.location.hash.match(/\blang=([\w-]+)/); |
| 369 if (match) { | 388 if (match) { |
| 370 var specifiedLanguageCode = match[1]; | 389 var specifiedLanguageCode = match[1]; |
| 371 if (languageOptionsList.selectLanguageByCode(specifiedLanguageCode)) { | 390 if (languageOptionsList.selectLanguageByCode(specifiedLanguageCode)) { |
| 372 languageCode = specifiedLanguageCode; | 391 languageCode = specifiedLanguageCode; |
| 373 } | 392 } |
| 374 } | 393 } |
| 375 | 394 |
| 395 this.updateDontTranslateCheckbox_(languageCode); |
| 396 |
| 376 if (cr.isWindows || cr.isChromeOS) | 397 if (cr.isWindows || cr.isChromeOS) |
| 377 this.updateUiLanguageButton_(languageCode); | 398 this.updateUiLanguageButton_(languageCode); |
| 378 | 399 |
| 379 if (!cr.isMac) { | 400 if (!cr.isMac) { |
| 380 this.updateSelectedLanguageName_(languageCode); | 401 this.updateSelectedLanguageName_(languageCode); |
| 381 this.updateSpellCheckLanguageButton_(languageCode); | 402 this.updateSpellCheckLanguageButton_(languageCode); |
| 382 } | 403 } |
| 383 | 404 |
| 384 if (cr.isChromeOS) | 405 if (cr.isChromeOS) |
| 385 this.updateInputMethodList_(languageCode); | 406 this.updateInputMethodList_(languageCode); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 spellCheckLanguageMessage.hidden = true; | 620 spellCheckLanguageMessage.hidden = true; |
| 600 } else { | 621 } else { |
| 601 spellCheckLanguageMessage.textContent = | 622 spellCheckLanguageMessage.textContent = |
| 602 loadTimeData.getString('cannot_be_used_for_spell_checking'); | 623 loadTimeData.getString('cannot_be_used_for_spell_checking'); |
| 603 showMutuallyExclusiveNodes( | 624 showMutuallyExclusiveNodes( |
| 604 [spellCheckLanguageButton, spellCheckLanguageMessage], 1); | 625 [spellCheckLanguageButton, spellCheckLanguageMessage], 1); |
| 605 } | 626 } |
| 606 }, | 627 }, |
| 607 | 628 |
| 608 /** | 629 /** |
| 630 * Updates the checkbox for stopping translation. |
| 631 * @param {string} languageCode Language code (ex. "fr"). |
| 632 * @private |
| 633 */ |
| 634 updateDontTranslateCheckbox_: function(languageCode) { |
| 635 var dontTranslate = $('language-options-dont-translate'); |
| 636 var checkbox = dontTranslate.querySelector('input'); |
| 637 |
| 638 // TODO(hajimehoshi): Create more general function to determine this. |
| 639 if (this.isTranslatableLanguage_(languageCode)) { |
| 640 dontTranslate.hidden = false; |
| 641 } else { |
| 642 dontTranslate.hidden = true; |
| 643 return; |
| 644 } |
| 645 |
| 646 var lang = this.convertLangCodeForTranslation_(languageCode); |
| 647 var checked = (this.translateLanguageBlacklist_.indexOf(lang) != -1); |
| 648 checkbox.checked = checked; |
| 649 }, |
| 650 |
| 651 /** |
| 609 * Updates the input method list. | 652 * Updates the input method list. |
| 610 * @param {string} languageCode Language code (ex. "fr"). | 653 * @param {string} languageCode Language code (ex. "fr"). |
| 611 * @private | 654 * @private |
| 612 */ | 655 */ |
| 613 updateInputMethodList_: function(languageCode) { | 656 updateInputMethodList_: function(languageCode) { |
| 614 // Give one of the checkboxes or buttons focus, if it's specified in the | 657 // Give one of the checkboxes or buttons focus, if it's specified in the |
| 615 // URL hash (ex. focus=mozc). Used for automated testing. | 658 // URL hash (ex. focus=mozc). Used for automated testing. |
| 616 var focusInputMethodId = -1; | 659 var focusInputMethodId = -1; |
| 617 var match = document.location.hash.match(/\bfocus=([\w:-]+)\b/); | 660 var match = document.location.hash.match(/\bfocus=([\w:-]+)\b/); |
| 618 if (match) { | 661 if (match) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 * @param {Event} e Change event. | 736 * @param {Event} e Change event. |
| 694 * @private | 737 * @private |
| 695 */ | 738 */ |
| 696 handleEnabledExtensionsPrefChange_: function(e) { | 739 handleEnabledExtensionsPrefChange_: function(e) { |
| 697 var value = e.value.value; | 740 var value = e.value.value; |
| 698 this.enabledExtensionImes_ = value.split(','); | 741 this.enabledExtensionImes_ = value.split(','); |
| 699 this.updateCheckboxesFromEnabledExtensions_(); | 742 this.updateCheckboxesFromEnabledExtensions_(); |
| 700 }, | 743 }, |
| 701 | 744 |
| 702 /** | 745 /** |
| 746 * Handles don't-translate checkbox's click event. |
| 747 * @param {Event} e Click event. |
| 748 * @private |
| 749 */ |
| 750 handleDontTranslateCheckboxClick_: function(e) { |
| 751 var checkbox = e.target; |
| 752 var checked = checkbox.checked; |
| 753 |
| 754 var languageOptionsList = $('language-options-list'); |
| 755 var selectedLanguageCode = languageOptionsList.getSelectedLanguageCode(); |
| 756 |
| 757 var langCode = this.convertLangCodeForTranslation_(selectedLanguageCode); |
| 758 var blacklist = this.translateLanguageBlacklist_; |
| 759 if (checked && blacklist.indexOf(langCode) == -1) { |
| 760 blacklist.push(langCode); |
| 761 } else if (!checked && blacklist.indexOf(langCode) != -1) { |
| 762 blacklist = blacklist.filter(function(blacklistedLangCode) { |
| 763 return blacklistedLangCode != langCode; |
| 764 }); |
| 765 } |
| 766 this.translateLanguageBlacklist_ = blacklist; |
| 767 |
| 768 Preferences.setListPref(TRANSLATE_LANGUAGE_BLACKLIST_PREF, |
| 769 this.translateLanguageBlacklist_, true); |
| 770 }, |
| 771 |
| 772 /** |
| 703 * Handles input method checkbox's click event. | 773 * Handles input method checkbox's click event. |
| 704 * @param {Event} e Click event. | 774 * @param {Event} e Click event. |
| 705 * @private | 775 * @private |
| 706 */ | 776 */ |
| 707 handleCheckboxClick_: function(e) { | 777 handleCheckboxClick_: function(e) { |
| 708 var checkbox = e.target; | 778 var checkbox = e.target; |
| 709 | 779 |
| 710 if (checkbox.inputMethodId.match(/^_ext_ime_/)) { | 780 if (checkbox.inputMethodId.match(/^_ext_ime_/)) { |
| 711 this.updateEnabledExtensionsFromCheckboxes_(); | 781 this.updateEnabledExtensionsFromCheckboxes_(); |
| 712 this.saveEnabledExtensionPref_(); | 782 this.saveEnabledExtensionPref_(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 return false; | 820 return false; |
| 751 return (!cr.isChromeOS || | 821 return (!cr.isChromeOS || |
| 752 this.canDeleteLanguage_(languageCode)); | 822 this.canDeleteLanguage_(languageCode)); |
| 753 }, | 823 }, |
| 754 | 824 |
| 755 /** | 825 /** |
| 756 * Handles browse.enable_spellchecking change. | 826 * Handles browse.enable_spellchecking change. |
| 757 * @param {Event} e Change event. | 827 * @param {Event} e Change event. |
| 758 * @private | 828 * @private |
| 759 */ | 829 */ |
| 760 updateEnableSpellCheck_: function() { | 830 updateEnableSpellCheck_: function() { |
| 761 var value = !$('enable-spell-check').checked; | 831 var value = !$('enable-spell-check').checked; |
| 762 $('language-options-spell-check-language-button').disabled = value; | 832 $('language-options-spell-check-language-button').disabled = value; |
| 763 if (!cr.IsMac) | 833 if (!cr.IsMac) |
| 764 $('edit-dictionary-button').hidden = value; | 834 $('edit-dictionary-button').hidden = value; |
| 765 }, | 835 }, |
| 766 | 836 |
| 767 /** | 837 /** |
| 838 * Handles translateLanguageBlacklistPref change. |
| 839 * @param {Event} e Change event. |
| 840 * @private |
| 841 */ |
| 842 handleTranslateLanguageBlacklistPrefChange_: function(e) { |
| 843 var languageOptionsList = $('language-options-list'); |
| 844 var selectedLanguageCode = languageOptionsList.getSelectedLanguageCode(); |
| 845 this.translateLanguageBlacklist_ = e.value.value; |
| 846 |
| 847 this.updateDontTranslateCheckbox_(selectedLanguageCode); |
| 848 }, |
| 849 |
| 850 /** |
| 768 * Handles spellCheckDictionaryPref change. | 851 * Handles spellCheckDictionaryPref change. |
| 769 * @param {Event} e Change event. | 852 * @param {Event} e Change event. |
| 770 * @private | 853 * @private |
| 771 */ | 854 */ |
| 772 handleSpellCheckDictionaryPrefChange_: function(e) { | 855 handleSpellCheckDictionaryPrefChange_: function(e) { |
| 773 var languageCode = e.value.value; | 856 var languageCode = e.value.value; |
| 774 this.spellCheckDictionary_ = languageCode; | 857 this.spellCheckDictionary_ = languageCode; |
| 775 var languageOptionsList = $('language-options-list'); | 858 var languageOptionsList = $('language-options-list'); |
| 776 var selectedLanguageCode = languageOptionsList.getSelectedLanguageCode(); | 859 var selectedLanguageCode = languageOptionsList.getSelectedLanguageCode(); |
| 777 if (!cr.isMac) | 860 if (!cr.isMac) |
| 778 this.updateSpellCheckLanguageButton_(selectedLanguageCode); | 861 this.updateSpellCheckLanguageButton_(selectedLanguageCode); |
| 779 }, | 862 }, |
| 780 | 863 |
| 781 /** | 864 /** |
| 782 * Handles spellCheckLanguageButton click. | 865 * Handles spellCheckLanguageButton click. |
| 783 * @param {Event} e Click event. | 866 * @param {Event} e Click event. |
| 784 * @private | 867 * @private |
| 785 */ | 868 */ |
| 786 handleSpellCheckLanguageButtonClick_: function(e) { | 869 handleSpellCheckLanguageButtonClick_: function(e) { |
| 787 var languageCode = e.target.languageCode; | 870 var languageCode = e.target.languageCode; |
| 788 // Save the preference. | 871 // Save the preference. |
| 789 Preferences.setStringPref(this.spellCheckDictionaryPref_, | 872 Preferences.setStringPref(SPELL_CHECK_DICTIONARY_PREF, |
| 790 languageCode, true); | 873 languageCode, true); |
| 791 chrome.send('spellCheckLanguageChange', [languageCode]); | 874 chrome.send('spellCheckLanguageChange', [languageCode]); |
| 792 }, | 875 }, |
| 793 | 876 |
| 794 /** | 877 /** |
| 795 * Checks whether it's possible to remove the language specified by | 878 * Checks whether it's possible to remove the language specified by |
| 796 * languageCode and returns true if possible. This function returns false | 879 * languageCode and returns true if possible. This function returns false |
| 797 * if the removal causes the number of preload engines to be zero. | 880 * if the removal causes the number of preload engines to be zero. |
| 798 * | 881 * |
| 799 * @param {string} languageCode Language code (ex. "fr"). | 882 * @param {string} languageCode Language code (ex. "fr"). |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 // Don't allow this operation if it causes the number of preload | 931 // Don't allow this operation if it causes the number of preload |
| 849 // engines to be zero. | 932 // engines to be zero. |
| 850 return (newPreloadEngines.length > 0); | 933 return (newPreloadEngines.length > 0); |
| 851 }, | 934 }, |
| 852 | 935 |
| 853 /** | 936 /** |
| 854 * Saves the enabled extension preference. | 937 * Saves the enabled extension preference. |
| 855 * @private | 938 * @private |
| 856 */ | 939 */ |
| 857 saveEnabledExtensionPref_: function() { | 940 saveEnabledExtensionPref_: function() { |
| 858 Preferences.setStringPref(this.enabledExtensionImePref_, | 941 Preferences.setStringPref(ENABLED_EXTENSION_IME_PREF, |
| 859 this.enabledExtensionImes_.join(','), true); | 942 this.enabledExtensionImes_.join(','), true); |
| 860 }, | 943 }, |
| 861 | 944 |
| 862 /** | 945 /** |
| 863 * Updates the checkboxes in the input method list from the enabled | 946 * Updates the checkboxes in the input method list from the enabled |
| 864 * extensions preference. | 947 * extensions preference. |
| 865 * @private | 948 * @private |
| 866 */ | 949 */ |
| 867 updateCheckboxesFromEnabledExtensions_: function() { | 950 updateCheckboxesFromEnabledExtensions_: function() { |
| 868 // Convert the list into a dictonary for simpler lookup. | 951 // Convert the list into a dictonary for simpler lookup. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 893 this.enabledExtensionImes_.push(checkboxes[i].inputMethodId); | 976 this.enabledExtensionImes_.push(checkboxes[i].inputMethodId); |
| 894 } | 977 } |
| 895 } | 978 } |
| 896 }, | 979 }, |
| 897 | 980 |
| 898 /** | 981 /** |
| 899 * Saves the preload engines preference. | 982 * Saves the preload engines preference. |
| 900 * @private | 983 * @private |
| 901 */ | 984 */ |
| 902 savePreloadEnginesPref_: function() { | 985 savePreloadEnginesPref_: function() { |
| 903 Preferences.setStringPref(this.preloadEnginesPref_, | 986 Preferences.setStringPref(PRELOAD_ENGINES_PREF, |
| 904 this.preloadEngines_.join(','), true); | 987 this.preloadEngines_.join(','), true); |
| 905 }, | 988 }, |
| 906 | 989 |
| 907 /** | 990 /** |
| 908 * Updates the checkboxes in the input method list from the preload | 991 * Updates the checkboxes in the input method list from the preload |
| 909 * engines preference. | 992 * engines preference. |
| 910 * @private | 993 * @private |
| 911 */ | 994 */ |
| 912 updateCheckboxesFromPreloadEngines_: function() { | 995 updateCheckboxesFromPreloadEngines_: function() { |
| 913 // Convert the list into a dictonary for simpler lookup. | 996 // Convert the list into a dictonary for simpler lookup. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 | 1135 |
| 1053 onDictionaryDownloadFailure_: function(languageCode) { | 1136 onDictionaryDownloadFailure_: function(languageCode) { |
| 1054 this.spellcheckDictionaryDownloadStatus_[languageCode] = | 1137 this.spellcheckDictionaryDownloadStatus_[languageCode] = |
| 1055 DOWNLOAD_STATUS.FAILED; | 1138 DOWNLOAD_STATUS.FAILED; |
| 1056 this.spellcheckDictionaryDownloadFailures_++; | 1139 this.spellcheckDictionaryDownloadFailures_++; |
| 1057 if (!cr.isMac && | 1140 if (!cr.isMac && |
| 1058 languageCode == | 1141 languageCode == |
| 1059 $('language-options-list').getSelectedLanguageCode()) { | 1142 $('language-options-list').getSelectedLanguageCode()) { |
| 1060 this.updateSpellCheckLanguageButton_(languageCode); | 1143 this.updateSpellCheckLanguageButton_(languageCode); |
| 1061 } | 1144 } |
| 1062 } | 1145 }, |
| 1146 |
| 1147 /* |
| 1148 * Converts the language code for Translation. There are some differences |
| 1149 * between the language set for Translation and that for Accept-Language. |
| 1150 * @param {string} languageCode The language code like 'fr'. |
| 1151 * @return {string} The converted language code. |
| 1152 * @private |
| 1153 */ |
| 1154 convertLangCodeForTranslation_: function(languageCode) { |
| 1155 var tokens = languageCode.split('-'); |
| 1156 var main = tokens[0]; |
| 1157 var dialect = tokens[1]; |
| 1158 |
| 1159 // See also: chrome/renderer/translate/translate_helper.cc. |
| 1160 var synonyms = { |
| 1161 'nb': 'no', |
| 1162 'he': 'iw', |
| 1163 'jv': 'jw', |
| 1164 'fil': 'tl', |
| 1165 }; |
| 1166 |
| 1167 if (main in synonyms) { |
| 1168 return synonyms[main]; |
| 1169 } else if (main == 'zh') { |
| 1170 // In Translation, general Chinese is not used. |
| 1171 assert(dialect); |
| 1172 return languageCode; |
| 1173 } |
| 1174 |
| 1175 return main; |
| 1176 }, |
| 1177 |
| 1178 /* |
| 1179 * Checks whether or not |languageCode| is supported for Translation. |
| 1180 * @param {string} languageCode The language code like 'fr'. |
| 1181 * @return {boolean} Retruns true if |languageCode| is supported for |
| 1182 * Translation. |
| 1183 * @private |
| 1184 */ |
| 1185 isTranslatableLanguage_: function(languageCode) { |
| 1186 if (languageCode == 'zh') |
| 1187 return false; |
| 1188 |
| 1189 return true; |
| 1190 }, |
| 1063 }; | 1191 }; |
| 1064 | 1192 |
| 1065 /** | 1193 /** |
| 1066 * Shows the node at |index| in |nodes|, hides all others. | 1194 * Shows the node at |index| in |nodes|, hides all others. |
| 1067 * @param {Array<HTMLElement>} nodes The nodes to be shown or hidden. | 1195 * @param {Array<HTMLElement>} nodes The nodes to be shown or hidden. |
| 1068 * @param {number} index The index of |nodes| to show. | 1196 * @param {number} index The index of |nodes| to show. |
| 1069 */ | 1197 */ |
| 1070 function showMutuallyExclusiveNodes(nodes, index) { | 1198 function showMutuallyExclusiveNodes(nodes, index) { |
| 1071 assert(index >= 0 && index < nodes.length); | 1199 assert(index >= 0 && index < nodes.length); |
| 1072 for (var i = 0; i < nodes.length; ++i) { | 1200 for (var i = 0; i < nodes.length; ++i) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 | 1242 |
| 1115 LanguageOptions.onComponentManagerInitialized = function(componentImes) { | 1243 LanguageOptions.onComponentManagerInitialized = function(componentImes) { |
| 1116 LanguageOptions.getInstance().appendComponentExtensionIme_(componentImes); | 1244 LanguageOptions.getInstance().appendComponentExtensionIme_(componentImes); |
| 1117 }; | 1245 }; |
| 1118 | 1246 |
| 1119 // Export | 1247 // Export |
| 1120 return { | 1248 return { |
| 1121 LanguageOptions: LanguageOptions | 1249 LanguageOptions: LanguageOptions |
| 1122 }; | 1250 }; |
| 1123 }); | 1251 }); |
| OLD | NEW |