Chromium Code Reviews| Index: components/spellcheck/renderer/spellcheck_panel.cc |
| diff --git a/components/spellcheck/renderer/spellcheck_panel.cc b/components/spellcheck/renderer/spellcheck_panel.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b17cceb30f1192c53e5fa93e56f096641574aecc |
| --- /dev/null |
| +++ b/components/spellcheck/renderer/spellcheck_panel.cc |
| @@ -0,0 +1,78 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/spellcheck/renderer/spellcheck_panel.h" |
| + |
| +#include "base/metrics/histogram_macros.h" |
| +#include "components/spellcheck/common/spellcheck_messages.h" |
| +#include "content/public/renderer/render_view.h" |
| +#include "third_party/WebKit/public/web/WebLocalFrame.h" |
| +#include "third_party/WebKit/public/web/WebView.h" |
| + |
| +using blink::WebString; |
| + |
| +SpellCheckPanel::SpellCheckPanel(content::RenderView* render_view) |
| + : content::RenderViewObserver(render_view), |
| + content::RenderViewObserverTracker<SpellCheckPanel>(render_view), |
| + spelling_panel_visible_(false) { |
| + if (render_view) // NULL in unit tests. |
| + render_view->GetWebView()->setSpellCheckClient(this); |
| +} |
| + |
| +SpellCheckPanel::~SpellCheckPanel() = default; |
| + |
| +void SpellCheckPanel::showSpellingUI(bool show) { |
| +#if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| + 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.
|
| + Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show)); |
| +#endif |
| +} |
| + |
| +bool SpellCheckPanel::isShowingSpellingUI() { |
| + return spelling_panel_visible_; |
| +} |
| + |
| +void SpellCheckPanel::updateSpellingUIWithMisspelledWord( |
| + const WebString& word) { |
| +#if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| + Send(new SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord( |
| + routing_id(), word.utf16())); |
| +#endif |
| +} |
| + |
| +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
|
| + bool handled = true; |
| + IPC_BEGIN_MESSAGE_MAP(SpellCheckPanel, message) |
| +#if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| + IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, |
| + OnAdvanceToNextMisspelling) |
| + IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) |
| +#endif |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + return handled; |
| +} |
| + |
| +#if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| +void SpellCheckProvider::OnAdvanceToNextMisspelling() { |
| + if (!render_view()->GetWebView()) |
| + return; |
| + render_view()->GetWebView()->focusedFrame()->executeCommand( |
| + WebString::fromUTF8("AdvanceToNextMisspelling")); |
| +} |
| + |
| +void SpellCheckPanel::OnToggleSpellPanel(bool is_currently_visible) { |
| + if (!render_view()->GetWebView()) |
| + return; |
| + // We need to tell the webView whether the spelling panel is visible or not so |
| + // that it won't need to make ipc calls later. |
| + spelling_panel_visible_ = is_currently_visible; |
| + render_view()->GetWebView()->focusedFrame()->executeCommand( |
| + WebString::fromUTF8("ToggleSpellPanel")); |
| +} |
| +#endif |
| + |
| +void SpellCheckPanel::OnDestruct() { |
| + delete this; |
| +} |