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

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, clarified code. 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}
please use gerrit instead 2015/06/05 17:50:05 Unless some Chrome tool or bot told you to do it t
Julius 2015/06/05 21:38:32 I changed this because a comment on Klemen's patch
please use gerrit instead 2015/06/06 01:42:12 Sounds good. let's leave it as is.
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}
please use gerrit instead 2015/06/05 17:50:05 Best to following existing conventions of this fil
Julius 2015/06/05 21:38:32 See previous comment.
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_: '',
please use gerrit instead 2015/06/05 17:50:05 I thinks this renaming is not necessary and makes
Julius 2015/06/05 21:38:32 I changed it because in Klemen's patch someone men
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_: {},
please use gerrit instead 2015/06/05 17:50:05 If you undo rename of spellCheckDictionary_, then
please use gerrit instead 2015/06/05 17:50:05 Can you look through Klemen's review and see wheth
Julius 2015/06/05 21:38:32 Done.
Julius 2015/06/05 21:38:33 Dan Beam had a write-up about it here ( https://co
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 var spellCheckLanguageCheckbox = getRequiredElement(
245 spellCheckLanguageButton.addEventListener( 262 'language-options-spellcheck-language-checkbox');
246 'click', 263 spellCheckLanguageCheckbox.addEventListener(
247 this.handleSpellCheckLanguageButtonClick_.bind(this)); 264 'click',
265 this.handleSpellCheckLanguageCheckboxClick_.bind(this));
266 } else {
267 var spellCheckLanguageButton = getRequiredElement(
268 'language-options-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 $('language-options-spellcheck-language-button');
636 var spellCheckLanguageCheckboxDiv =
637 $('language-options-spellcheck-language-checkbox-div');
638 var spellCheckLanguageCheckbox =
639 $('language-options-spellcheck-language-checkbox');
611 var spellCheckLanguageMessage = 640 var spellCheckLanguageMessage =
612 $('language-options-spell-check-language-message'); 641 $('language-options-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;
625 656
626 if (languageCode == this.spellCheckDictionary_) { 657 spellCheckLanguageCheckbox.checked = false;
627 if (!(languageCode in this.spellcheckDictionaryDownloadStatus_)) { 658
628 spellCheckLanguageMessage.textContent = 659 if (!languageCode)
629 loadTimeData.getString('isUsedForSpellChecking'); 660 return;
630 showMutuallyExclusiveNodes( 661
631 [spellCheckLanguageButton, spellCheckLanguageMessage], 1); 662 if (languageCode in loadTimeData.getValue('spellCheckLanguageCodeSet')) {
632 } else if (this.spellcheckDictionaryDownloadStatus_[languageCode] == 663 if (loadTimeData.getBoolean('enableMultilingualSpellChecker')) {
633 DOWNLOAD_STATUS.IN_PROGRESS) { 664 spellCheckLanguageCheckbox.languageCode = languageCode;
634 dictionaryDownloadInProgress.hidden = false; 665 spellCheckLanguageCheckbox.checked =
635 } else if (this.spellcheckDictionaryDownloadStatus_[languageCode] == 666 this.spellCheckLanguages_.hasOwnProperty(languageCode);
636 DOWNLOAD_STATUS.FAILED) { 667 spellCheckLanguageCheckboxDiv.hidden = false;
637 spellCheckLanguageSection.hidden = true; 668 } else if (languageCode == this.spellCheckLanguage_) {
638 dictionaryDownloadFailed.hidden = false; 669 if (!(languageCode in this.spellcheckDictionaryDownloadStatus_)) {
639 if (this.spellcheckDictionaryDownloadFailures_ > 1) 670 spellCheckLanguageMessage.textContent =
640 dictionaryDownloadFailHelp.hidden = false; 671 loadTimeData.getString('isUsedForSpellChecking');
672 spellCheckLanguageMessage.hidden = false;
673 }
674 } else {
675 spellCheckLanguageButton.textContent =
676 loadTimeData.getString('useThisForSpellChecking');
677 spellCheckLanguageButton.hidden = false;
678 spellCheckLanguageButton.languageCode = languageCode;
641 } 679 }
642 } else if (languageCode in 680
643 loadTimeData.getValue('spellCheckLanguageCodeSet')) { 681 switch (this.spellcheckDictionaryDownloadStatus_[languageCode]) {
644 spellCheckLanguageButton.textContent = 682 case DOWNLOAD_STATUS.IN_PROGRESS:
645 loadTimeData.getString('useThisForSpellChecking'); 683 dictionaryDownloadInProgress.hidden = false;
646 showMutuallyExclusiveNodes( 684 break;
647 [spellCheckLanguageButton, spellCheckLanguageMessage], 0); 685 case DOWNLOAD_STATUS.FAILED:
648 spellCheckLanguageButton.languageCode = languageCode; 686 showMutuallyExclusiveNodes(
649 } else if (!languageCode) { 687 [spellCheckLanguageSection, dictionaryDownloadFailed], 1);
650 spellCheckLanguageButton.hidden = true; 688 if (this.spellcheckDictionaryDownloadFailures_ > 1)
651 spellCheckLanguageMessage.hidden = true; 689 dictionaryDownloadFailHelp.hidden = false;
690 break;
691 }
652 } else { 692 } else {
653 spellCheckLanguageMessage.textContent = 693 spellCheckLanguageMessage.textContent =
654 loadTimeData.getString('cannotBeUsedForSpellChecking'); 694 loadTimeData.getString('cannotBeUsedForSpellChecking');
655 showMutuallyExclusiveNodes( 695 spellCheckLanguageMessage.hidden = false;
656 [spellCheckLanguageButton, spellCheckLanguageMessage], 1);
657 } 696 }
658 }, 697 },
659 698
660 /** 699 /**
661 * Updates the checkbox for stopping translation. 700 * Updates the checkbox for stopping translation.
662 * @param {string} languageCode Language code (ex. "fr"). 701 * @param {string} languageCode Language code (ex. "fr").
663 * @private 702 * @private
664 */ 703 */
665 updateOfferToTranslateCheckbox_: function(languageCode) { 704 updateOfferToTranslateCheckbox_: function(languageCode) {
666 var div = $('language-options-offer-to-translate'); 705 var div = $('language-options-offer-to-translate');
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 return (!cr.isChromeOS || 951 return (!cr.isChromeOS ||
913 this.canDeleteLanguage_(languageCode)); 952 this.canDeleteLanguage_(languageCode));
914 }, 953 },
915 954
916 /** 955 /**
917 * Handles browse.enable_spellchecking change. 956 * Handles browse.enable_spellchecking change.
918 * @param {Event} e Change event. 957 * @param {Event} e Change event.
919 * @private 958 * @private
920 */ 959 */
921 updateEnableSpellCheck_: function(e) { 960 updateEnableSpellCheck_: function(e) {
922 var value = !$('enable-spell-check').checked; 961 var value = !$('enable-spellcheck').checked;
923 $('language-options-spell-check-language-button').disabled = value; 962 $('language-options-spellcheck-language-button').disabled = value;
924 if (!cr.isMac) 963 if (!cr.isMac)
925 $('edit-dictionary-button').hidden = value; 964 $('edit-dictionary-button').hidden = value;
926 }, 965 },
927 966
928 /** 967 /**
929 * Handles translateBlockedLanguagesPref change. 968 * Handles translateBlockedLanguagesPref change.
930 * @param {Event} e Change event. 969 * @param {Event} e Change event.
931 * @private 970 * @private
932 */ 971 */
933 handleTranslateBlockedLanguagesPrefChange_: function(e) { 972 handleTranslateBlockedLanguagesPrefChange_: function(e) {
934 this.translateBlockedLanguages_ = e.value.value; 973 this.translateBlockedLanguages_ = e.value.value;
935 this.updateOfferToTranslateCheckbox_( 974 this.updateOfferToTranslateCheckbox_(
936 $('language-options-list').getSelectedLanguageCode()); 975 $('language-options-list').getSelectedLanguageCode());
937 }, 976 },
938 977
939 /** 978 /**
940 * Handles spellCheckDictionaryPref change. 979 * Handles spellCheckDictionaryPref change.
941 * @param {Event} e Change event. 980 * @param {Event} e Change event.
942 * @private 981 * @private
943 */ 982 */
944 handleSpellCheckDictionaryPrefChange_: function(e) { 983 handleSpellCheckDictionaryPrefChange_: function(e) {
945 var languageCode = e.value.value; 984 var languageCode = e.value.value;
please use gerrit instead 2015/06/05 17:50:05 Inline this variable into the next statement.
Julius 2015/06/05 21:38:32 Done.
946 this.spellCheckDictionary_ = languageCode; 985 this.spellCheckLanguage_ = languageCode;
947 if (!cr.isMac) { 986 if (!cr.isMac) {
please use gerrit instead 2015/06/05 17:50:05 Make both handleSpellCheckDictionaryPrefChange_()
Julius 2015/06/05 21:38:32 Done.
948 this.updateSpellCheckLanguageButton_( 987 this.updateSpellCheckLanguageControls_(
949 $('language-options-list').getSelectedLanguageCode()); 988 $('language-options-list').getSelectedLanguageCode());
950 } 989 }
951 }, 990 },
952 991
953 /** 992 /**
993 * Updates spellcheck dictionary UI (checkboxes, buttons, and labels) when
994 * preferences change.
995 * @param {Event} e. Preference change event where e.value.value is the
please use gerrit instead 2015/06/05 17:50:05 No period (.) after the first mention of the varia
Julius 2015/06/05 21:38:32 Done.
996 * comma separated list of languages currently used for spellchecking.
997 * @private
998 */
999 handleSpellCheckDictionariesPrefChange_: function(e) {
1000 if (cr.isMac)
1001 return;
1002
1003 var commaSeparatedLanguageCodes = e.value.value;
please use gerrit instead 2015/06/05 17:50:05 Inline this variable into the next statement.
Julius 2015/06/05 21:38:32 Done.
1004 var languageCodesSplit = commaSeparatedLanguageCodes.split(',');
1005
1006 this.spellCheckLanguages_ = {};
1007 for (var i = 0; i < languageCodesSplit.length; i++)
please use gerrit instead 2015/06/05 17:50:05 Easier to write this? for (var i in languageCodes
Julius 2015/06/05 21:38:32 This isn't the right way to iterate over array ele
1008 this.spellCheckLanguages_[languageCodesSplit[i]] = true;
1009
1010 this.updateSpellCheckLanguageControls_(
1011 $('language-options-list').getSelectedLanguageCode());
1012 },
1013
1014 /**
954 * Handles translate.enabled change. 1015 * Handles translate.enabled change.
955 * @param {Event} e Change event. 1016 * @param {Event} e Change event.
956 * @private 1017 * @private
957 */ 1018 */
958 handleEnableTranslatePrefChange_: function(e) { 1019 handleEnableTranslatePrefChange_: function(e) {
959 var enabled = e.value.value; 1020 var enabled = e.value.value;
960 this.enableTranslate_ = enabled; 1021 this.enableTranslate_ = enabled;
961 this.updateOfferToTranslateCheckbox_( 1022 this.updateOfferToTranslateCheckbox_(
962 $('language-options-list').getSelectedLanguageCode()); 1023 $('language-options-list').getSelectedLanguageCode());
963 }, 1024 },
964 1025
965 /** 1026 /**
966 * Handles spellCheckLanguageButton click. 1027 * Handles spellCheckLanguageButton click.
967 * @param {Event} e Click event. 1028 * @param {Event} e Click event.
968 * @private 1029 * @private
969 */ 1030 */
970 handleSpellCheckLanguageButtonClick_: function(e) { 1031 handleSpellCheckLanguageButtonClick_: function(e) {
971 var languageCode = e.target.languageCode; 1032 var languageCode = e.target.languageCode;
972 // Save the preference. 1033 // Save the preference.
973 Preferences.setStringPref(SPELL_CHECK_DICTIONARY_PREF, 1034 Preferences.setStringPref(SPELL_CHECK_DICTIONARY_PREF,
974 languageCode, true); 1035 languageCode, true);
975 chrome.send('spellCheckLanguageChange', [languageCode]); 1036 chrome.send('spellCheckLanguageChange', [languageCode]);
976 chrome.send('coreOptionsUserMetricsAction', 1037 chrome.send('coreOptionsUserMetricsAction',
977 ['Options_Languages_SpellCheck']); 1038 ['Options_Languages_SpellCheck']);
978 }, 1039 },
979 1040
980 /** 1041 /**
1042 * Updates the spellcheck.dictionaries preference with the currently
1043 * selected language codes.
1044 * @param {Event} e Click event. e.target represents the "Use this language
1045 * for spellchecking"
1046 * @private
1047 */
1048 handleSpellCheckLanguageCheckboxClick_: function(e) {
1049 var languageCode = e.target.languageCode;
1050
1051 if (e.target.checked)
1052 this.spellCheckLanguages_[languageCode] = true;
1053 else
1054 delete this.spellCheckLanguages_[languageCode];
1055
1056 var languageCodes = [];
1057 for (var currentLanguageCode in this.spellCheckLanguages_) {
1058 if (this.spellCheckLanguages_.hasOwnProperty(currentLanguageCode))
please use gerrit instead 2015/06/05 17:50:05 Are you able to iterate over the elements in this.
Julius 2015/06/05 21:38:33 Yep, this is the standard way of iterating over ke
1059 languageCodes.push(currentLanguageCode);
1060 }
1061
1062 Preferences.setStringPref(SPELL_CHECK_DICTIONARIES_PREF,
1063 languageCodes.join(','), true);
1064 },
1065
1066 /**
981 * Checks whether it's possible to remove the language specified by 1067 * Checks whether it's possible to remove the language specified by
982 * languageCode and returns true if possible. This function returns false 1068 * languageCode and returns true if possible. This function returns false
983 * if the removal causes the number of preload engines to be zero. 1069 * if the removal causes the number of preload engines to be zero.
984 * 1070 *
985 * @param {string} languageCode Language code (ex. "fr"). 1071 * @param {string} languageCode Language code (ex. "fr").
986 * @return {boolean} Returns true on success. 1072 * @return {boolean} Returns true on success.
987 * @private 1073 * @private
988 */ 1074 */
989 canDeleteLanguage_: function(languageCode) { 1075 canDeleteLanguage_: function(languageCode) {
990 // First create the set of engines to be removed from input methods 1076 // 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 1355 * @param {string} languageCode The language of the dictionary that just
1270 * began downloading. 1356 * began downloading.
1271 * @private 1357 * @private
1272 */ 1358 */
1273 onDictionaryDownloadBegin_: function(languageCode) { 1359 onDictionaryDownloadBegin_: function(languageCode) {
1274 this.spellcheckDictionaryDownloadStatus_[languageCode] = 1360 this.spellcheckDictionaryDownloadStatus_[languageCode] =
1275 DOWNLOAD_STATUS.IN_PROGRESS; 1361 DOWNLOAD_STATUS.IN_PROGRESS;
1276 if (!cr.isMac && 1362 if (!cr.isMac &&
1277 languageCode == 1363 languageCode ==
1278 $('language-options-list').getSelectedLanguageCode()) { 1364 $('language-options-list').getSelectedLanguageCode()) {
1279 this.updateSpellCheckLanguageButton_(languageCode); 1365 this.updateSpellCheckLanguageControls_(languageCode);
1280 } 1366 }
1281 }, 1367 },
1282 1368
1283 /** 1369 /**
1284 * A handler for when dictionary for |languageCode| successfully downloaded. 1370 * A handler for when dictionary for |languageCode| successfully downloaded.
1285 * @param {string} languageCode The language of the dictionary that 1371 * @param {string} languageCode The language of the dictionary that
1286 * succeeded downloading. 1372 * succeeded downloading.
1287 * @private 1373 * @private
1288 */ 1374 */
1289 onDictionaryDownloadSuccess_: function(languageCode) { 1375 onDictionaryDownloadSuccess_: function(languageCode) {
1290 delete this.spellcheckDictionaryDownloadStatus_[languageCode]; 1376 delete this.spellcheckDictionaryDownloadStatus_[languageCode];
1291 this.spellcheckDictionaryDownloadFailures_ = 0; 1377 this.spellcheckDictionaryDownloadFailures_ = 0;
1292 if (!cr.isMac && 1378 if (!cr.isMac &&
1293 languageCode == 1379 languageCode ==
1294 $('language-options-list').getSelectedLanguageCode()) { 1380 $('language-options-list').getSelectedLanguageCode()) {
1295 this.updateSpellCheckLanguageButton_(languageCode); 1381 this.updateSpellCheckLanguageControls_(languageCode);
1296 } 1382 }
1297 }, 1383 },
1298 1384
1299 /** 1385 /**
1300 * A handler for when dictionary for |languageCode| fails to download. 1386 * A handler for when dictionary for |languageCode| fails to download.
1301 * @param {string} languageCode The language of the dictionary that failed 1387 * @param {string} languageCode The language of the dictionary that failed
1302 * to download. 1388 * to download.
1303 * @private 1389 * @private
1304 */ 1390 */
1305 onDictionaryDownloadFailure_: function(languageCode) { 1391 onDictionaryDownloadFailure_: function(languageCode) {
1306 this.spellcheckDictionaryDownloadStatus_[languageCode] = 1392 this.spellcheckDictionaryDownloadStatus_[languageCode] =
1307 DOWNLOAD_STATUS.FAILED; 1393 DOWNLOAD_STATUS.FAILED;
1308 this.spellcheckDictionaryDownloadFailures_++; 1394 this.spellcheckDictionaryDownloadFailures_++;
1309 if (!cr.isMac && 1395 if (!cr.isMac &&
1310 languageCode == 1396 languageCode ==
1311 $('language-options-list').getSelectedLanguageCode()) { 1397 $('language-options-list').getSelectedLanguageCode()) {
1312 this.updateSpellCheckLanguageButton_(languageCode); 1398 this.updateSpellCheckLanguageControls_(languageCode);
1313 } 1399 }
1314 }, 1400 },
1315 1401
1316 /** 1402 /**
1317 * Converts the language code for Translation. There are some differences 1403 * Converts the language code for Translation. There are some differences
1318 * between the language set for Translation and that for Accept-Language. 1404 * between the language set for Translation and that for Accept-Language.
1319 * @param {string} languageCode The language code like 'fr'. 1405 * @param {string} languageCode The language code like 'fr'.
1320 * @return {string} The converted language code. 1406 * @return {string} The converted language code.
1321 * @private 1407 * @private
1322 */ 1408 */
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 1460
1375 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { 1461 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) {
1376 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); 1462 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode);
1377 }; 1463 };
1378 1464
1379 // Export 1465 // Export
1380 return { 1466 return {
1381 LanguageOptions: LanguageOptions 1467 LanguageOptions: LanguageOptions
1382 }; 1468 };
1383 }); 1469 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698