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

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

Issue 9368052: Removed WebTextCheckingResult legacy API use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another trial... Created 8 years, 10 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 | Annotate | Revision Log
OLDNEW
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 #include "chrome/renderer/spellchecker/spellcheck_provider.h" 5 #include "chrome/renderer/spellchecker/spellcheck_provider.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/common/chrome_switches.h" 8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/spellcheck_messages.h" 9 #include "chrome/common/spellcheck_messages.h"
10 #include "chrome/common/spellcheck_result.h"
10 #include "chrome/renderer/chrome_content_renderer_client.h" 11 #include "chrome/renderer/chrome_content_renderer_client.h"
11 #include "chrome/renderer/spellchecker/spellcheck.h" 12 #include "chrome/renderer/spellchecker/spellcheck.h"
12 #include "content/public/renderer/render_view.h" 13 #include "content/public/renderer/render_view.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple tion.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple tion.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult .h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult .h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingType.h " 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingType.h "
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
19 20
20 using WebKit::WebFrame; 21 using WebKit::WebFrame;
21 using WebKit::WebString; 22 using WebKit::WebString;
22 using WebKit::WebTextCheckingCompletion; 23 using WebKit::WebTextCheckingCompletion;
23 using WebKit::WebTextCheckingResult; 24 using WebKit::WebTextCheckingResult;
25 using WebKit::WebTextCheckingType;
24 using WebKit::WebVector; 26 using WebKit::WebVector;
25 27
28 COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeSpelling) ==
29 int(SpellCheckResult::SPELLING), mismatching_enums);
30 COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeGrammar) ==
31 int(SpellCheckResult::GRAMMAR), mismatching_enums);
32 COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeLink) ==
33 int(SpellCheckResult::LINK), mismatching_enums);
34 COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeQuote) ==
35 int(SpellCheckResult::QUOTE), mismatching_enums);
36 COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeDash) ==
37 int(SpellCheckResult::DASH), mismatching_enums);
38 COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeReplacement) ==
39 int(SpellCheckResult::REPLACEMENT), mismatching_enums);
40 COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeCorrection) ==
41 int(SpellCheckResult::CORRECTION), mismatching_enums);
42 COMPILE_ASSERT(int(WebKit::WebTextCheckingTypeShowCorrectionPanel) ==
43 int(SpellCheckResult::SHOWCORRECTIONPANEL), mismatching_enums);
44
45 namespace {
46 void ToWebResultList(
47 const std::vector<SpellCheckResult>& results,
48 WebVector<WebTextCheckingResult>* web_results) {
49 WebVector<WebTextCheckingResult> list(results.size());
50 for (size_t i = 0; i < results.size(); ++i) {
51 list[i] = WebTextCheckingResult(
52 static_cast<WebTextCheckingType>(results[i].type),
53 results[i].location,
54 results[i].length,
55 results[i].replacement);
56 }
57
58 list.swap(*web_results);
59 }
60
61 WebVector<WebTextCheckingResult> ToWebResultList(
62 const std::vector<SpellCheckResult>& results) {
63 WebVector<WebTextCheckingResult> web_results;
64 ToWebResultList(results, &web_results);
65 return web_results;
66 }
67 } // namespace
68
26 SpellCheckProvider::SpellCheckProvider( 69 SpellCheckProvider::SpellCheckProvider(
27 content::RenderView* render_view, 70 content::RenderView* render_view,
28 chrome::ChromeContentRendererClient* renderer_client) 71 chrome::ChromeContentRendererClient* renderer_client)
29 : content::RenderViewObserver(render_view), 72 : content::RenderViewObserver(render_view),
30 #if defined(OS_MACOSX) 73 #if defined(OS_MACOSX)
31 has_document_tag_(false), 74 has_document_tag_(false),
32 #endif 75 #endif
33 document_tag_(0), 76 document_tag_(0),
34 spelling_panel_visible_(false), 77 spelling_panel_visible_(false),
35 chrome_content_renderer_client_(renderer_client) { 78 chrome_content_renderer_client_(renderer_client) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 193
151 if (!(mask & WebKit::WebTextCheckingTypeSpelling)) 194 if (!(mask & WebKit::WebTextCheckingTypeSpelling))
152 return; 195 return;
153 196
154 EnsureDocumentTag(); 197 EnsureDocumentTag();
155 198
156 // Will be NULL during unit tets. 199 // Will be NULL during unit tets.
157 if (!chrome_content_renderer_client_) 200 if (!chrome_content_renderer_client_)
158 return; 201 return;
159 202
160 std::vector<WebKit::WebTextCheckingResult> tmp_results; 203 std::vector<SpellCheckResult> tmp_results;
161 chrome_content_renderer_client_->spellcheck()->SpellCheckParagraph( 204 chrome_content_renderer_client_->spellcheck()->SpellCheckParagraph(
162 string16(text), 205 string16(text),
163 document_tag_, 206 document_tag_,
164 &tmp_results); 207 &tmp_results);
165 *results = tmp_results; 208 ToWebResultList(tmp_results, results);
166 #endif 209 #endif
167 } 210 }
168 211
169 void SpellCheckProvider::requestCheckingOfText( 212 void SpellCheckProvider::requestCheckingOfText(
170 const WebString& text, 213 const WebString& text,
171 WebTextCheckingCompletion* completion) { 214 WebTextCheckingCompletion* completion) {
172 RequestTextChecking(text, document_tag_, completion); 215 RequestTextChecking(text, document_tag_, completion);
173 } 216 }
174 217
175 WebString SpellCheckProvider::autoCorrectWord(const WebString& word) { 218 WebString SpellCheckProvider::autoCorrectWord(const WebString& word) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 if (!render_view()->GetWebView()) 250 if (!render_view()->GetWebView())
208 return; 251 return;
209 render_view()->GetWebView()->focusedFrame()->executeCommand( 252 render_view()->GetWebView()->focusedFrame()->executeCommand(
210 WebString::fromUTF8("AdvanceToNextMisspelling")); 253 WebString::fromUTF8("AdvanceToNextMisspelling"));
211 } 254 }
212 255
213 #if !defined(OS_MACOSX) 256 #if !defined(OS_MACOSX)
214 void SpellCheckProvider::OnRespondSpellingService( 257 void SpellCheckProvider::OnRespondSpellingService(
215 int identifier, 258 int identifier,
216 int tag, 259 int tag,
217 const std::vector<WebTextCheckingResult>& results) { 260 const std::vector<SpellCheckResult>& results) {
218 WebTextCheckingCompletion* completion = 261 WebTextCheckingCompletion* completion =
219 text_check_completions_.Lookup(identifier); 262 text_check_completions_.Lookup(identifier);
220 if (!completion) 263 if (!completion)
221 return; 264 return;
222 text_check_completions_.Remove(identifier); 265 text_check_completions_.Remove(identifier);
223 completion->didFinishCheckingText(results); 266 completion->didFinishCheckingText(ToWebResultList(results));
224 } 267 }
225 #endif 268 #endif
226 269
227 #if defined(OS_MACOSX) 270 #if defined(OS_MACOSX)
228 void SpellCheckProvider::OnRespondTextCheck( 271 void SpellCheckProvider::OnRespondTextCheck(
229 int identifier, 272 int identifier,
230 int tag, 273 int tag,
231 const std::vector<WebTextCheckingResult>& results) { 274 const std::vector<SpellCheckResult>& results) {
232 WebTextCheckingCompletion* completion = 275 WebTextCheckingCompletion* completion =
233 text_check_completions_.Lookup(identifier); 276 text_check_completions_.Lookup(identifier);
234 if (!completion) 277 if (!completion)
235 return; 278 return;
236 text_check_completions_.Remove(identifier); 279 text_check_completions_.Remove(identifier);
237 completion->didFinishCheckingText(results); 280 completion->didFinishCheckingText(ToWebResultList(results));
238 } 281 }
239 #endif 282 #endif
240 283
241 void SpellCheckProvider::OnToggleSpellPanel(bool is_currently_visible) { 284 void SpellCheckProvider::OnToggleSpellPanel(bool is_currently_visible) {
242 if (!render_view()->GetWebView()) 285 if (!render_view()->GetWebView())
243 return; 286 return;
244 // We need to tell the webView whether the spelling panel is visible or not so 287 // We need to tell the webView whether the spelling panel is visible or not so
245 // that it won't need to make ipc calls later. 288 // that it won't need to make ipc calls later.
246 spelling_panel_visible_ = is_currently_visible; 289 spelling_panel_visible_ = is_currently_visible;
247 render_view()->GetWebView()->focusedFrame()->executeCommand( 290 render_view()->GetWebView()->focusedFrame()->executeCommand(
(...skipping 13 matching lines...) Expand all
261 // TODO(darin): There's actually no reason for this to be here. We should 304 // TODO(darin): There's actually no reason for this to be here. We should
262 // have the browser side manage the document tag. 305 // have the browser side manage the document tag.
263 #if defined(OS_MACOSX) 306 #if defined(OS_MACOSX)
264 if (!has_document_tag_) { 307 if (!has_document_tag_) {
265 // Make the call to get the tag. 308 // Make the call to get the tag.
266 Send(new SpellCheckHostMsg_GetDocumentTag(routing_id(), &document_tag_)); 309 Send(new SpellCheckHostMsg_GetDocumentTag(routing_id(), &document_tag_));
267 has_document_tag_ = true; 310 has_document_tag_ = true;
268 } 311 }
269 #endif 312 #endif
270 } 313 }
OLDNEW
« no previous file with comments | « chrome/renderer/spellchecker/spellcheck_provider.h ('k') | chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698