15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/renderer/render_view_impl.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/command_line.h"
89ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "base/message_loop/message_loop.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/trees/layer_tree_host.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/common/view_messages.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/renderer/gpu/render_widget_compositor.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "third_party/WebKit/public/web/WebView.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Check content::TopControlsState and cc::TopControlsState are kept in sync.
1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)COMPILE_ASSERT(int(SHOWN) == int(cc::SHOWN), mismatching_enums);
1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)COMPILE_ASSERT(int(HIDDEN) == int(cc::HIDDEN), mismatching_enums);
1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)COMPILE_ASSERT(int(BOTH) == int(cc::BOTH), mismatching_enums);
2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)cc::TopControlsState ContentToCcTopControlsState(
2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    TopControlsState state) {
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return static_cast<cc::TopControlsState>(state);
2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// TODO(mvanouwerkerk): Stop calling this code path and delete it.
27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void RenderViewImpl::OnUpdateTopControlsState(bool enable_hiding,
28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                              bool enable_showing,
29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                              bool animate) {
30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // TODO(tedchoc): Investigate why messages are getting here before the
31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  //                compositor has been initialized.
32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  LOG_IF(WARNING, !compositor_) << "OnUpdateTopControlsState was unhandled.";
3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (compositor_) {
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    cc::TopControlsState constraints = cc::BOTH;
3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if (!enable_showing)
3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      constraints = cc::HIDDEN;
3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if (!enable_hiding)
3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      constraints = cc::SHOWN;
3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    cc::TopControlsState current = cc::BOTH;
4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    compositor_->UpdateTopControlsState(constraints, current, animate);
417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    top_controls_constraints_ = constraints;
4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  }
4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void RenderViewImpl::UpdateTopControlsState(TopControlsState constraints,
4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                                            TopControlsState current,
4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                                            bool animate) {
4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  cc::TopControlsState constraints_cc =
4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      ContentToCcTopControlsState(constraints);
5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  cc::TopControlsState current_cc = ContentToCcTopControlsState(current);
51c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (compositor_)
5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    compositor_->UpdateTopControlsState(constraints_cc, current_cc, animate);
537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  top_controls_constraints_ = constraints_cc;
547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void RenderViewImpl::didScrollWithKeyboard(const blink::WebSize& delta) {
577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (delta.height == 0)
587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (compositor_) {
607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    cc::TopControlsState current = delta.height < 0 ? cc::SHOWN : cc::HIDDEN;
617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    compositor_->UpdateTopControlsState(top_controls_constraints_,
627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                        current,
637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                        true);
647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderViewImpl::OnExtractSmartClipData(const gfx::Rect& rect) {
68116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  blink::WebString clip_text;
69116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  blink::WebString clip_html;
70116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  blink::WebRect clip_rect;
71116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  webview()->extractSmartClipData(rect, clip_text, clip_html, clip_rect);
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Send(new ViewHostMsg_SmartClipDataExtracted(
73116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      routing_id_, clip_text, clip_html, clip_rect));
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace content
77