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

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: Addressed comments, added browsertest, fixed failures. Created 5 years, 6 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 spellCheckDictionary_: '',
145 146
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 spellCheckDictionaries_: {},
154
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 /**
155 * The value that indicates if Translate feature is enabled or not. 164 * The value that indicates if Translate feature is enabled or not.
156 * @type {boolean} 165 * @type {boolean}
(...skipping 23 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 var spellCheckLanguageCheckbox = getRequiredElement(
245 spellCheckLanguageButton.addEventListener( 262 'spellcheck-language-checkbox');
246 'click', 263 spellCheckLanguageCheckbox.addEventListener(
247 this.handleSpellCheckLanguageButtonClick_.bind(this)); 264 'change',
265 this.handleSpellCheckLanguageCheckboxClick_.bind(this));
266 } else {
267 var spellCheckLanguageButton = getRequiredElement(
268 'spellcheck-language-button');
269 spellCheckLanguageButton.addEventListener(
270 'click',
271 this.handleSpellCheckLanguageButtonClick_.bind(this));
272 }
248 } 273 }
249 274
250 if (cr.isChromeOS) { 275 if (cr.isChromeOS) {
251 $('language-options-ui-restart-button').onclick = function() { 276 $('language-options-ui-restart-button').onclick = function() {
252 chrome.send('uiLanguageRestart'); 277 chrome.send('uiLanguageRestart');
253 }; 278 };
254 } 279 }
255 280
256 $('language-confirm').onclick = 281 $('language-confirm').onclick =
257 PageManager.closeOverlay.bind(PageManager); 282 PageManager.closeOverlay.bind(PageManager);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 } 445 }
421 446
422 this.updateOfferToTranslateCheckbox_(languageCode); 447 this.updateOfferToTranslateCheckbox_(languageCode);
423 448
424 if (cr.isWindows || cr.isChromeOS) 449 if (cr.isWindows || cr.isChromeOS)
425 this.updateUiLanguageButton_(languageCode); 450 this.updateUiLanguageButton_(languageCode);
426 451
427 this.updateSelectedLanguageName_(languageCode); 452 this.updateSelectedLanguageName_(languageCode);
428 453
429 if (!cr.isMac) 454 if (!cr.isMac)
430 this.updateSpellCheckLanguageButton_(languageCode); 455 this.updateSpellCheckLanguageControls_(languageCode);
431 456
432 if (cr.isChromeOS) 457 if (cr.isChromeOS)
433 this.updateInputMethodList_(languageCode); 458 this.updateInputMethodList_(languageCode);
434 459
435 this.updateLanguageListInAddLanguageOverlay_(); 460 this.updateLanguageListInAddLanguageOverlay_();
436 }, 461 },
437 462
438 /** 463 /**
439 * Handles languageOptionsList's save event. 464 * Handles languageOptionsList's save event.
440 * @param {Event} e Save event. 465 * @param {Event} e Save event.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 showMutuallyExclusiveNodes( 622 showMutuallyExclusiveNodes(
598 [uiLanguageButton, uiLanguageMessage, uiLanguageNotification], 1); 623 [uiLanguageButton, uiLanguageMessage, uiLanguageNotification], 1);
599 } 624 }
600 }, 625 },
601 626
602 /** 627 /**
603 * Updates the spell check language button. 628 * Updates the spell check language button.
604 * @param {string} languageCode Language code (ex. "fr"). 629 * @param {string} languageCode Language code (ex. "fr").
605 * @private 630 * @private
606 */ 631 */
607 updateSpellCheckLanguageButton_: function(languageCode) { 632 updateSpellCheckLanguageControls_: function(languageCode) {
608 var spellCheckLanguageSection = $('language-options-spellcheck'); 633 var spellCheckLanguageSection = $('language-options-spellcheck');
609 var spellCheckLanguageButton = 634 var spellCheckLanguageButton =
610 $('language-options-spell-check-language-button'); 635 $('spellcheck-language-button');
636 var spellCheckLanguageCheckboxDiv =
637 $('spellcheck-language-checkbox-container');
638 var spellCheckLanguageCheckbox =
639 $('spellcheck-language-checkbox');
611 var spellCheckLanguageMessage = 640 var spellCheckLanguageMessage =
612 $('language-options-spell-check-language-message'); 641 $('spellcheck-language-message');
613 var dictionaryDownloadInProgress = 642 var dictionaryDownloadInProgress =
614 $('language-options-dictionary-downloading-message'); 643 $('language-options-dictionary-downloading-message');
615 var dictionaryDownloadFailed = 644 var dictionaryDownloadFailed =
616 $('language-options-dictionary-download-failed-message'); 645 $('language-options-dictionary-download-failed-message');
617 var dictionaryDownloadFailHelp = 646 var dictionaryDownloadFailHelp =
618 $('language-options-dictionary-download-fail-help-message'); 647 $('language-options-dictionary-download-fail-help-message');
648
619 spellCheckLanguageSection.hidden = false; 649 spellCheckLanguageSection.hidden = false;
620 spellCheckLanguageMessage.hidden = true; 650 spellCheckLanguageMessage.hidden = true;
621 spellCheckLanguageButton.hidden = true; 651 spellCheckLanguageButton.hidden = true;
652 spellCheckLanguageCheckboxDiv.hidden = true;
622 dictionaryDownloadInProgress.hidden = true; 653 dictionaryDownloadInProgress.hidden = true;
623 dictionaryDownloadFailed.hidden = true; 654 dictionaryDownloadFailed.hidden = true;
624 dictionaryDownloadFailHelp.hidden = true; 655 dictionaryDownloadFailHelp.hidden = true;
656 spellCheckLanguageCheckbox.checked = false;
625 657
626 if (languageCode == this.spellCheckDictionary_) { 658 if (!languageCode)
627 if (!(languageCode in this.spellcheckDictionaryDownloadStatus_)) { 659 return;
628 spellCheckLanguageMessage.textContent = 660
629 loadTimeData.getString('isUsedForSpellChecking'); 661 if (languageCode in loadTimeData.getValue('spellCheckLanguageCodeSet')) {
630 showMutuallyExclusiveNodes( 662 if (loadTimeData.getBoolean('enableMultilingualSpellChecker')) {
631 [spellCheckLanguageButton, spellCheckLanguageMessage], 1); 663 spellCheckLanguageCheckbox.languageCode = languageCode;
632 } else if (this.spellcheckDictionaryDownloadStatus_[languageCode] == 664 spellCheckLanguageCheckbox.checked =
633 DOWNLOAD_STATUS.IN_PROGRESS) { 665 this.spellCheckDictionaries_.hasOwnProperty(languageCode);
634 dictionaryDownloadInProgress.hidden = false; 666 spellCheckLanguageCheckboxDiv.hidden = false;
635 } else if (this.spellcheckDictionaryDownloadStatus_[languageCode] == 667 } else if (languageCode == this.spellCheckDictionary_) {
636 DOWNLOAD_STATUS.FAILED) { 668 if (!(languageCode in this.spellcheckDictionaryDownloadStatus_)) {
637 spellCheckLanguageSection.hidden = true; 669 spellCheckLanguageMessage.textContent =
638 dictionaryDownloadFailed.hidden = false; 670 loadTimeData.getString('isUsedForSpellChecking');
639 if (this.spellcheckDictionaryDownloadFailures_ > 1) 671 spellCheckLanguageMessage.hidden = false;
640 dictionaryDownloadFailHelp.hidden = false; 672 }
673 } else {
674 spellCheckLanguageButton.textContent =
675 loadTimeData.getString('useThisForSpellChecking');
676 spellCheckLanguageButton.hidden = false;
677 spellCheckLanguageButton.languageCode = languageCode;
641 } 678 }
642 } else if (languageCode in 679
643 loadTimeData.getValue('spellCheckLanguageCodeSet')) { 680 switch (this.spellcheckDictionaryDownloadStatus_[languageCode]) {
644 spellCheckLanguageButton.textContent = 681 case DOWNLOAD_STATUS.IN_PROGRESS:
645 loadTimeData.getString('useThisForSpellChecking'); 682 dictionaryDownloadInProgress.hidden = false;
646 showMutuallyExclusiveNodes( 683 break;
647 [spellCheckLanguageButton, spellCheckLanguageMessage], 0); 684 case DOWNLOAD_STATUS.FAILED:
648 spellCheckLanguageButton.languageCode = languageCode; 685 showMutuallyExclusiveNodes(
649 } else if (!languageCode) { 686 [spellCheckLanguageSection, dictionaryDownloadFailed], 1);
650 spellCheckLanguageButton.hidden = true; 687 if (this.spellcheckDictionaryDownloadFailures_ > 1)
651 spellCheckLanguageMessage.hidden = true; 688 dictionaryDownloadFailHelp.hidden = false;
689 break;
690 }
652 } else { 691 } else {
653 spellCheckLanguageMessage.textContent = 692 spellCheckLanguageMessage.textContent =
654 loadTimeData.getString('cannotBeUsedForSpellChecking'); 693 loadTimeData.getString('cannotBeUsedForSpellChecking');
655 showMutuallyExclusiveNodes( 694 spellCheckLanguageMessage.hidden = false;
656 [spellCheckLanguageButton, spellCheckLanguageMessage], 1);
657 } 695 }
658 }, 696 },
659 697
660 /** 698 /**
661 * Updates the checkbox for stopping translation. 699 * Updates the checkbox for stopping translation.
662 * @param {string} languageCode Language code (ex. "fr"). 700 * @param {string} languageCode Language code (ex. "fr").
663 * @private 701 * @private
664 */ 702 */
665 updateOfferToTranslateCheckbox_: function(languageCode) { 703 updateOfferToTranslateCheckbox_: function(languageCode) {
666 var div = $('language-options-offer-to-translate'); 704 var div = $('language-options-offer-to-translate');
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 return (!cr.isChromeOS || 950 return (!cr.isChromeOS ||
913 this.canDeleteLanguage_(languageCode)); 951 this.canDeleteLanguage_(languageCode));
914 }, 952 },
915 953
916 /** 954 /**
917 * Handles browse.enable_spellchecking change. 955 * Handles browse.enable_spellchecking change.
918 * @param {Event} e Change event. 956 * @param {Event} e Change event.
919 * @private 957 * @private
920 */ 958 */
921 updateEnableSpellCheck_: function(e) { 959 updateEnableSpellCheck_: function(e) {
922 var value = !$('enable-spell-check').checked; 960 var value = !$('enable-spellcheck').checked;
923 $('language-options-spell-check-language-button').disabled = value; 961 $('spellcheck-language-button').disabled = value;
924 if (!cr.isMac) 962 if (!cr.isMac)
925 $('edit-dictionary-button').hidden = value; 963 $('edit-dictionary-button').hidden = value;
926 }, 964 },
927 965
928 /** 966 /**
929 * Handles translateBlockedLanguagesPref change. 967 * Handles translateBlockedLanguagesPref change.
930 * @param {Event} e Change event. 968 * @param {Event} e Change event.
931 * @private 969 * @private
932 */ 970 */
933 handleTranslateBlockedLanguagesPrefChange_: function(e) { 971 handleTranslateBlockedLanguagesPrefChange_: function(e) {
934 this.translateBlockedLanguages_ = e.value.value; 972 this.translateBlockedLanguages_ = e.value.value;
935 this.updateOfferToTranslateCheckbox_( 973 this.updateOfferToTranslateCheckbox_(
936 $('language-options-list').getSelectedLanguageCode()); 974 $('language-options-list').getSelectedLanguageCode());
937 }, 975 },
938 976
939 /** 977 /**
940 * Handles spellCheckDictionaryPref change. 978 * Handles spellCheckDictionaryPref change.
941 * @param {Event} e Change event. 979 * @param {Event} e Change event.
942 * @private 980 * @private
943 */ 981 */
944 handleSpellCheckDictionaryPrefChange_: function(e) { 982 handleSpellCheckDictionaryPrefChange_: function(e) {
945 var languageCode = e.value.value; 983 this.spellCheckDictionary_ = e.value.value;
946 this.spellCheckDictionary_ = languageCode;
947 if (!cr.isMac) { 984 if (!cr.isMac) {
948 this.updateSpellCheckLanguageButton_( 985 this.updateSpellCheckLanguageControls_(
949 $('language-options-list').getSelectedLanguageCode()); 986 $('language-options-list').getSelectedLanguageCode());
950 } 987 }
951 }, 988 },
989
990 /**
991 * Updates spellcheck dictionary UI (checkboxes, buttons, and labels) when
992 * preferences change.
993 * @param {Event} e Preference change event where e.value.value is the
994 * comma separated list of languages currently used for spellchecking.
995 * @private
996 */
997 handleSpellCheckDictionariesPrefChange_: function(e) {
998 if (!cr.isMac) {
999 var languageCodesSplit = e.value.value.split(',');
1000
1001 this.spellCheckDictionaries_ = {};
1002 for (var i = 0; i < languageCodesSplit.length; i++)
1003 this.spellCheckDictionaries_[languageCodesSplit[i]] = true;
1004
1005 this.updateSpellCheckLanguageControls_(
1006 $('language-options-list').getSelectedLanguageCode());
1007 }
1008 },
952 1009
953 /** 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.spellCheckDictionaries_[languageCode] = true;
1049 else
1050 delete this.spellCheckDictionaries_[languageCode];
1051
1052 var languageCodes = Object.keys(this.spellCheckDictionaries_);
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
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 }; 1446 };
1370 1447
1371 LanguageOptions.onDictionaryDownloadSuccess = function(languageCode) { 1448 LanguageOptions.onDictionaryDownloadSuccess = function(languageCode) {
1372 LanguageOptions.getInstance().onDictionaryDownloadSuccess_(languageCode); 1449 LanguageOptions.getInstance().onDictionaryDownloadSuccess_(languageCode);
1373 }; 1450 };
1374 1451
1375 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { 1452 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) {
1376 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); 1453 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode);
1377 }; 1454 };
1378 1455
1456 LanguageOptions.updateSpellCheckLanguageControls = function(languageCode) {
1457 LanguageOptions.getInstance().updateSpellCheckLanguageControls_(
1458 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