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.h" | 5 #include "chrome/renderer/spellchecker/spellcheck.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
11 #include "chrome/common/spellcheck_common.h" | 11 #include "chrome/common/spellcheck_common.h" |
12 #include "chrome/common/spellcheck_messages.h" | 12 #include "chrome/common/spellcheck_messages.h" |
13 #include "chrome/common/spellcheck_result.h" | 13 #include "chrome/common/spellcheck_result.h" |
14 #include "chrome/renderer/spellchecker/spellcheck_language.h" | 14 #include "chrome/renderer/spellchecker/spellcheck_language.h" |
15 #include "chrome/renderer/spellchecker/spellcheck_provider.h" | 15 #include "chrome/renderer/spellchecker/spellcheck_provider.h" |
16 #include "content/public/renderer/render_frame.h" | |
groby-ooo-7-16
2014/08/19 20:42:05
Do you need this?
Klemen Forstnerič
2014/08/20 20:07:16
Whoops, this is a relic from when I was still eval
| |
16 #include "content/public/renderer/render_thread.h" | 17 #include "content/public/renderer/render_thread.h" |
17 #include "content/public/renderer/render_view.h" | 18 #include "content/public/renderer/render_view.h" |
18 #include "content/public/renderer/render_view_visitor.h" | 19 #include "content/public/renderer/render_view_visitor.h" |
20 #include "third_party/WebKit/public/web/WebFrame.h" | |
groby-ooo-7-16
2014/08/19 20:42:05
Or this?
Klemen Forstnerič
2014/08/20 20:07:16
Same as above. Removed.
| |
19 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" | 21 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" |
20 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" | 22 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" |
21 #include "third_party/WebKit/public/web/WebTextDecorationType.h" | 23 #include "third_party/WebKit/public/web/WebTextDecorationType.h" |
22 #include "third_party/WebKit/public/web/WebView.h" | 24 #include "third_party/WebKit/public/web/WebView.h" |
23 | 25 |
24 using blink::WebVector; | 26 using blink::WebVector; |
27 using blink::WebString; | |
25 using blink::WebTextCheckingResult; | 28 using blink::WebTextCheckingResult; |
26 using blink::WebTextDecorationType; | 29 using blink::WebTextDecorationType; |
27 | 30 |
28 namespace { | 31 namespace { |
29 | 32 |
30 class UpdateSpellcheckEnabled : public content::RenderViewVisitor { | 33 class UpdateSpellcheckEnabled : public content::RenderViewVisitor { |
31 public: | 34 public: |
32 explicit UpdateSpellcheckEnabled(bool enabled) : enabled_(enabled) {} | 35 explicit UpdateSpellcheckEnabled(bool enabled) : enabled_(enabled) {} |
33 virtual bool Visit(content::RenderView* render_view) OVERRIDE; | 36 virtual bool Visit(content::RenderView* render_view) OVERRIDE; |
34 | 37 |
(...skipping 25 matching lines...) Expand all Loading... | |
60 if (!render_view || !render_view->GetWebView()) | 63 if (!render_view || !render_view->GetWebView()) |
61 return true; | 64 return true; |
62 WebVector<uint32> markers; | 65 WebVector<uint32> markers; |
63 render_view->GetWebView()->spellingMarkers(&markers); | 66 render_view->GetWebView()->spellingMarkers(&markers); |
64 for (size_t i = 0; i < markers.size(); ++i) | 67 for (size_t i = 0; i < markers.size(); ++i) |
65 markers_.push_back(markers[i]); | 68 markers_.push_back(markers[i]); |
66 // Visit all render views. | 69 // Visit all render views. |
67 return true; | 70 return true; |
68 } | 71 } |
69 | 72 |
73 class DocumentMarkersRemover : public content::RenderViewVisitor { | |
74 public: | |
75 explicit DocumentMarkersRemover(const std::vector<std::string>& words); | |
76 virtual ~DocumentMarkersRemover() {} | |
77 virtual bool Visit(content::RenderView* render_view) OVERRIDE; | |
78 | |
79 private: | |
80 WebVector<WebString> words_; | |
81 DISALLOW_COPY_AND_ASSIGN(DocumentMarkersRemover); | |
82 }; | |
83 | |
84 DocumentMarkersRemover::DocumentMarkersRemover( | |
85 const std::vector<std::string>& words) | |
86 : words_(words.size()) { | |
87 for (size_t i = 0; i < words.size(); ++i) | |
88 words_[i] = WebString::fromUTF8(words[i]); | |
89 } | |
90 | |
91 bool DocumentMarkersRemover::Visit(content::RenderView* render_view) { | |
92 if (render_view && render_view->GetWebView()) | |
93 render_view->GetWebView()->removeSpellingMarkersUnderWords(words_); | |
94 return true; | |
95 } | |
96 | |
70 } // namespace | 97 } // namespace |
71 | 98 |
72 class SpellCheck::SpellcheckRequest { | 99 class SpellCheck::SpellcheckRequest { |
73 public: | 100 public: |
74 SpellcheckRequest(const base::string16& text, | 101 SpellcheckRequest(const base::string16& text, |
75 blink::WebTextCheckingCompletion* completion) | 102 blink::WebTextCheckingCompletion* completion) |
76 : text_(text), completion_(completion) { | 103 : text_(text), completion_(completion) { |
77 DCHECK(completion); | 104 DCHECK(completion); |
78 } | 105 } |
79 ~SpellcheckRequest() {} | 106 ~SpellcheckRequest() {} |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 auto_spell_correct_turned_on_ = auto_spell_correct; | 166 auto_spell_correct_turned_on_ = auto_spell_correct; |
140 #if !defined(OS_MACOSX) | 167 #if !defined(OS_MACOSX) |
141 PostDelayedSpellCheckTask(pending_request_param_.release()); | 168 PostDelayedSpellCheckTask(pending_request_param_.release()); |
142 #endif | 169 #endif |
143 } | 170 } |
144 | 171 |
145 void SpellCheck::OnCustomDictionaryChanged( | 172 void SpellCheck::OnCustomDictionaryChanged( |
146 const std::vector<std::string>& words_added, | 173 const std::vector<std::string>& words_added, |
147 const std::vector<std::string>& words_removed) { | 174 const std::vector<std::string>& words_removed) { |
148 custom_dictionary_.OnCustomDictionaryChanged(words_added, words_removed); | 175 custom_dictionary_.OnCustomDictionaryChanged(words_added, words_removed); |
176 if (words_added.empty()) | |
177 return; | |
178 DocumentMarkersRemover markersRemover(words_added); | |
groby-ooo-7-16
2014/08/19 20:42:05
I'm slightly queasy about this. OnCustomDictionary
Klemen Forstnerič
2014/08/20 20:07:16
I opened 10 tabs, loaded 10 different websites and
| |
179 content::RenderView::ForEach(&markersRemover); | |
149 } | 180 } |
150 | 181 |
151 void SpellCheck::OnEnableAutoSpellCorrect(bool enable) { | 182 void SpellCheck::OnEnableAutoSpellCorrect(bool enable) { |
152 auto_spell_correct_turned_on_ = enable; | 183 auto_spell_correct_turned_on_ = enable; |
153 } | 184 } |
154 | 185 |
155 void SpellCheck::OnEnableSpellCheck(bool enable) { | 186 void SpellCheck::OnEnableSpellCheck(bool enable) { |
156 spellcheck_enabled_ = enable; | 187 spellcheck_enabled_ = enable; |
157 UpdateSpellcheckEnabled updater(enable); | 188 UpdateSpellcheckEnabled updater(enable); |
158 content::RenderView::ForEach(&updater); | 189 content::RenderView::ForEach(&updater); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 list.push_back(WebTextCheckingResult( | 405 list.push_back(WebTextCheckingResult( |
375 static_cast<WebTextDecorationType>(decoration), | 406 static_cast<WebTextDecorationType>(decoration), |
376 word_location + line_offset, | 407 word_location + line_offset, |
377 word_length, | 408 word_length, |
378 spellcheck_results[i].replacement, | 409 spellcheck_results[i].replacement, |
379 spellcheck_results[i].hash)); | 410 spellcheck_results[i].hash)); |
380 } | 411 } |
381 } | 412 } |
382 textcheck_results->assign(list); | 413 textcheck_results->assign(list); |
383 } | 414 } |
OLD | NEW |