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 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 Loading... | |
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 spellCheckDictionary_: '', |
Dan Beam
2015/06/09 17:57:47
Can we rename this to something other than diction
Julius
2015/06/17 00:59:51
Renamed spellCheckDictionary_ and spellCheckDictio
| |
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 Loading... | |
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 Loading... | |
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', |
please use gerrit instead
2015/06/06 01:42:12
Will this catch taps on a touch screen? Many chrom
Dan Beam
2015/06/09 17:57:47
Yes, but change is an arguably better event to lis
Julius
2015/06/12 20:10:14
Acknowledged.
Julius
2015/06/15 22:47:34
Done.
| |
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 Loading... | |
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 Loading... | |
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.spellCheckDictionaries_.hasOwnProperty(languageCode); |
636 DOWNLOAD_STATUS.FAILED) { | 667 spellCheckLanguageCheckboxDiv.hidden = false; |
637 spellCheckLanguageSection.hidden = true; | 668 } else if (languageCode == this.spellCheckDictionary_) { |
Dan Beam
2015/06/09 17:57:47
I'm confused. Is this comparing a string to a dict
Julius
2015/06/17 00:59:51
Variables have been renamed to eliminate confusion
| |
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); |
Dan Beam
2015/06/09 17:57:47
Needs 2 more spaces
Julius
2015/06/15 22:47:34
Done.
| |
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 Loading... | |
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 this.spellCheckDictionary_ = e.value.value; |
946 this.spellCheckDictionary_ = languageCode; | |
947 if (!cr.isMac) { | 985 if (!cr.isMac) { |
948 this.updateSpellCheckLanguageButton_( | 986 this.updateSpellCheckLanguageControls_( |
949 $('language-options-list').getSelectedLanguageCode()); | 987 $('language-options-list').getSelectedLanguageCode()); |
950 } | 988 } |
951 }, | 989 }, |
990 | |
991 /** | |
992 * Updates spellcheck dictionary UI (checkboxes, buttons, and labels) when | |
993 * preferences change. | |
994 * @param {Event} e Preference change event where e.value.value is the | |
995 * comma separated list of languages currently used for spellchecking. | |
996 * @private | |
997 */ | |
998 handleSpellCheckDictionariesPrefChange_: function(e) { | |
999 if (!cr.isMac) { | |
Dan Beam
2015/06/09 17:57:47
Should this ever happen on Mac?
assert(!cr.isMac)
Julius
2015/06/17 00:59:51
It shouldn't. I added the assert.
| |
1000 var languageCodesSplit = e.value.value.split(','); | |
1001 | |
1002 this.spellCheckDictionaries_ = {}; | |
1003 for (var i = 0; i < languageCodesSplit.length; i++) | |
1004 this.spellCheckDictionaries_[languageCodesSplit[i]] = true; | |
1005 | |
1006 this.updateSpellCheckLanguageControls_( | |
1007 $('language-options-list').getSelectedLanguageCode()); | |
1008 } | |
1009 }, | |
952 | 1010 |
953 /** | 1011 /** |
954 * Handles translate.enabled change. | 1012 * Handles translate.enabled change. |
955 * @param {Event} e Change event. | 1013 * @param {Event} e Change event. |
956 * @private | 1014 * @private |
957 */ | 1015 */ |
958 handleEnableTranslatePrefChange_: function(e) { | 1016 handleEnableTranslatePrefChange_: function(e) { |
959 var enabled = e.value.value; | 1017 var enabled = e.value.value; |
960 this.enableTranslate_ = enabled; | 1018 this.enableTranslate_ = enabled; |
961 this.updateOfferToTranslateCheckbox_( | 1019 this.updateOfferToTranslateCheckbox_( |
962 $('language-options-list').getSelectedLanguageCode()); | 1020 $('language-options-list').getSelectedLanguageCode()); |
963 }, | 1021 }, |
964 | 1022 |
965 /** | 1023 /** |
966 * Handles spellCheckLanguageButton click. | 1024 * Handles spellCheckLanguageButton click. |
967 * @param {Event} e Click event. | 1025 * @param {Event} e Click event. |
968 * @private | 1026 * @private |
969 */ | 1027 */ |
970 handleSpellCheckLanguageButtonClick_: function(e) { | 1028 handleSpellCheckLanguageButtonClick_: function(e) { |
971 var languageCode = e.target.languageCode; | 1029 var languageCode = e.target.languageCode; |
972 // Save the preference. | 1030 // Save the preference. |
973 Preferences.setStringPref(SPELL_CHECK_DICTIONARY_PREF, | 1031 Preferences.setStringPref(SPELL_CHECK_DICTIONARY_PREF, |
974 languageCode, true); | 1032 languageCode, true); |
975 chrome.send('spellCheckLanguageChange', [languageCode]); | 1033 chrome.send('spellCheckLanguageChange', [languageCode]); |
976 chrome.send('coreOptionsUserMetricsAction', | 1034 chrome.send('coreOptionsUserMetricsAction', |
977 ['Options_Languages_SpellCheck']); | 1035 ['Options_Languages_SpellCheck']); |
978 }, | 1036 }, |
979 | 1037 |
980 /** | 1038 /** |
1039 * Updates the spellcheck.dictionaries preference with the currently | |
1040 * selected language codes. | |
1041 * @param {Event} e Click event. e.target represents the "Use this language | |
1042 * for spellchecking" | |
1043 * @private | |
1044 */ | |
1045 handleSpellCheckLanguageCheckboxClick_: function(e) { | |
1046 var languageCode = e.target.languageCode; | |
1047 | |
1048 if (e.target.checked) | |
1049 this.spellCheckDictionaries_[languageCode] = true; | |
1050 else | |
1051 delete this.spellCheckDictionaries_[languageCode]; | |
1052 | |
1053 var languageCodes = []; | |
Dan Beam
2015/06/09 17:57:47
I think this can be
var languageCodes = Object.
Julius
2015/06/15 22:47:34
Done.
| |
1054 for (var currentLanguageCode in this.spellCheckDictionaries_) { | |
1055 if (this.spellCheckDictionaries_.hasOwnProperty(currentLanguageCode)) | |
1056 languageCodes.push(currentLanguageCode); | |
1057 } | |
1058 | |
1059 Preferences.setStringPref(SPELL_CHECK_DICTIONARIES_PREF, | |
1060 languageCodes.join(','), true); | |
1061 }, | |
1062 | |
1063 /** | |
981 * Checks whether it's possible to remove the language specified by | 1064 * Checks whether it's possible to remove the language specified by |
982 * languageCode and returns true if possible. This function returns false | 1065 * languageCode and returns true if possible. This function returns false |
983 * if the removal causes the number of preload engines to be zero. | 1066 * if the removal causes the number of preload engines to be zero. |
984 * | 1067 * |
985 * @param {string} languageCode Language code (ex. "fr"). | 1068 * @param {string} languageCode Language code (ex. "fr"). |
986 * @return {boolean} Returns true on success. | 1069 * @return {boolean} Returns true on success. |
987 * @private | 1070 * @private |
988 */ | 1071 */ |
989 canDeleteLanguage_: function(languageCode) { | 1072 canDeleteLanguage_: function(languageCode) { |
990 // First create the set of engines to be removed from input methods | 1073 // First create the set of engines to be removed from input methods |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1269 * @param {string} languageCode The language of the dictionary that just | 1352 * @param {string} languageCode The language of the dictionary that just |
1270 * began downloading. | 1353 * began downloading. |
1271 * @private | 1354 * @private |
1272 */ | 1355 */ |
1273 onDictionaryDownloadBegin_: function(languageCode) { | 1356 onDictionaryDownloadBegin_: function(languageCode) { |
1274 this.spellcheckDictionaryDownloadStatus_[languageCode] = | 1357 this.spellcheckDictionaryDownloadStatus_[languageCode] = |
1275 DOWNLOAD_STATUS.IN_PROGRESS; | 1358 DOWNLOAD_STATUS.IN_PROGRESS; |
1276 if (!cr.isMac && | 1359 if (!cr.isMac && |
1277 languageCode == | 1360 languageCode == |
1278 $('language-options-list').getSelectedLanguageCode()) { | 1361 $('language-options-list').getSelectedLanguageCode()) { |
1279 this.updateSpellCheckLanguageButton_(languageCode); | 1362 this.updateSpellCheckLanguageControls_(languageCode); |
1280 } | 1363 } |
1281 }, | 1364 }, |
1282 | 1365 |
1283 /** | 1366 /** |
1284 * A handler for when dictionary for |languageCode| successfully downloaded. | 1367 * A handler for when dictionary for |languageCode| successfully downloaded. |
1285 * @param {string} languageCode The language of the dictionary that | 1368 * @param {string} languageCode The language of the dictionary that |
1286 * succeeded downloading. | 1369 * succeeded downloading. |
1287 * @private | 1370 * @private |
1288 */ | 1371 */ |
1289 onDictionaryDownloadSuccess_: function(languageCode) { | 1372 onDictionaryDownloadSuccess_: function(languageCode) { |
1290 delete this.spellcheckDictionaryDownloadStatus_[languageCode]; | 1373 delete this.spellcheckDictionaryDownloadStatus_[languageCode]; |
1291 this.spellcheckDictionaryDownloadFailures_ = 0; | 1374 this.spellcheckDictionaryDownloadFailures_ = 0; |
1292 if (!cr.isMac && | 1375 if (!cr.isMac && |
1293 languageCode == | 1376 languageCode == |
1294 $('language-options-list').getSelectedLanguageCode()) { | 1377 $('language-options-list').getSelectedLanguageCode()) { |
1295 this.updateSpellCheckLanguageButton_(languageCode); | 1378 this.updateSpellCheckLanguageControls_(languageCode); |
1296 } | 1379 } |
1297 }, | 1380 }, |
1298 | 1381 |
1299 /** | 1382 /** |
1300 * A handler for when dictionary for |languageCode| fails to download. | 1383 * A handler for when dictionary for |languageCode| fails to download. |
1301 * @param {string} languageCode The language of the dictionary that failed | 1384 * @param {string} languageCode The language of the dictionary that failed |
1302 * to download. | 1385 * to download. |
1303 * @private | 1386 * @private |
1304 */ | 1387 */ |
1305 onDictionaryDownloadFailure_: function(languageCode) { | 1388 onDictionaryDownloadFailure_: function(languageCode) { |
1306 this.spellcheckDictionaryDownloadStatus_[languageCode] = | 1389 this.spellcheckDictionaryDownloadStatus_[languageCode] = |
1307 DOWNLOAD_STATUS.FAILED; | 1390 DOWNLOAD_STATUS.FAILED; |
1308 this.spellcheckDictionaryDownloadFailures_++; | 1391 this.spellcheckDictionaryDownloadFailures_++; |
1309 if (!cr.isMac && | 1392 if (!cr.isMac && |
1310 languageCode == | 1393 languageCode == |
1311 $('language-options-list').getSelectedLanguageCode()) { | 1394 $('language-options-list').getSelectedLanguageCode()) { |
1312 this.updateSpellCheckLanguageButton_(languageCode); | 1395 this.updateSpellCheckLanguageControls_(languageCode); |
1313 } | 1396 } |
1314 }, | 1397 }, |
1315 | 1398 |
1316 /** | 1399 /** |
1317 * Converts the language code for Translation. There are some differences | 1400 * Converts the language code for Translation. There are some differences |
1318 * between the language set for Translation and that for Accept-Language. | 1401 * between the language set for Translation and that for Accept-Language. |
1319 * @param {string} languageCode The language code like 'fr'. | 1402 * @param {string} languageCode The language code like 'fr'. |
1320 * @return {string} The converted language code. | 1403 * @return {string} The converted language code. |
1321 * @private | 1404 * @private |
1322 */ | 1405 */ |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1374 | 1457 |
1375 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { | 1458 LanguageOptions.onDictionaryDownloadFailure = function(languageCode) { |
1376 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); | 1459 LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); |
1377 }; | 1460 }; |
1378 | 1461 |
1379 // Export | 1462 // Export |
1380 return { | 1463 return { |
1381 LanguageOptions: LanguageOptions | 1464 LanguageOptions: LanguageOptions |
1382 }; | 1465 }; |
1383 }); | 1466 }); |
OLD | NEW |