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 "third_party/WebKit/public/web/WebView.h"
13
14namespace content {
15
16// 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.
27void RenderViewImpl::OnUpdateTopControlsState(bool enable_hiding,
28                                              bool enable_showing,
29                                              bool animate) {
30  // TODO(tedchoc): Investigate why messages are getting here before the
31  //                compositor has been initialized.
32  LOG_IF(WARNING, !compositor_) << "OnUpdateTopControlsState was unhandled.";
33  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);
41    top_controls_constraints_ = constraints;
42  }
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);
51  if (compositor_)
52    compositor_->UpdateTopControlsState(constraints_cc, current_cc, animate);
53  top_controls_constraints_ = constraints_cc;
54}
55
56void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) {
57  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  }
65}
66
67void RenderViewImpl::OnExtractSmartClipData(const gfx::Rect& rect) {
68  blink::WebString clip_text;
69  blink::WebString clip_html;
70  blink::WebRect clip_rect;
71  webview()->extractSmartClipData(rect, clip_text, clip_html, clip_rect);
72  Send(new ViewHostMsg_SmartClipDataExtracted(
73      routing_id_, clip_text, clip_html, clip_rect));
74}
75
76}  // namespace content
77