Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: chrome/renderer/spellchecker/spellcheck.cc

Issue 411393004: Adding a word to dictionary should remove spelling markers (Chrome part) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added OVERRIDE to DocumentMarkersRemover destructor Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_thread.h" 16 #include "content/public/renderer/render_thread.h"
17 #include "content/public/renderer/render_view.h" 17 #include "content/public/renderer/render_view.h"
18 #include "content/public/renderer/render_view_visitor.h" 18 #include "content/public/renderer/render_view_visitor.h"
19 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" 19 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h"
20 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" 20 #include "third_party/WebKit/public/web/WebTextCheckingResult.h"
21 #include "third_party/WebKit/public/web/WebTextDecorationType.h" 21 #include "third_party/WebKit/public/web/WebTextDecorationType.h"
22 #include "third_party/WebKit/public/web/WebView.h" 22 #include "third_party/WebKit/public/web/WebView.h"
23 23
24 using blink::WebVector; 24 using blink::WebVector;
25 using blink::WebString;
25 using blink::WebTextCheckingResult; 26 using blink::WebTextCheckingResult;
26 using blink::WebTextDecorationType; 27 using blink::WebTextDecorationType;
27 28
28 namespace { 29 namespace {
29 30
30 class UpdateSpellcheckEnabled : public content::RenderViewVisitor { 31 class UpdateSpellcheckEnabled : public content::RenderViewVisitor {
31 public: 32 public:
32 explicit UpdateSpellcheckEnabled(bool enabled) : enabled_(enabled) {} 33 explicit UpdateSpellcheckEnabled(bool enabled) : enabled_(enabled) {}
33 virtual bool Visit(content::RenderView* render_view) OVERRIDE; 34 virtual bool Visit(content::RenderView* render_view) OVERRIDE;
34 35
(...skipping 25 matching lines...) Expand all
60 if (!render_view || !render_view->GetWebView()) 61 if (!render_view || !render_view->GetWebView())
61 return true; 62 return true;
62 WebVector<uint32> markers; 63 WebVector<uint32> markers;
63 render_view->GetWebView()->spellingMarkers(&markers); 64 render_view->GetWebView()->spellingMarkers(&markers);
64 for (size_t i = 0; i < markers.size(); ++i) 65 for (size_t i = 0; i < markers.size(); ++i)
65 markers_.push_back(markers[i]); 66 markers_.push_back(markers[i]);
66 // Visit all render views. 67 // Visit all render views.
67 return true; 68 return true;
68 } 69 }
69 70
71 class DocumentMarkersRemover : public content::RenderViewVisitor {
72 public:
73 explicit DocumentMarkersRemover(const std::vector<std::string>& words);
74 virtual ~DocumentMarkersRemover() OVERRIDE {}
75 virtual bool Visit(content::RenderView* render_view) OVERRIDE;
76
77 private:
78 WebVector<WebString> words_;
79 DISALLOW_COPY_AND_ASSIGN(DocumentMarkersRemover);
80 };
81
82 DocumentMarkersRemover::DocumentMarkersRemover(
83 const std::vector<std::string>& words)
84 : words_(words.size()) {
85 for (size_t i = 0; i < words.size(); ++i)
86 words_[i] = WebString::fromUTF8(words[i]);
87 }
88
89 bool DocumentMarkersRemover::Visit(content::RenderView* render_view) {
90 if (render_view && render_view->GetWebView())
91 render_view->GetWebView()->removeSpellingMarkersUnderWords(words_);
92 return true;
93 }
94
70 } // namespace 95 } // namespace
71 96
72 class SpellCheck::SpellcheckRequest { 97 class SpellCheck::SpellcheckRequest {
73 public: 98 public:
74 SpellcheckRequest(const base::string16& text, 99 SpellcheckRequest(const base::string16& text,
75 blink::WebTextCheckingCompletion* completion) 100 blink::WebTextCheckingCompletion* completion)
76 : text_(text), completion_(completion) { 101 : text_(text), completion_(completion) {
77 DCHECK(completion); 102 DCHECK(completion);
78 } 103 }
79 ~SpellcheckRequest() {} 104 ~SpellcheckRequest() {}
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 auto_spell_correct_turned_on_ = auto_spell_correct; 164 auto_spell_correct_turned_on_ = auto_spell_correct;
140 #if !defined(OS_MACOSX) 165 #if !defined(OS_MACOSX)
141 PostDelayedSpellCheckTask(pending_request_param_.release()); 166 PostDelayedSpellCheckTask(pending_request_param_.release());
142 #endif 167 #endif
143 } 168 }
144 169
145 void SpellCheck::OnCustomDictionaryChanged( 170 void SpellCheck::OnCustomDictionaryChanged(
146 const std::vector<std::string>& words_added, 171 const std::vector<std::string>& words_added,
147 const std::vector<std::string>& words_removed) { 172 const std::vector<std::string>& words_removed) {
148 custom_dictionary_.OnCustomDictionaryChanged(words_added, words_removed); 173 custom_dictionary_.OnCustomDictionaryChanged(words_added, words_removed);
174 if (words_added.empty())
175 return;
176 DocumentMarkersRemover markersRemover(words_added);
177 content::RenderView::ForEach(&markersRemover);
149 } 178 }
150 179
151 void SpellCheck::OnEnableAutoSpellCorrect(bool enable) { 180 void SpellCheck::OnEnableAutoSpellCorrect(bool enable) {
152 auto_spell_correct_turned_on_ = enable; 181 auto_spell_correct_turned_on_ = enable;
153 } 182 }
154 183
155 void SpellCheck::OnEnableSpellCheck(bool enable) { 184 void SpellCheck::OnEnableSpellCheck(bool enable) {
156 spellcheck_enabled_ = enable; 185 spellcheck_enabled_ = enable;
157 UpdateSpellcheckEnabled updater(enable); 186 UpdateSpellcheckEnabled updater(enable);
158 content::RenderView::ForEach(&updater); 187 content::RenderView::ForEach(&updater);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 list.push_back(WebTextCheckingResult( 403 list.push_back(WebTextCheckingResult(
375 static_cast<WebTextDecorationType>(decoration), 404 static_cast<WebTextDecorationType>(decoration),
376 word_location + line_offset, 405 word_location + line_offset,
377 word_length, 406 word_length,
378 spellcheck_results[i].replacement, 407 spellcheck_results[i].replacement,
379 spellcheck_results[i].hash)); 408 spellcheck_results[i].hash));
380 } 409 }
381 } 410 }
382 textcheck_results->assign(list); 411 textcheck_results->assign(list);
383 } 412 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698