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 dafc01e9ee26bd73217c02f3dc87a8bbfc0996ec..955437ce99dec6c5a774ee601f4facc200662c8a 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" |
| @@ -30,8 +32,7 @@ SpellCheckerSubMenuObserver::SpellCheckerSubMenuObserver( |
| int group) |
| : proxy_(proxy), |
| submenu_model_(delegate), |
| - language_group_(group), |
| - language_selected_(0) { |
| + language_group_(group) { |
| DCHECK(proxy_); |
| } |
| @@ -45,17 +46,24 @@ void SpellCheckerSubMenuObserver::InitMenu( |
| // Add available spell-checker languages to the sub menu. |
| content::BrowserContext* browser_context = proxy_->GetBrowserContext(); |
| DCHECK(browser_context); |
| - language_selected_ = |
| + spellcheck_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(); |
| - for (size_t i = 0; i < languages_.size(); ++i) { |
| + const base::CommandLine* command_line = |
| + base::CommandLine::ForCurrentProcess(); |
| + |
| + for (std::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)) { |
| + 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 +85,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 +123,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 spellcheck_languages_.count(command_id - |
|
please use gerrit instead
2015/02/23 18:51:47
Please use "spellcheck_languages_.find(command_id
Klemen Forstnerič
2015/02/24 21:57:45
Done.
|
| + IDC_SPELLCHECK_LANGUAGES_FIRST) == 1; |
| } |
| // Check box for 'Check Spelling while typing'. |
| @@ -157,23 +164,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) { |
| - 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]); |
| - } |
| - return; |
| - } |
| - switch (command_id) { |
|
please use gerrit instead
2015/02/23 18:51:47
No need to change this code. Please change it back
Klemen Forstnerič
2015/02/24 21:57:45
Done.
|
| - case IDC_CHECK_SPELLING_WHILE_TYPING: |
| - profile->GetPrefs()->SetBoolean( |
| - prefs::kEnableContinuousSpellcheck, |
| - !profile->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck)); |
| - break; |
| + 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 std::size_t language = command_id - IDC_SPELLCHECK_LANGUAGES_FIRST; |
|
please use gerrit instead
2015/02/23 18:51:47
size_t should be OK. No need to change it to std::
Klemen Forstnerič
2015/02/24 21:57:45
Done.
|
| + |
| + if (language >= languages_.size()) |
|
please use gerrit instead
2015/02/23 18:51:47
This should never happen. Put a DCHECK here:
DCHE
Klemen Forstnerič
2015/02/24 21:57:45
Done.
|
| + return; |
| + |
| + const base::CommandLine* command_line = |
| + base::CommandLine::ForCurrentProcess(); |
| + if (command_line->HasSwitch(switches::kEnableMultilingualSpellChecker)) { |
| + std::vector<std::string> languages_split; |
| + base::SplitString(prefs->GetString(prefs::kSpellCheckDictionaries), |
| + ',', |
|
please use gerrit instead
2015/02/23 18:51:47
Put a "static const char kLanguagesSeparator = ','
Klemen Forstnerič
2015/02/24 21:57:45
Done.
|
| + &languages_split); |
| + |
| + auto found_language = std::find(languages_split.begin(), |
|
please use gerrit instead
2015/02/23 18:51:47
#include <algorithm>
Klemen Forstnerič
2015/02/24 21:57:45
Done.
|
| + languages_split.end(), |
| + languages_[language]); |
| + |
| + if (found_language != languages_split.end()) |
| + languages_split.erase(found_language); |
| + else |
| + languages_split.push_back(languages_[language]); |
| + |
| + prefs->SetString(prefs::kSpellCheckDictionaries, |
| + JoinString(languages_split, ',')); |
|
please use gerrit instead
2015/02/23 18:51:47
base::JoinString
Klemen Forstnerič
2015/02/24 21:57:45
JoinString is in the global namespace.
|
| + } else { |
| + prefs->SetString(prefs::kSpellCheckDictionary, languages_[language]); |
|
please use gerrit instead
2015/02/23 18:51:47
Is this equivalent to the original code?
StringPr
Klemen Forstnerič
2015/02/24 21:57:45
Yes, |StringPrefMember::SetValue()| calls |StringP
|
| + } |
| } |
| } |