OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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_panel.h" | 5 #include "components/spellcheck/renderer/spellcheck_panel.h" |
6 | 6 |
7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "components/spellcheck/common/spellcheck_messages.h" | 8 #include "components/spellcheck/common/spellcheck_messages.h" |
9 #include "content/public/renderer/render_view.h" | 9 #include "content/public/renderer/render_view.h" |
10 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 10 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
11 #include "third_party/WebKit/public/web/WebView.h" | 11 #include "third_party/WebKit/public/web/WebView.h" |
12 | 12 |
13 using blink::WebString; | 13 using blink::WebString; |
14 | 14 |
15 SpellCheckPanel::SpellCheckPanel(content::RenderView* render_view) | 15 SpellCheckPanel::SpellCheckPanel(content::RenderView* render_view) |
16 : content::RenderViewObserver(render_view), | 16 : content::RenderViewObserver(render_view), |
17 content::RenderViewObserverTracker<SpellCheckPanel>(render_view), | 17 content::RenderViewObserverTracker<SpellCheckPanel>(render_view), |
18 spelling_panel_visible_(false) { | 18 spelling_panel_visible_(false) { |
19 render_view->GetWebView()->SetSpellCheckClient(this); | 19 render_view->GetWebView()->SetSpellCheckClient(this); |
20 } | 20 } |
21 | 21 |
22 SpellCheckPanel::~SpellCheckPanel() = default; | 22 SpellCheckPanel::~SpellCheckPanel() = default; |
23 | 23 |
24 void SpellCheckPanel::ShowSpellingUI(bool show) { | 24 void SpellCheckPanel::ShowSpellingUI(bool show) { |
25 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) | |
26 UMA_HISTOGRAM_BOOLEAN("SpellCheck.api.showUI", show); | 25 UMA_HISTOGRAM_BOOLEAN("SpellCheck.api.showUI", show); |
27 Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show)); | 26 Send(new SpellCheckHostMsg_ShowSpellingPanel(routing_id(), show)); |
28 #endif | |
29 } | 27 } |
30 | 28 |
31 bool SpellCheckPanel::IsShowingSpellingUI() { | 29 bool SpellCheckPanel::IsShowingSpellingUI() { |
32 return spelling_panel_visible_; | 30 return spelling_panel_visible_; |
33 } | 31 } |
34 | 32 |
35 void SpellCheckPanel::UpdateSpellingUIWithMisspelledWord( | 33 void SpellCheckPanel::UpdateSpellingUIWithMisspelledWord( |
36 const WebString& word) { | 34 const WebString& word) { |
37 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) | |
38 Send(new SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord( | 35 Send(new SpellCheckHostMsg_UpdateSpellingPanelWithMisspelledWord( |
39 routing_id(), word.Utf16())); | 36 routing_id(), word.Utf16())); |
40 #endif | |
41 } | 37 } |
42 | 38 |
43 bool SpellCheckPanel::OnMessageReceived(const IPC::Message& message) { | 39 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; | 40 bool handled = true; |
49 IPC_BEGIN_MESSAGE_MAP(SpellCheckPanel, message) | 41 IPC_BEGIN_MESSAGE_MAP(SpellCheckPanel, message) |
50 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, | 42 IPC_MESSAGE_HANDLER(SpellCheckMsg_AdvanceToNextMisspelling, |
51 OnAdvanceToNextMisspelling) | 43 OnAdvanceToNextMisspelling) |
52 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) | 44 IPC_MESSAGE_HANDLER(SpellCheckMsg_ToggleSpellPanel, OnToggleSpellPanel) |
53 IPC_MESSAGE_UNHANDLED(handled = false) | 45 IPC_MESSAGE_UNHANDLED(handled = false) |
54 IPC_END_MESSAGE_MAP() | 46 IPC_END_MESSAGE_MAP() |
55 return handled; | 47 return handled; |
56 #endif | |
57 } | 48 } |
58 | 49 |
59 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) | |
60 void SpellCheckPanel::OnAdvanceToNextMisspelling() { | 50 void SpellCheckPanel::OnAdvanceToNextMisspelling() { |
61 if (!render_view()->GetWebView()) | 51 if (!render_view()->GetWebView()) |
62 return; | 52 return; |
63 render_view()->GetWebView()->FocusedFrame()->ExecuteCommand( | 53 render_view()->GetWebView()->FocusedFrame()->ExecuteCommand( |
64 WebString::FromUTF8("AdvanceToNextMisspelling")); | 54 WebString::FromUTF8("AdvanceToNextMisspelling")); |
65 } | 55 } |
66 | 56 |
67 void SpellCheckPanel::OnToggleSpellPanel(bool is_currently_visible) { | 57 void SpellCheckPanel::OnToggleSpellPanel(bool is_currently_visible) { |
68 if (!render_view()->GetWebView()) | 58 if (!render_view()->GetWebView()) |
69 return; | 59 return; |
70 // We need to tell the webView whether the spelling panel is visible or not so | 60 // 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. | 61 // that it won't need to make ipc calls later. |
72 spelling_panel_visible_ = is_currently_visible; | 62 spelling_panel_visible_ = is_currently_visible; |
73 render_view()->GetWebView()->FocusedFrame()->ExecuteCommand( | 63 render_view()->GetWebView()->FocusedFrame()->ExecuteCommand( |
74 WebString::FromUTF8("ToggleSpellPanel")); | 64 WebString::FromUTF8("ToggleSpellPanel")); |
75 } | 65 } |
76 #endif | |
77 | 66 |
78 void SpellCheckPanel::OnDestruct() { | 67 void SpellCheckPanel::OnDestruct() { |
79 delete this; | 68 delete this; |
80 } | 69 } |
OLD | NEW |