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"
19 class SurfacesScheduler
;
22 namespace view_manager
{
24 class ConnectionManager
;
25 class ViewManagerRootDelegate
;
26 class ViewManagerServiceImpl
;
28 // ViewManagerRootImpl is an implementation of the ViewManagerRoot interface.
29 // It serves as a top level root view for a window. Its lifetime is managed by
30 // ConnectionManager. If the connection to the client breaks or if the user
31 // closes the associated window, then this object and related state will be
33 class ViewManagerRootImpl
: public DisplayManagerDelegate
,
34 public mojo::ViewManagerRoot
{
36 // TODO(fsamuel): All these parameters are just plumbing for creating
37 // DisplayManagers. We should probably just store these common parameters
38 // in the DisplayManagerFactory and pass them along on DisplayManager::Create.
40 ConnectionManager
* connection_manager
,
42 mojo::ApplicationImpl
* app_impl
,
43 const scoped_refptr
<gles2::GpuState
>& gpu_state
,
44 const scoped_refptr
<surfaces::SurfacesState
>& surfaces_state
);
45 ~ViewManagerRootImpl() override
;
47 // Initializes state that depends on the existence of a ViewManagerRootImpl.
48 void Init(ViewManagerRootDelegate
* delegate
);
50 ViewManagerServiceImpl
* GetViewManagerService();
52 mojo::ViewManagerRootClient
* client() const { return client_
.get(); }
54 // Returns whether |view| is a descendant of this root but not itself a
56 bool IsViewAttachedToRoot(const ServerView
* view
) const;
58 // Schedules a paint for the specified region in the coordinates of |view| if
59 // the |view| is in this viewport. Returns whether |view| is in the viewport.
60 bool SchedulePaintIfInViewport(const ServerView
* view
,
61 const gfx::Rect
& bounds
);
63 // Returns the metrics for this viewport.
64 const mojo::ViewportMetrics
& GetViewportMetrics() const;
66 ConnectionManager
* connection_manager() { return connection_manager_
; }
68 // Returns the root ServerView of this viewport.
69 ServerView
* root_view() { return root_
.get(); }
71 void UpdateTextInputState(const ui::TextInputState
& state
);
72 void SetImeVisibility(bool visible
);
75 void SetViewManagerRootClient(mojo::ViewManagerRootClientPtr client
) override
;
76 void SetViewportSize(mojo::SizePtr size
) override
;
77 void CloneAndAnimate(mojo::Id transport_view_id
) override
;
78 void AddAccelerator(mojo::KeyboardCode keyboard_code
,
79 mojo::EventFlags flags
) override
;
80 void RemoveAccelerator(mojo::KeyboardCode keyboard_code
,
81 mojo::EventFlags flags
) override
;
84 // DisplayManagerDelegate:
85 ServerView
* GetRootView() override
;
86 void OnEvent(mojo::EventPtr event
) override
;
87 void OnDisplayClosed() override
;
88 void OnViewportMetricsChanged(
89 const mojo::ViewportMetrics
& old_metrics
,
90 const mojo::ViewportMetrics
& new_metrics
) override
;
92 ViewManagerRootDelegate
* delegate_
;
93 ConnectionManager
* const connection_manager_
;
94 mojo::ViewManagerRootClientPtr client_
;
95 scoped_ptr
<ServerView
> root_
;
96 scoped_ptr
<DisplayManager
> display_manager_
;
98 DISALLOW_COPY_AND_ASSIGN(ViewManagerRootImpl
);
101 } // namespace view_manager
103 #endif // COMPONENTS_VIEW_MANAGER_VIEW_MANAGER_ROOT_IMPL_H_