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 "mojo/converters/geometry/geometry_type_converters.h"
12 namespace view_manager
{
14 ViewManagerRootImpl::ViewManagerRootImpl(
15 const ViewId
& root_view_id
,
16 ConnectionManager
* connection_manager
,
18 mojo::ApplicationImpl
* app_impl
,
19 const scoped_refptr
<gles2::GpuState
>& gpu_state
)
20 : connection_manager_(connection_manager
),
21 root_(connection_manager
->CreateServerView(root_view_id
)),
23 DisplayManager::Create(is_headless
, app_impl
, gpu_state
)) {
26 ViewManagerRootImpl::~ViewManagerRootImpl() {
29 void ViewManagerRootImpl::Init() {
30 root_
->SetBounds(gfx::Rect(800, 600));
31 root_
->SetVisible(true);
32 display_manager_
->Init(this);
35 bool ViewManagerRootImpl::IsViewAttachedToRoot(const ServerView
* view
) const {
36 return root_
->Contains(view
) && view
!= root_
.get();
39 bool ViewManagerRootImpl::SchedulePaintIfInViewport(const ServerView
* view
,
40 const gfx::Rect
& bounds
) {
41 if (root_
->Contains(view
)) {
42 display_manager_
->SchedulePaint(view
, bounds
);
48 const mojo::ViewportMetrics
& ViewManagerRootImpl::GetViewportMetrics() const {
49 return display_manager_
->GetViewportMetrics();
52 void ViewManagerRootImpl::SetViewManagerRootClient(
53 mojo::ViewManagerRootClientPtr client
) {
54 client_
= client
.Pass();
57 void ViewManagerRootImpl::SetViewportSize(mojo::SizePtr size
) {
58 display_manager_
->SetViewportSize(size
.To
<gfx::Size
>());
61 void ViewManagerRootImpl::CloneAndAnimate(mojo::Id transport_view_id
) {
62 connection_manager_
->CloneAndAnimate(
63 ViewIdFromTransportId(transport_view_id
));
66 void ViewManagerRootImpl::AddAccelerator(mojo::KeyboardCode keyboard_code
,
67 mojo::EventFlags flags
) {
68 connection_manager_
->AddAccelerator(this, keyboard_code
, flags
);
71 void ViewManagerRootImpl::RemoveAccelerator(mojo::KeyboardCode keyboard_code
,
72 mojo::EventFlags flags
) {
73 connection_manager_
->RemoveAccelerator(this, keyboard_code
, flags
);
76 ServerView
* ViewManagerRootImpl::GetRootView() {
80 void ViewManagerRootImpl::OnEvent(mojo::EventPtr event
) {
81 connection_manager_
->OnEvent(this, event
.Pass());
84 void ViewManagerRootImpl::OnDisplayClosed() {
85 connection_manager_
->OnDisplayClosed();
88 void ViewManagerRootImpl::OnViewportMetricsChanged(
89 const mojo::ViewportMetrics
& old_metrics
,
90 const mojo::ViewportMetrics
& new_metrics
) {
91 // TODO(fsamuel: We shouldn't broadcast this to all connections but only those
92 // within a window root.
93 connection_manager_
->ProcessViewportMetricsChanged(old_metrics
, new_metrics
);
96 } // namespace view_manager