-
Notifications
You must be signed in to change notification settings - Fork 15k
/
atom_api_spell_check_client.h
114 lines (91 loc) · 4.1 KB
/
atom_api_spell_check_client.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// 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_
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "components/spellcheck/renderer/spellcheck_worditerator.h"
#include "native_mate/scoped_persistent.h"
#include "third_party/blink/public/platform/web_spell_check_panel_host_client.h"
#include "third_party/blink/public/platform/web_vector.h"
#include "third_party/blink/public/web/web_text_check_client.h"
namespace blink {
struct WebTextCheckingResult;
class WebTextCheckingCompletion;
} // namespace blink
namespace atom {
namespace api {
class SpellCheckClient : public blink::WebSpellCheckPanelHostClient,
public blink::WebTextCheckClient,
public base::SupportsWeakPtr<SpellCheckClient> {
public:
SpellCheckClient(const std::string& language,
v8::Isolate* isolate,
v8::Local<v8::Object> provider);
~SpellCheckClient() override;
private:
class SpellcheckRequest;
// blink::WebTextCheckClient:
void RequestCheckingOfText(const blink::WebString& textToCheck,
std::unique_ptr<blink::WebTextCheckingCompletion>
completionCallback) override;
bool IsSpellCheckingEnabled() const override;
// blink::WebSpellCheckPanelHostClient:
void ShowSpellingUI(bool show) override;
bool IsShowingSpellingUI() override;
void UpdateSpellingUIWithMisspelledWord(
const blink::WebString& word) override;
struct SpellCheckScope {
v8::HandleScope handle_scope_;
v8::Context::Scope context_scope_;
v8::Local<v8::Object> provider_;
v8::Local<v8::Function> spell_check_;
explicit SpellCheckScope(const SpellCheckClient& client);
~SpellCheckScope();
};
// Run through the word iterator and send out requests
// to the JS API for checking spellings of words in the current
// request.
void SpellCheckText();
// Call JavaScript to check spelling a word.
// The javascript function will callback OnSpellCheckDone
// with the results of all the misspelled words.
void SpellCheckWords(const SpellCheckScope& scope,
const std::set<base::string16>& words);
// Returns whether or not the given word is a contraction of valid words
// (e.g. "word:word").
// Output variable contraction_words will contain individual
// words in the contraction.
bool IsContraction(const SpellCheckScope& scope,
const base::string16& word,
std::vector<base::string16>* contraction_words);
// Callback for the JS API which returns the list of misspelled words.
void OnSpellCheckDone(const std::vector<base::string16>& misspelled_words);
// 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_;
// The parameters of a pending background-spellchecking request.
// (When WebKit sends two or more requests, we cancel the previous
// requests so we do not have to use vectors.)
std::unique_ptr<SpellcheckRequest> pending_request_param_;
v8::Isolate* isolate_;
v8::Persistent<v8::Context> context_;
mate::ScopedPersistent<v8::Object> provider_;
mate::ScopedPersistent<v8::Function> spell_check_;
DISALLOW_COPY_AND_ASSIGN(SpellCheckClient);
};
} // namespace api
} // namespace atom
#endif // ATOM_RENDERER_API_ATOM_API_SPELL_CHECK_CLIENT_H_