[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 | |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 16 | // Check content::TopControlsState and cc::TopControlsState are kept in sync. |
| 17 | COMPILE_ASSERT(int(SHOWN) == int(cc::SHOWN), mismatching_enums); |
| 18 | COMPILE_ASSERT(int(HIDDEN) == int(cc::HIDDEN), mismatching_enums); |
| 19 | COMPILE_ASSERT(int(BOTH) == int(cc::BOTH), mismatching_enums); |
| 20 | |
| 21 | cc::TopControlsState ContentToCcTopControlsState( |
| 22 | TopControlsState state) { |
| 23 | return static_cast<cc::TopControlsState>(state); |
| 24 | } |
| 25 | |
| 26 | // TODO(mvanouwerkerk): Stop calling this code path and delete it. |
[email protected] | 452b4a9 | 2013-03-28 21:24:38 | [diff] [blame] | 27 | void RenderViewImpl::OnUpdateTopControlsState(bool enable_hiding, |
| 28 | bool enable_showing, |
| 29 | bool animate) { |
[email protected] | 1e62dfcf | 2013-03-29 08:43:41 | [diff] [blame] | 30 | // TODO(tedchoc): Investigate why messages are getting here before the |
| 31 | // compositor has been initialized. |
| 32 | LOG_IF(WARNING, !compositor_) << "OnUpdateTopControlsState was unhandled."; |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 33 | if (compositor_) { |
| 34 | cc::TopControlsState constraints = cc::BOTH; |
| 35 | if (!enable_showing) |
| 36 | constraints = cc::HIDDEN; |
| 37 | if (!enable_hiding) |
| 38 | constraints = cc::SHOWN; |
| 39 | cc::TopControlsState current = cc::BOTH; |
| 40 | compositor_->UpdateTopControlsState(constraints, current, animate); |
[email protected] | bbc8856d | 2013-06-14 10:37:04 | [diff] [blame] | 41 | top_controls_constraints_ = constraints; |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
| 45 | void RenderViewImpl::UpdateTopControlsState(TopControlsState constraints, |
| 46 | TopControlsState current, |
| 47 | bool animate) { |
| 48 | cc::TopControlsState constraints_cc = |
| 49 | ContentToCcTopControlsState(constraints); |
| 50 | cc::TopControlsState current_cc = ContentToCcTopControlsState(current); |
[email protected] | 1e62dfcf | 2013-03-29 08:43:41 | [diff] [blame] | 51 | if (compositor_) |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 52 | compositor_->UpdateTopControlsState(constraints_cc, current_cc, animate); |
[email protected] | bbc8856d | 2013-06-14 10:37:04 | [diff] [blame] | 53 | top_controls_constraints_ = constraints_cc; |
| 54 | } |
| 55 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 56 | void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) { |
[email protected] | bbc8856d | 2013-06-14 10:37:04 | [diff] [blame] | 57 | if (delta.height == 0) |
| 58 | return; |
| 59 | if (compositor_) { |
| 60 | cc::TopControlsState current = delta.height < 0 ? cc::SHOWN : cc::HIDDEN; |
| 61 | compositor_->UpdateTopControlsState(top_controls_constraints_, |
| 62 | current, |
| 63 | true); |
| 64 | } |
[email protected] | da82a1f | 2013-02-26 03:17:59 | [diff] [blame] | 65 | } |
| 66 | |
[email protected] | c4790dcb | 2013-12-27 22:08:02 | [diff] [blame] | 67 | void RenderViewImpl::OnExtractSmartClipData(const gfx::Rect& rect) { |
[email protected] | e753c05 | 2014-06-23 09:52:02 | [diff] [blame] | 68 | blink::WebString clip_text; |
| 69 | blink::WebRect clip_rect; |
| 70 | webview()->getSmartClipData(rect, clip_text, clip_rect); |
[email protected] | c4790dcb | 2013-12-27 22:08:02 | [diff] [blame] | 71 | Send(new ViewHostMsg_SmartClipDataExtracted( |
[email protected] | e753c05 | 2014-06-23 09:52:02 | [diff] [blame] | 72 | routing_id_, clip_text, clip_rect)); |
[email protected] | c4790dcb | 2013-12-27 22:08:02 | [diff] [blame] | 73 | } |
| 74 | |
[email protected] | 198f6412 | 2012-11-05 13:09:31 | [diff] [blame] | 75 | } // namespace content |