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 7956e85ab74770a6306bfd4e1f677eb8de494e52..179b0e5dfe636a4f2c82dac0a4dc96bafebbf408 100644 |
--- a/chrome/browser/resources/options/language_options.js |
+++ b/chrome/browser/resources/options/language_options.js |
@@ -60,6 +60,14 @@ cr.define('options', function() { |
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"). |
+ * @type {string} |
+ * @const |
+ */ |
+ var SPELL_CHECK_DICTIONARIES_PREF = 'spellcheck.dictionaries'; |
+ |
+ /** |
* The preference that indicates if the Translate feature is enabled. |
* @type {string} |
* @const |
@@ -144,6 +152,14 @@ cr.define('options', function() { |
spellCheckDictionary_: '', |
/** |
+ * The list of currently selected spell check dictionary languages, like |
+ * "en-US, sl-SI". |
please use gerrit instead
2015/02/24 23:38:38
Since this is a list of strings instead of a comma
Klemen Forstnerič
2015/02/25 09:48:23
Actually it's a dictionary. I forgot to change the
please use gerrit instead
2015/02/25 18:16:15
I'm not sure why this is a dictionary instead of a
Klemen Forstnerič
2015/02/26 15:37:42
I figured that since we're determining whether som
please use gerrit instead
2015/02/26 16:03:12
Dan, what's the best JS collection data structure
Dan Beam
2015/02/26 18:49:50
yeah, an object (see: hash map) is good for this.
|
+ * @type {array} |
+ * @private |
+ */ |
+ spellCheckDictionaries_: {}, |
+ |
+ /** |
* The map of language code to input method IDs, like: |
* {'ja': ['mozc', 'mozc-jp'], 'zh-CN': ['pinyin'], ...} |
* @type {Object} |
@@ -187,8 +203,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 +264,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( |
+ 'language-options-spell-check-language-checkbox'); |
+ spellCheckLanguageCheckbox.addEventListener( |
+ 'click', |
+ this.handleSpellCheckLanguageCheckboxClick_.bind(this)); |
+ } else { |
+ var spellCheckLanguageButton = getRequiredElement( |
+ 'language-options-spell-check-language-button'); |
+ spellCheckLanguageButton.addEventListener( |
+ 'click', |
+ this.handleSpellCheckLanguageButtonClick_.bind(this)); |
+ } |
} |
if (cr.isChromeOS) { |
@@ -427,7 +459,7 @@ cr.define('options', function() { |
this.updateSelectedLanguageName_(languageCode); |
if (!cr.isMac) |
- this.updateSpellCheckLanguageButton_(languageCode); |
+ this.updateSpellCheckLanguageControls_(languageCode); |
if (cr.isChromeOS) |
this.updateInputMethodList_(languageCode); |
@@ -604,10 +636,14 @@ 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'); |
+ var spellCheckLanguageCheckboxDiv = |
+ $('language-options-spell-check-language-checkbox-div'); |
+ var spellCheckLanguageCheckbox = |
+ $('language-options-spell-check-language-checkbox'); |
var spellCheckLanguageMessage = |
$('language-options-spell-check-language-message'); |
var dictionaryDownloadInProgress = |
@@ -616,44 +652,52 @@ cr.define('options', function() { |
$('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; |
- 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) { |
+ spellCheckLanguageCheckbox.checked = false; |
+ |
+ if (!languageCode) |
+ return; |
+ |
+ if (languageCode in loadTimeData.getValue('spellCheckLanguageCodeSet')) { |
+ if (loadTimeData.getBoolean('enableMultilingualSpellChecker')) { |
+ spellCheckLanguageCheckbox.languageCode = languageCode; |
+ if (languageCode in this.spellCheckDictionaries_) |
+ spellCheckLanguageCheckbox.checked = true; |
please use gerrit instead
2015/02/24 23:38:38
We usually put a newline after an if-statement to
Klemen Forstnerič
2015/02/25 09:48:23
Done.
|
+ spellCheckLanguageCheckboxDiv.hidden = false; |
+ } else if (languageCode == this.spellCheckDictionary_) { |
+ if (!(languageCode in this.spellcheckDictionaryDownloadStatus_)) { |
+ spellCheckLanguageMessage.textContent = |
+ loadTimeData.getString('isUsedForSpellChecking'); |
+ spellCheckLanguageMessage.hidden = false; |
+ } |
+ } else { |
+ spellCheckLanguageButton.textContent = |
+ loadTimeData.getString('useThisForSpellChecking'); |
+ spellCheckLanguageButton.hidden = false; |
+ } |
+ |
+ 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; |
+ showMutuallyExclusiveNodes( |
+ [spellCheckLanguageSection, dictionaryDownloadFailed], 1); |
if (this.spellcheckDictionaryDownloadFailures_ > 1) |
dictionaryDownloadFailHelp.hidden = false; |
} |
- } 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; |
} |
}, |
@@ -945,11 +989,26 @@ cr.define('options', function() { |
var languageCode = e.value.value; |
this.spellCheckDictionary_ = languageCode; |
if (!cr.isMac) { |
- this.updateSpellCheckLanguageButton_( |
+ this.updateSpellCheckLanguageControls_( |
$('language-options-list').getSelectedLanguageCode()); |
} |
}, |
+ handleSpellCheckDictionariesPrefChange_: function(e) { |
please use gerrit instead
2015/02/24 23:38:38
Add a comment please.
Klemen Forstnerič
2015/02/25 09:48:23
Done.
|
+ if (cr.isMac) |
+ return; |
+ |
+ var commaSeparatedLanguageCodes = e.value.value; |
+ var languageCodesSplit = commaSeparatedLanguageCodes.split(','); |
+ |
+ this.spellCheckDictionaries_ = {}; |
+ for (var i = 0; i < languageCodesSplit.length; i++) |
+ this.spellCheckDictionaries_[languageCodesSplit[i]] = true; |
+ |
+ this.updateSpellCheckLanguageControls_( |
+ $('language-options-list').getSelectedLanguageCode()); |
+ }, |
+ |
/** |
* Handles translate.enabled change. |
* @param {Event} e Change event. |
@@ -978,6 +1037,29 @@ cr.define('options', function() { |
}, |
/** |
+ * Handles spellCheckLanguageCheckbox click. |
+ * @param {Event} e Click event. |
+ * @private |
+ */ |
+ handleSpellCheckLanguageCheckboxClick_: function(e) { |
+ var languageCode = e.target.languageCode; |
+ |
+ if (e.target.checked) |
+ this.spellCheckDictionaries_[languageCode] = true; |
+ else |
+ delete this.spellCheckDictionaries_[languageCode]; |
+ |
+ var languageCodes = []; |
+ for (var currentLanguageCode in this.spellCheckDictionaries_) { |
+ if (this.spellCheckDictionaries_.hasOwnProperty(currentLanguageCode)) |
+ languageCodes.push(currentLanguageCode); |
+ } |
+ |
+ 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 +1358,7 @@ cr.define('options', function() { |
if (!cr.isMac && |
languageCode == |
$('language-options-list').getSelectedLanguageCode()) { |
- this.updateSpellCheckLanguageButton_(languageCode); |
+ this.updateSpellCheckLanguageControls_(languageCode); |
} |
}, |
@@ -1292,7 +1374,7 @@ cr.define('options', function() { |
if (!cr.isMac && |
languageCode == |
$('language-options-list').getSelectedLanguageCode()) { |
- this.updateSpellCheckLanguageButton_(languageCode); |
+ this.updateSpellCheckLanguageControls_(languageCode); |
} |
}, |
@@ -1309,7 +1391,7 @@ cr.define('options', function() { |
if (!cr.isMac && |
languageCode == |
$('language-options-list').getSelectedLanguageCode()) { |
- this.updateSpellCheckLanguageButton_(languageCode); |
+ this.updateSpellCheckLanguageControls_(languageCode); |
} |
}, |