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 #ifndef COMPONENTS_VIEW_MANAGER_VIEW_MANAGER_ROOT_IMPL_H_
6 #define COMPONENTS_VIEW_MANAGER_VIEW_MANAGER_ROOT_IMPL_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "components/view_manager/display_manager.h"
10 #include "components/view_manager/public/cpp/types.h"
11 #include "components/view_manager/public/interfaces/view_manager_root.mojom.h"
12 #include "components/view_manager/server_view.h"
14 namespace view_manager
{
16 class ConnectionManager
;
17 class ViewManagerServiceImpl
;
19 // ViewManagerRootImpl is an implementation of the ViewManagerRoot interface.
20 // It serves as a top level root view for a window. Its lifetime is managed by
21 // ConnectionManager. If the connection to the client breaks or if the user
22 // closes the associated window, then this object and related state will be
24 class ViewManagerRootImpl
: public DisplayManagerDelegate
,
25 public mojo::ViewManagerRoot
{
27 // TODO(fsamuel): All these parameters are just plumbing for creating
28 // DisplayManagers. We should probably just store these common parameters
29 // in the DisplayManagerFactory and pass them along on DisplayManager::Create.
30 ViewManagerRootImpl(const ViewId
& root_view_id
,
31 ConnectionManager
* connection_manager
,
33 mojo::ApplicationImpl
* app_impl
,
34 const scoped_refptr
<gles2::GpuState
>& gpu_state
);
35 ~ViewManagerRootImpl() override
;
37 // Initializes state that depends on the existence of a ViewManagerRootImpl.
40 mojo::ViewManagerRootClient
* client() { return client_
.get(); }
42 // Returns whether |view| is a descendant of this root but not itself a
44 bool IsViewAttachedToRoot(const ServerView
* view
) const;
46 // Schedules a paint for the specified region in the coordinates of |view| if
47 // the |view| is in this viewport. Returns whether |view| is in the viewport.
48 bool SchedulePaintIfInViewport(const ServerView
* view
,
49 const gfx::Rect
& bounds
);
51 // Returns the metrics for this viewport.
52 const mojo::ViewportMetrics
& GetViewportMetrics() const;
54 ConnectionManager
* connection_manager() { return connection_manager_
; }
56 // Returns the root ServerView of this viewport.
57 ServerView
* root_view() { return root_
.get(); }
60 void SetViewManagerRootClient(mojo::ViewManagerRootClientPtr client
) override
;
61 void SetViewportSize(mojo::SizePtr size
) override
;
62 void CloneAndAnimate(mojo::Id transport_view_id
) override
;
63 void AddAccelerator(mojo::KeyboardCode keyboard_code
,
64 mojo::EventFlags flags
) override
;
65 void RemoveAccelerator(mojo::KeyboardCode keyboard_code
,
66 mojo::EventFlags flags
) override
;
69 // DisplayManagerDelegate:
70 ServerView
* GetRootView() override
;
71 void OnEvent(mojo::EventPtr event
) override
;
72 void OnDisplayClosed() override
;
73 void OnViewportMetricsChanged(
74 const mojo::ViewportMetrics
& old_metrics
,
75 const mojo::ViewportMetrics
& new_metrics
) override
;
77 ConnectionManager
* const connection_manager_
;
78 mojo::ViewManagerRootClientPtr client_
;
79 scoped_ptr
<ServerView
> root_
;
80 scoped_ptr
<DisplayManager
> display_manager_
;
82 DISALLOW_COPY_AND_ASSIGN(ViewManagerRootImpl
);
85 } // namespace view_manager
87 #endif // COMPONENTS_VIEW_MANAGER_VIEW_MANAGER_ROOT_IMPL_H_