forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore custom spellcheck dictionary words when using server-side spel…
…lcheck Chrome has been storing custom spellcheck dictionary words in the platform spelling engine (Hunspell), which does not interact with the server-side spellcheck. This has caused server-side spellcheck to not take into account user's custom spellcheck dictionary. This CL moves handling of custom words from platform spelling engine to spellchecker that uses both the platform spelling engine and the server-side spellcheck. BUG=169629 Review URL: https://chromiumcodereview.appspot.com/12303011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183497 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
rouslan@chromium.org
committed
Feb 20, 2013
1 parent
8925e0f
commit 4ba74d9
Showing
12 changed files
with
139 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/renderer/spellchecker/custom_dictionary_engine.h" | ||
|
||
#include "base/logging.h" | ||
#include "base/utf_string_conversions.h" | ||
|
||
CustomDictionaryEngine::CustomDictionaryEngine() { | ||
} | ||
|
||
CustomDictionaryEngine::~CustomDictionaryEngine() { | ||
} | ||
|
||
void CustomDictionaryEngine::Init( | ||
const std::vector<std::string>& custom_words) { | ||
// SpellingMenuOberver calls UTF16ToUTF8(word) to convert words for storage, | ||
// synchronization, and use in the custom dictionary engine. Since | ||
// (UTF8ToUTF16(UTF16ToUTF8(word)) == word) holds, the engine does not need to | ||
// normalize the strings. | ||
for (std::vector<std::string>::const_iterator it = custom_words.begin(); | ||
it != custom_words.end(); | ||
++it) { | ||
dictionary_.insert(UTF8ToUTF16(*it)); | ||
} | ||
} | ||
|
||
void CustomDictionaryEngine::OnCustomDictionaryChanged( | ||
const std::vector<std::string>& words_added, | ||
const std::vector<std::string>& words_removed) { | ||
for (std::vector<std::string>::const_iterator it = words_added.begin(); | ||
it != words_added.end(); | ||
++it) { | ||
dictionary_.insert(UTF8ToUTF16(*it)); | ||
} | ||
for (std::vector<std::string>::const_iterator it = words_removed.begin(); | ||
it != words_removed.end(); | ||
++it) { | ||
dictionary_.erase(UTF8ToUTF16(*it)); | ||
} | ||
} | ||
|
||
bool CustomDictionaryEngine::SpellCheckWord( | ||
const char16* text, | ||
int misspelling_start, | ||
int misspelling_len) { | ||
DCHECK(text); | ||
return misspelling_start >= 0 && | ||
misspelling_len > 0 && | ||
dictionary_.count(string16(text, misspelling_start, misspelling_len)) > 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_RENDERER_SPELLCHECKER_CUSTOM_DICTIONARY_ENGINE_H_ | ||
#define CHROME_RENDERER_SPELLCHECKER_CUSTOM_DICTIONARY_ENGINE_H_ | ||
|
||
#include <set> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "base/string16.h" | ||
|
||
// Custom spellcheck dictionary. Words in this dictionary are always correctly | ||
// spelled. Words that are not in this dictionary may or may not be correctly | ||
// spelled. | ||
class CustomDictionaryEngine { | ||
public: | ||
CustomDictionaryEngine(); | ||
~CustomDictionaryEngine(); | ||
|
||
// Initialize the custom dictionary engine. | ||
void Init(const std::vector<std::string>& words); | ||
|
||
// Spellcheck |text|. Assumes that another spelling engine has set | ||
// |misspelling_start| and |misspelling_len| to indicate a misspelling. | ||
// Returns true if there are no misspellings, otherwise returns false. | ||
bool SpellCheckWord(const char16* text, | ||
int misspelling_start, | ||
int misspelling_len); | ||
|
||
// Update custom dictionary words. | ||
void OnCustomDictionaryChanged( | ||
const std::vector<std::string>& words_added, | ||
const std::vector<std::string>& words_removed); | ||
|
||
private: | ||
// Correctly spelled words. | ||
std::set<string16> dictionary_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(CustomDictionaryEngine); | ||
}; | ||
|
||
#endif // CHROME_RENDERER_SPELLCHECKER_CUSTOM_DICTIONARY_ENGINE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.