diff --git a/atom/renderer/api/atom_api_spell_check_client.cc b/atom/renderer/api/atom_api_spell_check_client.cc index aa069523cc..fc32e071bb 100644 --- a/atom/renderer/api/atom_api_spell_check_client.cc +++ b/atom/renderer/api/atom_api_spell_check_client.cc @@ -4,13 +4,21 @@ #include "atom/renderer/api/atom_api_spell_check_client.h" +#include + +#include "atom/common/native_mate_converters/string16_converter.h" +#include "native_mate/converter.h" +#include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" + +#include "atom/common/node_includes.h" + namespace atom { namespace api { SpellCheckClient::SpellCheckClient(v8::Isolate* isolate, v8::Handle provider) - : provider_(isolate, provider) {} + : isolate_(isolate), provider_(isolate, provider) {} SpellCheckClient::~SpellCheckClient() {} @@ -19,10 +27,19 @@ void SpellCheckClient::spellCheck( int& misspelledOffset, int& misspelledLength, blink::WebVector* optionalSuggestions) { + std::vector result; + if (!CallProviderMethod("spellCheck", text, &result)) + return; + + if (result.size() != 2) + return; + + misspelledOffset = result[0]; + misspelledLength = result[1]; } void SpellCheckClient::checkTextOfParagraph( - const blink::WebString&, + const blink::WebString& text, blink::WebTextCheckingTypeMask mask, blink::WebVector* results) { } @@ -32,11 +49,17 @@ void SpellCheckClient::requestCheckingOfText( const blink::WebVector& markersInText, const blink::WebVector& markerOffsets, blink::WebTextCheckingCompletion* completionCallback) { + if (completionCallback) + completionCallback->didCancelCheckingText(); } blink::WebString SpellCheckClient::autoCorrectWord( const blink::WebString& misspelledWord) { - return blink::WebString(); + base::string16 result; + if (!CallProviderMethod("autoCorrectWord", misspelledWord, &result)) + return blink::WebString(); + + return result; } void SpellCheckClient::showSpellingUI(bool show) { @@ -50,6 +73,24 @@ void SpellCheckClient::updateSpellingUIWithMisspelledWord( const blink::WebString& word) { } +template +bool SpellCheckClient::CallProviderMethod(const char* method, + const blink::WebString& text, + T* result) { + v8::HandleScope handle_scope(isolate_); + + v8::Handle provider = provider_.NewHandle(); + if (!provider->Has(mate::StringToV8(isolate_, method))) + return false; + + v8::Handle v8_str = + mate::ConvertToV8(isolate_, base::string16(text)); + v8::Handle v8_result = + node::MakeCallback(isolate_, provider, method, 1, &v8_str); + + return mate::ConvertFromV8(isolate_, v8_result, result);; +} + } // namespace api } // namespace atom diff --git a/atom/renderer/api/atom_api_spell_check_client.h b/atom/renderer/api/atom_api_spell_check_client.h index d662f79ce7..a6d05f8645 100644 --- a/atom/renderer/api/atom_api_spell_check_client.h +++ b/atom/renderer/api/atom_api_spell_check_client.h @@ -40,6 +40,12 @@ class SpellCheckClient : public blink::WebSpellCheckClient { void updateSpellingUIWithMisspelledWord( const blink::WebString& word) override; + template + bool CallProviderMethod(const char* method, + const blink::WebString& text, + T* result); + + v8::Isolate* isolate_; mate::ScopedPersistent provider_; DISALLOW_COPY_AND_ASSIGN(SpellCheckClient); diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index 36f13c7976..e1b016c5b5 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -60,6 +60,7 @@ void WebFrame::AttachGuest(int id) { void WebFrame::SetSpellCheckProvider(v8::Isolate* isolate, v8::Handle provider) { spell_check_client_.reset(new SpellCheckClient(isolate, provider)); + web_frame_->view()->setSpellCheckClient(spell_check_client_.get()); } mate::ObjectTemplateBuilder WebFrame::GetObjectTemplateBuilder(