[email protected] | 198f6412 | 2012-11-05 13:09:31 | [diff] [blame] | 1 | // Copyright (c) 2012 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 "content/renderer/render_view_impl.h" |
| 6 | |
[email protected] | bf189f6 | 2012-12-18 03:42:11 | [diff] [blame] | 7 | #include "base/command_line.h" |
[email protected] | aaf6889 | 2013-07-18 00:11:30 | [diff] [blame] | 8 | #include "base/message_loop/message_loop.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 9 | #include "cc/trees/layer_tree_host.h" |
[email protected] | c4790dcb | 2013-12-27 22:08:02 | [diff] [blame] | 10 | #include "content/common/view_messages.h" |
[email protected] | da82a1f | 2013-02-26 03:17:59 | [diff] [blame] | 11 | #include "content/renderer/gpu/render_widget_compositor.h" |
[email protected] | c4790dcb | 2013-12-27 22:08:02 | [diff] [blame] | 12 | #include "third_party/WebKit/public/web/WebView.h" |
[email protected] | 198f6412 | 2012-11-05 13:09:31 | [diff] [blame] | 13 | |
| 14 | namespace content { |
| 15 | |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 16 | // Check content::TopControlsState, and blink::WebWidget::TopControlsState |
| 17 | // are kept in sync. |
| 18 | static_assert( |
| 19 | int(TOP_CONTROLS_STATE_SHOWN) == int(blink::WebTopControlsShown), |
| 20 | "mismatching enums: SHOWN"); |
| 21 | static_assert( |
| 22 | int(TOP_CONTROLS_STATE_HIDDEN) == int(blink::WebTopControlsHidden), |
| 23 | "mismatching enums: HIDDEN"); |
| 24 | static_assert( |
| 25 | int(TOP_CONTROLS_STATE_BOTH) == int(blink::WebTopControlsBoth), |
| 26 | "mismatching enums: BOTH"); |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 27 | |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 28 | blink::WebTopControlsState ContentToBlink( |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 29 | TopControlsState state) { |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 30 | return static_cast<blink::WebTopControlsState>(state); |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 31 | } |
| 32 | |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 33 | |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 34 | // TODO(mvanouwerkerk): Stop calling this code path and delete it. |
[email protected] | 452b4a9 | 2013-03-28 21:24:38 | [diff] [blame] | 35 | void RenderViewImpl::OnUpdateTopControlsState(bool enable_hiding, |
| 36 | bool enable_showing, |
| 37 | bool animate) { |
[email protected] | 1e62dfcf | 2013-03-29 08:43:41 | [diff] [blame] | 38 | // TODO(tedchoc): Investigate why messages are getting here before the |
| 39 | // compositor has been initialized. |
| 40 | LOG_IF(WARNING, !compositor_) << "OnUpdateTopControlsState was unhandled."; |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 41 | TopControlsState constraints = TOP_CONTROLS_STATE_BOTH; |
| 42 | if (!enable_showing) |
| 43 | constraints = TOP_CONTROLS_STATE_HIDDEN; |
| 44 | if (!enable_hiding) |
| 45 | constraints = TOP_CONTROLS_STATE_SHOWN; |
| 46 | TopControlsState current = TOP_CONTROLS_STATE_BOTH; |
| 47 | |
| 48 | UpdateTopControlsState(constraints, current, animate); |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void RenderViewImpl::UpdateTopControlsState(TopControlsState constraints, |
| 52 | TopControlsState current, |
| 53 | bool animate) { |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 54 | if (webwidget()) |
| 55 | webwidget()->updateTopControlsState(ContentToBlink(constraints), |
| 56 | ContentToBlink(current), |
| 57 | animate); |
| 58 | |
| 59 | top_controls_constraints_ = constraints; |
[email protected] | bbc8856d | 2013-06-14 10:37:04 | [diff] [blame] | 60 | } |
| 61 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 62 | void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) { |
[email protected] | bbc8856d | 2013-06-14 10:37:04 | [diff] [blame] | 63 | if (delta.height == 0) |
| 64 | return; |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 65 | |
| 66 | TopControlsState current = delta.height < 0 ? TOP_CONTROLS_STATE_SHOWN |
| 67 | : TOP_CONTROLS_STATE_HIDDEN; |
| 68 | |
| 69 | UpdateTopControlsState(top_controls_constraints_, current, true); |
[email protected] | da82a1f | 2013-02-26 03:17:59 | [diff] [blame] | 70 | } |
| 71 | |
[email protected] | c4790dcb | 2013-12-27 22:08:02 | [diff] [blame] | 72 | void RenderViewImpl::OnExtractSmartClipData(const gfx::Rect& rect) { |
[email protected] | e753c05 | 2014-06-23 09:52:02 | [diff] [blame] | 73 | blink::WebString clip_text; |
[email protected] | a3e88a57 | 2014-07-15 06:48:31 | [diff] [blame] | 74 | blink::WebString clip_html; |
[email protected] | e753c05 | 2014-06-23 09:52:02 | [diff] [blame] | 75 | blink::WebRect clip_rect; |
[email protected] | a3e88a57 | 2014-07-15 06:48:31 | [diff] [blame] | 76 | webview()->extractSmartClipData(rect, clip_text, clip_html, clip_rect); |
[email protected] | c4790dcb | 2013-12-27 22:08:02 | [diff] [blame] | 77 | Send(new ViewHostMsg_SmartClipDataExtracted( |
[email protected] | a3e88a57 | 2014-07-15 06:48:31 | [diff] [blame] | 78 | routing_id_, clip_text, clip_html, clip_rect)); |
[email protected] | c4790dcb | 2013-12-27 22:08:02 | [diff] [blame] | 79 | } |
| 80 | |
[email protected] | 198f6412 | 2012-11-05 13:09:31 | [diff] [blame] | 81 | } // namespace content |