Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // TODO(kochi): Generalize the notification as a component and put it | 5 // TODO(kochi): Generalize the notification as a component and put it |
| 6 // in js/cr/ui/notification.js . | 6 // in js/cr/ui/notification.js . |
| 7 | 7 |
| 8 cr.define('options', function() { | 8 cr.define('options', function() { |
| 9 /** @const */ var OptionsPage = options.OptionsPage; | 9 /** @const */ var OptionsPage = options.OptionsPage; |
| 10 /** @const */ var LanguageList = options.LanguageList; | 10 /** @const */ var LanguageList = options.LanguageList; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 enabledExtensionImePref_: 'settings.language.enabled_extension_imes', | 104 enabledExtensionImePref_: 'settings.language.enabled_extension_imes', |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * The list of extension IMEs that are enabled out of the language menu. | 107 * The list of extension IMEs that are enabled out of the language menu. |
| 108 * @type {Array} | 108 * @type {Array} |
| 109 * @private | 109 * @private |
| 110 */ | 110 */ |
| 111 enabledExtensionImes_: [], | 111 enabledExtensionImes_: [], |
| 112 | 112 |
| 113 /** | 113 /** |
| 114 * The preference that lists the languages which is not translated. | |
| 115 * @type {string} | |
| 116 * @private | |
| 117 * @const | |
| 118 */ | |
| 119 translateLanguageBlacklistPref_: 'translate_language_blacklist', | |
|
Evan Stade
2013/05/28 17:08:11
as a const this should go up by DOWNLOAD_STATUS
hajimehoshi
2013/05/29 03:52:23
Done.
| |
| 120 | |
| 121 /** | |
| 122 * The list of the languages which is not translated. | |
|
Evan Stade
2013/05/28 17:08:11
nit: s/is/are
hajimehoshi
2013/05/29 03:52:23
Done.
| |
| 123 * @type {Array} | |
| 124 * @private | |
| 125 */ | |
| 126 translateLanguageBlacklist_: [], | |
| 127 | |
| 128 /** | |
| 114 * The preference key that is a string that describes the spell check | 129 * The preference key that is a string that describes the spell check |
| 115 * dictionary language, like "en-US". | 130 * dictionary language, like "en-US". |
| 116 * @type {string} | 131 * @type {string} |
| 117 * @private | 132 * @private |
| 118 * @const | 133 * @const |
| 119 */ | 134 */ |
| 120 spellCheckDictionaryPref_: 'spellcheck.dictionary', | 135 spellCheckDictionaryPref_: 'spellcheck.dictionary', |
| 121 | 136 |
| 122 /** | 137 /** |
| 123 * The preference is a string that describes the spell check dictionary | 138 * The preference is a string that describes the spell check dictionary |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 this.handleVisibleChange_.bind(this)); | 171 this.handleVisibleChange_.bind(this)); |
| 157 | 172 |
| 158 if (cr.isChromeOS) { | 173 if (cr.isChromeOS) { |
| 159 $('chewing-confirm').onclick = $('hangul-confirm').onclick = | 174 $('chewing-confirm').onclick = $('hangul-confirm').onclick = |
| 160 $('mozc-confirm').onclick = $('pinyin-confirm').onclick = | 175 $('mozc-confirm').onclick = $('pinyin-confirm').onclick = |
| 161 OptionsPage.closeOverlay.bind(OptionsPage); | 176 OptionsPage.closeOverlay.bind(OptionsPage); |
| 162 | 177 |
| 163 this.initializeInputMethodList_(); | 178 this.initializeInputMethodList_(); |
| 164 this.initializeLanguageCodeToInputMethodIdsMap_(); | 179 this.initializeLanguageCodeToInputMethodIdsMap_(); |
| 165 } | 180 } |
| 181 | |
| 182 var cb = $('language-options-dont-translate').querySelector('input'); | |
|
Evan Stade
2013/05/28 17:08:11
don't abbreviate variable names.
hajimehoshi
2013/05/29 03:52:23
Done.
| |
| 183 cb.addEventListener('click', | |
| 184 this.handleDontTranslateCheckboxClick_.bind(this)); | |
| 185 | |
| 186 Preferences.getInstance().addEventListener( | |
| 187 this.translateLanguageBlacklistPref_, | |
| 188 this.handleTranslateLanguageBlacklistPrefChange_.bind(this)); | |
| 166 Preferences.getInstance().addEventListener(this.spellCheckDictionaryPref_, | 189 Preferences.getInstance().addEventListener(this.spellCheckDictionaryPref_, |
| 167 this.handleSpellCheckDictionaryPrefChange_.bind(this)); | 190 this.handleSpellCheckDictionaryPrefChange_.bind(this)); |
| 168 | 191 |
| 169 // Set up add button. | 192 // Set up add button. |
| 170 $('language-options-add-button').onclick = function(e) { | 193 $('language-options-add-button').onclick = function(e) { |
| 171 // Add the language without showing the overlay if it's specified in | 194 // Add the language without showing the overlay if it's specified in |
| 172 // the URL hash (ex. lang_add=ja). Used for automated testing. | 195 // the URL hash (ex. lang_add=ja). Used for automated testing. |
| 173 var match = document.location.hash.match(/\blang_add=([\w-]+)/); | 196 var match = document.location.hash.match(/\blang_add=([\w-]+)/); |
| 174 if (match) { | 197 if (match) { |
| 175 var addLanguageCode = match[1]; | 198 var addLanguageCode = match[1]; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 // Select the language if it's specified in the URL hash (ex. lang=ja). | 389 // Select the language if it's specified in the URL hash (ex. lang=ja). |
| 367 // Used for automated testing. | 390 // Used for automated testing. |
| 368 var match = document.location.hash.match(/\blang=([\w-]+)/); | 391 var match = document.location.hash.match(/\blang=([\w-]+)/); |
| 369 if (match) { | 392 if (match) { |
| 370 var specifiedLanguageCode = match[1]; | 393 var specifiedLanguageCode = match[1]; |
| 371 if (languageOptionsList.selectLanguageByCode(specifiedLanguageCode)) { | 394 if (languageOptionsList.selectLanguageByCode(specifiedLanguageCode)) { |
| 372 languageCode = specifiedLanguageCode; | 395 languageCode = specifiedLanguageCode; |
| 373 } | 396 } |
| 374 } | 397 } |
| 375 | 398 |
| 399 this.updateDontTranslateCheckbox_(languageCode); | |
| 400 | |
| 376 if (cr.isWindows || cr.isChromeOS) | 401 if (cr.isWindows || cr.isChromeOS) |
| 377 this.updateUiLanguageButton_(languageCode); | 402 this.updateUiLanguageButton_(languageCode); |
| 378 | 403 |
| 379 if (!cr.isMac) { | 404 if (!cr.isMac) { |
| 380 this.updateSelectedLanguageName_(languageCode); | 405 this.updateSelectedLanguageName_(languageCode); |
| 381 this.updateSpellCheckLanguageButton_(languageCode); | 406 this.updateSpellCheckLanguageButton_(languageCode); |
| 382 } | 407 } |
| 383 | 408 |
| 384 if (cr.isChromeOS) | 409 if (cr.isChromeOS) |
| 385 this.updateInputMethodList_(languageCode); | 410 this.updateInputMethodList_(languageCode); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 599 spellCheckLanguageMessage.hidden = true; | 624 spellCheckLanguageMessage.hidden = true; |
| 600 } else { | 625 } else { |
| 601 spellCheckLanguageMessage.textContent = | 626 spellCheckLanguageMessage.textContent = |
| 602 loadTimeData.getString('cannot_be_used_for_spell_checking'); | 627 loadTimeData.getString('cannot_be_used_for_spell_checking'); |
| 603 showMutuallyExclusiveNodes( | 628 showMutuallyExclusiveNodes( |
| 604 [spellCheckLanguageButton, spellCheckLanguageMessage], 1); | 629 [spellCheckLanguageButton, spellCheckLanguageMessage], 1); |
| 605 } | 630 } |
| 606 }, | 631 }, |
| 607 | 632 |
| 608 /** | 633 /** |
| 634 * Updates the checkbox for stopping translation. | |
| 635 * @param {string} languageCode Language code (ex. "fr"). | |
| 636 * @private | |
| 637 */ | |
| 638 updateDontTranslateCheckbox_: function(languageCode) { | |
| 639 var dontTranslate = $('language-options-dont-translate'); | |
| 640 var checkbox = dontTranslate.querySelector('input'); | |
| 641 | |
| 642 // TODO(hajimehoshi): Create more general function to determine this. | |
| 643 if (this.isTranslatableLanguage_(languageCode)) { | |
| 644 dontTranslate.hidden = false; | |
| 645 } else { | |
| 646 dontTranslate.hidden = true; | |
| 647 return; | |
| 648 } | |
| 649 | |
| 650 var lang = this.convertLangCodeForTranslation_(languageCode); | |
| 651 var checked = (this.translateLanguageBlacklist_.indexOf(lang) != -1); | |
| 652 checkbox.checked = checked; | |
| 653 }, | |
| 654 | |
| 655 /** | |
| 609 * Updates the input method list. | 656 * Updates the input method list. |
| 610 * @param {string} languageCode Language code (ex. "fr"). | 657 * @param {string} languageCode Language code (ex. "fr"). |
| 611 * @private | 658 * @private |
| 612 */ | 659 */ |
| 613 updateInputMethodList_: function(languageCode) { | 660 updateInputMethodList_: function(languageCode) { |
| 614 // Give one of the checkboxes or buttons focus, if it's specified in the | 661 // Give one of the checkboxes or buttons focus, if it's specified in the |
| 615 // URL hash (ex. focus=mozc). Used for automated testing. | 662 // URL hash (ex. focus=mozc). Used for automated testing. |
| 616 var focusInputMethodId = -1; | 663 var focusInputMethodId = -1; |
| 617 var match = document.location.hash.match(/\bfocus=([\w:-]+)\b/); | 664 var match = document.location.hash.match(/\bfocus=([\w:-]+)\b/); |
| 618 if (match) { | 665 if (match) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 * @param {Event} e Change event. | 740 * @param {Event} e Change event. |
| 694 * @private | 741 * @private |
| 695 */ | 742 */ |
| 696 handleEnabledExtensionsPrefChange_: function(e) { | 743 handleEnabledExtensionsPrefChange_: function(e) { |
| 697 var value = e.value.value; | 744 var value = e.value.value; |
| 698 this.enabledExtensionImes_ = value.split(','); | 745 this.enabledExtensionImes_ = value.split(','); |
| 699 this.updateCheckboxesFromEnabledExtensions_(); | 746 this.updateCheckboxesFromEnabledExtensions_(); |
| 700 }, | 747 }, |
| 701 | 748 |
| 702 /** | 749 /** |
| 750 * Handles don't-translate checkbox's click event. | |
| 751 * @param {Event} e Click event. | |
| 752 * @private | |
| 753 */ | |
| 754 handleDontTranslateCheckboxClick_: function(e) { | |
| 755 var checkbox = e.target; | |
| 756 var checked = checkbox.checked; | |
| 757 | |
| 758 var languageOptionsList = $('language-options-list'); | |
| 759 var selectedLanguageCode = languageOptionsList.getSelectedLanguageCode(); | |
| 760 | |
| 761 var langCode = this.convertLangCodeForTranslation_(selectedLanguageCode); | |
| 762 var blacklist = this.translateLanguageBlacklist_; | |
| 763 if (checked && blacklist.indexOf(langCode) == -1) { | |
| 764 blacklist.push(langCode); | |
| 765 } else if (!checked && blacklist.indexOf(langCode) != -1) { | |
| 766 blacklist = blacklist.filter(function(l) { | |
|
Evan Stade
2013/05/28 17:08:11
don't abbreviate variable names
hajimehoshi
2013/05/29 03:52:23
Done.
| |
| 767 return l != langCode; | |
| 768 }); | |
| 769 } | |
| 770 this.translateLanguageBlacklist_ = blacklist; | |
| 771 | |
| 772 Preferences.setListPref(this.translateLanguageBlacklistPref_, | |
| 773 this.translateLanguageBlacklist_, true); | |
| 774 }, | |
| 775 | |
| 776 /** | |
| 703 * Handles input method checkbox's click event. | 777 * Handles input method checkbox's click event. |
| 704 * @param {Event} e Click event. | 778 * @param {Event} e Click event. |
| 705 * @private | 779 * @private |
| 706 */ | 780 */ |
| 707 handleCheckboxClick_: function(e) { | 781 handleCheckboxClick_: function(e) { |
| 708 var checkbox = e.target; | 782 var checkbox = e.target; |
| 709 | 783 |
| 710 if (checkbox.inputMethodId.match(/^_ext_ime_/)) { | 784 if (checkbox.inputMethodId.match(/^_ext_ime_/)) { |
| 711 this.updateEnabledExtensionsFromCheckboxes_(); | 785 this.updateEnabledExtensionsFromCheckboxes_(); |
| 712 this.saveEnabledExtensionPref_(); | 786 this.saveEnabledExtensionPref_(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 750 return false; | 824 return false; |
| 751 return (!cr.isChromeOS || | 825 return (!cr.isChromeOS || |
| 752 this.canDeleteLanguage_(languageCode)); | 826 this.canDeleteLanguage_(languageCode)); |
| 753 }, | 827 }, |
| 754 | 828 |
| 755 /** | 829 /** |
| 756 * Handles browse.enable_spellchecking change. | 830 * Handles browse.enable_spellchecking change. |
| 757 * @param {Event} e Change event. | 831 * @param {Event} e Change event. |
| 758 * @private | 832 * @private |
| 759 */ | 833 */ |
| 760 updateEnableSpellCheck_: function() { | 834 updateEnableSpellCheck_: function() { |
| 761 var value = !$('enable-spell-check').checked; | 835 var value = !$('enable-spell-check').checked; |
| 762 $('language-options-spell-check-language-button').disabled = value; | 836 $('language-options-spell-check-language-button').disabled = value; |
| 763 if (!cr.IsMac) | 837 if (!cr.IsMac) |
| 764 $('edit-dictionary-button').hidden = value; | 838 $('edit-dictionary-button').hidden = value; |
| 765 }, | 839 }, |
| 766 | 840 |
| 767 /** | 841 /** |
| 842 * Handles translateLanguageBlacklistPref change. | |
| 843 * @param {Event} e Change event. | |
| 844 * @private | |
| 845 */ | |
| 846 handleTranslateLanguageBlacklistPrefChange_: function(e) { | |
| 847 var languageOptionsList = $('language-options-list'); | |
| 848 var selectedLanguageCode = languageOptionsList.getSelectedLanguageCode(); | |
| 849 this.translateLanguageBlacklist_ = e.value.value; | |
| 850 | |
| 851 this.updateDontTranslateCheckbox_(selectedLanguageCode); | |
| 852 }, | |
| 853 | |
| 854 /** | |
| 768 * Handles spellCheckDictionaryPref change. | 855 * Handles spellCheckDictionaryPref change. |
| 769 * @param {Event} e Change event. | 856 * @param {Event} e Change event. |
| 770 * @private | 857 * @private |
| 771 */ | 858 */ |
| 772 handleSpellCheckDictionaryPrefChange_: function(e) { | 859 handleSpellCheckDictionaryPrefChange_: function(e) { |
| 773 var languageCode = e.value.value; | 860 var languageCode = e.value.value; |
| 774 this.spellCheckDictionary_ = languageCode; | 861 this.spellCheckDictionary_ = languageCode; |
| 775 var languageOptionsList = $('language-options-list'); | 862 var languageOptionsList = $('language-options-list'); |
| 776 var selectedLanguageCode = languageOptionsList.getSelectedLanguageCode(); | 863 var selectedLanguageCode = languageOptionsList.getSelectedLanguageCode(); |
| 777 if (!cr.isMac) | 864 if (!cr.isMac) |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1052 | 1139 |
| 1053 onDictionaryDownloadFailure_: function(languageCode) { | 1140 onDictionaryDownloadFailure_: function(languageCode) { |
| 1054 this.spellcheckDictionaryDownloadStatus_[languageCode] = | 1141 this.spellcheckDictionaryDownloadStatus_[languageCode] = |
| 1055 DOWNLOAD_STATUS.FAILED; | 1142 DOWNLOAD_STATUS.FAILED; |
| 1056 this.spellcheckDictionaryDownloadFailures_++; | 1143 this.spellcheckDictionaryDownloadFailures_++; |
| 1057 if (!cr.isMac && | 1144 if (!cr.isMac && |
| 1058 languageCode == | 1145 languageCode == |
| 1059 $('language-options-list').getSelectedLanguageCode()) { | 1146 $('language-options-list').getSelectedLanguageCode()) { |
| 1060 this.updateSpellCheckLanguageButton_(languageCode); | 1147 this.updateSpellCheckLanguageButton_(languageCode); |
| 1061 } | 1148 } |
| 1062 } | 1149 }, |
| 1150 | |
| 1151 /* | |
| 1152 * Converts the language code for Translation. There are some differences | |
| 1153 * between the language set for Translation and that for Accept-Language. | |
| 1154 * @param {string} languageCode The language code like 'fr'. | |
| 1155 * @return {string} The converted language code. | |
| 1156 * @private | |
| 1157 */ | |
| 1158 convertLangCodeForTranslation_: function(languageCode) { | |
| 1159 var tokens = languageCode.split('-'); | |
| 1160 var main = tokens[0]; | |
| 1161 var dialect = tokens[1]; | |
| 1162 | |
| 1163 // See also: chrome/renderer/translate/translate_helper.cc. | |
| 1164 var synonyms = { | |
| 1165 'nb': 'no', | |
| 1166 'he': 'iw', | |
| 1167 'jv': 'jw', | |
| 1168 'fil': 'tl', | |
| 1169 }; | |
| 1170 | |
| 1171 if (main in synonyms) { | |
| 1172 return synonyms[main]; | |
| 1173 } else if (main == 'zh') { | |
| 1174 // In Translation, general Chinese is not used. | |
| 1175 assert(dialect); | |
| 1176 return languageCode; | |
| 1177 } | |
| 1178 | |
| 1179 return main; | |
| 1180 }, | |
| 1181 | |
| 1182 /* | |
| 1183 * Checks whether or not |languageCode| is supported for Translation. | |
| 1184 * @param {string} languageCode The language code like 'fr'. | |
| 1185 * @return {boolean} Retruns true if |languageCode| is supported for | |
| 1186 * Translation. | |
| 1187 * @private | |
| 1188 */ | |
| 1189 isTranslatableLanguage_: function(languageCode) { | |
| 1190 if (languageCode == 'zh') | |
| 1191 return false; | |
| 1192 | |
| 1193 return true; | |
| 1194 }, | |
| 1063 }; | 1195 }; |
| 1064 | 1196 |
| 1065 /** | 1197 /** |
| 1066 * Shows the node at |index| in |nodes|, hides all others. | 1198 * Shows the node at |index| in |nodes|, hides all others. |
| 1067 * @param {Array<HTMLElement>} nodes The nodes to be shown or hidden. | 1199 * @param {Array<HTMLElement>} nodes The nodes to be shown or hidden. |
| 1068 * @param {number} index The index of |nodes| to show. | 1200 * @param {number} index The index of |nodes| to show. |
| 1069 */ | 1201 */ |
| 1070 function showMutuallyExclusiveNodes(nodes, index) { | 1202 function showMutuallyExclusiveNodes(nodes, index) { |
| 1071 assert(index >= 0 && index < nodes.length); | 1203 assert(index >= 0 && index < nodes.length); |
| 1072 for (var i = 0; i < nodes.length; ++i) { | 1204 for (var i = 0; i < nodes.length; ++i) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1114 | 1246 |
| 1115 LanguageOptions.onComponentManagerInitialized = function(componentImes) { | 1247 LanguageOptions.onComponentManagerInitialized = function(componentImes) { |
| 1116 LanguageOptions.getInstance().appendComponentExtensionIme_(componentImes); | 1248 LanguageOptions.getInstance().appendComponentExtensionIme_(componentImes); |
| 1117 }; | 1249 }; |
| 1118 | 1250 |
| 1119 // Export | 1251 // Export |
| 1120 return { | 1252 return { |
| 1121 LanguageOptions: LanguageOptions | 1253 LanguageOptions: LanguageOptions |
| 1122 }; | 1254 }; |
| 1123 }); | 1255 }); |
| OLD | NEW |