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