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