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 CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_H_ | 5 #ifndef CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_H_ |
6 #define CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_H_ | 6 #define CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/id_map.h" | 10 #include "base/id_map.h" |
11 #include "content/public/renderer/render_view_observer.h" | 11 #include "content/public/renderer/render_view_observer.h" |
12 #include "content/public/renderer/render_view_observer_tracker.h" | 12 #include "content/public/renderer/render_view_observer_tracker.h" |
13 #include "third_party/WebKit/public/web/WebSpellCheckClient.h" | 13 #include "third_party/WebKit/public/web/WebSpellCheckClient.h" |
14 | 14 |
15 class RenderView; | 15 class RenderView; |
16 class SpellCheck; | 16 class SpellCheck; |
17 class SpellCheckMarker; | 17 class SpellCheckMarker; |
18 struct SpellCheckResult; | 18 struct SpellCheckResult; |
19 | 19 |
20 namespace WebKit { | 20 namespace blink { |
21 class WebString; | 21 class WebString; |
22 class WebTextCheckingCompletion; | 22 class WebTextCheckingCompletion; |
23 struct WebTextCheckingResult; | 23 struct WebTextCheckingResult; |
24 } | 24 } |
25 | 25 |
26 // This class deals with invoking browser-side spellcheck mechanism | 26 // This class deals with invoking browser-side spellcheck mechanism |
27 // which is done asynchronously. | 27 // which is done asynchronously. |
28 class SpellCheckProvider | 28 class SpellCheckProvider |
29 : public content::RenderViewObserver, | 29 : public content::RenderViewObserver, |
30 public content::RenderViewObserverTracker<SpellCheckProvider>, | 30 public content::RenderViewObserverTracker<SpellCheckProvider>, |
31 public WebKit::WebSpellCheckClient { | 31 public blink::WebSpellCheckClient { |
32 public: | 32 public: |
33 typedef IDMap<WebKit::WebTextCheckingCompletion> WebTextCheckCompletions; | 33 typedef IDMap<blink::WebTextCheckingCompletion> WebTextCheckCompletions; |
34 | 34 |
35 SpellCheckProvider(content::RenderView* render_view, | 35 SpellCheckProvider(content::RenderView* render_view, |
36 SpellCheck* spellcheck); | 36 SpellCheck* spellcheck); |
37 virtual ~SpellCheckProvider(); | 37 virtual ~SpellCheckProvider(); |
38 | 38 |
39 // Requests async spell and grammar checker to the platform text | 39 // Requests async spell and grammar checker to the platform text |
40 // checker, which is available on the browser process. | 40 // checker, which is available on the browser process. |
41 void RequestTextChecking( | 41 void RequestTextChecking( |
42 const string16& text, | 42 const string16& text, |
43 WebKit::WebTextCheckingCompletion* completion, | 43 blink::WebTextCheckingCompletion* completion, |
44 const std::vector<SpellCheckMarker>& markers); | 44 const std::vector<SpellCheckMarker>& markers); |
45 | 45 |
46 // The number of ongoing IPC requests. | 46 // The number of ongoing IPC requests. |
47 size_t pending_text_request_size() const { | 47 size_t pending_text_request_size() const { |
48 return text_check_completions_.size(); | 48 return text_check_completions_.size(); |
49 } | 49 } |
50 | 50 |
51 // Replace shared spellcheck data. | 51 // Replace shared spellcheck data. |
52 void set_spellcheck(SpellCheck* spellcheck) { spellcheck_ = spellcheck; } | 52 void set_spellcheck(SpellCheck* spellcheck) { spellcheck_ = spellcheck; } |
53 | 53 |
54 // Enables document-wide spellchecking. | 54 // Enables document-wide spellchecking. |
55 void EnableSpellcheck(bool enabled); | 55 void EnableSpellcheck(bool enabled); |
56 | 56 |
57 // RenderViewObserver implementation. | 57 // RenderViewObserver implementation. |
58 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 58 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
59 virtual void FocusedNodeChanged(const WebKit::WebNode& node) OVERRIDE; | 59 virtual void FocusedNodeChanged(const blink::WebNode& node) OVERRIDE; |
60 | 60 |
61 private: | 61 private: |
62 friend class TestingSpellCheckProvider; | 62 friend class TestingSpellCheckProvider; |
63 | 63 |
64 // Tries to satisfy a spell check request from the cache in |last_request_|. | 64 // Tries to satisfy a spell check request from the cache in |last_request_|. |
65 // Returns true (and cancels/finishes the completion) if it can, false | 65 // Returns true (and cancels/finishes the completion) if it can, false |
66 // if the provider should forward the query on. | 66 // if the provider should forward the query on. |
67 bool SatisfyRequestFromCache(const string16& text, | 67 bool SatisfyRequestFromCache(const string16& text, |
68 WebKit::WebTextCheckingCompletion* completion); | 68 blink::WebTextCheckingCompletion* completion); |
69 | 69 |
70 // WebKit::WebSpellCheckClient implementation. | 70 // blink::WebSpellCheckClient implementation. |
71 virtual void spellCheck( | 71 virtual void spellCheck( |
72 const WebKit::WebString& text, | 72 const blink::WebString& text, |
73 int& offset, | 73 int& offset, |
74 int& length, | 74 int& length, |
75 WebKit::WebVector<WebKit::WebString>* optional_suggestions) OVERRIDE; | 75 blink::WebVector<blink::WebString>* optional_suggestions) OVERRIDE; |
76 virtual void checkTextOfParagraph( | 76 virtual void checkTextOfParagraph( |
77 const WebKit::WebString& text, | 77 const blink::WebString& text, |
78 WebKit::WebTextCheckingTypeMask mask, | 78 blink::WebTextCheckingTypeMask mask, |
79 WebKit::WebVector<WebKit::WebTextCheckingResult>* results) OVERRIDE; | 79 blink::WebVector<blink::WebTextCheckingResult>* results) OVERRIDE; |
80 | 80 |
81 virtual void requestCheckingOfText( | 81 virtual void requestCheckingOfText( |
82 const WebKit::WebString& text, | 82 const blink::WebString& text, |
83 const WebKit::WebVector<uint32>& markers, | 83 const blink::WebVector<uint32>& markers, |
84 const WebKit::WebVector<unsigned>& marker_offsets, | 84 const blink::WebVector<unsigned>& marker_offsets, |
85 WebKit::WebTextCheckingCompletion* completion) OVERRIDE; | 85 blink::WebTextCheckingCompletion* completion) OVERRIDE; |
86 | 86 |
87 virtual WebKit::WebString autoCorrectWord( | 87 virtual blink::WebString autoCorrectWord( |
88 const WebKit::WebString& misspelled_word) OVERRIDE; | 88 const blink::WebString& misspelled_word) OVERRIDE; |
89 virtual void showSpellingUI(bool show) OVERRIDE; | 89 virtual void showSpellingUI(bool show) OVERRIDE; |
90 virtual bool isShowingSpellingUI() OVERRIDE; | 90 virtual bool isShowingSpellingUI() OVERRIDE; |
91 virtual void updateSpellingUIWithMisspelledWord( | 91 virtual void updateSpellingUIWithMisspelledWord( |
92 const WebKit::WebString& word) OVERRIDE; | 92 const blink::WebString& word) OVERRIDE; |
93 | 93 |
94 #if !defined(OS_MACOSX) | 94 #if !defined(OS_MACOSX) |
95 void OnRespondSpellingService( | 95 void OnRespondSpellingService( |
96 int identifier, | 96 int identifier, |
97 bool succeeded, | 97 bool succeeded, |
98 const string16& text, | 98 const string16& text, |
99 const std::vector<SpellCheckResult>& results); | 99 const std::vector<SpellCheckResult>& results); |
100 #endif | 100 #endif |
101 | 101 |
102 // Returns whether |text| has word characters, i.e. whether a spellchecker | 102 // Returns whether |text| has word characters, i.e. whether a spellchecker |
103 // needs to check this text. | 103 // needs to check this text. |
104 bool HasWordCharacters(const string16& text, int index) const; | 104 bool HasWordCharacters(const string16& text, int index) const; |
105 | 105 |
106 #if defined(OS_MACOSX) | 106 #if defined(OS_MACOSX) |
107 void OnAdvanceToNextMisspelling(); | 107 void OnAdvanceToNextMisspelling(); |
108 void OnRespondTextCheck( | 108 void OnRespondTextCheck( |
109 int identifier, | 109 int identifier, |
110 const std::vector<SpellCheckResult>& results); | 110 const std::vector<SpellCheckResult>& results); |
111 void OnToggleSpellPanel(bool is_currently_visible); | 111 void OnToggleSpellPanel(bool is_currently_visible); |
112 #endif | 112 #endif |
113 | 113 |
114 // Holds ongoing spellchecking operations, assigns IDs for the IPC routing. | 114 // Holds ongoing spellchecking operations, assigns IDs for the IPC routing. |
115 WebTextCheckCompletions text_check_completions_; | 115 WebTextCheckCompletions text_check_completions_; |
116 | 116 |
117 // The last text sent to the browser process to spellcheck it and its | 117 // The last text sent to the browser process to spellcheck it and its |
118 // spellchecking results. | 118 // spellchecking results. |
119 string16 last_request_; | 119 string16 last_request_; |
120 WebKit::WebVector<WebKit::WebTextCheckingResult> last_results_; | 120 blink::WebVector<blink::WebTextCheckingResult> last_results_; |
121 | 121 |
122 // True if the browser is showing the spelling panel for us. | 122 // True if the browser is showing the spelling panel for us. |
123 bool spelling_panel_visible_; | 123 bool spelling_panel_visible_; |
124 | 124 |
125 // Weak pointer to shared (per RenderView) spellcheck data. | 125 // Weak pointer to shared (per RenderView) spellcheck data. |
126 SpellCheck* spellcheck_; | 126 SpellCheck* spellcheck_; |
127 | 127 |
128 DISALLOW_COPY_AND_ASSIGN(SpellCheckProvider); | 128 DISALLOW_COPY_AND_ASSIGN(SpellCheckProvider); |
129 }; | 129 }; |
130 | 130 |
131 #endif // CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_H_ | 131 #endif // CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_H_ |
OLD | NEW |