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

Side by Side Diff: components/spellcheck/renderer/spellcheck.cc

Issue 2816263003: Move spelling marker related functions from WebView to WebLocalFrame (Closed)
Patch Set: Created 3 years, 8 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 | third_party/WebKit/Source/web/WebLocalFrameImpl.h » ('j') | 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 "components/spellcheck/renderer/spellcheck.h" 5 #include "components/spellcheck/renderer/spellcheck.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 11 matching lines...) Expand all
22 #include "components/spellcheck/common/spellcheck_features.h" 22 #include "components/spellcheck/common/spellcheck_features.h"
23 #include "components/spellcheck/common/spellcheck_messages.h" 23 #include "components/spellcheck/common/spellcheck_messages.h"
24 #include "components/spellcheck/common/spellcheck_result.h" 24 #include "components/spellcheck/common/spellcheck_result.h"
25 #include "components/spellcheck/common/spellcheck_switches.h" 25 #include "components/spellcheck/common/spellcheck_switches.h"
26 #include "components/spellcheck/renderer/spellcheck_language.h" 26 #include "components/spellcheck/renderer/spellcheck_language.h"
27 #include "components/spellcheck/renderer/spellcheck_provider.h" 27 #include "components/spellcheck/renderer/spellcheck_provider.h"
28 #include "components/spellcheck/spellcheck_build_features.h" 28 #include "components/spellcheck/spellcheck_build_features.h"
29 #include "content/public/renderer/render_frame.h" 29 #include "content/public/renderer/render_frame.h"
30 #include "content/public/renderer/render_frame_visitor.h" 30 #include "content/public/renderer/render_frame_visitor.h"
31 #include "content/public/renderer/render_thread.h" 31 #include "content/public/renderer/render_thread.h"
32 #include "content/public/renderer/render_view.h"
33 #include "content/public/renderer/render_view_visitor.h"
34 #include "ipc/ipc_platform_file.h" 32 #include "ipc/ipc_platform_file.h"
35 #include "third_party/WebKit/public/platform/WebString.h" 33 #include "third_party/WebKit/public/platform/WebString.h"
36 #include "third_party/WebKit/public/platform/WebVector.h" 34 #include "third_party/WebKit/public/platform/WebVector.h"
35 #include "third_party/WebKit/public/web/WebLocalFrame.h"
37 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" 36 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h"
38 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" 37 #include "third_party/WebKit/public/web/WebTextCheckingResult.h"
39 #include "third_party/WebKit/public/web/WebTextDecorationType.h" 38 #include "third_party/WebKit/public/web/WebTextDecorationType.h"
40 #include "third_party/WebKit/public/web/WebView.h"
41 39
42 using blink::WebVector; 40 using blink::WebVector;
43 using blink::WebString; 41 using blink::WebString;
44 using blink::WebTextCheckingResult; 42 using blink::WebTextCheckingResult;
45 using blink::WebTextDecorationType; 43 using blink::WebTextDecorationType;
46 44
47 namespace { 45 namespace {
48 const int kNoOffset = 0; 46 const int kNoOffset = 0;
49 const int kNoTag = 0; 47 const int kNoTag = 0;
50 48
51 class UpdateSpellcheckEnabled : public content::RenderFrameVisitor { 49 class UpdateSpellcheckEnabled : public content::RenderFrameVisitor {
52 public: 50 public:
53 explicit UpdateSpellcheckEnabled(bool enabled) : enabled_(enabled) {} 51 explicit UpdateSpellcheckEnabled(bool enabled) : enabled_(enabled) {}
54 bool Visit(content::RenderFrame* render_frame) override; 52 bool Visit(content::RenderFrame* render_frame) override;
55 53
56 private: 54 private:
57 bool enabled_; // New spellcheck-enabled state. 55 bool enabled_; // New spellcheck-enabled state.
58 DISALLOW_COPY_AND_ASSIGN(UpdateSpellcheckEnabled); 56 DISALLOW_COPY_AND_ASSIGN(UpdateSpellcheckEnabled);
59 }; 57 };
60 58
61 bool UpdateSpellcheckEnabled::Visit(content::RenderFrame* render_frame) { 59 bool UpdateSpellcheckEnabled::Visit(content::RenderFrame* render_frame) {
62 SpellCheckProvider* provider = SpellCheckProvider::Get(render_frame); 60 SpellCheckProvider* provider = SpellCheckProvider::Get(render_frame);
63 DCHECK(provider); 61 DCHECK(provider);
64 provider->EnableSpellcheck(enabled_); 62 provider->EnableSpellcheck(enabled_);
65 return true; 63 return true;
66 } 64 }
67 65
68 class DocumentMarkersRemover : public content::RenderViewVisitor { 66 class DocumentMarkersRemover : public content::RenderFrameVisitor {
69 public: 67 public:
70 explicit DocumentMarkersRemover(const std::set<std::string>& words); 68 explicit DocumentMarkersRemover(const std::set<std::string>& words);
71 ~DocumentMarkersRemover() override {} 69 ~DocumentMarkersRemover() override {}
72 bool Visit(content::RenderView* render_view) override; 70 bool Visit(content::RenderFrame* render_frame) override;
73 71
74 private: 72 private:
75 WebVector<WebString> words_; 73 WebVector<WebString> words_;
76 DISALLOW_COPY_AND_ASSIGN(DocumentMarkersRemover); 74 DISALLOW_COPY_AND_ASSIGN(DocumentMarkersRemover);
77 }; 75 };
78 76
79 DocumentMarkersRemover::DocumentMarkersRemover( 77 DocumentMarkersRemover::DocumentMarkersRemover(
80 const std::set<std::string>& words) 78 const std::set<std::string>& words)
81 : words_(words.size()) { 79 : words_(words.size()) {
82 std::transform(words.begin(), words.end(), words_.begin(), 80 std::transform(words.begin(), words.end(), words_.begin(),
83 [](const std::string& w) { return WebString::FromUTF8(w); }); 81 [](const std::string& w) { return WebString::FromUTF8(w); });
84 } 82 }
85 83
86 bool DocumentMarkersRemover::Visit(content::RenderView* render_view) { 84 bool DocumentMarkersRemover::Visit(content::RenderFrame* render_frame) {
87 if (render_view && render_view->GetWebView()) 85 // TODO(xiaochengh): Both nullptr checks seem unnecessary.
88 render_view->GetWebView()->RemoveSpellingMarkersUnderWords(words_); 86 if (render_frame && render_frame->GetWebFrame())
87 render_frame->GetWebFrame()->RemoveSpellingMarkersUnderWords(words_);
89 return true; 88 return true;
90 } 89 }
91 90
92 bool IsApostrophe(base::char16 c) { 91 bool IsApostrophe(base::char16 c) {
93 const base::char16 kApostrophe = 0x27; 92 const base::char16 kApostrophe = 0x27;
94 const base::char16 kRightSingleQuotationMark = 0x2019; 93 const base::char16 kRightSingleQuotationMark = 0x2019;
95 return c == kApostrophe || c == kRightSingleQuotationMark; 94 return c == kApostrophe || c == kRightSingleQuotationMark;
96 } 95 }
97 96
98 // Makes sure that the apostrophes in the |spelling_suggestion| are the same 97 // Makes sure that the apostrophes in the |spelling_suggestion| are the same
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 #endif 212 #endif
214 } 213 }
215 214
216 void SpellCheck::OnCustomDictionaryChanged( 215 void SpellCheck::OnCustomDictionaryChanged(
217 const std::set<std::string>& words_added, 216 const std::set<std::string>& words_added,
218 const std::set<std::string>& words_removed) { 217 const std::set<std::string>& words_removed) {
219 custom_dictionary_.OnCustomDictionaryChanged(words_added, words_removed); 218 custom_dictionary_.OnCustomDictionaryChanged(words_added, words_removed);
220 if (words_added.empty()) 219 if (words_added.empty())
221 return; 220 return;
222 DocumentMarkersRemover markersRemover(words_added); 221 DocumentMarkersRemover markersRemover(words_added);
223 content::RenderView::ForEach(&markersRemover); 222 content::RenderFrame::ForEach(&markersRemover);
224 } 223 }
225 224
226 void SpellCheck::OnEnableSpellCheck(bool enable) { 225 void SpellCheck::OnEnableSpellCheck(bool enable) {
227 spellcheck_enabled_ = enable; 226 spellcheck_enabled_ = enable;
228 UpdateSpellcheckEnabled updater(enable); 227 UpdateSpellcheckEnabled updater(enable);
229 content::RenderFrame::ForEach(&updater); 228 content::RenderFrame::ForEach(&updater);
230 } 229 }
231 230
232 // TODO(groby): Make sure we always have a spelling engine, even before 231 // TODO(groby): Make sure we always have a spelling engine, even before
233 // AddSpellcheckLanguage() is called. 232 // AddSpellcheckLanguage() is called.
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 500
502 textcheck_results->Assign(results); 501 textcheck_results->Assign(results);
503 } 502 }
504 503
505 bool SpellCheck::IsSpellcheckEnabled() { 504 bool SpellCheck::IsSpellcheckEnabled() {
506 #if defined(OS_ANDROID) 505 #if defined(OS_ANDROID)
507 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; 506 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false;
508 #endif 507 #endif
509 return spellcheck_enabled_; 508 return spellcheck_enabled_;
510 } 509 }
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/web/WebLocalFrameImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698