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

Unified Diff: chrome/browser/resources/options/language_options.js

Issue 654653002: Enables the user to select multiple languages for spellchecking (UI) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed a regression. Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
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..0c6127705794a87a6790beb42dd5758426947789 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}
Dan Beam 2015/03/02 22:40:08 nit: @const {string} is shorter (and a newer synta
+ * @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 dictionary of currently selected spell check dictionary languages,
+ * like "{"en-US": true, "sl-SI": true}".
Dan Beam 2015/03/02 22:40:08 nit: remove quotes around the dictionary, e.g.
+ * @type {Object}
+ * @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,54 @@ 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 (this.spellCheckDictionaries_.hasOwnProperty(languageCode))
+ spellCheckLanguageCheckbox.checked = true;
Dan Beam 2015/03/02 22:40:08 nit: spellCheckLanguageCheckbox.checked =
+
+ spellCheckLanguageCheckboxDiv.hidden = false;
+ } else if (languageCode == this.spellCheckDictionary_) {
Dan Beam 2015/03/02 22:40:08 how will a string ever be equal to a dictionary?
+ 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;
+ }
+
Dan Beam 2015/03/02 22:40:08 var status = this.spellcheckDictionaryDownloadStat
+ 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,12 +991,34 @@ cr.define('options', function() {
var languageCode = e.value.value;
this.spellCheckDictionary_ = languageCode;
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) {
+ 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.
* @private
@@ -978,6 +1046,31 @@ 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.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 +1369,7 @@ cr.define('options', function() {
if (!cr.isMac &&
languageCode ==
$('language-options-list').getSelectedLanguageCode()) {
- this.updateSpellCheckLanguageButton_(languageCode);
+ this.updateSpellCheckLanguageControls_(languageCode);
}
},
@@ -1292,7 +1385,7 @@ cr.define('options', function() {
if (!cr.isMac &&
languageCode ==
$('language-options-list').getSelectedLanguageCode()) {
- this.updateSpellCheckLanguageButton_(languageCode);
+ this.updateSpellCheckLanguageControls_(languageCode);
}
},
@@ -1309,7 +1402,7 @@ cr.define('options', function() {
if (!cr.isMac &&
languageCode ==
$('language-options-list').getSelectedLanguageCode()) {
- this.updateSpellCheckLanguageButton_(languageCode);
+ this.updateSpellCheckLanguageControls_(languageCode);
}
},

Powered by Google App Engine
This is Rietveld 408576698