Chromium Code Reviews| 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 110dd3016ea7a5c95cd5b030d24474fc180cd28f..d4410a4afa27909bd926d7ea6cf23b5645791b00 100644 |
| --- a/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_hunspell.cc |
| +++ b/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_hunspell.cc |
| @@ -8,6 +8,8 @@ |
| #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" |
| @@ -28,10 +30,7 @@ SpellCheckerSubMenuObserver::SpellCheckerSubMenuObserver( |
| RenderViewContextMenuProxy* proxy, |
| ui::SimpleMenuModel::Delegate* delegate, |
| int group) |
| - : proxy_(proxy), |
| - submenu_model_(delegate), |
| - language_group_(group), |
| - language_selected_(0) { |
| + : proxy_(proxy), submenu_model_(delegate), language_group_(group) { |
| DCHECK(proxy_); |
| } |
| @@ -45,24 +44,34 @@ void SpellCheckerSubMenuObserver::InitMenu( |
| // Add available spell-checker languages to the sub menu. |
| content::BrowserContext* browser_context = proxy_->GetBrowserContext(); |
| DCHECK(browser_context); |
| - language_selected_ = |
| + languages_selected_ = |
| 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(); |
| - 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_); |
| + |
| + const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + if (command_line->HasSwitch(switches::kEnableMultilingualSpellChecker)) { |
|
please use gerrit instead
2014/11/07 16:20:08
It's best to put this line into a separate functio
Klemen Forstnerič
2014/11/11 21:52:01
Good idea, I'll do it this way.
|
| + for (size_t i = 0; i < languages_.size(); ++i) { |
| + base::string16 display_name( |
| + l10n_util::GetDisplayNameForLocale(languages_[i], app_locale, true)); |
| + submenu_model_.AddCheckItem(IDC_SPELLCHECK_LANGUAGES_FIRST + i, |
| + display_name); |
| + } |
| + } else { |
| + 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_); |
| + } |
| } |
| // Add an item that opens the 'fonts and languages options' page. |
| submenu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| - submenu_model_.AddItemWithStringId( |
| - IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS, |
| - IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS); |
| + submenu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS, |
| + IDS_CONTENT_CONTEXT_LANGUAGE_SETTINGS); |
| // Add a 'Check spelling while typing' item in the sub menu. |
| submenu_model_.AddCheckItem( |
| @@ -73,13 +82,14 @@ void SpellCheckerSubMenuObserver::InitMenu( |
| // Add a check item "Ask Google for spelling suggestions" item. (This class |
| // does not handle this item because the SpellingMenuObserver class handles it |
| // on behalf of this class.) |
| - submenu_model_.AddCheckItem(IDC_CONTENT_CONTEXT_SPELLING_TOGGLE, |
| + submenu_model_.AddCheckItem( |
| + IDC_CONTENT_CONTEXT_SPELLING_TOGGLE, |
| l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_ASK_GOOGLE)); |
| // Add a check item "Automatically correct spelling". |
| - const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| if (command_line->HasSwitch(switches::kEnableSpellingAutoCorrect)) { |
| - submenu_model_.AddCheckItem(IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE, |
| + submenu_model_.AddCheckItem( |
| + IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE, |
| l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_AUTOCORRECT)); |
| } |
| @@ -116,7 +126,8 @@ 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 languages_selected_.count(command_id - |
| + IDC_SPELLCHECK_LANGUAGES_FIRST) == 1; |
| } |
| // Check box for 'Check Spelling while typing'. |
| @@ -156,23 +167,39 @@ 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) { |
| + |
| + PrefService* prefs = profile->GetPrefs(); |
| + |
| + if (command_id == IDC_CHECK_SPELLING_WHILE_TYPING) { |
| + prefs->SetBoolean(prefs::kEnableContinuousSpellcheck, |
| + !prefs->GetBoolean(prefs::kEnableContinuousSpellcheck)); |
| + } else 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]); |
| + if (!profile || language >= languages_.size()) |
| + return; |
| + |
| + const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + if (command_line->HasSwitch(switches::kEnableMultilingualSpellChecker)) { |
| + std::vector<std::string> languages_separated; |
| + base::SplitString(prefs->GetString(prefs::kSpellCheckDictionaries), |
| + ',', |
| + &languages_separated); |
| + |
| + std::vector<std::string>::iterator language_iter = |
| + std::find(languages_separated.begin(), |
| + languages_separated.end(), |
| + languages_[language]); |
| + |
| + if (language_iter != languages_separated.end()) |
| + languages_separated.erase(language_iter); |
| + else |
| + languages_separated.push_back(languages_[language]); |
| + |
| + prefs->SetString(prefs::kSpellCheckDictionaries, |
| + JoinString(languages_separated, ',')); |
| + } else { |
| + prefs->SetString(prefs::kSpellCheckDictionary, languages_[language]); |
| } |
| - return; |
| - } |
| - |
| - switch (command_id) { |
| - case IDC_CHECK_SPELLING_WHILE_TYPING: |
| - profile->GetPrefs()->SetBoolean( |
| - prefs::kEnableContinuousSpellcheck, |
| - !profile->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck)); |
| - break; |
| } |
| } |