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

Unified Diff: chrome/browser/spellchecker/spellcheck_service.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: Answered comments. Created 5 years, 5 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/spellchecker/spellcheck_service.cc
diff --git a/chrome/browser/spellchecker/spellcheck_service.cc b/chrome/browser/spellchecker/spellcheck_service.cc
index e03289626ee2cb238d3b7094d3ba4d55b9218e6f..e76f495951034885f31365b6c365ff888fdf5f5d 100644
--- a/chrome/browser/spellchecker/spellcheck_service.cc
+++ b/chrome/browser/spellchecker/spellcheck_service.cc
@@ -8,6 +8,7 @@
#include "base/prefs/pref_member.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_split.h"
+#include "base/supports_user_data.h"
#include "base/synchronization/waitable_event.h"
#include "chrome/browser/spellchecker/feedback_sender.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
@@ -42,12 +43,13 @@ SpellcheckService::SpellcheckService(content::BrowserContext* context)
DCHECK_CURRENTLY_ON(BrowserThread::UI);
PrefService* prefs = user_prefs::UserPrefs::Get(context);
pref_change_registrar_.Init(prefs);
-
StringListPrefMember dictionaries_pref;
dictionaries_pref.Init(prefs::kSpellCheckDictionaries, prefs);
+
std::string first_of_dictionaries;
- if (!dictionaries_pref.GetValue().empty())
+ if (!dictionaries_pref.GetValue().empty()) {
first_of_dictionaries = dictionaries_pref.GetValue().front();
+ }
please use gerrit instead 2015/07/07 01:30:40 Unnecessary whitespace and curly changes. Please u
Julius 2015/07/07 22:16:25 Done.
// For preference migration, set the new preference kSpellCheckDictionaries
// to be the same as the old kSpellCheckDictionary.
@@ -78,7 +80,7 @@ SpellcheckService::SpellcheckService(content::BrowserContext* context)
base::Unretained(this)));
pref_change_registrar_.Add(
prefs::kSpellCheckDictionaries,
- base::Bind(&SpellcheckService::OnSpellCheckDictionaryChanged,
+ base::Bind(&SpellcheckService::OnSpellCheckDictionariesChanged,
base::Unretained(this)));
if (!chrome::spellcheck_common::IsMultilingualSpellcheckEnabled()) {
pref_change_registrar_.Add(
@@ -86,12 +88,13 @@ SpellcheckService::SpellcheckService(content::BrowserContext* context)
base::Bind(&SpellcheckService::OnUseSpellingServiceChanged,
base::Unretained(this)));
}
+
pref_change_registrar_.Add(
prefs::kEnableContinuousSpellcheck,
base::Bind(&SpellcheckService::InitForAllRenderers,
base::Unretained(this)));
- OnSpellCheckDictionaryChanged();
+ OnSpellCheckDictionariesChanged();
custom_dictionary_.reset(new SpellcheckCustomDictionary(context_->GetPath()));
custom_dictionary_->AddObserver(this);
@@ -111,32 +114,22 @@ base::WeakPtr<SpellcheckService> SpellcheckService::GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
+#if !defined(OS_MACOSX)
// static
-int SpellcheckService::GetSpellCheckLanguages(
+size_t SpellcheckService::GetSpellCheckLanguages(
base::SupportsUserData* context,
std::vector<std::string>* languages) {
PrefService* prefs = user_prefs::UserPrefs::Get(context);
StringPrefMember accept_languages_pref;
accept_languages_pref.Init(prefs::kAcceptLanguages, prefs);
- std::string dictionary_language;
- prefs->GetList(prefs::kSpellCheckDictionaries)
- ->GetString(0, &dictionary_language);
-
- // Now scan through the list of accept languages, and find possible mappings
- // from this list to the existing list of spell check languages.
std::vector<std::string> accept_languages;
-
-#if defined(OS_MACOSX)
- if (spellcheck_mac::SpellCheckerAvailable())
- spellcheck_mac::GetAvailableLanguages(&accept_languages);
- else
- base::SplitString(accept_languages_pref.GetValue(), ',', &accept_languages);
-#else
base::SplitString(accept_languages_pref.GetValue(), ',', &accept_languages);
-#endif // !OS_MACOSX
- languages->push_back(dictionary_language);
+ StringListPrefMember dictionaries_pref;
+ dictionaries_pref.Init(prefs::kSpellCheckDictionaries, prefs);
+ *languages = dictionaries_pref.GetValue();
+ size_t enabled_spellcheck_languages = languages->size();
for (std::vector<std::string>::const_iterator i = accept_languages.begin();
i != accept_languages.end(); ++i) {
@@ -149,13 +142,9 @@ int SpellcheckService::GetSpellCheckLanguages(
}
}
- for (size_t i = 0; i < languages->size(); ++i) {
- if ((*languages)[i] == dictionary_language)
- return i;
- }
-
- return -1;
+ return enabled_spellcheck_languages;
}
+#endif // !OS_MACOSX
// static
bool SpellcheckService::SignalStatusEvent(
@@ -299,7 +288,7 @@ void SpellcheckService::OnEnableAutoSpellCorrectChanged() {
}
}
-void SpellcheckService::OnSpellCheckDictionaryChanged() {
+void SpellcheckService::OnSpellCheckDictionariesChanged() {
if (hunspell_dictionary_.get())
hunspell_dictionary_->RemoveObserver(this);
PrefService* prefs = user_prefs::UserPrefs::Get(context_);

Powered by Google App Engine
This is Rietveld 408576698