OLD | NEW |
---|---|
(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. | |
groby-ooo-7-16
2017/04/05 21:19:54
I don't think that's still true, given we don't ha
Xiaocheng
2017/04/05 22:17:48
The nullptr check is removed.
| |
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); | |
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) { | |
45 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) | |
46 return false; | |
47 #endif | |
48 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) | |
49 bool handled = true; | |
50 IPC_BEGIN_MESSAGE_MAP(SpellCheckPanel, message) | |
51 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, | |
52 OnAdvanceToNextMisspelling) | |
53 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) | |
54 IPC_MESSAGE_UNHANDLED(handled = false) | |
55 IPC_END_MESSAGE_MAP() | |
56 return handled; | |
57 #endif | |
58 } | |
59 | |
60 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) | |
61 void SpellCheckPanel::OnAdvanceToNextMisspelling() { | |
62 if (!render_view()->GetWebView()) | |
63 return; | |
64 render_view()->GetWebView()->focusedFrame()->executeCommand( | |
65 WebString::fromUTF8("AdvanceToNextMisspelling")); | |
66 } | |
67 | |
68 void SpellCheckPanel::OnToggleSpellPanel(bool is_currently_visible) { | |
69 if (!render_view()->GetWebView()) | |
70 return; | |
71 // We need to tell the webView whether the spelling panel is visible or not so | |
72 // that it won't need to make ipc calls later. | |
73 spelling_panel_visible_ = is_currently_visible; | |
74 render_view()->GetWebView()->focusedFrame()->executeCommand( | |
75 WebString::fromUTF8("ToggleSpellPanel")); | |
76 } | |
77 #endif | |
78 | |
79 void SpellCheckPanel::OnDestruct() { | |
80 delete this; | |
81 } | |
OLD | NEW |