OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_ | 5 #ifndef MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_ |
6 #define MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_ | 6 #define MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "mojo/aura/window_tree_host_mojo.h" | |
13 #include "mojo/public/cpp/application/application_delegate.h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
14 #include "mojo/public/cpp/application/interface_factory_impl.h" | 13 #include "mojo/public/cpp/application/interface_factory_impl.h" |
15 #include "mojo/public/cpp/bindings/string.h" | 14 #include "mojo/public/cpp/bindings/string.h" |
16 #include "mojo/services/public/cpp/view_manager/types.h" | 15 #include "mojo/services/public/cpp/view_manager/types.h" |
17 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" | 16 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h" |
18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 17 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
19 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 18 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
20 #include "mojo/services/public/interfaces/window_manager/window_manager_internal
.mojom.h" | 19 #include "mojo/services/public/interfaces/window_manager/window_manager_internal
.mojom.h" |
| 20 #include "mojo/services/window_manager/focus_controller_observer.h" |
21 #include "mojo/services/window_manager/native_viewport_event_dispatcher_impl.h" | 21 #include "mojo/services/window_manager/native_viewport_event_dispatcher_impl.h" |
| 22 #include "mojo/services/window_manager/view_target.h" |
22 #include "mojo/services/window_manager/window_manager_impl.h" | 23 #include "mojo/services/window_manager/window_manager_impl.h" |
23 #include "ui/aura/client/focus_change_observer.h" | |
24 #include "ui/events/event_handler.h" | 24 #include "ui/events/event_handler.h" |
25 #include "ui/wm/public/activation_change_observer.h" | |
26 | 25 |
27 namespace aura { | 26 namespace gfx { |
28 namespace client { | 27 class Size; |
29 class ActivationClient; | |
30 class FocusClient; | |
31 } | |
32 class Window; | |
33 } | |
34 | |
35 namespace wm { | |
36 class FocusRules; | |
37 class ScopedCaptureClient; | |
38 } | 28 } |
39 | 29 |
40 namespace mojo { | 30 namespace mojo { |
41 | 31 |
42 class AuraInit; | 32 class FocusController; |
43 class DummyDelegate; | 33 class FocusRules; |
44 class WindowManagerClient; | 34 class WindowManagerClient; |
45 class WindowManagerDelegate; | 35 class WindowManagerDelegate; |
46 class WindowManagerImpl; | 36 class WindowManagerImpl; |
| 37 class ViewEventDispatcher; |
47 | 38 |
48 // Implements core window manager functionality that could conceivably be shared | 39 // Implements core window manager functionality that could conceivably be shared |
49 // across multiple window managers implementing superficially different user | 40 // across multiple window managers implementing superficially different user |
50 // experiences. Establishes communication with the view manager. | 41 // experiences. Establishes communication with the view manager. |
51 // A window manager wishing to use this core should create and own an instance | 42 // A window manager wishing to use this core should create and own an instance |
52 // of this object. They may implement the associated ViewManager/WindowManager | 43 // of this object. They may implement the associated ViewManager/WindowManager |
53 // delegate interfaces exposed by the view manager, this object provides the | 44 // delegate interfaces exposed by the view manager, this object provides the |
54 // canonical implementation of said interfaces but will call out to the wrapped | 45 // canonical implementation of said interfaces but will call out to the wrapped |
55 // instances. | 46 // instances. |
56 // This object maintains an aura::WindowTreeHost containing a hierarchy of | |
57 // aura::Windows. Window manager functionality (e.g. focus, activation, | |
58 // modality, etc.) are implemented using aura core window manager components. | |
59 class WindowManagerApp : public ApplicationDelegate, | 47 class WindowManagerApp : public ApplicationDelegate, |
60 public ViewManagerDelegate, | 48 public ViewManagerDelegate, |
61 public ViewObserver, | 49 public ViewObserver, |
62 public ui::EventHandler, | 50 public ui::EventHandler, |
63 public aura::client::FocusChangeObserver, | 51 public FocusControllerObserver, |
64 public aura::client::ActivationChangeObserver, | |
65 public InterfaceFactory<WindowManagerInternal> { | 52 public InterfaceFactory<WindowManagerInternal> { |
66 public: | 53 public: |
67 WindowManagerApp(ViewManagerDelegate* view_manager_delegate, | 54 WindowManagerApp(ViewManagerDelegate* view_manager_delegate, |
68 WindowManagerDelegate* window_manager_delegate); | 55 WindowManagerDelegate* window_manager_delegate); |
69 ~WindowManagerApp() override; | 56 ~WindowManagerApp() override; |
70 | 57 |
71 static View* GetViewForWindow(aura::Window* window); | 58 static View* GetViewForViewTarget(ViewTarget* view); |
72 aura::Window* GetWindowForViewId(Id view); | 59 ViewTarget* GetViewTargetForViewId(Id view); |
| 60 |
| 61 mojo::ViewEventDispatcher* event_dispatcher() { |
| 62 return view_event_dispatcher_.get(); |
| 63 } |
73 | 64 |
74 // Register/deregister new connections to the window manager service. | 65 // Register/deregister new connections to the window manager service. |
75 void AddConnection(WindowManagerImpl* connection); | 66 void AddConnection(WindowManagerImpl* connection); |
76 void RemoveConnection(WindowManagerImpl* connection); | 67 void RemoveConnection(WindowManagerImpl* connection); |
77 | 68 |
78 // These are canonical implementations of the window manager API methods. | 69 // These are canonical implementations of the window manager API methods. |
79 void SetCapture(Id view); | 70 void SetCapture(Id view); |
80 void FocusWindow(Id view); | 71 void FocusWindow(Id view); |
81 void ActivateWindow(Id view); | 72 void ActivateWindow(Id view); |
82 | 73 |
83 void SetViewportSize(const gfx::Size&); | 74 void SetViewportSize(const gfx::Size& size); |
84 | 75 |
85 bool IsReady() const; | 76 bool IsReady() const; |
86 | 77 |
87 // A client of this object will use this accessor to gain access to the | 78 FocusController* focus_controller() { return focus_controller_.get(); } |
88 // aura::Window hierarchy and attach event handlers. | |
89 WindowTreeHostMojo* host() { return window_tree_host_.get(); } | |
90 | 79 |
91 void InitFocus(wm::FocusRules* rules); | 80 void InitFocus(scoped_ptr<FocusRules> rules); |
92 | 81 |
93 // WindowManagerImpl::Embed() forwards to this. If connected to ViewManager | 82 // WindowManagerImpl::Embed() forwards to this. If connected to ViewManager |
94 // then forwards to delegate, otherwise waits for connection to establish then | 83 // then forwards to delegate, otherwise waits for connection to establish then |
95 // forwards. | 84 // forwards. |
96 void Embed(const String& url, | 85 void Embed(const String& url, |
97 InterfaceRequest<ServiceProvider> service_provider); | 86 InterfaceRequest<ServiceProvider> service_provider); |
98 | 87 |
99 // Overridden from ApplicationDelegate: | 88 // Overridden from ApplicationDelegate: |
100 void Initialize(ApplicationImpl* impl) override; | 89 void Initialize(ApplicationImpl* impl) override; |
101 bool ConfigureIncomingConnection(ApplicationConnection* connection) override; | 90 bool ConfigureIncomingConnection(ApplicationConnection* connection) override; |
102 | 91 |
103 private: | 92 private: |
104 // TODO(sky): rename this. Connections is ambiguous. | 93 // TODO(sky): rename this. Connections is ambiguous. |
105 typedef std::set<WindowManagerImpl*> Connections; | 94 typedef std::set<WindowManagerImpl*> Connections; |
106 typedef std::map<Id, aura::Window*> ViewIdToWindowMap; | 95 typedef std::map<Id, ViewTarget*> ViewIdToViewTargetMap; |
107 | 96 |
108 struct PendingEmbed; | 97 struct PendingEmbed; |
109 class WindowManagerInternalImpl; | 98 class WindowManagerInternalImpl; |
110 | 99 |
| 100 // Creates an ViewTarget for every view in the hierarchy beneath |view|, |
| 101 // and adds to the registry so that it can be retrieved later via |
| 102 // GetViewTargetForViewId(). |
| 103 // TODO(beng): perhaps View should have a property bag. |
| 104 void RegisterSubtree(View* view, ViewTarget* parent); |
| 105 |
| 106 // Recursively invokes Unregister() for |view| and all its descendants. |
| 107 void UnregisterSubtree(View* view); |
| 108 |
| 109 // Deletes the ViewTarget associated with the hierarchy beneath |id|, |
| 110 // and removes from the registry. |
| 111 void Unregister(View* view); |
| 112 |
111 // Overridden from ViewManagerDelegate: | 113 // Overridden from ViewManagerDelegate: |
112 void OnEmbed(ViewManager* view_manager, | 114 void OnEmbed(ViewManager* view_manager, |
113 View* root, | 115 View* root, |
114 ServiceProviderImpl* exported_services, | 116 ServiceProviderImpl* exported_services, |
115 scoped_ptr<ServiceProvider> imported_services) override; | 117 scoped_ptr<ServiceProvider> imported_services) override; |
116 void OnViewManagerDisconnected(ViewManager* view_manager) override; | 118 void OnViewManagerDisconnected(ViewManager* view_manager) override; |
117 | 119 |
118 // Overridden from ViewObserver: | 120 // Overridden from ViewObserver: |
119 void OnTreeChanged(const ViewObserver::TreeChangeParams& params) override; | 121 void OnTreeChanged(const ViewObserver::TreeChangeParams& params) override; |
120 void OnViewDestroying(View* view) override; | 122 void OnViewDestroying(View* view) override; |
121 void OnViewBoundsChanged(View* view, | 123 void OnViewBoundsChanged(View* view, |
122 const Rect& old_bounds, | 124 const Rect& old_bounds, |
123 const Rect& new_bounds) override; | 125 const Rect& new_bounds) override; |
124 | 126 |
125 // Overridden from ui::EventHandler: | 127 // Overridden from ui::EventHandler: |
126 void OnEvent(ui::Event* event) override; | 128 void OnEvent(ui::Event* event) override; |
127 | 129 |
128 // Overridden from aura::client::FocusChangeObserver: | 130 // Overridden from mojo::FocusControllerObserver: |
129 void OnWindowFocused(aura::Window* gained_focus, | 131 void OnViewFocused(View* gained_focus, View* lost_focus) override; |
130 aura::Window* lost_focus) override; | 132 void OnViewActivated(View* gained_active, View* lost_active) override; |
131 | |
132 // Overridden from aura::client::ActivationChangeObserver: | |
133 void OnWindowActivated(aura::Window* gained_active, | |
134 aura::Window* lost_active) override; | |
135 | |
136 // Creates an aura::Window for every view in the hierarchy beneath |view|, | |
137 // and adds to the registry so that it can be retrieved later via | |
138 // GetWindowForViewId(). | |
139 // TODO(beng): perhaps View should have a property bag. | |
140 void RegisterSubtree(View* view, aura::Window* parent); | |
141 // Recursively invokes Unregister() for |view| and all its descendants. | |
142 void UnregisterSubtree(View* view); | |
143 // Deletes the aura::Windows associated with the hierarchy beneath |id|, | |
144 // and removes from the registry. | |
145 void Unregister(View* view); | |
146 | 133 |
147 // Creates the connection to the ViewManager. | 134 // Creates the connection to the ViewManager. |
148 void LaunchViewManager(ApplicationImpl* app); | 135 void LaunchViewManager(ApplicationImpl* app); |
149 | 136 |
150 // InterfaceFactory<WindowManagerInternal>: | 137 // InterfaceFactory<WindowManagerInternal>: |
151 void Create(ApplicationConnection* connection, | 138 void Create(ApplicationConnection* connection, |
152 InterfaceRequest<WindowManagerInternal> request) override; | 139 InterfaceRequest<WindowManagerInternal> request) override; |
153 | 140 |
154 Shell* shell_; | 141 Shell* shell_; |
155 | 142 |
156 InterfaceFactoryImplWithContext<WindowManagerImpl, WindowManagerApp> | 143 InterfaceFactoryImplWithContext<WindowManagerImpl, WindowManagerApp> |
157 window_manager_factory_; | 144 window_manager_factory_; |
158 | 145 |
159 InterfaceFactoryImplWithContext<NativeViewportEventDispatcherImpl, | 146 InterfaceFactoryImplWithContext<NativeViewportEventDispatcherImpl, |
160 WindowManagerApp> | 147 WindowManagerApp> |
161 native_viewport_event_dispatcher_factory_; | 148 native_viewport_event_dispatcher_factory_; |
162 | 149 |
163 ViewManagerDelegate* wrapped_view_manager_delegate_; | 150 ViewManagerDelegate* wrapped_view_manager_delegate_; |
164 WindowManagerDelegate* window_manager_delegate_; | 151 WindowManagerDelegate* window_manager_delegate_; |
165 | 152 |
166 ViewManager* view_manager_; | 153 ViewManager* view_manager_; |
167 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; | 154 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
168 View* root_; | 155 View* root_; |
169 | 156 |
170 scoped_ptr<AuraInit> aura_init_; | 157 scoped_ptr<mojo::FocusController> focus_controller_; |
171 scoped_ptr<WindowTreeHostMojo> window_tree_host_; | |
172 | |
173 scoped_ptr<wm::ScopedCaptureClient> capture_client_; | |
174 scoped_ptr<aura::client::FocusClient> focus_client_; | |
175 aura::client::ActivationClient* activation_client_; | |
176 | 158 |
177 Connections connections_; | 159 Connections connections_; |
178 ViewIdToWindowMap view_id_to_window_map_; | 160 ViewIdToViewTargetMap view_id_to_view_target_map_; |
179 | |
180 scoped_ptr<DummyDelegate> dummy_delegate_; | |
181 | 161 |
182 WindowManagerInternalClientPtr window_manager_client_; | 162 WindowManagerInternalClientPtr window_manager_client_; |
183 | 163 |
184 ScopedVector<PendingEmbed> pending_embeds_; | 164 ScopedVector<PendingEmbed> pending_embeds_; |
185 | 165 |
186 scoped_ptr<ViewManagerClient> view_manager_client_; | 166 scoped_ptr<ViewManagerClient> view_manager_client_; |
187 | 167 |
| 168 scoped_ptr<ViewEventDispatcher> view_event_dispatcher_; |
| 169 |
188 DISALLOW_COPY_AND_ASSIGN(WindowManagerApp); | 170 DISALLOW_COPY_AND_ASSIGN(WindowManagerApp); |
189 }; | 171 }; |
190 | 172 |
191 } // namespace mojo | 173 } // namespace mojo |
192 | 174 |
193 #endif // MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_ | 175 #endif // MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_ |
OLD | NEW |