summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-03 20:20:58 +0000
committersidchat@google.com <sidchat@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-03 20:20:58 +0000
commit154a4338764560595dd49305a2343985f728c935 (patch)
tree4ba37d24a2f4980c27145af7c46cd5fdcf1f49a9 /chrome
parent7822e018e5ebabeeb3e8ff46aa67a52b1b1c1cf8 (diff)
downloadchromium_src-154a4338764560595dd49305a2343985f728c935.zip
chromium_src-154a4338764560595dd49305a2343985f728c935.tar.gz
chromium_src-154a4338764560595dd49305a2343985f728c935.tar.bz2
UI Support for Auto Spell Correct. Currently, it is still under the command line flag --auto-spell-correct, which means that this UI support will appear only when the command line flag is enabled.BUG=www.crbug.com/13102TEST=enable this feature through the command line flag --auto-spell-correct and then use the Languages Options menu check box to toggle this feature on/off - test by typing "teh" in a text box.
Review URL: http://codereview.chromium.org/119002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17528 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/generated_resources.grd3
-rw-r--r--chrome/browser/profile.cc12
-rw-r--r--chrome/browser/spellcheck_unittest.cc1
-rw-r--r--chrome/browser/spellchecker.cc10
-rw-r--r--chrome/browser/spellchecker.h7
-rw-r--r--chrome/browser/views/options/languages_page_view.cc33
-rw-r--r--chrome/browser/views/options/languages_page_view.h5
-rw-r--r--chrome/common/pref_names.cc3
-rw-r--r--chrome/common/pref_names.h1
9 files changed, 72 insertions, 3 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 02e753b..e18a890 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -3666,6 +3666,9 @@ each locale. -->
<message name="IDS_OPTIONS_ENABLE_SPELLCHECK" desc="The documentation string of the 'Enable spellcheck' option">
Check spelling:
</message>
+ <message name="IDS_OPTIONS_ENABLE_AUTO_SPELL_CORRECTION" desc="The documentation string of the 'Enable auto spell correction' option">
+ Correct spelling automatically:
+ </message>
<message name="IDS_OPTIONS_RESET" desc="The label of the 'Reset all settings to defaults' button">
Reset to defaults
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index c859c02..513eb28 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -70,6 +70,7 @@ void Profile::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterLocalizedStringPref(prefs::kSpellCheckDictionary,
IDS_SPELLCHECK_DICTIONARY);
prefs->RegisterBooleanPref(prefs::kEnableSpellCheck, true);
+ prefs->RegisterBooleanPref(prefs::kEnableAutoSpellCorrect, true);
prefs->RegisterBooleanPref(prefs::kEnableUserScripts, false);
prefs->RegisterStringPref(prefs::kCurrentThemeID, L"");
prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
@@ -406,6 +407,7 @@ ProfileImpl::ProfileImpl(const FilePath& path)
PrefService* prefs = GetPrefs();
prefs->AddPrefObserver(prefs::kSpellCheckDictionary, this);
prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
+ prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
#ifdef CHROME_PERSONALIZATION
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableP13n))
@@ -477,6 +479,7 @@ ProfileImpl::~ProfileImpl() {
PrefService* prefs = GetPrefs();
prefs->RemovePrefObserver(prefs::kSpellCheckDictionary, this);
prefs->RemovePrefObserver(prefs::kEnableSpellCheck, this);
+ prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
#ifdef CHROME_PERSONALIZATION
personalization_.reset();
@@ -924,6 +927,12 @@ void ProfileImpl::InitializeSpellChecker(bool need_to_broadcast) {
spellchecker_ = NULL;
}
+ // Set auto spell correct status for spellchecker.
+ if (spellchecker_) {
+ spellchecker_->EnableAutoSpellCorrect(
+ prefs->GetBoolean(prefs::kEnableAutoSpellCorrect));
+ }
+
if (need_to_broadcast && io_thread) { // Notify resource message filters.
SpellcheckerReinitializedDetails scoped_spellchecker;
scoped_spellchecker.spellchecker = spellchecker_;
@@ -971,7 +980,8 @@ void ProfileImpl::Observe(NotificationType type,
PrefService* prefs = Source<PrefService>(source).ptr();
DCHECK(pref_name_in && prefs);
if (*pref_name_in == prefs::kSpellCheckDictionary ||
- *pref_name_in == prefs::kEnableSpellCheck) {
+ *pref_name_in == prefs::kEnableSpellCheck ||
+ *pref_name_in == prefs::kEnableAutoSpellCorrect) {
InitializeSpellChecker(true);
}
} else if (NotificationType::THEME_INSTALLED == type) {
diff --git a/chrome/browser/spellcheck_unittest.cc b/chrome/browser/spellcheck_unittest.cc
index aa76bf0..47b608f 100644
--- a/chrome/browser/spellcheck_unittest.cc
+++ b/chrome/browser/spellcheck_unittest.cc
@@ -517,6 +517,7 @@ TEST_F(SpellCheckTest, GetAutoCorrectionWord_EN_US) {
scoped_refptr<SpellChecker> spell_checker(new SpellChecker(
hunspell_directory, "en-US", NULL, FilePath()));
+ spell_checker->EnableAutoSpellCorrect(true);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
std::wstring misspelled_word(kTestCases[i].input);
diff --git a/chrome/browser/spellchecker.cc b/chrome/browser/spellchecker.cc
index 68643b5..2a8053d 100644
--- a/chrome/browser/spellchecker.cc
+++ b/chrome/browser/spellchecker.cc
@@ -392,6 +392,7 @@ SpellChecker::SpellChecker(const FilePath& dict_dir,
file_loop_(NULL),
url_request_context_(request_context),
dic_is_downloading_(false),
+ auto_spell_correct_turned_on_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(
dic_download_state_changer_factory_(this)) {
// Remember UI loop to later use this as a proxy to get IO loop.
@@ -414,7 +415,7 @@ SpellChecker::SpellChecker(const FilePath& dict_dir,
}
// Use this dictionary language as the default one of the
- // SpecllcheckCharAttribute object.
+ // SpellcheckCharAttribute object.
character_attributes_.SetDefaultLanguage(language);
}
@@ -479,6 +480,9 @@ bool SpellChecker::Initialize() {
void SpellChecker::GetAutoCorrectionWord(const std::wstring& word,
std::wstring* autocorrect_word) {
autocorrect_word->clear();
+ if (!auto_spell_correct_turned_on_)
+ return;
+
int word_length = static_cast<int>(word.size());
if (word_length < 2 || word_length > kMaxAutoCorrectWordSize)
return;
@@ -519,6 +523,10 @@ void SpellChecker::GetAutoCorrectionWord(const std::wstring& word,
}
}
+void SpellChecker::EnableAutoSpellCorrect(bool turn_on) {
+ auto_spell_correct_turned_on_ = turn_on;
+}
+
void SpellChecker::AddCustomWordsToHunspell() {
// Add custom words to Hunspell.
// This should be done in File Loop, but since Hunspell is in this IO Loop,
diff --git a/chrome/browser/spellchecker.h b/chrome/browser/spellchecker.h
index 0c0b535..a9c2946 100644
--- a/chrome/browser/spellchecker.h
+++ b/chrome/browser/spellchecker.h
@@ -81,6 +81,10 @@ class SpellChecker : public base::RefCountedThreadSafe<SpellChecker> {
void GetAutoCorrectionWord(const std::wstring& word,
std::wstring* autocorrect_word);
+ // Turn auto spell correct support ON or OFF.
+ // |turn_on| = true means turn ON; false means turn OFF.
+ void EnableAutoSpellCorrect(bool turn_on);
+
// Add custom word to the dictionary, which means:
// a) Add it to the current hunspell object for immediate use,
// b) Add the word to a file in disk for custom dictionary.
@@ -184,6 +188,9 @@ class SpellChecker : public base::RefCountedThreadSafe<SpellChecker> {
// Set when the dictionary file is currently downloading.
bool dic_is_downloading_;
+ // Remember state for auto spell correct.
+ bool auto_spell_correct_turned_on_;
+
// Used for generating callbacks to spellchecker, since spellchecker is a
// non-reference counted object. The callback is generated by generating tasks
// using NewRunableMethod on these objects.
diff --git a/chrome/browser/views/options/languages_page_view.cc b/chrome/browser/views/options/languages_page_view.cc
index 400cb16..d402b8e 100644
--- a/chrome/browser/views/options/languages_page_view.cc
+++ b/chrome/browser/views/options/languages_page_view.cc
@@ -12,6 +12,7 @@
#include "app/gfx/font.h"
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
+#include "base/command_line.h"
#include "base/file_util.h"
#include "base/string_util.h"
#include "base/gfx/native_theme.h"
@@ -21,6 +22,7 @@
#include "chrome/browser/spellchecker.h"
#include "chrome/browser/views/options/language_combobox_model.h"
#include "chrome/browser/views/restart_message_box.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
#include "grit/chromium_strings.h"
@@ -477,11 +479,13 @@ LanguagesPageView::LanguagesPageView(Profile* profile)
change_ui_language_combobox_(NULL),
change_dictionary_language_combobox_(NULL),
enable_spellchecking_checkbox_(NULL),
+ enable_autospellcorrect_checkbox_(NULL),
dictionary_language_label_(NULL),
OptionsPageView(profile),
language_table_edited_(false),
language_warning_shown_(false),
enable_spellcheck_checkbox_clicked_(false),
+ enable_autospellcorrect_checkbox_clicked_(false),
spellcheck_language_index_selected_(-1),
ui_language_index_selected_(-1),
starting_ui_language_index_(-1) {
@@ -489,6 +493,8 @@ LanguagesPageView::LanguagesPageView(Profile* profile)
profile->GetPrefs(), NULL);
enable_spellcheck_.Init(prefs::kEnableSpellCheck,
profile->GetPrefs(), NULL);
+ enable_autospellcorrect_.Init(prefs::kEnableAutoSpellCorrect,
+ profile->GetPrefs(), NULL);
}
LanguagesPageView::~LanguagesPageView() {
@@ -513,7 +519,9 @@ void LanguagesPageView::ButtonPressed(views::Button* sender) {
new AddLanguageWindowView(this, profile()))->Show();
language_table_edited_ = true;
} else if (sender == enable_spellchecking_checkbox_) {
- enable_spellcheck_checkbox_clicked_ = true;
+ enable_spellcheck_checkbox_clicked_ = true;
+ } else if (sender == enable_autospellcorrect_checkbox_) {
+ enable_autospellcorrect_checkbox_clicked_ = true;
}
}
@@ -626,6 +634,12 @@ void LanguagesPageView::InitControlLayout() {
views::Label::ALIGN_LEFT);
enable_spellchecking_checkbox_ = new views::Checkbox(
l10n_util::GetString(IDS_OPTIONS_ENABLE_SPELLCHECK));
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ if (command_line.HasSwitch(switches::kAutoSpellCorrect)) {
+ enable_autospellcorrect_checkbox_ = new views::Checkbox(
+ l10n_util::GetString(IDS_OPTIONS_ENABLE_AUTO_SPELL_CORRECTION));
+ enable_autospellcorrect_checkbox_->set_listener(this);
+ }
enable_spellchecking_checkbox_->set_listener(this);
enable_spellchecking_checkbox_->SetMultiLine(true);
@@ -642,6 +656,11 @@ void LanguagesPageView::InitControlLayout() {
layout->StartRow(0, single_column_view_set_id);
layout->AddView(enable_spellchecking_checkbox_);
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
+ if (command_line.HasSwitch(switches::kAutoSpellCorrect)) {
+ layout->StartRow(0, single_column_view_set_id);
+ layout->AddView(enable_autospellcorrect_checkbox_);
+ layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
+ }
const int double_column_view_set_2_id = 2;
column_set = layout->AddColumnSet(double_column_view_set_2_id);
column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0,
@@ -727,6 +746,13 @@ void LanguagesPageView::NotifyPrefChanged(const std::wstring* pref_name) {
enable_spellchecking_checkbox_->SetChecked(
enable_spellcheck_.GetValue());
}
+ if (!pref_name || *pref_name == prefs::kEnableAutoSpellCorrect) {
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ if (command_line.HasSwitch(switches::kAutoSpellCorrect)) {
+ enable_autospellcorrect_checkbox_->SetChecked(
+ enable_autospellcorrect_.GetValue());
+ }
+ }
}
void LanguagesPageView::ItemChanged(views::Combobox* sender,
@@ -846,4 +872,9 @@ void LanguagesPageView::SaveChanges() {
if (enable_spellcheck_checkbox_clicked_)
enable_spellcheck_.SetValue(enable_spellchecking_checkbox_->checked());
+
+ if (enable_autospellcorrect_checkbox_clicked_) {
+ enable_autospellcorrect_.SetValue(
+ enable_autospellcorrect_checkbox_->checked());
+ }
}
diff --git a/chrome/browser/views/options/languages_page_view.h b/chrome/browser/views/options/languages_page_view.h
index 3f6522d..168d67e 100644
--- a/chrome/browser/views/options/languages_page_view.h
+++ b/chrome/browser/views/options/languages_page_view.h
@@ -78,6 +78,7 @@ class LanguagesPageView : public OptionsPageView,
views::Label* ui_language_label_;
views::Combobox* change_ui_language_combobox_;
views::Combobox* change_dictionary_language_combobox_;
+ views::Checkbox* enable_autospellcorrect_checkbox_;
views::Checkbox* enable_spellchecking_checkbox_;
views::Label* dictionary_language_label_;
@@ -98,6 +99,9 @@ class LanguagesPageView : public OptionsPageView,
// SpellChecker enable pref.
BooleanPrefMember enable_spellcheck_;
+ // Auto spell correction pref.
+ BooleanPrefMember enable_autospellcorrect_;
+
// This is assigned the new index of spellcheck language if the language
// is changed. Otherwise, it remains -1, and pref members are not updated.
int spellcheck_language_index_selected_;
@@ -106,6 +110,7 @@ class LanguagesPageView : public OptionsPageView,
bool language_table_edited_;
bool language_warning_shown_;
bool enable_spellcheck_checkbox_clicked_;
+ bool enable_autospellcorrect_checkbox_clicked_;
DISALLOW_EVIL_CONSTRUCTORS(LanguagesPageView);
};
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index fd227a8..63bab2b 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -241,6 +241,9 @@ const wchar_t kBookmarkManagerSplitLocation[] =
// Boolean pref to define the default values for using spellchecker.
const wchar_t kEnableSpellCheck[] = L"browser.enable_spellchecking";
+// Boolean pref to define the default values for using auto spell correct.
+const wchar_t kEnableAutoSpellCorrect[] = L"browser.enable_autospellcorrect";
+
// String pref to define the default values for print overlays.
const wchar_t kPrintingPageHeaderLeft[] = L"printing.page.header.left";
const wchar_t kPrintingPageHeaderCenter[] = L"printing.page.header.center";
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 3a12f57..a592f41 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -82,6 +82,7 @@ extern const wchar_t kBookmarkTablePathWidth[];
extern const wchar_t kBookmarkManagerPlacement[];
extern const wchar_t kBookmarkManagerSplitLocation[];
extern const wchar_t kEnableSpellCheck[];
+extern const wchar_t kEnableAutoSpellCorrect[];
extern const wchar_t kDeleteTimePeriod[];
extern const wchar_t kPrintingPageHeaderLeft[];
extern const wchar_t kPrintingPageHeaderCenter[];