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 render_view->GetWebView()->setSpellCheckClient(this); |
| 20 } |
| 21 |
| 22 SpellCheckPanel::~SpellCheckPanel() = default; |
| 23 |
| 24 void SpellCheckPanel::showSpellingUI(bool show) { |
| 25 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 26 UMA_HISTOGRAM_BOOLEAN("SpellCheck.api.showUI", show); |
| 27 Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show)); |
| 28 #endif |
| 29 } |
| 30 |
| 31 bool SpellCheckPanel::isShowingSpellingUI() { |
| 32 return spelling_panel_visible_; |
| 33 } |
| 34 |
| 35 void SpellCheckPanel::updateSpellingUIWithMisspelledWord( |
| 36 const WebString& word) { |
| 37 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 38 Send(new SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord( |
| 39 routing_id(), word.utf16())); |
| 40 #endif |
| 41 } |
| 42 |
| 43 bool SpellCheckPanel::OnMessageReceived(const IPC::Message& message) { |
| 44 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 45 return false; |
| 46 #endif |
| 47 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 48 bool handled = true; |
| 49 IPC_BEGIN_MESSAGE_MAP(SpellCheckPanel, message) |
| 50 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, |
| 51 OnAdvanceToNextMisspelling) |
| 52 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) |
| 53 IPC_MESSAGE_UNHANDLED(handled = false) |
| 54 IPC_END_MESSAGE_MAP() |
| 55 return handled; |
| 56 #endif |
| 57 } |
| 58 |
| 59 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 60 void SpellCheckPanel::OnAdvanceToNextMisspelling() { |
| 61 if (!render_view()->GetWebView()) |
| 62 return; |
| 63 render_view()->GetWebView()->focusedFrame()->executeCommand( |
| 64 WebString::fromUTF8("AdvanceToNextMisspelling")); |
| 65 } |
| 66 |
| 67 void SpellCheckPanel::OnToggleSpellPanel(bool is_currently_visible) { |
| 68 if (!render_view()->GetWebView()) |
| 69 return; |
| 70 // We need to tell the webView whether the spelling panel is visible or not so |
| 71 // that it won't need to make ipc calls later. |
| 72 spelling_panel_visible_ = is_currently_visible; |
| 73 render_view()->GetWebView()->focusedFrame()->executeCommand( |
| 74 WebString::fromUTF8("ToggleSpellPanel")); |
| 75 } |
| 76 #endif |
| 77 |
| 78 void SpellCheckPanel::OnDestruct() { |
| 79 delete this; |
| 80 } |
OLD | NEW |