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
7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h"
9 #include "cc/trees/layer_tree_host.h"
10 #include "content/common/view_messages.h"
11 #include "content/renderer/gpu/render_widget_compositor.h"
12 #include "content/renderer/media/video_capture_impl_manager.h"
13 #include "content/renderer/render_thread_impl.h"
14 #include "third_party/WebKit/public/web/WebView.h"
15
16 namespace content {
17
18 // Check content::TopControlsState and cc::TopControlsState are kept in sync.
19 COMPILE_ASSERT(int(SHOWN) == int(cc::SHOWN), mismatching_enums);
20 COMPILE_ASSERT(int(HIDDEN) == int(cc::HIDDEN), mismatching_enums);
21 COMPILE_ASSERT(int(BOTH) == int(cc::BOTH), mismatching_enums);
22
ContentToCcTopControlsState(TopControlsState state)23 cc::TopControlsState ContentToCcTopControlsState(
24 TopControlsState state) {
25 return static_cast<cc::TopControlsState>(state);
26 }
27
28 // TODO(mvanouwerkerk): Stop calling this code path and delete it.
OnUpdateTopControlsState(bool enable_hiding,bool enable_showing,bool animate)29 void RenderViewImpl::OnUpdateTopControlsState(bool enable_hiding,
30 bool enable_showing,
31 bool animate) {
32 // TODO(tedchoc): Investigate why messages are getting here before the
33 // compositor has been initialized.
34 LOG_IF(WARNING, !compositor_) << "OnUpdateTopControlsState was unhandled.";
35 if (compositor_) {
36 cc::TopControlsState constraints = cc::BOTH;
37 if (!enable_showing)
38 constraints = cc::HIDDEN;
39 if (!enable_hiding)
40 constraints = cc::SHOWN;
41 cc::TopControlsState current = cc::BOTH;
42 compositor_->UpdateTopControlsState(constraints, current, animate);
43 top_controls_constraints_ = constraints;
44 }
45 }
46
UpdateTopControlsState(TopControlsState constraints,TopControlsState current,bool animate)47 void RenderViewImpl::UpdateTopControlsState(TopControlsState constraints,
48 TopControlsState current,
49 bool animate) {
50 cc::TopControlsState constraints_cc =
51 ContentToCcTopControlsState(constraints);
52 cc::TopControlsState current_cc = ContentToCcTopControlsState(current);
53 if (compositor_)
54 compositor_->UpdateTopControlsState(constraints_cc, current_cc, animate);
55 top_controls_constraints_ = constraints_cc;
56 }
57
didScrollWithKeyboard(const blink::WebSize & delta)58 void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) {
59 if (delta.height == 0)
60 return;
61 if (compositor_) {
62 cc::TopControlsState current = delta.height < 0 ? cc::SHOWN : cc::HIDDEN;
63 compositor_->UpdateTopControlsState(top_controls_constraints_,
64 current,
65 true);
66 }
67 }
68
OnExtractSmartClipData(const gfx::Rect & rect)69 void RenderViewImpl::OnExtractSmartClipData(const gfx::Rect& rect) {
70 blink::WebString clip_text;
71 blink::WebString clip_html;
72 blink::WebRect clip_rect;
73 webview()->extractSmartClipData(rect, clip_text, clip_html, clip_rect);
74 Send(new ViewHostMsg_SmartClipDataExtracted(
75 routing_id_, clip_text, clip_html, clip_rect));
76 }
77
OnPauseVideoCaptureStream()78 void RenderViewImpl::OnPauseVideoCaptureStream() {
79 #if defined(ENABLE_WEBRTC)
80 RenderThreadImpl::current()->video_capture_impl_manager()->
81 SuspendDevices(true);
82 #endif
83 }
84
OnResumeVideoCaptureStream()85 void RenderViewImpl::OnResumeVideoCaptureStream() {
86 #if defined(ENABLE_WEBRTC)
87 RenderThreadImpl::current()->video_capture_impl_manager()->
88 SuspendDevices(false);
89 #endif
90 }
91
92 } // namespace content
93