Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(816)

Side by Side Diff: chrome/browser/resources/options/language_options.js

Issue 1156473007: Enables the user to select multiple languages for spellchecking (UI) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed bug and added a test for it. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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}
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
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
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
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
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
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) {
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
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 var languages = e.value.value.split(',');
996
997 this.spellCheckLanguages_ = {};
998 for (var i = 0; i < languages.length; i++) {
999 if (languages[i] !== '')
please use gerrit instead 2015/06/24 20:35:10 In which case would |languages[i]| be empty? Is th
Julius 2015/06/24 21:18:00 e.value.value can be an empty string and splitting
1000 this.spellCheckLanguages_[languages[i]] = true;
1001 }
1002 this.updateSpellCheckLanguageControls_(
1003 $('language-options-list').getSelectedLanguageCode());
1004 },
1005
1006 /**
954 * Handles translate.enabled change. 1007 * Handles translate.enabled change.
955 * @param {Event} e Change event. 1008 * @param {Event} e Change event.
956 * @private 1009 * @private
957 */ 1010 */
958 handleEnableTranslatePrefChange_: function(e) { 1011 handleEnableTranslatePrefChange_: function(e) {
959 var enabled = e.value.value; 1012 var enabled = e.value.value;
960 this.enableTranslate_ = enabled; 1013 this.enableTranslate_ = enabled;
961 this.updateOfferToTranslateCheckbox_( 1014 this.updateOfferToTranslateCheckbox_(
962 $('language-options-list').getSelectedLanguageCode()); 1015 $('language-options-list').getSelectedLanguageCode());
963 }, 1016 },
964 1017
965 /** 1018 /**
966 * Handles spellCheckLanguageButton click. 1019 * Handles spellCheckLanguageButton click.
967 * @param {Event} e Click event. 1020 * @param {Event} e Click event.
968 * @private 1021 * @private
969 */ 1022 */
970 handleSpellCheckLanguageButtonClick_: function(e) { 1023 handleSpellCheckLanguageButtonClick_: function(e) {
971 var languageCode = e.target.languageCode; 1024 var languageCode = e.target.languageCode;
972 // Save the preference. 1025 // Save the preference.
973 Preferences.setStringPref(SPELL_CHECK_DICTIONARY_PREF, 1026 Preferences.setStringPref(SPELL_CHECK_DICTIONARY_PREF,
974 languageCode, true); 1027 languageCode, true);
975 chrome.send('spellCheckLanguageChange', [languageCode]); 1028 chrome.send('spellCheckLanguageChange', [languageCode]);
976 chrome.send('coreOptionsUserMetricsAction', 1029 chrome.send('coreOptionsUserMetricsAction',
977 ['Options_Languages_SpellCheck']); 1030 ['Options_Languages_SpellCheck']);
978 }, 1031 },
979 1032
980 /** 1033 /**
1034 * Updates the spellcheck.dictionaries preference with the currently
1035 * selected language codes.
1036 * @param {Event} e Click event. e.target represents the "Use this language
1037 * for spellchecking"
1038 * @private
1039 */
1040 handleSpellCheckLanguageCheckboxClick_: function(e) {
1041 var languageCode = e.target.languageCode;
1042
1043 if (e.target.checked)
1044 this.spellCheckLanguages_[languageCode] = true;
1045 else
1046 delete this.spellCheckLanguages_[languageCode];
1047
1048 var languageCodes = Object.keys(this.spellCheckLanguages_);
1049 Preferences.setStringPref(SPELL_CHECK_DICTIONARIES_PREF,
1050 languageCodes.join(','), true);
1051 },
1052
1053 /**
981 * Checks whether it's possible to remove the language specified by 1054 * Checks whether it's possible to remove the language specified by
982 * languageCode and returns true if possible. This function returns false 1055 * languageCode and returns true if possible. This function returns false
983 * if the removal causes the number of preload engines to be zero. 1056 * if the removal causes the number of preload engines to be zero.
984 * 1057 *
985 * @param {string} languageCode Language code (ex. "fr"). 1058 * @param {string} languageCode Language code (ex. "fr").
986 * @return {boolean} Returns true on success. 1059 * @return {boolean} Returns true on success.
987 * @private 1060 * @private
988 */ 1061 */
989 canDeleteLanguage_: function(languageCode) { 1062 canDeleteLanguage_: function(languageCode) {
990 // First create the set of engines to be removed from input methods 1063 // First create the set of engines to be removed from input methods
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 * @param {string} languageCode The language of the dictionary that just 1342 * @param {string} languageCode The language of the dictionary that just
1270 * began downloading. 1343 * began downloading.
1271 * @private 1344 * @private
1272 */ 1345 */
1273 onDictionaryDownloadBegin_: function(languageCode) { 1346 onDictionaryDownloadBegin_: function(languageCode) {
1274 this.spellcheckDictionaryDownloadStatus_[languageCode] = 1347 this.spellcheckDictionaryDownloadStatus_[languageCode] =
1275 DOWNLOAD_STATUS.IN_PROGRESS; 1348 DOWNLOAD_STATUS.IN_PROGRESS;
1276 if (!cr.isMac && 1349 if (!cr.isMac &&
1277 languageCode == 1350 languageCode ==
1278 $('language-options-list').getSelectedLanguageCode()) { 1351 $('language-options-list').getSelectedLanguageCode()) {
1279 this.updateSpellCheckLanguageButton_(languageCode); 1352 this.updateSpellCheckLanguageControls_(languageCode);
1280 } 1353 }
1281 }, 1354 },
1282 1355
1283 /** 1356 /**
1284 * A handler for when dictionary for |languageCode| successfully downloaded. 1357 * A handler for when dictionary for |languageCode| successfully downloaded.
1285 * @param {string} languageCode The language of the dictionary that 1358 * @param {string} languageCode The language of the dictionary that
1286 * succeeded downloading. 1359 * succeeded downloading.
1287 * @private 1360 * @private
1288 */ 1361 */
1289 onDictionaryDownloadSuccess_: function(languageCode) { 1362 onDictionaryDownloadSuccess_: function(languageCode) {
1290 delete this.spellcheckDictionaryDownloadStatus_[languageCode]; 1363 delete this.spellcheckDictionaryDownloadStatus_[languageCode];
1291 this.spellcheckDictionaryDownloadFailures_ = 0; 1364 this.spellcheckDictionaryDownloadFailures_ = 0;
1292 if (!cr.isMac && 1365 if (!cr.isMac &&
1293 languageCode == 1366 languageCode ==
1294 $('language-options-list').getSelectedLanguageCode()) { 1367 $('language-options-list').getSelectedLanguageCode()) {
1295 this.updateSpellCheckLanguageButton_(languageCode); 1368 this.updateSpellCheckLanguageControls_(languageCode);
1296 } 1369 }
1297 }, 1370 },
1298 1371
1299 /** 1372 /**
1300 * A handler for when dictionary for |languageCode| fails to download. 1373 * A handler for when dictionary for |languageCode| fails to download.
1301 * @param {string} languageCode The language of the dictionary that failed 1374 * @param {string} languageCode The language of the dictionary that failed
1302 * to download. 1375 * to download.
1303 * @private 1376 * @private
1304 */ 1377 */
1305 onDictionaryDownloadFailure_: function(languageCode) { 1378 onDictionaryDownloadFailure_: function(languageCode) {
1306 this.spellcheckDictionaryDownloadStatus_[languageCode] = 1379 this.spellcheckDictionaryDownloadStatus_[languageCode] =
1307 DOWNLOAD_STATUS.FAILED; 1380 DOWNLOAD_STATUS.FAILED;
1308 this.spellcheckDictionaryDownloadFailures_++; 1381 this.spellcheckDictionaryDownloadFailures_++;
1309 if (!cr.isMac && 1382 if (!cr.isMac &&
1310 languageCode == 1383 languageCode ==
1311 $('language-options-list').getSelectedLanguageCode()) { 1384 $('language-options-list').getSelectedLanguageCode()) {
1312 this.updateSpellCheckLanguageButton_(languageCode); 1385 this.updateSpellCheckLanguageControls_(languageCode);
1313 } 1386 }
1314 }, 1387 },
1315 1388
1316 /** 1389 /**
1317 * Converts the language code for Translation. There are some differences 1390 * Converts the language code for Translation. There are some differences
1318 * between the language set for Translation and that for Accept-Language. 1391 * between the language set for Translation and that for Accept-Language.
1319 * @param {string} languageCode The language code like 'fr'. 1392 * @param {string} languageCode The language code like 'fr'.
1320 * @return {string} The converted language code. 1393 * @return {string} The converted language code.
1321 * @private 1394 * @private
1322 */ 1395 */
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 */ 1427 */
1355 function showMutuallyExclusiveNodes(nodes, index) { 1428 function showMutuallyExclusiveNodes(nodes, index) {
1356 assert(index >= 0 && index < nodes.length); 1429 assert(index >= 0 && index < nodes.length);
1357 for (var i = 0; i < nodes.length; ++i) { 1430 for (var i = 0; i < nodes.length; ++i) {
1358 assert(nodes[i] instanceof HTMLElement); // TODO(dbeam): Ignore null? 1431 assert(nodes[i] instanceof HTMLElement); // TODO(dbeam): Ignore null?
1359 nodes[i].hidden = i != index; 1432 nodes[i].hidden = i != index;
1360 } 1433 }
1361 } 1434 }
1362 1435
1363 LanguageOptions.uiLanguageSaved = function(languageCode) { 1436 LanguageOptions.uiLanguageSaved = function(languageCode) {
1364 LanguageOptions.getInstance().uiLanguageSaved_(languageCode); 1437 var instance = LanguageOptions.getInstance();
1438 instance.uiLanguageSaved_(languageCode);
1365 }; 1439 };
1366 1440
1367 LanguageOptions.onDictionaryDownloadBegin = function(languageCode) { 1441 LanguageOptions.onDictionaryDownloadBegin = function(languageCode) {
1368 LanguageOptions.getInstance().onDictionaryDownloadBegin_(languageCode); 1442 var instance = LanguageOptions.getInstance();
1443 instance.onDictionaryDownloadBegin_(languageCode);
1369 }; 1444 };
1370 1445
1371 LanguageOptions.onDictionaryDownloadSuccess = function(languageCode) { 1446 LanguageOptions.onDictionaryDownloadSuccess = function(languageCode) {
1372 LanguageOptions.getInstance().onDictionaryDownloadSuccess_(languageCode); 1447 var instance = LanguageOptions.getInstance();
1448 instance.onDictionaryDownloadSuccess_(languageCode);
1373 }; 1449 };
1374 1450
1375 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { 1451 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) {
1376 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); 1452 var instance = LanguageOptions.getInstance();
1453 instance.onDictionaryDownloadFailure_(languageCode);
1377 }; 1454 };
1378 1455
1456 LanguageOptions.updateSpellCheckLanguageControls = function(languageCode) {
1457 var instance = LanguageOptions.getInstance();
1458 instance.updateSpellCheckLanguageControls_(languageCode);
1459 };
1379 // Export 1460 // Export
1380 return { 1461 return {
1381 LanguageOptions: LanguageOptions 1462 LanguageOptions: LanguageOptions
1382 }; 1463 };
1383 }); 1464 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698