Update Spellcheck API

Update WebTexhCheckingCompletion as per chromium 0e8c828e02
This commit is contained in:
Nitish Sakhawalkar 2019-05-16 21:58:03 -07:00
parent 2d14a0e90d
commit 8a7de89b97
2 changed files with 16 additions and 13 deletions

View file

@ -5,6 +5,7 @@
#include "atom/renderer/api/atom_api_spell_check_client.h" #include "atom/renderer/api/atom_api_spell_check_client.h"
#include <map> #include <map>
#include <utility>
#include <vector> #include <vector>
#include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/native_mate_converters/string16_converter.h"
@ -46,22 +47,23 @@ class SpellCheckClient::SpellcheckRequest {
using WordMap = using WordMap =
std::map<base::string16, std::vector<blink::WebTextCheckingResult>>; std::map<base::string16, std::vector<blink::WebTextCheckingResult>>;
SpellcheckRequest(const base::string16& text, SpellcheckRequest(
blink::WebTextCheckingCompletion* completion) const base::string16& text,
: text_(text), completion_(completion) { std::unique_ptr<blink::WebTextCheckingCompletion> completion)
DCHECK(completion); : text_(text), completion_(std::move(completion)) {}
}
~SpellcheckRequest() {} ~SpellcheckRequest() {}
const base::string16& text() const { return text_; } const base::string16& text() const { return text_; }
blink::WebTextCheckingCompletion* completion() { return completion_; } std::shared_ptr<blink::WebTextCheckingCompletion> completion() {
return completion_;
}
WordMap& wordmap() { return word_map_; } WordMap& wordmap() { return word_map_; }
private: private:
base::string16 text_; // Text to be checked in this task. base::string16 text_; // Text to be checked in this task.
WordMap word_map_; // WordMap to hold distinct words in text WordMap word_map_; // WordMap to hold distinct words in text
// The interface to send the misspelled ranges to WebKit. // The interface to send the misspelled ranges to WebKit.
blink::WebTextCheckingCompletion* completion_; std::shared_ptr<blink::WebTextCheckingCompletion> completion_;
DISALLOW_COPY_AND_ASSIGN(SpellcheckRequest); DISALLOW_COPY_AND_ASSIGN(SpellcheckRequest);
}; };
@ -88,7 +90,7 @@ SpellCheckClient::~SpellCheckClient() {
void SpellCheckClient::RequestCheckingOfText( void SpellCheckClient::RequestCheckingOfText(
const blink::WebString& textToCheck, const blink::WebString& textToCheck,
blink::WebTextCheckingCompletion* completionCallback) { std::unique_ptr<blink::WebTextCheckingCompletion> completionCallback) {
base::string16 text(textToCheck.Utf16()); base::string16 text(textToCheck.Utf16());
// Ignore invalid requests. // Ignore invalid requests.
if (text.empty() || !HasWordCharacters(text, 0)) { if (text.empty() || !HasWordCharacters(text, 0)) {
@ -101,7 +103,8 @@ void SpellCheckClient::RequestCheckingOfText(
pending_request_param_->completion()->DidCancelCheckingText(); pending_request_param_->completion()->DidCancelCheckingText();
} }
pending_request_param_.reset(new SpellcheckRequest(text, completionCallback)); pending_request_param_.reset(
new SpellcheckRequest(text, std::move(completionCallback)));
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
@ -188,7 +191,7 @@ void SpellCheckClient::SpellCheckText() {
void SpellCheckClient::OnSpellCheckDone( void SpellCheckClient::OnSpellCheckDone(
const std::vector<base::string16>& misspelled_words) { const std::vector<base::string16>& misspelled_words) {
std::vector<blink::WebTextCheckingResult> results; std::vector<blink::WebTextCheckingResult> results;
auto* const completion_handler = pending_request_param_->completion(); auto completion_handler = pending_request_param_->completion();
auto& word_map = pending_request_param_->wordmap(); auto& word_map = pending_request_param_->wordmap();

View file

@ -38,9 +38,9 @@ class SpellCheckClient : public blink::WebSpellCheckPanelHostClient,
private: private:
class SpellcheckRequest; class SpellcheckRequest;
// blink::WebTextCheckClient: // blink::WebTextCheckClient:
void RequestCheckingOfText( void RequestCheckingOfText(const blink::WebString& textToCheck,
const blink::WebString& textToCheck, std::unique_ptr<blink::WebTextCheckingCompletion>
blink::WebTextCheckingCompletion* completionCallback) override; completionCallback) override;
bool IsSpellCheckingEnabled() const override; bool IsSpellCheckingEnabled() const override;
// blink::WebSpellCheckPanelHostClient: // blink::WebSpellCheckPanelHostClient: