2014-12-18 21:43:51 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_RENDERER_API_ATOM_API_SPELL_CHECK_CLIENT_H_
|
|
|
|
#define ATOM_RENDERER_API_ATOM_API_SPELL_CHECK_CLIENT_H_
|
|
|
|
|
2014-12-20 04:42:19 +00:00
|
|
|
#include <string>
|
2014-12-20 06:13:07 +00:00
|
|
|
#include <vector>
|
2014-12-20 04:42:19 +00:00
|
|
|
|
|
|
|
#include "base/callback.h"
|
|
|
|
#include "chrome/renderer/spellchecker/spellcheck_worditerator.h"
|
2014-12-18 21:43:51 +00:00
|
|
|
#include "native_mate/scoped_persistent.h"
|
2017-06-16 22:13:30 +00:00
|
|
|
#include "third_party/WebKit/public/platform/WebVector.h"
|
2014-12-18 21:43:51 +00:00
|
|
|
#include "third_party/WebKit/public/web/WebSpellCheckClient.h"
|
|
|
|
|
2017-04-11 07:18:40 +00:00
|
|
|
namespace blink {
|
|
|
|
struct WebTextCheckingResult;
|
|
|
|
}
|
|
|
|
|
2014-12-18 21:43:51 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
class SpellCheckClient : public blink::WebSpellCheckClient {
|
|
|
|
public:
|
2014-12-20 05:01:47 +00:00
|
|
|
SpellCheckClient(const std::string& language,
|
|
|
|
bool auto_spell_correct_turned_on,
|
|
|
|
v8::Isolate* isolate,
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Object> provider);
|
2014-12-18 21:43:51 +00:00
|
|
|
virtual ~SpellCheckClient();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// blink::WebSpellCheckClient:
|
2017-06-16 20:42:33 +00:00
|
|
|
void CheckSpelling(
|
2014-12-18 21:43:51 +00:00
|
|
|
const blink::WebString& text,
|
|
|
|
int& misspelledOffset,
|
|
|
|
int& misspelledLength,
|
|
|
|
blink::WebVector<blink::WebString>* optionalSuggestions) override;
|
2017-06-16 20:42:33 +00:00
|
|
|
void RequestCheckingOfText(
|
2014-12-18 21:43:51 +00:00
|
|
|
const blink::WebString& textToCheck,
|
2017-06-16 22:13:30 +00:00
|
|
|
blink::WebTextCheckingResult completionCallback) override;
|
2017-06-16 20:42:33 +00:00
|
|
|
void ShowSpellingUI(bool show) override;
|
|
|
|
bool IsShowingSpellingUI() override;
|
|
|
|
void UpdateSpellingUIWithMisspelledWord(
|
2014-12-18 21:43:51 +00:00
|
|
|
const blink::WebString& word) override;
|
|
|
|
|
2014-12-20 06:13:07 +00:00
|
|
|
// Check the spelling of text.
|
|
|
|
void SpellCheckText(const base::string16& text,
|
|
|
|
bool stop_at_first_result,
|
|
|
|
std::vector<blink::WebTextCheckingResult>* results);
|
2014-12-19 00:44:38 +00:00
|
|
|
|
2014-12-20 06:13:07 +00:00
|
|
|
// Call JavaScript to check spelling a word.
|
|
|
|
bool SpellCheckWord(const base::string16& word_to_check);
|
2014-12-20 04:42:19 +00:00
|
|
|
|
2014-12-20 04:56:16 +00:00
|
|
|
// Find a possible correctly spelled word for a misspelled word. Computes an
|
|
|
|
// empty string if input misspelled word is too long, there is ambiguity, or
|
|
|
|
// the correct spelling cannot be determined.
|
|
|
|
base::string16 GetAutoCorrectionWord(const base::string16& word);
|
|
|
|
|
2014-12-20 04:42:19 +00:00
|
|
|
// Returns whether or not the given word is a contraction of valid words
|
|
|
|
// (e.g. "word:word").
|
|
|
|
bool IsValidContraction(const base::string16& word);
|
|
|
|
|
|
|
|
// Represents character attributes used for filtering out characters which
|
|
|
|
// are not supported by this SpellCheck object.
|
|
|
|
SpellcheckCharAttribute character_attributes_;
|
|
|
|
|
|
|
|
// Represents word iterators used in this spellchecker. The |text_iterator_|
|
|
|
|
// splits text provided by WebKit into words, contractions, or concatenated
|
|
|
|
// words. The |contraction_iterator_| splits a concatenated word extracted by
|
|
|
|
// |text_iterator_| into word components so we can treat a concatenated word
|
|
|
|
// consisting only of correct words as a correct word.
|
|
|
|
SpellcheckWordIterator text_iterator_;
|
|
|
|
SpellcheckWordIterator contraction_iterator_;
|
|
|
|
|
2014-12-20 05:01:47 +00:00
|
|
|
bool auto_spell_correct_turned_on_;
|
|
|
|
|
2014-12-19 00:44:38 +00:00
|
|
|
v8::Isolate* isolate_;
|
2014-12-18 21:43:51 +00:00
|
|
|
mate::ScopedPersistent<v8::Object> provider_;
|
2014-12-20 04:42:19 +00:00
|
|
|
mate::ScopedPersistent<v8::Function> spell_check_;
|
2014-12-18 21:43:51 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(SpellCheckClient);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_RENDERER_API_ATOM_API_SPELL_CHECK_CLIENT_H_
|