Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(662)

Side by Side Diff: chrome/renderer/spellchecker/spellcheck_provider.h

Issue 2198143002: Componentize spellcheck [3]: move renderer/ files to component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_H_
6 #define CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <vector>
12
13 #include "base/id_map.h"
14 #include "base/macros.h"
15 #include "content/public/renderer/render_view_observer.h"
16 #include "content/public/renderer/render_view_observer_tracker.h"
17 #include "third_party/WebKit/public/web/WebSpellCheckClient.h"
18
19 class RenderView;
20 class SpellCheck;
21 class SpellCheckMarker;
22 struct SpellCheckResult;
23
24 namespace blink {
25 class WebString;
26 class WebTextCheckingCompletion;
27 struct WebTextCheckingResult;
28 }
29
30 // This class deals with invoking browser-side spellcheck mechanism
31 // which is done asynchronously.
32 class SpellCheckProvider
33 : public content::RenderViewObserver,
34 public content::RenderViewObserverTracker<SpellCheckProvider>,
35 public blink::WebSpellCheckClient {
36 public:
37 typedef IDMap<blink::WebTextCheckingCompletion> WebTextCheckCompletions;
38
39 SpellCheckProvider(content::RenderView* render_view,
40 SpellCheck* spellcheck);
41 ~SpellCheckProvider() override;
42
43 // Requests async spell and grammar checker to the platform text
44 // checker, which is available on the browser process.
45 void RequestTextChecking(
46 const base::string16& text,
47 blink::WebTextCheckingCompletion* completion,
48 const std::vector<SpellCheckMarker>& markers);
49
50 // The number of ongoing IPC requests.
51 size_t pending_text_request_size() const {
52 return text_check_completions_.size();
53 }
54
55 // Replace shared spellcheck data.
56 void set_spellcheck(SpellCheck* spellcheck) { spellcheck_ = spellcheck; }
57
58 // Enables document-wide spellchecking.
59 void EnableSpellcheck(bool enabled);
60
61 // RenderViewObserver implementation.
62 bool OnMessageReceived(const IPC::Message& message) override;
63 void FocusedNodeChanged(const blink::WebNode& node) override;
64
65 private:
66 friend class TestingSpellCheckProvider;
67
68 // Tries to satisfy a spell check request from the cache in |last_request_|.
69 // Returns true (and cancels/finishes the completion) if it can, false
70 // if the provider should forward the query on.
71 bool SatisfyRequestFromCache(const base::string16& text,
72 blink::WebTextCheckingCompletion* completion);
73
74 // RenderViewObserver implementation.
75 void OnDestruct() override;
76
77 // blink::WebSpellCheckClient implementation.
78 void spellCheck(
79 const blink::WebString& text,
80 int& offset,
81 int& length,
82 blink::WebVector<blink::WebString>* optional_suggestions) override;
83
84 void requestCheckingOfText(
85 const blink::WebString& text,
86 const blink::WebVector<uint32_t>& markers,
87 const blink::WebVector<unsigned>& marker_offsets,
88 blink::WebTextCheckingCompletion* completion) override;
89
90 void cancelAllPendingRequests() override;
91 void showSpellingUI(bool show) override;
92 bool isShowingSpellingUI() override;
93 void updateSpellingUIWithMisspelledWord(
94 const blink::WebString& word) override;
95
96 #if !defined(USE_BROWSER_SPELLCHECKER)
97 void OnRespondSpellingService(
98 int identifier,
99 bool succeeded,
100 const base::string16& text,
101 const std::vector<SpellCheckResult>& results);
102 #endif
103
104 // Returns whether |text| has word characters, i.e. whether a spellchecker
105 // needs to check this text.
106 bool HasWordCharacters(const base::string16& text, int index) const;
107
108 #if defined(USE_BROWSER_SPELLCHECKER)
109 void OnAdvanceToNextMisspelling();
110 void OnRespondTextCheck(
111 int identifier,
112 const base::string16& line,
113 const std::vector<SpellCheckResult>& results);
114 void OnToggleSpellPanel(bool is_currently_visible);
115 #endif
116
117 // Holds ongoing spellchecking operations, assigns IDs for the IPC routing.
118 WebTextCheckCompletions text_check_completions_;
119
120 // The last text sent to the browser process to spellcheck it and its
121 // spellchecking results.
122 base::string16 last_request_;
123 blink::WebVector<blink::WebTextCheckingResult> last_results_;
124
125 // True if the browser is showing the spelling panel for us.
126 bool spelling_panel_visible_;
127
128 // Weak pointer to shared (per RenderView) spellcheck data.
129 SpellCheck* spellcheck_;
130
131 DISALLOW_COPY_AND_ASSIGN(SpellCheckProvider);
132 };
133
134 #endif // CHROME_RENDERER_SPELLCHECKER_SPELLCHECK_PROVIDER_H_
OLDNEW
« no previous file with comments | « chrome/renderer/spellchecker/spellcheck_multilingual_unittest.cc ('k') | chrome/renderer/spellchecker/spellcheck_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698