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
,
18 mojo::ApplicationImpl
* app_impl
,
19 const scoped_refptr
<gles2::GpuState
>& gpu_state
,
20 const scoped_refptr
<surfaces::SurfacesState
>& surfaces_state
)
22 connection_manager_(connection_manager
),
24 DisplayManager::Create(is_headless
,
28 display_manager_
->Init(this);
31 ViewManagerRootImpl::~ViewManagerRootImpl() {
34 void ViewManagerRootImpl::Init(ViewManagerRootDelegate
* delegate
) {
36 if (delegate_
&& root_
)
37 delegate_
->OnDisplayInitialized();
40 ViewManagerServiceImpl
* ViewManagerRootImpl::GetViewManagerService() {
41 return delegate_
? delegate_
->GetViewManagerService() : nullptr;
44 bool ViewManagerRootImpl::IsViewAttachedToRoot(const ServerView
* view
) const {
45 return root_
->Contains(view
) && view
!= root_
.get();
48 bool ViewManagerRootImpl::SchedulePaintIfInViewport(const ServerView
* view
,
49 const gfx::Rect
& bounds
) {
50 if (root_
->Contains(view
)) {
51 display_manager_
->SchedulePaint(view
, bounds
);
57 const mojo::ViewportMetrics
& ViewManagerRootImpl::GetViewportMetrics() const {
58 return display_manager_
->GetViewportMetrics();
61 void ViewManagerRootImpl::UpdateTextInputState(
62 const ui::TextInputState
& state
) {
63 display_manager_
->UpdateTextInputState(state
);
66 void ViewManagerRootImpl::SetImeVisibility(bool visible
) {
67 display_manager_
->SetImeVisibility(visible
);
70 void ViewManagerRootImpl::SetViewManagerRootClient(
71 mojo::ViewManagerRootClientPtr client
) {
72 client_
= client
.Pass();
75 void ViewManagerRootImpl::SetViewportSize(mojo::SizePtr size
) {
76 display_manager_
->SetViewportSize(size
.To
<gfx::Size
>());
79 void ViewManagerRootImpl::CloneAndAnimate(mojo::Id transport_view_id
) {
80 connection_manager_
->CloneAndAnimate(
81 ViewIdFromTransportId(transport_view_id
));
84 void ViewManagerRootImpl::AddAccelerator(mojo::KeyboardCode keyboard_code
,
85 mojo::EventFlags flags
) {
86 connection_manager_
->AddAccelerator(this, keyboard_code
, flags
);
89 void ViewManagerRootImpl::RemoveAccelerator(mojo::KeyboardCode keyboard_code
,
90 mojo::EventFlags flags
) {
91 connection_manager_
->RemoveAccelerator(this, keyboard_code
, flags
);
94 ServerView
* ViewManagerRootImpl::GetRootView() {
98 void ViewManagerRootImpl::OnEvent(mojo::EventPtr event
) {
99 connection_manager_
->OnEvent(this, event
.Pass());
102 void ViewManagerRootImpl::OnDisplayClosed() {
104 delegate_
->OnDisplayClosed();
107 void ViewManagerRootImpl::OnViewportMetricsChanged(
108 const mojo::ViewportMetrics
& old_metrics
,
109 const mojo::ViewportMetrics
& new_metrics
) {
111 root_
.reset(connection_manager_
->CreateServerView(
112 RootViewId(connection_manager_
->GetAndAdvanceNextRootId())));
113 root_
->SetBounds(gfx::Rect(new_metrics
.size_in_pixels
.To
<gfx::Size
>()));
114 root_
->SetVisible(true);
116 delegate_
->OnDisplayInitialized();
118 root_
->SetBounds(gfx::Rect(new_metrics
.size_in_pixels
.To
<gfx::Size
>()));
120 // TODO(fsamuel): We shouldn't broadcast this to all connections but only
121 // those within a window root.
122 connection_manager_
->ProcessViewportMetricsChanged(old_metrics
, new_metrics
);
125 } // namespace view_manager