| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 COMPONENTS_MUS_WS_WINDOW_TREE_HOST_IMPL_H_ | 5 #ifndef COMPONENTS_MUS_WS_WINDOW_TREE_HOST_IMPL_H_ |
| 6 #define COMPONENTS_MUS_WS_WINDOW_TREE_HOST_IMPL_H_ | 6 #define COMPONENTS_MUS_WS_WINDOW_TREE_HOST_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <queue> | 11 #include <queue> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "components/mus/common/types.h" | 16 #include "components/mus/common/types.h" |
| 17 #include "components/mus/public/interfaces/window_manager_constants.mojom.h" | 17 #include "components/mus/public/interfaces/window_manager_constants.mojom.h" |
| 18 #include "components/mus/public/interfaces/window_tree_host.mojom.h" | 18 #include "components/mus/public/interfaces/window_tree_host.mojom.h" |
| 19 #include "components/mus/ws/display_manager.h" | 19 #include "components/mus/ws/display_manager.h" |
| 20 #include "components/mus/ws/event_dispatcher.h" | 20 #include "components/mus/ws/event_dispatcher.h" |
| 21 #include "components/mus/ws/event_dispatcher_delegate.h" | 21 #include "components/mus/ws/event_dispatcher_delegate.h" |
| 22 #include "components/mus/ws/focus_controller_delegate.h" | 22 #include "components/mus/ws/focus_controller_delegate.h" |
| 23 #include "components/mus/ws/focus_controller_observer.h" | 23 #include "components/mus/ws/focus_controller_observer.h" |
| 24 #include "components/mus/ws/server_window.h" | 24 #include "components/mus/ws/server_window.h" |
| 25 #include "components/mus/ws/server_window_observer.h" | 25 #include "components/mus/ws/server_window_observer.h" |
| 26 #include "components/mus/ws/server_window_tracker.h" | 26 #include "components/mus/ws/server_window_tracker.h" |
| 27 #include "components/mus/ws/user_id_tracker_observer.h" |
| 28 #include "components/mus/ws/window_manager_factory_registry_observer.h" |
| 27 | 29 |
| 28 namespace mus { | 30 namespace mus { |
| 29 namespace ws { | 31 namespace ws { |
| 30 | 32 |
| 31 class ConnectionManager; | 33 class ConnectionManager; |
| 32 class FocusController; | 34 class FocusController; |
| 33 class WindowManagerState; | 35 class WindowManagerState; |
| 34 class WindowTreeHostConnection; | 36 class WindowTreeHostConnection; |
| 35 class WindowTreeImpl; | 37 class WindowTreeImpl; |
| 36 | 38 |
| 39 namespace test { |
| 40 class WindowTreeHostTestApi; |
| 41 } |
| 42 |
| 37 // WindowTreeHostImpl is an implementation of the WindowTreeHost interface. | 43 // WindowTreeHostImpl is an implementation of the WindowTreeHost interface. |
| 38 // It serves as a top level root window for a window. Its lifetime is managed by | 44 // It serves as a top level root window for a window. Its lifetime is managed by |
| 39 // ConnectionManager. If the connection to the client breaks or if the user | 45 // ConnectionManager. If the connection to the client breaks or if the user |
| 40 // closes the associated window, then this object and related state will be | 46 // closes the associated window, then this object and related state will be |
| 41 // deleted. | 47 // deleted. |
| 42 // | 48 // |
| 43 // WindowTreeHost has a single root window whose children are the roots for | 49 // WindowTreeHost has a single root window whose children are the roots for |
| 44 // a per-user WindowManager. WindowTreeHost is configured in two distinct | 50 // a per-user WindowManager. WindowTreeHost is configured in two distinct |
| 45 // ways: | 51 // ways: |
| 46 // . with a WindowTreeHostConnection. In this mode there is only ever one | 52 // . with a WindowTreeHostConnection. In this mode there is only ever one |
| 47 // WindowManager for the host, which comes from the client that created | 53 // WindowManager for the host, which comes from the client that created |
| 48 // the WindowTreeHost. | 54 // the WindowTreeHost. |
| 49 // . without a WindowTreeHostConnection. In this mode a WindowManager is | 55 // . without a WindowTreeHostConnection. In this mode a WindowManager is |
| 50 // automatically created per user. | 56 // automatically created per user. |
| 51 class WindowTreeHostImpl : public DisplayManagerDelegate, | 57 class WindowTreeHostImpl : public DisplayManagerDelegate, |
| 52 public mojom::WindowTreeHost, | 58 public mojom::WindowTreeHost, |
| 53 public FocusControllerObserver, | 59 public FocusControllerObserver, |
| 54 public FocusControllerDelegate, | 60 public FocusControllerDelegate, |
| 55 public EventDispatcherDelegate, | 61 public EventDispatcherDelegate, |
| 56 public ServerWindowObserver { | 62 public ServerWindowObserver, |
| 63 public UserIdTrackerObserver, |
| 64 public WindowManagerFactoryRegistryObserver { |
| 57 public: | 65 public: |
| 58 // TODO(fsamuel): All these parameters are just plumbing for creating | 66 // TODO(fsamuel): All these parameters are just plumbing for creating |
| 59 // DisplayManagers. We should probably just store these common parameters | 67 // DisplayManagers. We should probably just store these common parameters |
| 60 // in the DisplayManagerFactory and pass them along on DisplayManager::Create. | 68 // in the DisplayManagerFactory and pass them along on DisplayManager::Create. |
| 61 WindowTreeHostImpl(ConnectionManager* connection_manager, | 69 WindowTreeHostImpl(ConnectionManager* connection_manager, |
| 62 mojo::Connector* connector, | 70 mojo::Connector* connector, |
| 63 const scoped_refptr<GpuState>& gpu_state, | 71 const scoped_refptr<GpuState>& gpu_state, |
| 64 const scoped_refptr<SurfacesState>& surfaces_state); | 72 const scoped_refptr<SurfacesState>& surfaces_state); |
| 65 ~WindowTreeHostImpl() override; | 73 ~WindowTreeHostImpl() override; |
| 66 | 74 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Returns the root of the WindowTreeHost. The root's children are the roots | 106 // Returns the root of the WindowTreeHost. The root's children are the roots |
| 99 // of the corresponding WindowManagers. | 107 // of the corresponding WindowManagers. |
| 100 ServerWindow* root_window() { return root_.get(); } | 108 ServerWindow* root_window() { return root_.get(); } |
| 101 const ServerWindow* root_window() const { return root_.get(); } | 109 const ServerWindow* root_window() const { return root_.get(); } |
| 102 | 110 |
| 103 ServerWindow* GetRootWithId(const WindowId& id); | 111 ServerWindow* GetRootWithId(const WindowId& id); |
| 104 | 112 |
| 105 WindowManagerState* GetWindowManagerStateWithRoot(const ServerWindow* window); | 113 WindowManagerState* GetWindowManagerStateWithRoot(const ServerWindow* window); |
| 106 // TODO(sky): this is wrong, plumb through user_id. | 114 // TODO(sky): this is wrong, plumb through user_id. |
| 107 WindowManagerState* GetFirstWindowManagerState(); | 115 WindowManagerState* GetFirstWindowManagerState(); |
| 116 WindowManagerState* GetWindowManagerStateForUser(UserId user_id); |
| 117 size_t num_window_manger_states() const { |
| 118 return window_manager_state_map_.size(); |
| 119 } |
| 108 | 120 |
| 109 void SetCapture(ServerWindow* window, bool in_nonclient_area); | 121 void SetCapture(ServerWindow* window, bool in_nonclient_area); |
| 110 | 122 |
| 111 void SetFocusedWindow(ServerWindow* window); | 123 void SetFocusedWindow(ServerWindow* window); |
| 112 ServerWindow* GetFocusedWindow(); | 124 ServerWindow* GetFocusedWindow(); |
| 113 void DestroyFocusController(); | 125 void DestroyFocusController(); |
| 114 FocusController* focus_controller() { return focus_controller_.get(); } | 126 FocusController* focus_controller() { return focus_controller_.get(); } |
| 115 | 127 |
| 116 void AddActivationParent(ServerWindow* window); | 128 void AddActivationParent(ServerWindow* window); |
| 117 void RemoveActivationParent(ServerWindow* window); | 129 void RemoveActivationParent(ServerWindow* window); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 142 void MaybeChangeCursorOnWindowTreeChange(); | 154 void MaybeChangeCursorOnWindowTreeChange(); |
| 143 | 155 |
| 144 // WindowTreeHost: | 156 // WindowTreeHost: |
| 145 void SetSize(mojo::SizePtr size) override; | 157 void SetSize(mojo::SizePtr size) override; |
| 146 void SetTitle(const mojo::String& title) override; | 158 void SetTitle(const mojo::String& title) override; |
| 147 | 159 |
| 148 void OnEventAck(mojom::WindowTree* tree); | 160 void OnEventAck(mojom::WindowTree* tree); |
| 149 | 161 |
| 150 private: | 162 private: |
| 151 class ProcessedEventTarget; | 163 class ProcessedEventTarget; |
| 152 friend class WindowTreeTest; | 164 friend class test::WindowTreeHostTestApi; |
| 165 |
| 153 using WindowManagerStateMap = | 166 using WindowManagerStateMap = |
| 154 std::map<uint32_t, scoped_ptr<WindowManagerState>>; | 167 std::map<uint32_t, scoped_ptr<WindowManagerState>>; |
| 155 | 168 |
| 156 // There are two types of events that may be queued, both occur only when | 169 // There are two types of events that may be queued, both occur only when |
| 157 // waiting for an ack from a client. | 170 // waiting for an ack from a client. |
| 158 // . We get an event from the DisplayManager. This results in |event| being | 171 // . We get an event from the DisplayManager. This results in |event| being |
| 159 // set, but |processed_target| is null. | 172 // set, but |processed_target| is null. |
| 160 // . We get an event from the EventDispatcher. In this case both |event| and | 173 // . We get an event from the EventDispatcher. In this case both |event| and |
| 161 // |processed_target| are valid. | 174 // |processed_target| are valid. |
| 162 // The second case happens if EventDispatcher generates more than one event | 175 // The second case happens if EventDispatcher generates more than one event |
| (...skipping 22 matching lines...) Expand all Loading... |
| 185 | 198 |
| 186 // Dispatches the event to the appropriate client and starts the ack timer. | 199 // Dispatches the event to the appropriate client and starts the ack timer. |
| 187 void DispatchInputEventToWindowImpl(ServerWindow* target, | 200 void DispatchInputEventToWindowImpl(ServerWindow* target, |
| 188 bool in_nonclient_area, | 201 bool in_nonclient_area, |
| 189 const ui::Event& event); | 202 const ui::Event& event); |
| 190 | 203 |
| 191 // Creates the set of WindowManagerStates from the | 204 // Creates the set of WindowManagerStates from the |
| 192 // WindowManagerFactoryRegistry. | 205 // WindowManagerFactoryRegistry. |
| 193 void CreateWindowManagerStatesFromRegistry(); | 206 void CreateWindowManagerStatesFromRegistry(); |
| 194 | 207 |
| 208 void CreateWindowManagerStateFromService( |
| 209 WindowManagerFactoryService* service); |
| 210 |
| 195 void UpdateNativeCursor(int32_t cursor_id); | 211 void UpdateNativeCursor(int32_t cursor_id); |
| 196 | 212 |
| 197 // DisplayManagerDelegate: | 213 // DisplayManagerDelegate: |
| 198 ServerWindow* GetRootWindow() override; | 214 ServerWindow* GetRootWindow() override; |
| 199 void OnEvent(const ui::Event& event) override; | 215 void OnEvent(const ui::Event& event) override; |
| 200 void OnNativeCaptureLost() override; | 216 void OnNativeCaptureLost() override; |
| 201 void OnDisplayClosed() override; | 217 void OnDisplayClosed() override; |
| 202 void OnViewportMetricsChanged( | 218 void OnViewportMetricsChanged( |
| 203 const mojom::ViewportMetrics& old_metrics, | 219 const mojom::ViewportMetrics& old_metrics, |
| 204 const mojom::ViewportMetrics& new_metrics) override; | 220 const mojom::ViewportMetrics& new_metrics) override; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 222 void SetNativeCapture() override; | 238 void SetNativeCapture() override; |
| 223 void ReleaseNativeCapture() override; | 239 void ReleaseNativeCapture() override; |
| 224 void OnServerWindowCaptureLost(ServerWindow* window) override; | 240 void OnServerWindowCaptureLost(ServerWindow* window) override; |
| 225 void DispatchInputEventToWindow(ServerWindow* target, | 241 void DispatchInputEventToWindow(ServerWindow* target, |
| 226 bool in_nonclient_area, | 242 bool in_nonclient_area, |
| 227 const ui::Event& event) override; | 243 const ui::Event& event) override; |
| 228 | 244 |
| 229 // ServerWindowObserver: | 245 // ServerWindowObserver: |
| 230 void OnWindowDestroyed(ServerWindow* window) override; | 246 void OnWindowDestroyed(ServerWindow* window) override; |
| 231 | 247 |
| 248 // UserIdTrackerObserver: |
| 249 void OnActiveUserIdChanged(UserId id) override; |
| 250 void OnUserIdAdded(UserId id) override; |
| 251 void OnUserIdRemoved(UserId id) override; |
| 252 |
| 253 // WindowManagerFactoryRegistryObserver: |
| 254 void OnWindowManagerFactorySet(WindowManagerFactoryService* service) override; |
| 255 |
| 232 const uint32_t id_; | 256 const uint32_t id_; |
| 233 scoped_ptr<WindowTreeHostConnection> window_tree_host_connection_; | 257 scoped_ptr<WindowTreeHostConnection> window_tree_host_connection_; |
| 234 // Set once Init() has been called. | 258 // Set once Init() has been called. |
| 235 bool init_called_ = false; | 259 bool init_called_ = false; |
| 236 ConnectionManager* const connection_manager_; | 260 ConnectionManager* const connection_manager_; |
| 237 EventDispatcher event_dispatcher_; | 261 EventDispatcher event_dispatcher_; |
| 238 scoped_ptr<ServerWindow> root_; | 262 scoped_ptr<ServerWindow> root_; |
| 239 scoped_ptr<DisplayManager> display_manager_; | 263 scoped_ptr<DisplayManager> display_manager_; |
| 240 scoped_ptr<FocusController> focus_controller_; | 264 scoped_ptr<FocusController> focus_controller_; |
| 241 mojom::WindowTree* tree_awaiting_input_ack_; | 265 mojom::WindowTree* tree_awaiting_input_ack_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 256 | 280 |
| 257 mojom::FrameDecorationValuesPtr frame_decoration_values_; | 281 mojom::FrameDecorationValuesPtr frame_decoration_values_; |
| 258 | 282 |
| 259 DISALLOW_COPY_AND_ASSIGN(WindowTreeHostImpl); | 283 DISALLOW_COPY_AND_ASSIGN(WindowTreeHostImpl); |
| 260 }; | 284 }; |
| 261 | 285 |
| 262 } // namespace ws | 286 } // namespace ws |
| 263 } // namespace mus | 287 } // namespace mus |
| 264 | 288 |
| 265 #endif // COMPONENTS_MUS_WS_WINDOW_TREE_HOST_IMPL_H_ | 289 #endif // COMPONENTS_MUS_WS_WINDOW_TREE_HOST_IMPL_H_ |
| OLD | NEW |