OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_VIEW_MANAGER_VIEW_TREE_HOST_IMPL_H_ | |
6 #define COMPONENTS_VIEW_MANAGER_VIEW_TREE_HOST_IMPL_H_ | |
7 | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "components/view_manager/display_manager.h" | |
10 #include "components/view_manager/event_dispatcher.h" | |
11 #include "components/view_manager/focus_controller_delegate.h" | |
12 #include "components/view_manager/public/cpp/types.h" | |
13 #include "components/view_manager/public/interfaces/view_tree_host.mojom.h" | |
14 #include "components/view_manager/server_view.h" | |
15 | |
16 namespace cc { | |
17 class SurfaceManager; | |
18 } | |
19 | |
20 namespace surfaces { | |
21 class SurfacesScheduler; | |
22 } | |
23 | |
24 namespace view_manager { | |
25 | |
26 class ConnectionManager; | |
27 class FocusController; | |
28 class ViewTreeHostDelegate; | |
29 class ViewTreeImpl; | |
30 | |
31 // ViewTreeHostImpl is an implementation of the ViewTreeHost interface. | |
32 // It serves as a top level root view for a window. Its lifetime is managed by | |
33 // ConnectionManager. If the connection to the client breaks or if the user | |
34 // closes the associated window, then this object and related state will be | |
35 // deleted. | |
36 class ViewTreeHostImpl : public DisplayManagerDelegate, | |
37 public mojo::ViewTreeHost, | |
38 public FocusControllerDelegate { | |
39 public: | |
40 // TODO(fsamuel): All these parameters are just plumbing for creating | |
41 // DisplayManagers. We should probably just store these common parameters | |
42 // in the DisplayManagerFactory and pass them along on DisplayManager::Create. | |
43 ViewTreeHostImpl( | |
44 mojo::ViewTreeHostClientPtr client, | |
45 ConnectionManager* connection_manager, | |
46 bool is_headless, | |
47 mojo::ApplicationImpl* app_impl, | |
48 const scoped_refptr<gles2::GpuState>& gpu_state, | |
49 const scoped_refptr<surfaces::SurfacesState>& surfaces_state); | |
50 ~ViewTreeHostImpl() override; | |
51 | |
52 // Initializes state that depends on the existence of a ViewTreeHostImpl. | |
53 void Init(ViewTreeHostDelegate* delegate); | |
54 | |
55 ViewTreeImpl* GetViewTree(); | |
56 | |
57 mojo::ViewTreeHostClient* client() const { return client_.get(); } | |
58 | |
59 // Returns whether |view| is a descendant of this root but not itself a | |
60 // root view. | |
61 bool IsViewAttachedToRoot(const ServerView* view) const; | |
62 | |
63 // Schedules a paint for the specified region in the coordinates of |view| if | |
64 // the |view| is in this viewport. Returns whether |view| is in the viewport. | |
65 bool SchedulePaintIfInViewport(const ServerView* view, | |
66 const gfx::Rect& bounds); | |
67 | |
68 // Returns the metrics for this viewport. | |
69 const mojo::ViewportMetrics& GetViewportMetrics() const; | |
70 | |
71 ConnectionManager* connection_manager() { return connection_manager_; } | |
72 | |
73 // Returns the root ServerView of this viewport. | |
74 ServerView* root_view() { return root_.get(); } | |
75 const ServerView* root_view() const { return root_.get(); } | |
76 | |
77 void SetFocusedView(ServerView* view); | |
78 ServerView* GetFocusedView(); | |
79 void DestroyFocusController(); | |
80 | |
81 void UpdateTextInputState(ServerView* view, const ui::TextInputState& state); | |
82 void SetImeVisibility(ServerView* view, bool visible); | |
83 | |
84 void OnAccelerator(uint32_t accelerator_id, mojo::EventPtr event); | |
85 void DispatchInputEventToView(const ServerView* target, mojo::EventPtr event); | |
86 | |
87 // ViewTreeHost: | |
88 void SetSize(mojo::SizePtr size) override; | |
89 void SetTitle(const mojo::String& title) override; | |
90 void AddAccelerator(uint32_t id, | |
91 mojo::KeyboardCode keyboard_code, | |
92 mojo::EventFlags flags) override; | |
93 void RemoveAccelerator(uint32_t id) override; | |
94 | |
95 private: | |
96 void OnClientClosed(); | |
97 | |
98 // DisplayManagerDelegate: | |
99 ServerView* GetRootView() override; | |
100 void OnEvent(mojo::EventPtr event) override; | |
101 void OnDisplayClosed() override; | |
102 void OnViewportMetricsChanged( | |
103 const mojo::ViewportMetrics& old_metrics, | |
104 const mojo::ViewportMetrics& new_metrics) override; | |
105 | |
106 // FocusControllerDelegate: | |
107 void OnFocusChanged(ServerView* old_focused_view, | |
108 ServerView* new_focused_view) override; | |
109 | |
110 ViewTreeHostDelegate* delegate_; | |
111 ConnectionManager* const connection_manager_; | |
112 mojo::ViewTreeHostClientPtr client_; | |
113 EventDispatcher event_dispatcher_; | |
114 scoped_ptr<ServerView> root_; | |
115 scoped_ptr<DisplayManager> display_manager_; | |
116 scoped_ptr<FocusController> focus_controller_; | |
117 | |
118 DISALLOW_COPY_AND_ASSIGN(ViewTreeHostImpl); | |
119 }; | |
120 | |
121 } // namespace view_manager | |
122 | |
123 #endif // COMPONENTS_VIEW_MANAGER_VIEW_TREE_HOST_IMPL_H_ | |
OLD | NEW |