Add option to turn on/off auto correct word

This commit is contained in:
Cheng Zhao 2014-12-19 21:01:47 -08:00
parent f6c66e7ece
commit 90b2d12371
4 changed files with 20 additions and 9 deletions

View file

@ -55,10 +55,13 @@ bool HasWordCharacters(const base::string16& text, int index) {
} // namespace
SpellCheckClient::SpellCheckClient(v8::Isolate* isolate,
const std::string& language,
SpellCheckClient::SpellCheckClient(const std::string& language,
bool auto_spell_correct_turned_on,
v8::Isolate* isolate,
v8::Handle<v8::Object> provider)
: isolate_(isolate), provider_(isolate, provider) {
: auto_spell_correct_turned_on_(auto_spell_correct_turned_on),
isolate_(isolate),
provider_(isolate, provider) {
character_attributes_.SetDefaultLanguage(language);
// Persistent the method.
@ -141,7 +144,10 @@ void SpellCheckClient::requestCheckingOfText(
blink::WebString SpellCheckClient::autoCorrectWord(
const blink::WebString& misspelledWord) {
return GetAutoCorrectionWord(base::string16(misspelledWord));
if (auto_spell_correct_turned_on_)
return GetAutoCorrectionWord(base::string16(misspelledWord));
else
return blink::WebString();
}
void SpellCheckClient::showSpellingUI(bool show) {

View file

@ -18,8 +18,9 @@ namespace api {
class SpellCheckClient : public blink::WebSpellCheckClient {
public:
SpellCheckClient(v8::Isolate* isolate,
const std::string& language,
SpellCheckClient(const std::string& language,
bool auto_spell_correct_turned_on,
v8::Isolate* isolate,
v8::Handle<v8::Object> provider);
virtual ~SpellCheckClient();
@ -74,6 +75,8 @@ class SpellCheckClient : public blink::WebSpellCheckClient {
SpellcheckWordIterator text_iterator_;
SpellcheckWordIterator contraction_iterator_;
bool auto_spell_correct_turned_on_;
v8::Isolate* isolate_;
mate::ScopedPersistent<v8::Object> provider_;
mate::ScopedPersistent<v8::Function> spell_check_;

View file

@ -59,14 +59,15 @@ void WebFrame::AttachGuest(int id) {
void WebFrame::SetSpellCheckProvider(mate::Arguments* args,
const std::string& language,
bool auto_spell_correct_turned_on,
v8::Handle<v8::Object> provider) {
v8::Isolate* isolate = args->isolate();
if (!provider->Has(mate::StringToV8(isolate, "spellCheck"))) {
if (!provider->Has(mate::StringToV8(args->isolate(), "spellCheck"))) {
args->ThrowError("\"spellCheck\" has to be defined");
return;
}
spell_check_client_.reset(new SpellCheckClient(isolate, language, provider));
spell_check_client_.reset(new SpellCheckClient(
language, auto_spell_correct_turned_on, args->isolate(), provider));
web_frame_->view()->setSpellCheckClient(spell_check_client_.get());
}

View file

@ -47,6 +47,7 @@ class WebFrame : public mate::Wrappable {
// Set the provider that will be used by SpellCheckClient for spell check.
void SetSpellCheckProvider(mate::Arguments* args,
const std::string& language,
bool auto_spell_correct_turned_on,
v8::Handle<v8::Object> provider);
// mate::Wrappable: