Update V8 to version 4.6.52.
[chromium-blink-merge.git] / components / view_manager / view_manager_root_impl.cc
blob86e740b4bed4bd832f6d19b5851cd741ef9e3b5a
1 // Copyright 2015 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.
5 #include "components/view_manager/view_manager_root_impl.h"
7 #include "components/view_manager/connection_manager.h"
8 #include "components/view_manager/display_manager.h"
9 #include "components/view_manager/public/cpp/types.h"
10 #include "components/view_manager/view_manager_root_delegate.h"
11 #include "mojo/converters/geometry/geometry_type_converters.h"
13 namespace view_manager {
15 ViewManagerRootImpl::ViewManagerRootImpl(
16 ConnectionManager* connection_manager,
17 bool is_headless,
18 mojo::ApplicationImpl* app_impl,
19 const scoped_refptr<gles2::GpuState>& gpu_state)
20 : delegate_(nullptr),
21 connection_manager_(connection_manager),
22 display_manager_(
23 DisplayManager::Create(is_headless, app_impl, gpu_state)) {
24 display_manager_->Init(this);
27 ViewManagerRootImpl::~ViewManagerRootImpl() {
30 void ViewManagerRootImpl::Init(ViewManagerRootDelegate* delegate) {
31 delegate_ = delegate;
32 if (delegate_ && root_)
33 delegate_->OnDisplayInitialized();
36 ViewManagerServiceImpl* ViewManagerRootImpl::GetViewManagerService() {
37 return delegate_ ? delegate_->GetViewManagerService() : nullptr;
40 bool ViewManagerRootImpl::IsViewAttachedToRoot(const ServerView* view) const {
41 return root_->Contains(view) && view != root_.get();
44 bool ViewManagerRootImpl::SchedulePaintIfInViewport(const ServerView* view,
45 const gfx::Rect& bounds) {
46 if (root_->Contains(view)) {
47 display_manager_->SchedulePaint(view, bounds);
48 return true;
50 return false;
53 const mojo::ViewportMetrics& ViewManagerRootImpl::GetViewportMetrics() const {
54 return display_manager_->GetViewportMetrics();
57 void ViewManagerRootImpl::UpdateTextInputState(
58 const ui::TextInputState& state) {
59 display_manager_->UpdateTextInputState(state);
62 void ViewManagerRootImpl::SetImeVisibility(bool visible) {
63 display_manager_->SetImeVisibility(visible);
66 void ViewManagerRootImpl::SetViewManagerRootClient(
67 mojo::ViewManagerRootClientPtr client) {
68 client_ = client.Pass();
71 void ViewManagerRootImpl::SetViewportSize(mojo::SizePtr size) {
72 display_manager_->SetViewportSize(size.To<gfx::Size>());
75 void ViewManagerRootImpl::CloneAndAnimate(mojo::Id transport_view_id) {
76 connection_manager_->CloneAndAnimate(
77 ViewIdFromTransportId(transport_view_id));
80 void ViewManagerRootImpl::AddAccelerator(mojo::KeyboardCode keyboard_code,
81 mojo::EventFlags flags) {
82 connection_manager_->AddAccelerator(this, keyboard_code, flags);
85 void ViewManagerRootImpl::RemoveAccelerator(mojo::KeyboardCode keyboard_code,
86 mojo::EventFlags flags) {
87 connection_manager_->RemoveAccelerator(this, keyboard_code, flags);
90 ServerView* ViewManagerRootImpl::GetRootView() {
91 return root_.get();
94 void ViewManagerRootImpl::OnEvent(mojo::EventPtr event) {
95 connection_manager_->OnEvent(this, event.Pass());
98 void ViewManagerRootImpl::OnDisplayClosed() {
99 if (delegate_)
100 delegate_->OnDisplayClosed();
103 void ViewManagerRootImpl::OnViewportMetricsChanged(
104 const mojo::ViewportMetrics& old_metrics,
105 const mojo::ViewportMetrics& new_metrics) {
106 if (!root_) {
107 root_.reset(connection_manager_->CreateServerView(
108 RootViewId(connection_manager_->GetAndAdvanceNextRootId())));
109 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>()));
110 root_->SetVisible(true);
111 if (delegate_)
112 delegate_->OnDisplayInitialized();
113 } else {
114 root_->SetBounds(gfx::Rect(new_metrics.size_in_pixels.To<gfx::Size>()));
116 // TODO(fsamuel): We shouldn't broadcast this to all connections but only
117 // those within a window root.
118 connection_manager_->ProcessViewportMetricsChanged(old_metrics, new_metrics);
121 } // namespace view_manager