Chromium Code Reviews| 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 #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 void ToWebResultList( | |
|
Hironori Bono
2012/02/16 04:22:45
nit: need 'namespace {' above this function to pre
| |
| 46 const std::vector<SpellCheckResult>& results, | |
| 47 WebVector<WebTextCheckingResult>* web_results) { | |
| 48 WebVector<WebTextCheckingResult> list(results.size()); | |
| 49 for (size_t i = 0; i < results.size(); ++i) { | |
| 50 list[i] = WebTextCheckingResult( | |
| 51 static_cast<WebTextCheckingType>(results[i].type()), | |
| 52 results[i].location(), | |
| 53 results[i].length(), | |
| 54 results[i].replacement()); | |
| 55 } | |
| 56 | |
| 57 list.swap(*web_results); | |
| 58 } | |
| 59 | |
| 60 WebVector<WebTextCheckingResult> ToWebResultList( | |
| 61 const std::vector<SpellCheckResult>& results) { | |
| 62 WebVector<WebTextCheckingResult> web_results; | |
| 63 ToWebResultList(results, &web_results); | |
| 64 return web_results; | |
| 65 } | |
|
Hironori Bono
2012/02/16 04:22:45
nit: need '} // namespace' here.
| |
| 66 | |
| 26 SpellCheckProvider::SpellCheckProvider( | 67 SpellCheckProvider::SpellCheckProvider( |
| 27 content::RenderView* render_view, | 68 content::RenderView* render_view, |
| 28 chrome::ChromeContentRendererClient* renderer_client) | 69 chrome::ChromeContentRendererClient* renderer_client) |
| 29 : content::RenderViewObserver(render_view), | 70 : content::RenderViewObserver(render_view), |
| 30 #if defined(OS_MACOSX) | 71 #if defined(OS_MACOSX) |
| 31 has_document_tag_(false), | 72 has_document_tag_(false), |
| 32 #endif | 73 #endif |
| 33 document_tag_(0), | 74 document_tag_(0), |
| 34 spelling_panel_visible_(false), | 75 spelling_panel_visible_(false), |
| 35 chrome_content_renderer_client_(renderer_client) { | 76 chrome_content_renderer_client_(renderer_client) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 | 191 |
| 151 if (!(mask & WebKit::WebTextCheckingTypeSpelling)) | 192 if (!(mask & WebKit::WebTextCheckingTypeSpelling)) |
| 152 return; | 193 return; |
| 153 | 194 |
| 154 EnsureDocumentTag(); | 195 EnsureDocumentTag(); |
| 155 | 196 |
| 156 // Will be NULL during unit tets. | 197 // Will be NULL during unit tets. |
| 157 if (!chrome_content_renderer_client_) | 198 if (!chrome_content_renderer_client_) |
| 158 return; | 199 return; |
| 159 | 200 |
| 160 std::vector<WebKit::WebTextCheckingResult> tmp_results; | 201 std::vector<SpellCheckResult> tmp_results; |
| 161 chrome_content_renderer_client_->spellcheck()->SpellCheckParagraph( | 202 chrome_content_renderer_client_->spellcheck()->SpellCheckParagraph( |
| 162 string16(text), | 203 string16(text), |
| 163 document_tag_, | 204 document_tag_, |
| 164 &tmp_results); | 205 &tmp_results); |
| 165 *results = tmp_results; | 206 ToWebResultList(tmp_results, results); |
| 166 #endif | 207 #endif |
| 167 } | 208 } |
| 168 | 209 |
| 169 void SpellCheckProvider::requestCheckingOfText( | 210 void SpellCheckProvider::requestCheckingOfText( |
| 170 const WebString& text, | 211 const WebString& text, |
| 171 WebTextCheckingCompletion* completion) { | 212 WebTextCheckingCompletion* completion) { |
| 172 RequestTextChecking(text, document_tag_, completion); | 213 RequestTextChecking(text, document_tag_, completion); |
| 173 } | 214 } |
| 174 | 215 |
| 175 WebString SpellCheckProvider::autoCorrectWord(const WebString& word) { | 216 WebString SpellCheckProvider::autoCorrectWord(const WebString& word) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 if (!render_view()->GetWebView()) | 248 if (!render_view()->GetWebView()) |
| 208 return; | 249 return; |
| 209 render_view()->GetWebView()->focusedFrame()->executeCommand( | 250 render_view()->GetWebView()->focusedFrame()->executeCommand( |
| 210 WebString::fromUTF8("AdvanceToNextMisspelling")); | 251 WebString::fromUTF8("AdvanceToNextMisspelling")); |
| 211 } | 252 } |
| 212 | 253 |
| 213 #if !defined(OS_MACOSX) | 254 #if !defined(OS_MACOSX) |
| 214 void SpellCheckProvider::OnRespondSpellingService( | 255 void SpellCheckProvider::OnRespondSpellingService( |
| 215 int identifier, | 256 int identifier, |
| 216 int tag, | 257 int tag, |
| 217 const std::vector<WebTextCheckingResult>& results) { | 258 const std::vector<SpellCheckResult>& results) { |
| 218 WebTextCheckingCompletion* completion = | 259 WebTextCheckingCompletion* completion = |
| 219 text_check_completions_.Lookup(identifier); | 260 text_check_completions_.Lookup(identifier); |
| 220 if (!completion) | 261 if (!completion) |
| 221 return; | 262 return; |
| 222 text_check_completions_.Remove(identifier); | 263 text_check_completions_.Remove(identifier); |
| 223 completion->didFinishCheckingText(results); | 264 completion->didFinishCheckingText(ToWebResultList(results)); |
| 224 } | 265 } |
| 225 #endif | 266 #endif |
| 226 | 267 |
| 227 #if defined(OS_MACOSX) | 268 #if defined(OS_MACOSX) |
| 228 void SpellCheckProvider::OnRespondTextCheck( | 269 void SpellCheckProvider::OnRespondTextCheck( |
| 229 int identifier, | 270 int identifier, |
| 230 int tag, | 271 int tag, |
| 231 const std::vector<WebTextCheckingResult>& results) { | 272 const std::vector<SpellCheckResult>& results) { |
| 232 WebTextCheckingCompletion* completion = | 273 WebTextCheckingCompletion* completion = |
| 233 text_check_completions_.Lookup(identifier); | 274 text_check_completions_.Lookup(identifier); |
| 234 if (!completion) | 275 if (!completion) |
| 235 return; | 276 return; |
| 236 text_check_completions_.Remove(identifier); | 277 text_check_completions_.Remove(identifier); |
| 237 completion->didFinishCheckingText(results); | 278 completion->didFinishCheckingText(ToWebResultList(results)); |
| 238 } | 279 } |
| 239 #endif | 280 #endif |
| 240 | 281 |
| 241 void SpellCheckProvider::OnToggleSpellPanel(bool is_currently_visible) { | 282 void SpellCheckProvider::OnToggleSpellPanel(bool is_currently_visible) { |
| 242 if (!render_view()->GetWebView()) | 283 if (!render_view()->GetWebView()) |
| 243 return; | 284 return; |
| 244 // We need to tell the webView whether the spelling panel is visible or not so | 285 // 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. | 286 // that it won't need to make ipc calls later. |
| 246 spelling_panel_visible_ = is_currently_visible; | 287 spelling_panel_visible_ = is_currently_visible; |
| 247 render_view()->GetWebView()->focusedFrame()->executeCommand( | 288 render_view()->GetWebView()->focusedFrame()->executeCommand( |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 261 // TODO(darin): There's actually no reason for this to be here. We should | 302 // TODO(darin): There's actually no reason for this to be here. We should |
| 262 // have the browser side manage the document tag. | 303 // have the browser side manage the document tag. |
| 263 #if defined(OS_MACOSX) | 304 #if defined(OS_MACOSX) |
| 264 if (!has_document_tag_) { | 305 if (!has_document_tag_) { |
| 265 // Make the call to get the tag. | 306 // Make the call to get the tag. |
| 266 Send(new SpellCheckHostMsg_GetDocumentTag(routing_id(), &document_tag_)); | 307 Send(new SpellCheckHostMsg_GetDocumentTag(routing_id(), &document_tag_)); |
| 267 has_document_tag_ = true; | 308 has_document_tag_ = true; |
| 268 } | 309 } |
| 269 #endif | 310 #endif |
| 270 } | 311 } |
| OLD | NEW |