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 ViewManagerRootDelegate
;
18 class ViewManagerServiceImpl
;
20 // ViewManagerRootImpl is an implementation of the ViewManagerRoot interface.
21 // It serves as a top level root view for a window. Its lifetime is managed by
22 // ConnectionManager. If the connection to the client breaks or if the user
23 // closes the associated window, then this object and related state will be
25 class ViewManagerRootImpl
: public DisplayManagerDelegate
,
26 public mojo::ViewManagerRoot
{
28 // TODO(fsamuel): All these parameters are just plumbing for creating
29 // DisplayManagers. We should probably just store these common parameters
30 // in the DisplayManagerFactory and pass them along on DisplayManager::Create.
31 ViewManagerRootImpl(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.
38 void Init(ViewManagerRootDelegate
* delegate
);
40 ViewManagerServiceImpl
* GetViewManagerService();
42 mojo::ViewManagerRootClient
* client() const { return client_
.get(); }
44 // Returns whether |view| is a descendant of this root but not itself a
46 bool IsViewAttachedToRoot(const ServerView
* view
) const;
48 // Schedules a paint for the specified region in the coordinates of |view| if
49 // the |view| is in this viewport. Returns whether |view| is in the viewport.
50 bool SchedulePaintIfInViewport(const ServerView
* view
,
51 const gfx::Rect
& bounds
);
53 // Returns the metrics for this viewport.
54 const mojo::ViewportMetrics
& GetViewportMetrics() const;
56 ConnectionManager
* connection_manager() { return connection_manager_
; }
58 // Returns the root ServerView of this viewport.
59 ServerView
* root_view() { return root_
.get(); }
61 void UpdateTextInputState(const ui::TextInputState
& state
);
62 void SetImeVisibility(bool visible
);
65 void SetViewManagerRootClient(mojo::ViewManagerRootClientPtr client
) override
;
66 void SetViewportSize(mojo::SizePtr size
) override
;
67 void CloneAndAnimate(mojo::Id transport_view_id
) override
;
68 void AddAccelerator(mojo::KeyboardCode keyboard_code
,
69 mojo::EventFlags flags
) override
;
70 void RemoveAccelerator(mojo::KeyboardCode keyboard_code
,
71 mojo::EventFlags flags
) override
;
74 // DisplayManagerDelegate:
75 ServerView
* GetRootView() override
;
76 void OnEvent(mojo::EventPtr event
) override
;
77 void OnDisplayClosed() override
;
78 void OnViewportMetricsChanged(
79 const mojo::ViewportMetrics
& old_metrics
,
80 const mojo::ViewportMetrics
& new_metrics
) override
;
82 ViewManagerRootDelegate
* delegate_
;
83 ConnectionManager
* const connection_manager_
;
84 mojo::ViewManagerRootClientPtr client_
;
85 scoped_ptr
<ServerView
> root_
;
86 scoped_ptr
<DisplayManager
> display_manager_
;
88 DISALLOW_COPY_AND_ASSIGN(ViewManagerRootImpl
);
91 } // namespace view_manager
93 #endif // COMPONENTS_VIEW_MANAGER_VIEW_MANAGER_ROOT_IMPL_H_