blob: de6fa2d2790a33511b7daeb86643de9d60b8b5ec [file] [log] [blame]
[email protected]198f64122012-11-05 13:09:311// 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]bf189f62012-12-18 03:42:117#include "base/command_line.h"
[email protected]aaf68892013-07-18 00:11:308#include "base/message_loop/message_loop.h"
[email protected]556fd292013-03-18 08:03:049#include "cc/trees/layer_tree_host.h"
[email protected]c4790dcb2013-12-27 22:08:0210#include "content/common/view_messages.h"
[email protected]da82a1f2013-02-26 03:17:5911#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]c4790dcb2013-12-27 22:08:0212#include "third_party/WebKit/public/web/WebView.h"
[email protected]198f64122012-11-05 13:09:3113
14namespace content {
15
[email protected]9b003482013-05-21 14:00:1716// Check content::TopControlsState and cc::TopControlsState are kept in sync.
17COMPILE_ASSERT(int(SHOWN) == int(cc::SHOWN), mismatching_enums);
18COMPILE_ASSERT(int(HIDDEN) == int(cc::HIDDEN), mismatching_enums);
19COMPILE_ASSERT(int(BOTH) == int(cc::BOTH), mismatching_enums);
20
21cc::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]452b4a92013-03-28 21:24:3827void RenderViewImpl::OnUpdateTopControlsState(bool enable_hiding,
28 bool enable_showing,
29 bool animate) {
[email protected]1e62dfcf2013-03-29 08:43:4130 // 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]9b003482013-05-21 14:00:1733 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]bbc8856d2013-06-14 10:37:0441 top_controls_constraints_ = constraints;
[email protected]9b003482013-05-21 14:00:1742 }
43}
44
45void 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]1e62dfcf2013-03-29 08:43:4151 if (compositor_)
[email protected]9b003482013-05-21 14:00:1752 compositor_->UpdateTopControlsState(constraints_cc, current_cc, animate);
[email protected]bbc8856d2013-06-14 10:37:0453 top_controls_constraints_ = constraints_cc;
54}
55
[email protected]180ef242013-11-07 06:50:4656void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) {
[email protected]bbc8856d2013-06-14 10:37:0457 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]da82a1f2013-02-26 03:17:5965}
66
[email protected]c4790dcb2013-12-27 22:08:0267void RenderViewImpl::OnExtractSmartClipData(const gfx::Rect& rect) {
[email protected]e753c052014-06-23 09:52:0268 blink::WebString clip_text;
69 blink::WebRect clip_rect;
70 webview()->getSmartClipData(rect, clip_text, clip_rect);
[email protected]c4790dcb2013-12-27 22:08:0271 Send(new ViewHostMsg_SmartClipDataExtracted(
[email protected]e753c052014-06-23 09:52:0272 routing_id_, clip_text, clip_rect));
[email protected]c4790dcb2013-12-27 22:08:0273}
74
[email protected]198f64122012-11-05 13:09:3175} // namespace content