blob: 9ba176cfcb5597c9f7aae642b995e65e10ff9004 [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
majidvpfb80e432015-02-23 14:15:5016// Check content::TopControlsState, and blink::WebWidget::TopControlsState
17// are kept in sync.
18static_assert(
19 int(TOP_CONTROLS_STATE_SHOWN) == int(blink::WebTopControlsShown),
20 "mismatching enums: SHOWN");
21static_assert(
22 int(TOP_CONTROLS_STATE_HIDDEN) == int(blink::WebTopControlsHidden),
23 "mismatching enums: HIDDEN");
24static_assert(
25 int(TOP_CONTROLS_STATE_BOTH) == int(blink::WebTopControlsBoth),
26 "mismatching enums: BOTH");
[email protected]9b003482013-05-21 14:00:1727
majidvpfb80e432015-02-23 14:15:5028blink::WebTopControlsState ContentToBlink(
[email protected]9b003482013-05-21 14:00:1729 TopControlsState state) {
majidvpfb80e432015-02-23 14:15:5030 return static_cast<blink::WebTopControlsState>(state);
[email protected]9b003482013-05-21 14:00:1731}
32
majidvpfb80e432015-02-23 14:15:5033
[email protected]9b003482013-05-21 14:00:1734// TODO(mvanouwerkerk): Stop calling this code path and delete it.
[email protected]452b4a92013-03-28 21:24:3835void RenderViewImpl::OnUpdateTopControlsState(bool enable_hiding,
36 bool enable_showing,
37 bool animate) {
[email protected]1e62dfcf2013-03-29 08:43:4138 // TODO(tedchoc): Investigate why messages are getting here before the
39 // compositor has been initialized.
40 LOG_IF(WARNING, !compositor_) << "OnUpdateTopControlsState was unhandled.";
majidvpfb80e432015-02-23 14:15:5041 TopControlsState constraints = TOP_CONTROLS_STATE_BOTH;
42 if (!enable_showing)
43 constraints = TOP_CONTROLS_STATE_HIDDEN;
44 if (!enable_hiding)
45 constraints = TOP_CONTROLS_STATE_SHOWN;
46 TopControlsState current = TOP_CONTROLS_STATE_BOTH;
47
48 UpdateTopControlsState(constraints, current, animate);
[email protected]9b003482013-05-21 14:00:1749}
50
51void RenderViewImpl::UpdateTopControlsState(TopControlsState constraints,
52 TopControlsState current,
53 bool animate) {
majidvpfb80e432015-02-23 14:15:5054 if (webwidget())
55 webwidget()->updateTopControlsState(ContentToBlink(constraints),
56 ContentToBlink(current),
57 animate);
58
59 top_controls_constraints_ = constraints;
[email protected]bbc8856d2013-06-14 10:37:0460}
61
[email protected]180ef242013-11-07 06:50:4662void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) {
[email protected]bbc8856d2013-06-14 10:37:0463 if (delta.height == 0)
64 return;
majidvpfb80e432015-02-23 14:15:5065
66 TopControlsState current = delta.height < 0 ? TOP_CONTROLS_STATE_SHOWN
67 : TOP_CONTROLS_STATE_HIDDEN;
68
69 UpdateTopControlsState(top_controls_constraints_, current, true);
[email protected]da82a1f2013-02-26 03:17:5970}
71
[email protected]c4790dcb2013-12-27 22:08:0272void RenderViewImpl::OnExtractSmartClipData(const gfx::Rect& rect) {
[email protected]e753c052014-06-23 09:52:0273 blink::WebString clip_text;
[email protected]a3e88a572014-07-15 06:48:3174 blink::WebString clip_html;
[email protected]e753c052014-06-23 09:52:0275 blink::WebRect clip_rect;
[email protected]a3e88a572014-07-15 06:48:3176 webview()->extractSmartClipData(rect, clip_text, clip_html, clip_rect);
[email protected]c4790dcb2013-12-27 22:08:0277 Send(new ViewHostMsg_SmartClipDataExtracted(
[email protected]a3e88a572014-07-15 06:48:3178 routing_id_, clip_text, clip_html, clip_rect));
[email protected]c4790dcb2013-12-27 22:08:0279}
80
[email protected]198f64122012-11-05 13:09:3181} // namespace content