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 "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/spellcheck_marker.h" | 10 #include "chrome/common/spellcheck_marker.h" |
11 #include "chrome/common/spellcheck_messages.h" | 11 #include "chrome/common/spellcheck_messages.h" |
12 #include "chrome/common/spellcheck_result.h" | 12 #include "chrome/common/spellcheck_result.h" |
13 #include "chrome/renderer/spellchecker/spellcheck.h" | 13 #include "chrome/renderer/spellchecker/spellcheck.h" |
14 #include "chrome/renderer/spellchecker/spellcheck_language.h" | 14 #include "chrome/renderer/spellchecker/spellcheck_language.h" |
15 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
16 #include "third_party/WebKit/public/platform/WebVector.h" | 16 #include "third_party/WebKit/public/platform/WebVector.h" |
17 #include "third_party/WebKit/public/web/WebDocument.h" | 17 #include "third_party/WebKit/public/web/WebDocument.h" |
18 #include "third_party/WebKit/public/web/WebElement.h" | 18 #include "third_party/WebKit/public/web/WebElement.h" |
19 #include "third_party/WebKit/public/web/WebFrame.h" | 19 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
20 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" | 20 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" |
21 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" | 21 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" |
22 #include "third_party/WebKit/public/web/WebTextDecorationType.h" | 22 #include "third_party/WebKit/public/web/WebTextDecorationType.h" |
23 #include "third_party/WebKit/public/web/WebView.h" | 23 #include "third_party/WebKit/public/web/WebView.h" |
24 | 24 |
25 using blink::WebElement; | 25 using blink::WebElement; |
26 using blink::WebFrame; | 26 using blink::WebLocalFrame; |
27 using blink::WebString; | 27 using blink::WebString; |
28 using blink::WebTextCheckingCompletion; | 28 using blink::WebTextCheckingCompletion; |
29 using blink::WebTextCheckingResult; | 29 using blink::WebTextCheckingResult; |
30 using blink::WebTextDecorationType; | 30 using blink::WebTextDecorationType; |
31 using blink::WebVector; | 31 using blink::WebVector; |
32 | 32 |
33 static_assert(int(blink::WebTextDecorationTypeSpelling) == | 33 static_assert(int(blink::WebTextDecorationTypeSpelling) == |
34 int(SpellCheckResult::SPELLING), "mismatching enums"); | 34 int(SpellCheckResult::SPELLING), "mismatching enums"); |
35 static_assert(int(blink::WebTextDecorationTypeGrammar) == | 35 static_assert(int(blink::WebTextDecorationTypeGrammar) == |
36 int(SpellCheckResult::GRAMMAR), "mismatching enums"); | 36 int(SpellCheckResult::GRAMMAR), "mismatching enums"); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck) | 105 IPC_MESSAGE_HANDLER(SpellCheckMsg_RespondTextCheck, OnRespondTextCheck) |
106 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) | 106 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) |
107 #endif | 107 #endif |
108 IPC_MESSAGE_UNHANDLED(handled = false) | 108 IPC_MESSAGE_UNHANDLED(handled = false) |
109 IPC_END_MESSAGE_MAP() | 109 IPC_END_MESSAGE_MAP() |
110 return handled; | 110 return handled; |
111 } | 111 } |
112 | 112 |
113 void SpellCheckProvider::FocusedNodeChanged(const blink::WebNode& unused) { | 113 void SpellCheckProvider::FocusedNodeChanged(const blink::WebNode& unused) { |
114 #if defined(USE_BROWSER_SPELLCHECKER) | 114 #if defined(USE_BROWSER_SPELLCHECKER) |
115 WebFrame* frame = render_view()->GetWebView()->focusedFrame(); | 115 WebLocalFrame* frame = render_view()->GetWebView()->focusedFrame(); |
116 WebElement element = frame->document().isNull() ? WebElement() : | 116 WebElement element = frame->document().isNull() ? WebElement() : |
117 frame->document().focusedElement(); | 117 frame->document().focusedElement(); |
118 bool enabled = !element.isNull() && element.isEditable(); | 118 bool enabled = !element.isNull() && element.isEditable(); |
119 bool checked = enabled && frame->isContinuousSpellCheckingEnabled(); | 119 bool checked = enabled && frame->isContinuousSpellCheckingEnabled(); |
120 | 120 |
121 Send(new SpellCheckHostMsg_ToggleSpellCheck(routing_id(), enabled, checked)); | 121 Send(new SpellCheckHostMsg_ToggleSpellCheck(routing_id(), enabled, checked)); |
122 #endif // USE_BROWSER_SPELLCHECKER | 122 #endif // USE_BROWSER_SPELLCHECKER |
123 } | 123 } |
124 | 124 |
125 void SpellCheckProvider::spellCheck( | 125 void SpellCheckProvider::spellCheck( |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 spelling_panel_visible_ = is_currently_visible; | 283 spelling_panel_visible_ = is_currently_visible; |
284 render_view()->GetWebView()->focusedFrame()->executeCommand( | 284 render_view()->GetWebView()->focusedFrame()->executeCommand( |
285 WebString::fromUTF8("ToggleSpellPanel")); | 285 WebString::fromUTF8("ToggleSpellPanel")); |
286 } | 286 } |
287 #endif | 287 #endif |
288 | 288 |
289 void SpellCheckProvider::EnableSpellcheck(bool enable) { | 289 void SpellCheckProvider::EnableSpellcheck(bool enable) { |
290 if (!render_view()->GetWebView()) | 290 if (!render_view()->GetWebView()) |
291 return; | 291 return; |
292 | 292 |
293 WebFrame* frame = render_view()->GetWebView()->focusedFrame(); | 293 WebLocalFrame* frame = render_view()->GetWebView()->focusedFrame(); |
294 if (!frame) | |
dcheng
2016/06/13 17:29:45
This seems like the code is doing the wrong thing:
yabinh
2016/06/16 07:12:57
Most of the null checks is unnecessary, except for
| |
295 return; | |
296 | |
294 frame->enableContinuousSpellChecking(enable); | 297 frame->enableContinuousSpellChecking(enable); |
295 if (!enable) | 298 if (!enable) |
296 frame->removeSpellingMarkers(); | 299 frame->removeSpellingMarkers(); |
297 } | 300 } |
298 | 301 |
299 bool SpellCheckProvider::SatisfyRequestFromCache( | 302 bool SpellCheckProvider::SatisfyRequestFromCache( |
300 const base::string16& text, | 303 const base::string16& text, |
301 WebTextCheckingCompletion* completion) { | 304 WebTextCheckingCompletion* completion) { |
302 size_t last_length = last_request_.length(); | 305 size_t last_length = last_request_.length(); |
303 | 306 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 return true; | 349 return true; |
347 } | 350 } |
348 } | 351 } |
349 | 352 |
350 return false; | 353 return false; |
351 } | 354 } |
352 | 355 |
353 void SpellCheckProvider::OnDestruct() { | 356 void SpellCheckProvider::OnDestruct() { |
354 delete this; | 357 delete this; |
355 } | 358 } |
OLD | NEW |