Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / renderer / render_view_impl_android.cc
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
14 namespace content {
15
16 // Check content::TopControlsState and cc::TopControlsState are kept in sync.
17 COMPILE_ASSERT(int(TOP_CONTROLS_STATE_SHOWN) == int(cc::SHOWN),
18                mismatching_enums);
19 COMPILE_ASSERT(int(TOP_CONTROLS_STATE_HIDDEN) == int(cc::HIDDEN),
20                mismatching_enums);
21 COMPILE_ASSERT(int(TOP_CONTROLS_STATE_BOTH) == int(cc::BOTH),
22                mismatching_enums);
23
24 cc::TopControlsState ContentToCcTopControlsState(
25     TopControlsState state) {
26   return static_cast<cc::TopControlsState>(state);
27 }
28
29 // TODO(mvanouwerkerk): Stop calling this code path and delete it.
30 void RenderViewImpl::OnUpdateTopControlsState(bool enable_hiding,
31                                               bool enable_showing,
32                                               bool animate) {
33   // TODO(tedchoc): Investigate why messages are getting here before the
34   //                compositor has been initialized.
35   LOG_IF(WARNING, !compositor_) << "OnUpdateTopControlsState was unhandled.";
36   if (compositor_) {
37     cc::TopControlsState constraints = cc::BOTH;
38     if (!enable_showing)
39       constraints = cc::HIDDEN;
40     if (!enable_hiding)
41       constraints = cc::SHOWN;
42     cc::TopControlsState current = cc::BOTH;
43     compositor_->UpdateTopControlsState(constraints, current, animate);
44     top_controls_constraints_ = constraints;
45   }
46 }
47
48 void RenderViewImpl::UpdateTopControlsState(TopControlsState constraints,
49                                             TopControlsState current,
50                                             bool animate) {
51   cc::TopControlsState constraints_cc =
52       ContentToCcTopControlsState(constraints);
53   cc::TopControlsState current_cc = ContentToCcTopControlsState(current);
54   if (compositor_)
55     compositor_->UpdateTopControlsState(constraints_cc, current_cc, animate);
56   top_controls_constraints_ = constraints_cc;
57 }
58
59 void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) {
60   if (delta.height == 0)
61     return;
62   if (compositor_) {
63     cc::TopControlsState current = delta.height < 0 ? cc::SHOWN : cc::HIDDEN;
64     compositor_->UpdateTopControlsState(top_controls_constraints_,
65                                         current,
66                                         true);
67   }
68 }
69
70 void RenderViewImpl::OnExtractSmartClipData(const gfx::Rect& rect) {
71   blink::WebString clip_text;
72   blink::WebString clip_html;
73   blink::WebRect clip_rect;
74   webview()->extractSmartClipData(rect, clip_text, clip_html, clip_rect);
75   Send(new ViewHostMsg_SmartClipDataExtracted(
76       routing_id_, clip_text, clip_html, clip_rect));
77 }
78
79 }  // namespace content