| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/renderer/render_thread.h" | 10 #include "chrome/renderer/render_thread.h" |
| 11 #include "chrome/renderer/spellchecker/spellcheck.h" | 11 #include "chrome/renderer/spellchecker/spellcheck.h" |
| 12 #include "content/renderer/render_view.h" | 12 #include "content/renderer/render_view.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple
tion.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple
tion.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult
.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult
.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 18 | 18 |
| 19 using WebKit::WebFrame; | 19 using WebKit::WebFrame; |
| 20 using WebKit::WebString; | 20 using WebKit::WebString; |
| 21 using WebKit::WebTextCheckingCompletion; | 21 using WebKit::WebTextCheckingCompletion; |
| 22 using WebKit::WebTextCheckingResult; | 22 using WebKit::WebTextCheckingResult; |
| 23 using WebKit::WebVector; |
| 23 | 24 |
| 24 SpellCheckProvider::SpellCheckProvider(RenderView* render_view, | 25 SpellCheckProvider::SpellCheckProvider(RenderView* render_view, |
| 25 SpellCheck* spellcheck) | 26 SpellCheck* spellcheck) |
| 26 : RenderViewObserver(render_view), | 27 : RenderViewObserver(render_view), |
| 27 #if defined(OS_MACOSX) | 28 #if defined(OS_MACOSX) |
| 28 has_document_tag_(false), | 29 has_document_tag_(false), |
| 29 #endif | 30 #endif |
| 30 document_tag_(0), | 31 document_tag_(0), |
| 31 spelling_panel_visible_(false), | 32 spelling_panel_visible_(false), |
| 32 spellcheck_(spellcheck) { | 33 spellcheck_(spellcheck) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, | 70 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, |
| 70 OnAdvanceToNextMisspelling) | 71 OnAdvanceToNextMisspelling) |
| 71 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck) | 72 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck) |
| 72 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) | 73 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) |
| 73 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellCheck, OnToggleSpellCheck) | 74 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellCheck, OnToggleSpellCheck) |
| 74 IPC_MESSAGE_UNHANDLED(handled = false) | 75 IPC_MESSAGE_UNHANDLED(handled = false) |
| 75 IPC_END_MESSAGE_MAP() | 76 IPC_END_MESSAGE_MAP() |
| 76 return handled; | 77 return handled; |
| 77 } | 78 } |
| 78 | 79 |
| 79 void SpellCheckProvider::spellCheck(const WebString& text, | 80 void SpellCheckProvider::spellCheck( |
| 80 int& misspelled_offset, | 81 const WebString& text, |
| 81 int& misspelled_length) { | 82 int& offset, |
| 83 int& length, |
| 84 WebVector<WebString>* optional_suggestions) { |
| 82 EnsureDocumentTag(); | 85 EnsureDocumentTag(); |
| 83 | 86 |
| 84 string16 word(text); | 87 string16 word(text); |
| 85 RenderThread* thread = RenderThread::current(); | 88 RenderThread* thread = RenderThread::current(); |
| 86 // Will be NULL during unit tests. | 89 // Will be NULL during unit tests. |
| 87 if (thread) { | 90 if (thread) { |
| 91 std::vector<string16> suggestions; |
| 88 thread->spellchecker()->SpellCheckWord( | 92 thread->spellchecker()->SpellCheckWord( |
| 89 word.c_str(), word.size(), document_tag_, | 93 word.c_str(), word.size(), document_tag_, |
| 90 &misspelled_offset, &misspelled_length, NULL); | 94 &offset, &length, optional_suggestions ? & suggestions : NULL); |
| 95 if (optional_suggestions) |
| 96 *optional_suggestions = suggestions; |
| 91 } | 97 } |
| 92 } | 98 } |
| 93 | 99 |
| 100 void SpellCheckProvider::spellCheck(const WebString& text, |
| 101 int& offset, |
| 102 int& length) { |
| 103 spellCheck(text, offset, length, NULL); |
| 104 } |
| 105 |
| 94 void SpellCheckProvider::requestCheckingOfText( | 106 void SpellCheckProvider::requestCheckingOfText( |
| 95 const WebString& text, | 107 const WebString& text, |
| 96 WebTextCheckingCompletion* completion) { | 108 WebTextCheckingCompletion* completion) { |
| 97 RequestTextChecking(text, document_tag_, completion); | 109 RequestTextChecking(text, document_tag_, completion); |
| 98 } | 110 } |
| 99 | 111 |
| 100 WebString SpellCheckProvider::autoCorrectWord(const WebString& word) { | 112 WebString SpellCheckProvider::autoCorrectWord(const WebString& word) { |
| 101 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 113 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 102 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) { | 114 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) { |
| 103 EnsureDocumentTag(); | 115 EnsureDocumentTag(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 // TODO(darin): There's actually no reason for this to be here. We should | 181 // TODO(darin): There's actually no reason for this to be here. We should |
| 170 // have the browser side manage the document tag. | 182 // have the browser side manage the document tag. |
| 171 #if defined(OS_MACOSX) | 183 #if defined(OS_MACOSX) |
| 172 if (!has_document_tag_) { | 184 if (!has_document_tag_) { |
| 173 // Make the call to get the tag. | 185 // Make the call to get the tag. |
| 174 Send(new SpellCheckHostMsg_GetDocumentTag(routing_id(), &document_tag_)); | 186 Send(new SpellCheckHostMsg_GetDocumentTag(routing_id(), &document_tag_)); |
| 175 has_document_tag_ = true; | 187 has_document_tag_ = true; |
| 176 } | 188 } |
| 177 #endif | 189 #endif |
| 178 } | 190 } |
| OLD | NEW |