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

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

Issue 2792233003: Split SpellCheckPanel off SpellCheckProvider (Closed)
Patch Set: Tue Apr 4 15:05:22 PDT 2017 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/spellcheck/renderer/spellcheck_panel.h"
6
7 #include "base/metrics/histogram_macros.h"
8 #include "components/spellcheck/common/spellcheck_messages.h"
9 #include "content/public/renderer/render_view.h"
10 #include "third_party/WebKit/public/web/WebLocalFrame.h"
11 #include "third_party/WebKit/public/web/WebView.h"
12
13 using blink::WebString;
14
15 SpellCheckPanel::SpellCheckPanel(content::RenderView* render_view)
16 : content::RenderViewObserver(render_view),
17 content::RenderViewObserverTracker<SpellCheckPanel>(render_view),
18 spelling_panel_visible_(false) {
19 if (render_view) // NULL in unit tests.
20 render_view->GetWebView()->setSpellCheckClient(this);
21 }
22
23 SpellCheckPanel::~SpellCheckPanel() = default;
24
25 void SpellCheckPanel::showSpellingUI(bool show) {
26 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
27 UMA_HISTOGRAM_BOOLEAN("SpellCheck.api.showUI", show);
Xiaocheng 2017/04/04 22:16:48 Presubmit warning: Some UMA_HISTOGRAM lines have
please use gerrit instead 2017/04/05 15:17:40 I guess you need to update histograms.xml.
Xiaocheng 2017/04/05 18:13:32 Done.
28 Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show));
29 #endif
30 }
31
32 bool SpellCheckPanel::isShowingSpellingUI() {
33 return spelling_panel_visible_;
34 }
35
36 void SpellCheckPanel::updateSpellingUIWithMisspelledWord(
37 const WebString& word) {
38 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
39 Send(new SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord(
40 routing_id(), word.utf16()));
41 #endif
42 }
43
44 bool SpellCheckPanel::OnMessageReceived(const IPC::Message& message) {
please use gerrit instead 2017/04/05 15:17:40 The parent class has a concrete implementation. Se
Xiaocheng 2017/04/05 18:13:32 I think that's how RenderViewObservers are suppose
45 bool handled = true;
46 IPC_BEGIN_MESSAGE_MAP(SpellCheckPanel, message)
47 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
48 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling,
49 OnAdvanceToNextMisspelling)
50 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel)
51 #endif
52 IPC_MESSAGE_UNHANDLED(handled = false)
53 IPC_END_MESSAGE_MAP()
54 return handled;
55 }
56
57 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
58 void SpellCheckProvider::OnAdvanceToNextMisspelling() {
59 if (!render_view()->GetWebView())
60 return;
61 render_view()->GetWebView()->focusedFrame()->executeCommand(
62 WebString::fromUTF8("AdvanceToNextMisspelling"));
63 }
64
65 void SpellCheckPanel::OnToggleSpellPanel(bool is_currently_visible) {
66 if (!render_view()->GetWebView())
67 return;
68 // We need to tell the webView whether the spelling panel is visible or not so
69 // that it won't need to make ipc calls later.
70 spelling_panel_visible_ = is_currently_visible;
71 render_view()->GetWebView()->focusedFrame()->executeCommand(
72 WebString::fromUTF8("ToggleSpellPanel"));
73 }
74 #endif
75
76 void SpellCheckPanel::OnDestruct() {
77 delete this;
78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698