OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_ | 5 #ifndef COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_ |
6 #define COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_ | 6 #define COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/id_map.h" | 13 #include "base/id_map.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "components/spellcheck/spellcheck_build_features.h" | 15 #include "components/spellcheck/spellcheck_build_features.h" |
16 #include "content/public/renderer/render_view_observer.h" | 16 #include "content/public/renderer/render_view_observer.h" |
17 #include "content/public/renderer/render_view_observer_tracker.h" | 17 #include "content/public/renderer/render_view_observer_tracker.h" |
18 #include "third_party/WebKit/public/web/WebSpellCheckClient.h" | |
19 #include "third_party/WebKit/public/web/WebTextCheckClient.h" | 18 #include "third_party/WebKit/public/web/WebTextCheckClient.h" |
20 | 19 |
21 class RenderView; | |
22 class SpellCheck; | 20 class SpellCheck; |
23 struct SpellCheckResult; | 21 struct SpellCheckResult; |
24 | 22 |
25 namespace blink { | 23 namespace blink { |
26 class WebTextCheckingCompletion; | 24 class WebTextCheckingCompletion; |
27 struct WebTextCheckingResult; | 25 struct WebTextCheckingResult; |
28 } | 26 } |
29 | 27 |
| 28 // TODO(xiaochengh): Make SpellCheckProvider a RenderFrameObserver. |
30 // This class deals with invoking browser-side spellcheck mechanism | 29 // This class deals with invoking browser-side spellcheck mechanism |
31 // which is done asynchronously. | 30 // which is done asynchronously. |
32 // TODO(xiaochengh): Split this class to implement WebSpellCheckClient and | |
33 // WebTextCheckClient separately. | |
34 class SpellCheckProvider | 31 class SpellCheckProvider |
35 : public content::RenderViewObserver, | 32 : public content::RenderViewObserver, |
36 public content::RenderViewObserverTracker<SpellCheckProvider>, | 33 public content::RenderViewObserverTracker<SpellCheckProvider>, |
37 public blink::WebSpellCheckClient, | |
38 public blink::WebTextCheckClient { | 34 public blink::WebTextCheckClient { |
39 public: | 35 public: |
40 using WebTextCheckCompletions = IDMap<blink::WebTextCheckingCompletion*>; | 36 using WebTextCheckCompletions = IDMap<blink::WebTextCheckingCompletion*>; |
41 | 37 |
42 SpellCheckProvider(content::RenderView* render_view, | 38 SpellCheckProvider(content::RenderView* render_view, |
43 SpellCheck* spellcheck); | 39 SpellCheck* spellcheck); |
44 ~SpellCheckProvider() override; | 40 ~SpellCheckProvider() override; |
45 | 41 |
46 // Requests async spell and grammar checker to the platform text | 42 // Requests async spell and grammar checker to the platform text |
47 // checker, which is available on the browser process. The function does not | 43 // checker, which is available on the browser process. The function does not |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 void checkSpelling( | 77 void checkSpelling( |
82 const blink::WebString& text, | 78 const blink::WebString& text, |
83 int& offset, | 79 int& offset, |
84 int& length, | 80 int& length, |
85 blink::WebVector<blink::WebString>* optional_suggestions) override; | 81 blink::WebVector<blink::WebString>* optional_suggestions) override; |
86 void requestCheckingOfText( | 82 void requestCheckingOfText( |
87 const blink::WebString& text, | 83 const blink::WebString& text, |
88 blink::WebTextCheckingCompletion* completion) override; | 84 blink::WebTextCheckingCompletion* completion) override; |
89 void cancelAllPendingRequests() override; | 85 void cancelAllPendingRequests() override; |
90 | 86 |
91 // blink::WebSpellCheckClient implementation. | |
92 void showSpellingUI(bool show) override; | |
93 bool isShowingSpellingUI() override; | |
94 void updateSpellingUIWithMisspelledWord( | |
95 const blink::WebString& word) override; | |
96 | |
97 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) | 87 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
98 void OnRespondSpellingService( | 88 void OnRespondSpellingService( |
99 int identifier, | 89 int identifier, |
100 bool succeeded, | 90 bool succeeded, |
101 const base::string16& text, | 91 const base::string16& text, |
102 const std::vector<SpellCheckResult>& results); | 92 const std::vector<SpellCheckResult>& results); |
103 #endif | 93 #endif |
104 | 94 |
105 // Returns whether |text| has word characters, i.e. whether a spellchecker | 95 // Returns whether |text| has word characters, i.e. whether a spellchecker |
106 // needs to check this text. | 96 // needs to check this text. |
107 bool HasWordCharacters(const base::string16& text, int index) const; | 97 bool HasWordCharacters(const base::string16& text, int index) const; |
108 | 98 |
109 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) | 99 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
110 void OnAdvanceToNextMisspelling(); | |
111 void OnRespondTextCheck( | 100 void OnRespondTextCheck( |
112 int identifier, | 101 int identifier, |
113 const base::string16& line, | 102 const base::string16& line, |
114 const std::vector<SpellCheckResult>& results); | 103 const std::vector<SpellCheckResult>& results); |
115 void OnToggleSpellPanel(bool is_currently_visible); | |
116 #endif | 104 #endif |
117 | 105 |
118 // Holds ongoing spellchecking operations, assigns IDs for the IPC routing. | 106 // Holds ongoing spellchecking operations, assigns IDs for the IPC routing. |
119 WebTextCheckCompletions text_check_completions_; | 107 WebTextCheckCompletions text_check_completions_; |
120 | 108 |
121 // The last text sent to the browser process to spellcheck it and its | 109 // The last text sent to the browser process to spellcheck it and its |
122 // spellchecking results. | 110 // spellchecking results. |
123 base::string16 last_request_; | 111 base::string16 last_request_; |
124 blink::WebVector<blink::WebTextCheckingResult> last_results_; | 112 blink::WebVector<blink::WebTextCheckingResult> last_results_; |
125 | 113 |
126 // True if the browser is showing the spelling panel for us. | |
127 bool spelling_panel_visible_; | |
128 | |
129 // Weak pointer to shared (per RenderView) spellcheck data. | 114 // Weak pointer to shared (per RenderView) spellcheck data. |
130 SpellCheck* spellcheck_; | 115 SpellCheck* spellcheck_; |
131 | 116 |
132 DISALLOW_COPY_AND_ASSIGN(SpellCheckProvider); | 117 DISALLOW_COPY_AND_ASSIGN(SpellCheckProvider); |
133 }; | 118 }; |
134 | 119 |
135 #endif // COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_ | 120 #endif // COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_ |
OLD | NEW |