summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/spellchecker
diff options
context:
space:
mode:
authorrouslan@chromium.org <rouslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-20 08:26:46 +0000
committerrouslan@chromium.org <rouslan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-20 08:26:46 +0000
commit6cc4a844cc9caaf721728ba0097cff61bbf7fbeb (patch)
treee9cba89d5d28430f45e8053a274635006503386a /chrome/renderer/spellchecker
parent9687e5ef4025dca16d787afdef2bbda6c07e2272 (diff)
downloadchromium_src-6cc4a844cc9caaf721728ba0097cff61bbf7fbeb.zip
chromium_src-6cc4a844cc9caaf721728ba0097cff61bbf7fbeb.tar.gz
chromium_src-6cc4a844cc9caaf721728ba0097cff61bbf7fbeb.tar.bz2
Enable users to alter their custom dictionary from an overlay on chrome://settings/editDictionary. This overlay can also be accessed through:
Settings |_Show advanced settings... ..|_Language and spell-checker settings... ....|_Custom spelling dictionary When a user types an unknown word into a textarea, the browser underlines this word as a misspelling. The user can right-click on this word and select "Add to Dictionary". If the user made a mistake, the user needs a way to remove a word from their custom dictionary. This CL provides this functionality. Automated tests are in https://codereview.chromium.org/11280013/ and https://codereview.chromium.org/11308076/. BUG=18238 Review URL: https://chromiumcodereview.appspot.com/11362063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/spellchecker')
-rw-r--r--chrome/renderer/spellchecker/cocoa_spelling_engine_mac.cc6
-rw-r--r--chrome/renderer/spellchecker/cocoa_spelling_engine_mac.h1
-rw-r--r--chrome/renderer/spellchecker/hunspell_engine.cc21
-rw-r--r--chrome/renderer/spellchecker/hunspell_engine.h8
-rw-r--r--chrome/renderer/spellchecker/spellcheck.cc10
-rw-r--r--chrome/renderer/spellchecker/spellcheck.h1
-rw-r--r--chrome/renderer/spellchecker/spelling_engine.h1
7 files changed, 41 insertions, 7 deletions
diff --git a/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.cc b/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.cc
index 9c3ba9d..463940e 100644
--- a/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.cc
+++ b/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.cc
@@ -43,5 +43,9 @@ void CocoaSpellingEngine::FillSuggestionList(
}
void CocoaSpellingEngine::OnWordAdded(const std::string&) {
- // OSX doesn't support the custom dictionary.
+ // OSX doesn't support the custom dictionary yet.
+}
+
+void CocoaSpellingEngine::OnWordRemoved(const std::string&) {
+ // OSX doesn't support the custom dictionary yet.
}
diff --git a/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.h b/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.h
index 1b5183b..c2856c6 100644
--- a/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.h
+++ b/chrome/renderer/spellchecker/cocoa_spelling_engine_mac.h
@@ -16,6 +16,7 @@ class CocoaSpellingEngine : public SpellingEngine {
virtual void FillSuggestionList(const string16& wrong_word,
std::vector<string16>* optional_suggestions) OVERRIDE;
virtual void OnWordAdded(const std::string& word) OVERRIDE;
+ virtual void OnWordRemoved(const std::string& word) OVERRIDE;
};
#endif // CHROME_RENDERER_SPELLCHECKER_NSSPELLCHECKER_ENGINE_H_
diff --git a/chrome/renderer/spellchecker/hunspell_engine.cc b/chrome/renderer/spellchecker/hunspell_engine.cc
index 9b352d5..71a14d2 100644
--- a/chrome/renderer/spellchecker/hunspell_engine.cc
+++ b/chrome/renderer/spellchecker/hunspell_engine.cc
@@ -56,10 +56,9 @@ void HunspellEngine::InitializeHunspell() {
new Hunspell(bdict_file_->data(), bdict_file_->length()));
// Add custom words to Hunspell.
- for (std::vector<std::string>::iterator it = custom_words_.begin();
- it != custom_words_.end(); ++it) {
+ chrome::spellcheck_common::WordList::iterator it;
+ for (it = custom_words_.begin(); it != custom_words_.end(); ++it)
AddWordToHunspell(*it);
- }
DHISTOGRAM_TIMES("Spellcheck.InitTime",
base::Histogram::DebugNow() - debug_start_time);
@@ -73,6 +72,11 @@ void HunspellEngine::AddWordToHunspell(const std::string& word) {
hunspell_->add(word.c_str());
}
+void HunspellEngine::RemoveWordFromHunspell(const std::string& word) {
+ if (!word.empty() && word.length() < MAXWORDLEN)
+ hunspell_->remove(word.c_str());
+}
+
bool HunspellEngine::CheckSpelling(const string16& word_to_check, int tag) {
bool word_correct = false;
std::string word_to_check_utf8(UTF16ToUTF8(word_to_check));
@@ -124,6 +128,17 @@ void HunspellEngine::OnWordAdded(const std::string& word) {
}
}
+void HunspellEngine::OnWordRemoved(const std::string& word) {
+ if (!hunspell_.get()) {
+ chrome::spellcheck_common::WordList::iterator it = std::find(
+ custom_words_.begin(), custom_words_.end(), word);
+ if (it != custom_words_.end())
+ custom_words_.erase(it);
+ } else {
+ RemoveWordFromHunspell(word);
+ }
+}
+
bool HunspellEngine::InitializeIfNeeded() {
if (!initialized_ && !dictionary_requested_) {
// RenderThread will not exist in test.
diff --git a/chrome/renderer/spellchecker/hunspell_engine.h b/chrome/renderer/spellchecker/hunspell_engine.h
index 0d91b24..f96e5de 100644
--- a/chrome/renderer/spellchecker/hunspell_engine.h
+++ b/chrome/renderer/spellchecker/hunspell_engine.h
@@ -9,6 +9,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
+#include "chrome/common/spellcheck_common.h"
#include "chrome/renderer/spellchecker/spelling_engine.h"
#include <string>
@@ -30,6 +31,8 @@ class HunspellEngine : public SpellingEngine {
virtual void FillSuggestionList(const string16& wrong_word,
std::vector<string16>* optional_suggestions) OVERRIDE;
virtual void OnWordAdded(const std::string& word) OVERRIDE;
+ virtual void OnWordRemoved(const std::string& word) OVERRIDE;
+
private:
// Initializes the Hunspell dictionary, or does nothing if |hunspell_| is
// non-null. This blocks.
@@ -38,13 +41,16 @@ class HunspellEngine : public SpellingEngine {
// Add the given custom word to |hunspell_|.
void AddWordToHunspell(const std::string& word);
+ // Remove the given custom word from |hunspell_|.
+ void RemoveWordFromHunspell(const std::string& word);
+
// We memory-map the BDict file.
scoped_ptr<file_util::MemoryMappedFile> bdict_file_;
// The hunspell dictionary in use.
scoped_ptr<Hunspell> hunspell_;
- std::vector<std::string> custom_words_;
+ chrome::spellcheck_common::WordList custom_words_;
base::PlatformFile file_;
diff --git a/chrome/renderer/spellchecker/spellcheck.cc b/chrome/renderer/spellchecker/spellcheck.cc
index d289548..01eec7e 100644
--- a/chrome/renderer/spellchecker/spellcheck.cc
+++ b/chrome/renderer/spellchecker/spellcheck.cc
@@ -56,6 +56,7 @@ bool SpellCheck::OnControlMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(SpellCheck, message)
IPC_MESSAGE_HANDLER(SpellCheckMsg_Init, OnInit)
IPC_MESSAGE_HANDLER(SpellCheckMsg_WordAdded, OnWordAdded)
+ IPC_MESSAGE_HANDLER(SpellCheckMsg_WordRemoved, OnWordRemoved)
IPC_MESSAGE_HANDLER(SpellCheckMsg_EnableAutoSpellCorrect,
OnEnableAutoSpellCorrect)
IPC_MESSAGE_UNHANDLED(handled = false)
@@ -77,10 +78,15 @@ void SpellCheck::OnInit(IPC::PlatformFileForTransit bdict_file,
}
void SpellCheck::OnWordAdded(const std::string& word) {
- if (platform_spelling_engine_)
+ if (platform_spelling_engine_.get())
platform_spelling_engine_->OnWordAdded(word);
}
+void SpellCheck::OnWordRemoved(const std::string& word) {
+ if (platform_spelling_engine_.get())
+ platform_spelling_engine_->OnWordRemoved(word);
+}
+
void SpellCheck::OnEnableAutoSpellCorrect(bool enable) {
auto_spell_correct_turned_on_ = enable;
}
@@ -124,7 +130,7 @@ bool SpellCheck::SpellCheckWord(
return true;
// Do nothing if spell checking is disabled.
- if (!platform_spelling_engine_ ||
+ if (!platform_spelling_engine_.get() ||
!platform_spelling_engine_->IsEnabled())
return true;
diff --git a/chrome/renderer/spellchecker/spellcheck.h b/chrome/renderer/spellchecker/spellcheck.h
index 6292005..7c32d66 100644
--- a/chrome/renderer/spellchecker/spellcheck.h
+++ b/chrome/renderer/spellchecker/spellcheck.h
@@ -110,6 +110,7 @@ class SpellCheck : public content::RenderProcessObserver,
const std::string& language,
bool auto_spell_correct);
void OnWordAdded(const std::string& word);
+ void OnWordRemoved(const std::string& word);
void OnEnableAutoSpellCorrect(bool enable);
// If there is no dictionary file, then this requests one from the browser
diff --git a/chrome/renderer/spellchecker/spelling_engine.h b/chrome/renderer/spellchecker/spelling_engine.h
index 13d3b28..0901843 100644
--- a/chrome/renderer/spellchecker/spelling_engine.h
+++ b/chrome/renderer/spellchecker/spelling_engine.h
@@ -24,6 +24,7 @@ class SpellingEngine {
virtual void FillSuggestionList(const string16& wrong_word,
std::vector<string16>* optional_suggestions) = 0;
virtual void OnWordAdded(const std::string& word) = 0;
+ virtual void OnWordRemoved(const std::string& word) = 0;
};
#endif // CHROME_RENDERER_SPELLCHECKER_SPELLING_ENGINE_H_