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

Unified Diff: chrome/browser/renderer_context_menu/spellchecker_submenu_observer_hunspell.cc

Issue 1156473007: Enables the user to select multiple languages for spellchecking (UI) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replied to comments, added browser tests, rebased. Created 5 years, 6 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/renderer_context_menu/spellchecker_submenu_observer_hunspell.cc
diff --git a/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_hunspell.cc b/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_hunspell.cc
index ca943f5ae914b92be494ac417e92adb9d78627c0..d2e0e063e437a1aa5a931e48b1e6c3663b55431e 100644
--- a/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_hunspell.cc
+++ b/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_hunspell.cc
@@ -4,16 +4,21 @@
#include "chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h"
+#include <algorithm>
+
#include "base/command_line.h"
#include "base/logging.h"
#include "base/prefs/pref_member.h"
#include "base/prefs/pref_service.h"
+#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
#include "chrome/browser/spellchecker/spellcheck_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
+#include "chrome/common/spellcheck_common.h"
#include "chrome/common/spellcheck_messages.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/render_view_host.h"
@@ -30,8 +35,7 @@ SpellCheckerSubMenuObserver::SpellCheckerSubMenuObserver(
int group)
: proxy_(proxy),
submenu_model_(delegate),
- language_group_(group),
- language_selected_(0) {
please use gerrit instead 2015/06/04 19:41:05 Don't remove initialization of a member variable.
Julius 2015/06/05 03:41:12 Done.
+ language_group_(group) {
DCHECK(proxy_);
}
@@ -45,17 +49,24 @@ void SpellCheckerSubMenuObserver::InitMenu(
// Add available spell-checker languages to the sub menu.
content::BrowserContext* browser_context = proxy_->GetBrowserContext();
DCHECK(browser_context);
- language_selected_ =
+ selected_languages_ =
SpellcheckService::GetSpellCheckLanguages(browser_context, &languages_);
DCHECK(languages_.size() <
IDC_SPELLCHECK_LANGUAGES_LAST - IDC_SPELLCHECK_LANGUAGES_FIRST);
const std::string app_locale = g_browser_process->GetApplicationLocale();
+ const base::CommandLine* command_line =
+ base::CommandLine::ForCurrentProcess();
+
for (size_t i = 0; i < languages_.size(); ++i) {
base::string16 display_name(
l10n_util::GetDisplayNameForLocale(languages_[i], app_locale, true));
- submenu_model_.AddRadioItem(IDC_SPELLCHECK_LANGUAGES_FIRST + i,
- display_name,
- language_group_);
+ if (command_line->HasSwitch(switches::kEnableMultilingualSpellChecker)) {
please use gerrit instead 2015/06/04 19:41:05 Please put "command_line->HasSwitch(switches::kEna
Julius 2015/06/05 03:41:12 Done.
+ submenu_model_.AddCheckItem(
+ IDC_SPELLCHECK_LANGUAGES_FIRST + i, display_name);
+ } else {
+ submenu_model_.AddRadioItem(
+ IDC_SPELLCHECK_LANGUAGES_FIRST + i, display_name, language_group_);
+ }
}
// Add an item that opens the 'fonts and languages options' page.
@@ -77,8 +88,6 @@ void SpellCheckerSubMenuObserver::InitMenu(
l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE));
// Add a check item "Automatically correct spelling".
- const base::CommandLine* command_line =
- base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kEnableSpellingAutoCorrect)) {
submenu_model_.AddCheckItem(IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE,
l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_AUTOCORRECT));
@@ -117,7 +126,7 @@ bool SpellCheckerSubMenuObserver::IsCommandIdChecked(int command_id) {
if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
- return language_selected_ == command_id - IDC_SPELLCHECK_LANGUAGES_FIRST;
+ return selected_languages_ > command_id - IDC_SPELLCHECK_LANGUAGES_FIRST;
}
// Check box for 'Check Spelling while typing'.
@@ -157,14 +166,33 @@ void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) {
// Check to see if one of the spell check language ids have been clicked.
Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext());
DCHECK(profile);
+
if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST &&
command_id < IDC_SPELLCHECK_LANGUAGES_LAST) {
- const size_t language = command_id - IDC_SPELLCHECK_LANGUAGES_FIRST;
- if (profile && language < languages_.size()) {
- StringPrefMember dictionary_language;
- dictionary_language.Init(prefs::kSpellCheckDictionary,
- profile->GetPrefs());
- dictionary_language.SetValue(languages_[language]);
+ PrefService* prefs = profile->GetPrefs();
+ size_t language = command_id - IDC_SPELLCHECK_LANGUAGES_FIRST;
+ DCHECK_LT(language, languages_.size());
+
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableMultilingualSpellChecker)) {
+ std::vector<std::string> dictionary_languages =
+ chrome::spellcheck_common::GetDictionaryLanguagesPref(prefs);
+
+ auto found_language =
+ std::find(dictionary_languages.begin(), dictionary_languages.end(),
+ languages_[language]);
+
+ if (found_language != dictionary_languages.end())
+ dictionary_languages.erase(found_language);
+ else
+ dictionary_languages.push_back(languages_[language]);
+
+ prefs->SetString(
+ prefs::kSpellCheckDictionaries,
+ JoinString(dictionary_languages,
+ chrome::spellcheck_common::kDictionaryLanguagesSeparator));
+ } else {
+ prefs->SetString(prefs::kSpellCheckDictionary, languages_[language]);
}
return;
}

Powered by Google App Engine
This is Rietveld 408576698