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/render_view_commands.h" |
| 10 #include "chrome/common/render_messages.h" |
9 #include "chrome/common/spellcheck_messages.h" | 11 #include "chrome/common/spellcheck_messages.h" |
10 #include "chrome/renderer/spellchecker/spellcheck.h" | 12 #include "chrome/renderer/spellchecker/spellcheck.h" |
11 #include "content/renderer/render_view.h" | 13 #include "content/renderer/render_view.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple
tion.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingComple
tion.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult
.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult
.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
17 | 19 |
18 using WebKit::WebFrame; | 20 using WebKit::WebFrame; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, | 73 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, |
72 OnAdvanceToNextMisspelling) | 74 OnAdvanceToNextMisspelling) |
73 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck) | 75 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck) |
74 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) | 76 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) |
75 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellCheck, OnToggleSpellCheck) | 77 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellCheck, OnToggleSpellCheck) |
76 IPC_MESSAGE_UNHANDLED(handled = false) | 78 IPC_MESSAGE_UNHANDLED(handled = false) |
77 IPC_END_MESSAGE_MAP() | 79 IPC_END_MESSAGE_MAP() |
78 return handled; | 80 return handled; |
79 } | 81 } |
80 | 82 |
| 83 void SpellCheckProvider::FocusedNodeChanged(const WebKit::WebNode& unused) { |
| 84 bool is_enabled = false; |
| 85 WebKit::WebNode node = render_view()->GetFocusedNode(); |
| 86 if (!node.isNull()) |
| 87 is_enabled = render_view()->IsEditableNode(node); |
| 88 |
| 89 RenderViewCommandCheckedState checked_state = |
| 90 RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED; |
| 91 if (is_enabled && render_view()->webview()) { |
| 92 WebFrame* frame = render_view()->webview()->focusedFrame(); |
| 93 if (frame->isContinuousSpellCheckingEnabled()) |
| 94 checked_state = RENDER_VIEW_COMMAND_CHECKED_STATE_CHECKED; |
| 95 } |
| 96 |
| 97 Send(new ViewHostMsg_CommandStateChanged( |
| 98 routing_id(), |
| 99 RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK, |
| 100 is_enabled, |
| 101 checked_state)); |
| 102 } |
| 103 |
81 void SpellCheckProvider::spellCheck( | 104 void SpellCheckProvider::spellCheck( |
82 const WebString& text, | 105 const WebString& text, |
83 int& offset, | 106 int& offset, |
84 int& length, | 107 int& length, |
85 WebVector<WebString>* optional_suggestions) { | 108 WebVector<WebString>* optional_suggestions) { |
86 EnsureDocumentTag(); | 109 EnsureDocumentTag(); |
87 | 110 |
88 string16 word(text); | 111 string16 word(text); |
89 // Will be NULL during unit tests. | 112 // Will be NULL during unit tests. |
90 if (spellcheck_) { | 113 if (spellcheck_) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // TODO(darin): There's actually no reason for this to be here. We should | 197 // TODO(darin): There's actually no reason for this to be here. We should |
175 // have the browser side manage the document tag. | 198 // have the browser side manage the document tag. |
176 #if defined(OS_MACOSX) | 199 #if defined(OS_MACOSX) |
177 if (!has_document_tag_) { | 200 if (!has_document_tag_) { |
178 // Make the call to get the tag. | 201 // Make the call to get the tag. |
179 Send(new SpellCheckHostMsg_GetDocumentTag(routing_id(), &document_tag_)); | 202 Send(new SpellCheckHostMsg_GetDocumentTag(routing_id(), &document_tag_)); |
180 has_document_tag_ = true; | 203 has_document_tag_ = true; |
181 } | 204 } |
182 #endif | 205 #endif |
183 } | 206 } |
OLD | NEW |