[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 | |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 16 | // Check content::BrowserControlsState, and |
| 17 | // blink::WebWidget::BrowserControlsState |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 18 | // are kept in sync. |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 19 | static_assert(int(BROWSER_CONTROLS_STATE_SHOWN) == |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 20 | int(blink::kWebBrowserControlsShown), |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 21 | "mismatching enums: SHOWN"); |
| 22 | static_assert(int(BROWSER_CONTROLS_STATE_HIDDEN) == |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 23 | int(blink::kWebBrowserControlsHidden), |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 24 | "mismatching enums: HIDDEN"); |
| 25 | static_assert(int(BROWSER_CONTROLS_STATE_BOTH) == |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 26 | int(blink::kWebBrowserControlsBoth), |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 27 | "mismatching enums: BOTH"); |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 28 | |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 29 | blink::WebBrowserControlsState ContentToBlink(BrowserControlsState state) { |
| 30 | return static_cast<blink::WebBrowserControlsState>(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. |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 35 | void RenderViewImpl::OnUpdateBrowserControlsState(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. |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 40 | LOG_IF(WARNING, !compositor_) |
| 41 | << "OnUpdateBrowserControlsState was unhandled."; |
| 42 | BrowserControlsState constraints = BROWSER_CONTROLS_STATE_BOTH; |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 43 | if (!enable_showing) |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 44 | constraints = BROWSER_CONTROLS_STATE_HIDDEN; |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 45 | if (!enable_hiding) |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 46 | constraints = BROWSER_CONTROLS_STATE_SHOWN; |
| 47 | BrowserControlsState current = BROWSER_CONTROLS_STATE_BOTH; |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 48 | |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 49 | UpdateBrowserControlsState(constraints, current, animate); |
[email protected] | 9b00348 | 2013-05-21 14:00:17 | [diff] [blame] | 50 | } |
| 51 | |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 52 | void RenderViewImpl::UpdateBrowserControlsState( |
| 53 | BrowserControlsState constraints, |
| 54 | BrowserControlsState current, |
| 55 | bool animate) { |
lfg | 8ff3391 | 2016-09-13 20:59:21 | [diff] [blame] | 56 | if (GetWebWidget()) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 57 | GetWebWidget()->UpdateBrowserControlsState( |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 58 | ContentToBlink(constraints), ContentToBlink(current), animate); |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 59 | |
| 60 | top_controls_constraints_ = constraints; |
[email protected] | bbc8856d | 2013-06-14 10:37:04 | [diff] [blame] | 61 | } |
| 62 | |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 63 | void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) { |
[email protected] | bbc8856d | 2013-06-14 10:37:04 | [diff] [blame] | 64 | if (delta.height == 0) |
| 65 | return; |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 66 | |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 67 | BrowserControlsState current = delta.height < 0 |
| 68 | ? BROWSER_CONTROLS_STATE_SHOWN |
| 69 | : BROWSER_CONTROLS_STATE_HIDDEN; |
majidvp | fb80e43 | 2015-02-23 14:15:50 | [diff] [blame] | 70 | |
mdjones | 2ee41afd | 2016-10-27 16:50:20 | [diff] [blame] | 71 | UpdateBrowserControlsState(top_controls_constraints_, current, true); |
[email protected] | da82a1f | 2013-02-26 03:17:59 | [diff] [blame] | 72 | } |
| 73 | |
[email protected] | 198f6412 | 2012-11-05 13:09:31 | [diff] [blame] | 74 | } // namespace content |