Index: chrome/browser/resources/options/language_options.js |
diff --git a/chrome/browser/resources/options/language_options.js b/chrome/browser/resources/options/language_options.js |
index 9ab66bf8d28c61ad51d22c6668bfd9241de5b865..a00d17e46ab8e7958ebbf63dd3a6a88dfd06634b 100644 |
--- a/chrome/browser/resources/options/language_options.js |
+++ b/chrome/browser/resources/options/language_options.js |
@@ -23,46 +23,47 @@ cr.define('options', function() { |
/** |
* The preference is a boolean that enables/disables spell checking. |
- * @type {string} |
- * @const |
+ * @const {string} |
*/ |
var ENABLE_SPELL_CHECK_PREF = 'browser.enable_spellchecking'; |
/** |
* The preference is a CSV string that describes preload engines |
* (i.e. active input methods). |
- * @type {string} |
- * @const |
+ * @const {string} |
*/ |
var PRELOAD_ENGINES_PREF = 'settings.language.preload_engines'; |
/** |
* The preference that lists the extension IMEs that are enabled in the |
* language menu. |
- * @type {string} |
- * @const |
+ * @const {string} |
*/ |
var ENABLED_EXTENSION_IME_PREF = 'settings.language.enabled_extension_imes'; |
/** |
* The preference that lists the languages which are not translated. |
- * @type {string} |
- * @const |
+ * @const {string} |
*/ |
var TRANSLATE_BLOCKED_LANGUAGES_PREF = 'translate_blocked_languages'; |
/** |
* The preference key that is a string that describes the spell check |
* dictionary language, like "en-US". |
- * @type {string} |
- * @const |
+ * @const {string} |
*/ |
var SPELL_CHECK_DICTIONARY_PREF = 'spellcheck.dictionary'; |
/** |
+ * The preference key that describes the spell check dictionary languages |
+ * currently selected (as a comma separated string, like "en-US,sl-SI"). |
+ * @const {string} |
+ */ |
+ var SPELL_CHECK_DICTIONARIES_PREF = 'spellcheck.dictionaries'; |
+ |
+ /** |
* The preference that indicates if the Translate feature is enabled. |
- * @type {string} |
- * @const |
+ * @const {string} |
*/ |
var ENABLE_TRANSLATE = 'translate.enabled'; |
@@ -141,7 +142,15 @@ cr.define('options', function() { |
* @type {string} |
* @private |
*/ |
- spellCheckDictionary_: '', |
+ spellCheckLanguage_: '', |
+ |
+ /** |
+ * The dictionary of currently selected spell check dictionary languages, |
+ * like {"en-US": true, "sl-SI": true}. |
+ * @type {Object} |
+ * @private |
+ */ |
+ spellCheckLanguages_: {}, |
/** |
* The map of language code to input method IDs, like: |
@@ -187,8 +196,16 @@ cr.define('options', function() { |
Preferences.getInstance().addEventListener( |
TRANSLATE_BLOCKED_LANGUAGES_PREF, |
this.handleTranslateBlockedLanguagesPrefChange_.bind(this)); |
- Preferences.getInstance().addEventListener(SPELL_CHECK_DICTIONARY_PREF, |
+ |
+ if (loadTimeData.getBoolean('enableMultilingualSpellChecker')) { |
+ Preferences.getInstance().addEventListener( |
+ SPELL_CHECK_DICTIONARIES_PREF, |
+ this.handleSpellCheckDictionariesPrefChange_.bind(this)); |
+ } else { |
+ Preferences.getInstance().addEventListener(SPELL_CHECK_DICTIONARY_PREF, |
this.handleSpellCheckDictionaryPrefChange_.bind(this)); |
+ } |
+ |
Preferences.getInstance().addEventListener(ENABLE_TRANSLATE, |
this.handleEnableTranslatePrefChange_.bind(this)); |
this.translateSupportedLanguages_ = |
@@ -240,11 +257,19 @@ cr.define('options', function() { |
// Handle clicks on "Use this language for spell checking" button. |
if (!cr.isMac) { |
- var spellCheckLanguageButton = getRequiredElement( |
- 'language-options-spell-check-language-button'); |
- spellCheckLanguageButton.addEventListener( |
- 'click', |
- this.handleSpellCheckLanguageButtonClick_.bind(this)); |
+ if (loadTimeData.getBoolean('enableMultilingualSpellChecker')) { |
+ var spellCheckLanguageCheckbox = getRequiredElement( |
+ 'spellcheck-language-checkbox'); |
+ spellCheckLanguageCheckbox.addEventListener( |
+ 'change', |
+ this.handleSpellCheckLanguageCheckboxClick_.bind(this)); |
+ } else { |
+ var spellCheckLanguageButton = getRequiredElement( |
+ 'spellcheck-language-button'); |
+ spellCheckLanguageButton.addEventListener( |
+ 'click', |
+ this.handleSpellCheckLanguageButtonClick_.bind(this)); |
+ } |
} |
if (cr.isChromeOS) { |
@@ -427,7 +452,7 @@ cr.define('options', function() { |
this.updateSelectedLanguageName_(languageCode); |
if (!cr.isMac) |
- this.updateSpellCheckLanguageButton_(languageCode); |
+ this.updateSpellCheckLanguageControls_(languageCode); |
if (cr.isChromeOS) |
this.updateInputMethodList_(languageCode); |
@@ -604,56 +629,69 @@ cr.define('options', function() { |
* @param {string} languageCode Language code (ex. "fr"). |
* @private |
*/ |
- updateSpellCheckLanguageButton_: function(languageCode) { |
+ updateSpellCheckLanguageControls_: function(languageCode) { |
var spellCheckLanguageSection = $('language-options-spellcheck'); |
var spellCheckLanguageButton = |
- $('language-options-spell-check-language-button'); |
+ $('spellcheck-language-button'); |
+ var spellCheckLanguageCheckboxDiv = |
+ $('spellcheck-language-checkbox-container'); |
+ var spellCheckLanguageCheckbox = |
+ $('spellcheck-language-checkbox'); |
var spellCheckLanguageMessage = |
- $('language-options-spell-check-language-message'); |
+ $('spellcheck-language-message'); |
var dictionaryDownloadInProgress = |
$('language-options-dictionary-downloading-message'); |
var dictionaryDownloadFailed = |
$('language-options-dictionary-download-failed-message'); |
var dictionaryDownloadFailHelp = |
$('language-options-dictionary-download-fail-help-message'); |
+ |
spellCheckLanguageSection.hidden = false; |
spellCheckLanguageMessage.hidden = true; |
spellCheckLanguageButton.hidden = true; |
+ spellCheckLanguageCheckboxDiv.hidden = true; |
dictionaryDownloadInProgress.hidden = true; |
dictionaryDownloadFailed.hidden = true; |
dictionaryDownloadFailHelp.hidden = true; |
+ spellCheckLanguageCheckbox.checked = false; |
- if (languageCode == this.spellCheckDictionary_) { |
- if (!(languageCode in this.spellcheckDictionaryDownloadStatus_)) { |
- spellCheckLanguageMessage.textContent = |
- loadTimeData.getString('isUsedForSpellChecking'); |
- showMutuallyExclusiveNodes( |
- [spellCheckLanguageButton, spellCheckLanguageMessage], 1); |
- } else if (this.spellcheckDictionaryDownloadStatus_[languageCode] == |
- DOWNLOAD_STATUS.IN_PROGRESS) { |
- dictionaryDownloadInProgress.hidden = false; |
- } else if (this.spellcheckDictionaryDownloadStatus_[languageCode] == |
- DOWNLOAD_STATUS.FAILED) { |
- spellCheckLanguageSection.hidden = true; |
- dictionaryDownloadFailed.hidden = false; |
- if (this.spellcheckDictionaryDownloadFailures_ > 1) |
- dictionaryDownloadFailHelp.hidden = false; |
+ if (!languageCode) |
+ return; |
+ |
+ if (languageCode in loadTimeData.getValue('spellCheckLanguageCodeSet')) { |
+ if (loadTimeData.getBoolean('enableMultilingualSpellChecker')) { |
+ spellCheckLanguageCheckbox.languageCode = languageCode; |
+ spellCheckLanguageCheckbox.checked = |
+ this.spellCheckLanguages_.hasOwnProperty(languageCode); |
+ spellCheckLanguageCheckboxDiv.hidden = false; |
+ } else if (languageCode == this.spellCheckLanguage_) { |
+ if (!(languageCode in this.spellcheckDictionaryDownloadStatus_)) { |
+ spellCheckLanguageMessage.textContent = |
+ loadTimeData.getString('isUsedForSpellChecking'); |
+ spellCheckLanguageMessage.hidden = false; |
+ } |
+ } else { |
+ spellCheckLanguageButton.textContent = |
+ loadTimeData.getString('useThisForSpellChecking'); |
+ spellCheckLanguageButton.hidden = false; |
+ spellCheckLanguageButton.languageCode = languageCode; |
+ } |
+ |
+ switch (this.spellcheckDictionaryDownloadStatus_[languageCode]) { |
+ case DOWNLOAD_STATUS.IN_PROGRESS: |
+ dictionaryDownloadInProgress.hidden = false; |
+ break; |
+ case DOWNLOAD_STATUS.FAILED: |
+ showMutuallyExclusiveNodes( |
+ [spellCheckLanguageSection, dictionaryDownloadFailed], 1); |
+ if (this.spellcheckDictionaryDownloadFailures_ > 1) |
+ dictionaryDownloadFailHelp.hidden = false; |
+ break; |
} |
- } else if (languageCode in |
- loadTimeData.getValue('spellCheckLanguageCodeSet')) { |
- spellCheckLanguageButton.textContent = |
- loadTimeData.getString('useThisForSpellChecking'); |
- showMutuallyExclusiveNodes( |
- [spellCheckLanguageButton, spellCheckLanguageMessage], 0); |
- spellCheckLanguageButton.languageCode = languageCode; |
- } else if (!languageCode) { |
- spellCheckLanguageButton.hidden = true; |
- spellCheckLanguageMessage.hidden = true; |
} else { |
spellCheckLanguageMessage.textContent = |
loadTimeData.getString('cannotBeUsedForSpellChecking'); |
- showMutuallyExclusiveNodes( |
- [spellCheckLanguageButton, spellCheckLanguageMessage], 1); |
+ spellCheckLanguageMessage.hidden = false; |
} |
}, |
@@ -919,8 +957,8 @@ cr.define('options', function() { |
* @private |
*/ |
updateEnableSpellCheck_: function(e) { |
- var value = !$('enable-spell-check').checked; |
- $('language-options-spell-check-language-button').disabled = value; |
+ var value = !$('enable-spellcheck').checked; |
+ $('spellcheck-language-button').disabled = value; |
if (!cr.isMac) |
$('edit-dictionary-button').hidden = value; |
}, |
@@ -942,15 +980,34 @@ cr.define('options', function() { |
* @private |
*/ |
handleSpellCheckDictionaryPrefChange_: function(e) { |
- var languageCode = e.value.value; |
- this.spellCheckDictionary_ = languageCode; |
+ this.spellCheckLanguage_ = e.value.value; |
if (!cr.isMac) { |
- this.updateSpellCheckLanguageButton_( |
+ this.updateSpellCheckLanguageControls_( |
$('language-options-list').getSelectedLanguageCode()); |
} |
}, |
/** |
+ * Updates spellcheck dictionary UI (checkboxes, buttons, and labels) when |
+ * preferences change. |
+ * @param {Event} e Preference change event where e.value.value is the |
+ * comma separated list of languages currently used for spellchecking. |
+ * @private |
+ */ |
+ handleSpellCheckDictionariesPrefChange_: function(e) { |
+ assert(!cr.isMac); |
+ |
+ var languageCodesSplit = e.value.value.split(','); |
+ |
+ this.spellCheckLanguages_ = {}; |
+ for (var i = 0; i < languageCodesSplit.length; i++) |
+ this.spellCheckLanguages_[languageCodesSplit[i]] = true; |
+ |
+ this.updateSpellCheckLanguageControls_( |
+ $('language-options-list').getSelectedLanguageCode()); |
+ }, |
+ |
+ /** |
* Handles translate.enabled change. |
* @param {Event} e Change event. |
* @private |
@@ -978,6 +1035,26 @@ cr.define('options', function() { |
}, |
/** |
+ * Updates the spellcheck.dictionaries preference with the currently |
+ * selected language codes. |
+ * @param {Event} e Click event. e.target represents the "Use this language |
+ * for spellchecking" |
+ * @private |
+ */ |
+ handleSpellCheckLanguageCheckboxClick_: function(e) { |
+ var languageCode = e.target.languageCode; |
+ |
+ if (e.target.checked) |
+ this.spellCheckLanguages_[languageCode] = true; |
+ else |
+ delete this.spellCheckLanguages_[languageCode]; |
+ |
+ var languageCodes = Object.keys(this.spellCheckLanguages_); |
+ Preferences.setStringPref(SPELL_CHECK_DICTIONARIES_PREF, |
+ languageCodes.join(','), true); |
+ }, |
+ |
+ /** |
* Checks whether it's possible to remove the language specified by |
* languageCode and returns true if possible. This function returns false |
* if the removal causes the number of preload engines to be zero. |
@@ -1276,7 +1353,7 @@ cr.define('options', function() { |
if (!cr.isMac && |
languageCode == |
$('language-options-list').getSelectedLanguageCode()) { |
- this.updateSpellCheckLanguageButton_(languageCode); |
+ this.updateSpellCheckLanguageControls_(languageCode); |
} |
}, |
@@ -1292,7 +1369,7 @@ cr.define('options', function() { |
if (!cr.isMac && |
languageCode == |
$('language-options-list').getSelectedLanguageCode()) { |
- this.updateSpellCheckLanguageButton_(languageCode); |
+ this.updateSpellCheckLanguageControls_(languageCode); |
} |
}, |
@@ -1309,7 +1386,7 @@ cr.define('options', function() { |
if (!cr.isMac && |
languageCode == |
$('language-options-list').getSelectedLanguageCode()) { |
- this.updateSpellCheckLanguageButton_(languageCode); |
+ this.updateSpellCheckLanguageControls_(languageCode); |
} |
}, |
@@ -1376,6 +1453,10 @@ cr.define('options', function() { |
LanguageOptions.getInstance().onDictionaryDownloadFailure_(languageCode); |
}; |
+ LanguageOptions.updateSpellCheckLanguageControls = function(languageCode) { |
+ LanguageOptions.getInstance().updateSpellCheckLanguageControls_( |
+ languageCode); |
+ }; |
// Export |
return { |
LanguageOptions: LanguageOptions |