| 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 <queue> | 11 #include <queue> |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 15 #include "components/mus/common/types.h" | 16 #include "components/mus/common/types.h" |
| 16 #include "components/mus/public/interfaces/window_manager_constants.mojom.h" | 17 #include "components/mus/public/interfaces/window_manager_constants.mojom.h" |
| 17 #include "components/mus/public/interfaces/window_tree_host.mojom.h" | 18 #include "components/mus/public/interfaces/window_tree_host.mojom.h" |
| 18 #include "components/mus/ws/display_manager.h" | 19 #include "components/mus/ws/display_manager.h" |
| 19 #include "components/mus/ws/event_dispatcher.h" | 20 #include "components/mus/ws/event_dispatcher.h" |
| 20 #include "components/mus/ws/event_dispatcher_delegate.h" | 21 #include "components/mus/ws/event_dispatcher_delegate.h" |
| 21 #include "components/mus/ws/focus_controller_delegate.h" | 22 #include "components/mus/ws/focus_controller_delegate.h" |
| 22 #include "components/mus/ws/focus_controller_observer.h" | 23 #include "components/mus/ws/focus_controller_observer.h" |
| 23 #include "components/mus/ws/server_window.h" | 24 #include "components/mus/ws/server_window.h" |
| 24 #include "components/mus/ws/server_window_observer.h" | 25 #include "components/mus/ws/server_window_observer.h" |
| 25 #include "components/mus/ws/server_window_tracker.h" | 26 #include "components/mus/ws/server_window_tracker.h" |
| 26 | 27 |
| 27 namespace mus { | 28 namespace mus { |
| 28 namespace ws { | 29 namespace ws { |
| 29 | 30 |
| 30 class ConnectionManager; | 31 class ConnectionManager; |
| 31 class FocusController; | 32 class FocusController; |
| 33 class WindowManagerState; |
| 32 class WindowTreeHostConnection; | 34 class WindowTreeHostConnection; |
| 33 class WindowTreeImpl; | 35 class WindowTreeImpl; |
| 34 | 36 |
| 35 // WindowTreeHostImpl is an implementation of the WindowTreeHost interface. | 37 // WindowTreeHostImpl is an implementation of the WindowTreeHost interface. |
| 36 // It serves as a top level root window for a window. Its lifetime is managed by | 38 // It serves as a top level root window for a window. Its lifetime is managed by |
| 37 // ConnectionManager. If the connection to the client breaks or if the user | 39 // ConnectionManager. If the connection to the client breaks or if the user |
| 38 // closes the associated window, then this object and related state will be | 40 // closes the associated window, then this object and related state will be |
| 39 // deleted. | 41 // deleted. |
| 42 // |
| 43 // WindowTreeHost has a single root window whose children are the roots for |
| 44 // a per-user WindowManager. WindowTreeHost is configured in two distinct |
| 45 // ways: |
| 46 // . with a WindowTreeHostConnection. In this mode there is only ever one |
| 47 // WindowManager for the host, which comes from the client that created |
| 48 // the WindowTreeHost. |
| 49 // . without a WindowTreeHostConnection. In this mode a WindowManager is |
| 50 // automatically created per user. |
| 40 class WindowTreeHostImpl : public DisplayManagerDelegate, | 51 class WindowTreeHostImpl : public DisplayManagerDelegate, |
| 41 public mojom::WindowTreeHost, | 52 public mojom::WindowTreeHost, |
| 42 public FocusControllerObserver, | 53 public FocusControllerObserver, |
| 43 public FocusControllerDelegate, | 54 public FocusControllerDelegate, |
| 44 public EventDispatcherDelegate, | 55 public EventDispatcherDelegate, |
| 45 public ServerWindowObserver { | 56 public ServerWindowObserver { |
| 46 public: | 57 public: |
| 47 // TODO(fsamuel): All these parameters are just plumbing for creating | 58 // TODO(fsamuel): All these parameters are just plumbing for creating |
| 48 // DisplayManagers. We should probably just store these common parameters | 59 // DisplayManagers. We should probably just store these common parameters |
| 49 // in the DisplayManagerFactory and pass them along on DisplayManager::Create. | 60 // in the DisplayManagerFactory and pass them along on DisplayManager::Create. |
| 50 WindowTreeHostImpl(ConnectionManager* connection_manager, | 61 WindowTreeHostImpl(ConnectionManager* connection_manager, |
| 51 mojo::Connector* connector, | 62 mojo::Connector* connector, |
| 52 const scoped_refptr<GpuState>& gpu_state, | 63 const scoped_refptr<GpuState>& gpu_state, |
| 53 const scoped_refptr<SurfacesState>& surfaces_state); | 64 const scoped_refptr<SurfacesState>& surfaces_state); |
| 54 ~WindowTreeHostImpl() override; | 65 ~WindowTreeHostImpl() override; |
| 55 | 66 |
| 56 // Initializes state that depends on the existence of a WindowTreeHostImpl. | 67 // Initializes state that depends on the existence of a WindowTreeHostImpl. |
| 57 void Init(scoped_ptr<WindowTreeHostConnection> connection); | 68 void Init(scoped_ptr<WindowTreeHostConnection> connection); |
| 58 | 69 |
| 59 uint32_t id() const { return id_; } | 70 uint32_t id() const { return id_; } |
| 60 | 71 |
| 61 const WindowTreeImpl* GetWindowTree() const; | 72 // TODO(sky): move to WMM. |
| 62 WindowTreeImpl* GetWindowTree(); | |
| 63 | |
| 64 void SetFrameDecorationValues(mojom::FrameDecorationValuesPtr values); | 73 void SetFrameDecorationValues(mojom::FrameDecorationValuesPtr values); |
| 65 const mojom::FrameDecorationValues& frame_decoration_values() const { | 74 const mojom::FrameDecorationValues& frame_decoration_values() const { |
| 66 return *frame_decoration_values_; | 75 return *frame_decoration_values_; |
| 67 } | 76 } |
| 68 | 77 |
| 69 // Returns whether |window| is a descendant of this root but not itself a | |
| 70 // root window. | |
| 71 bool IsWindowAttachedToRoot(const ServerWindow* window) const; | |
| 72 | |
| 73 // Schedules a paint for the specified region in the coordinates of |window| | 78 // Schedules a paint for the specified region in the coordinates of |window| |
| 74 // if | 79 // if the |window| is in this viewport. Returns whether |window| is in the |
| 75 // the |window| is in this viewport. Returns whether |window| is in the | |
| 76 // viewport. | 80 // viewport. |
| 77 bool SchedulePaintIfInViewport(const ServerWindow* window, | 81 bool SchedulePaintIfInViewport(const ServerWindow* window, |
| 78 const gfx::Rect& bounds); | 82 const gfx::Rect& bounds); |
| 79 | 83 |
| 80 // Schedules destruction of surfaces in |window|. If a frame has been | 84 // Schedules destruction of surfaces in |window|. If a frame has been |
| 81 // scheduled but not drawn surface destruction is delayed until the frame is | 85 // scheduled but not drawn surface destruction is delayed until the frame is |
| 82 // drawn, otherwise destruction is immediate. | 86 // drawn, otherwise destruction is immediate. |
| 83 void ScheduleSurfaceDestruction(ServerWindow* window); | 87 void ScheduleSurfaceDestruction(ServerWindow* window); |
| 84 | 88 |
| 85 // Returns the metrics for this viewport. | 89 // Returns the metrics for this viewport. |
| 86 const mojom::ViewportMetrics& GetViewportMetrics() const; | 90 const mojom::ViewportMetrics& GetViewportMetrics() const; |
| 87 | 91 |
| 88 mojom::Rotation GetRotation() const; | 92 mojom::Rotation GetRotation() const; |
| 89 | 93 |
| 90 ConnectionManager* connection_manager() { return connection_manager_; } | 94 ConnectionManager* connection_manager() { return connection_manager_; } |
| 91 | 95 |
| 92 EventDispatcher* event_dispatcher() { return &event_dispatcher_; } | 96 EventDispatcher* event_dispatcher() { return &event_dispatcher_; } |
| 93 | 97 |
| 94 // Returns the root ServerWindow of this viewport. | 98 // Returns the root of the WindowTreeHost. The root's children are the roots |
| 99 // of the corresponding WindowManagers. |
| 95 ServerWindow* root_window() { return root_.get(); } | 100 ServerWindow* root_window() { return root_.get(); } |
| 96 const ServerWindow* root_window() const { return root_.get(); } | 101 const ServerWindow* root_window() const { return root_.get(); } |
| 97 | 102 |
| 103 ServerWindow* GetRootWithId(const WindowId& id); |
| 104 |
| 105 WindowManagerState* GetWindowManagerStateWithRoot(const ServerWindow* window); |
| 106 // TODO(sky): this is wrong, plumb through user_id. |
| 107 WindowManagerState* GetFirstWindowManagerState(); |
| 108 |
| 98 void SetCapture(ServerWindow* window, bool in_nonclient_area); | 109 void SetCapture(ServerWindow* window, bool in_nonclient_area); |
| 99 | 110 |
| 100 void SetFocusedWindow(ServerWindow* window); | 111 void SetFocusedWindow(ServerWindow* window); |
| 101 ServerWindow* GetFocusedWindow(); | 112 ServerWindow* GetFocusedWindow(); |
| 102 void DestroyFocusController(); | 113 void DestroyFocusController(); |
| 103 FocusController* focus_controller() { return focus_controller_.get(); } | 114 FocusController* focus_controller() { return focus_controller_.get(); } |
| 104 | 115 |
| 105 void AddActivationParent(ServerWindow* window); | 116 void AddActivationParent(ServerWindow* window); |
| 106 void RemoveActivationParent(ServerWindow* window); | 117 void RemoveActivationParent(ServerWindow* window); |
| 107 | 118 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 132 | 143 |
| 133 // WindowTreeHost: | 144 // WindowTreeHost: |
| 134 void SetSize(mojo::SizePtr size) override; | 145 void SetSize(mojo::SizePtr size) override; |
| 135 void SetTitle(const mojo::String& title) override; | 146 void SetTitle(const mojo::String& title) override; |
| 136 | 147 |
| 137 void OnEventAck(mojom::WindowTree* tree); | 148 void OnEventAck(mojom::WindowTree* tree); |
| 138 | 149 |
| 139 private: | 150 private: |
| 140 class ProcessedEventTarget; | 151 class ProcessedEventTarget; |
| 141 friend class WindowTreeTest; | 152 friend class WindowTreeTest; |
| 153 using WindowManagerStateMap = |
| 154 std::map<uint32_t, scoped_ptr<WindowManagerState>>; |
| 142 | 155 |
| 143 // There are two types of events that may be queued, both occur only when | 156 // There are two types of events that may be queued, both occur only when |
| 144 // waiting for an ack from a client. | 157 // waiting for an ack from a client. |
| 145 // . We get an event from the DisplayManager. This results in |event| being | 158 // . We get an event from the DisplayManager. This results in |event| being |
| 146 // set, but |processed_target| is null. | 159 // set, but |processed_target| is null. |
| 147 // . We get an event from the EventDispatcher. In this case both |event| and | 160 // . We get an event from the EventDispatcher. In this case both |event| and |
| 148 // |processed_target| are valid. | 161 // |processed_target| are valid. |
| 149 // The second case happens if EventDispatcher generates more than one event | 162 // The second case happens if EventDispatcher generates more than one event |
| 150 // at a time. | 163 // at a time. |
| 151 struct QueuedEvent { | 164 struct QueuedEvent { |
| 152 QueuedEvent(); | 165 QueuedEvent(); |
| 153 ~QueuedEvent(); | 166 ~QueuedEvent(); |
| 154 | 167 |
| 155 scoped_ptr<ui::Event> event; | 168 scoped_ptr<ui::Event> event; |
| 156 scoped_ptr<ProcessedEventTarget> processed_target; | 169 scoped_ptr<ProcessedEventTarget> processed_target; |
| 157 }; | 170 }; |
| 158 | 171 |
| 159 // Inits the necessary state once the display is ready. | 172 // Inits the necessary state once the display is ready. |
| 160 void CallOnDisplayInitializedIfNecessary(); | 173 void InitWindowManagersIfNecessary(); |
| 161 | 174 |
| 162 void OnEventAckTimeout(); | 175 void OnEventAckTimeout(); |
| 163 | 176 |
| 164 // Schedules an event to be processed later. | 177 // Schedules an event to be processed later. |
| 165 void QueueEvent(const ui::Event& event, | 178 void QueueEvent(const ui::Event& event, |
| 166 scoped_ptr<ProcessedEventTarget> processed_event_target); | 179 scoped_ptr<ProcessedEventTarget> processed_event_target); |
| 167 | 180 |
| 168 // Processes the next valid event in |event_queue_|. If the event has already | 181 // Processes the next valid event in |event_queue_|. If the event has already |
| 169 // been processed it is dispatched, otherwise the event is passed to the | 182 // been processed it is dispatched, otherwise the event is passed to the |
| 170 // EventDispatcher for processing. | 183 // EventDispatcher for processing. |
| 171 void ProcessNextEventFromQueue(); | 184 void ProcessNextEventFromQueue(); |
| 172 | 185 |
| 173 // Dispatches the event to the appropriate client and starts the ack timer. | 186 // Dispatches the event to the appropriate client and starts the ack timer. |
| 174 void DispatchInputEventToWindowImpl(ServerWindow* target, | 187 void DispatchInputEventToWindowImpl(ServerWindow* target, |
| 175 bool in_nonclient_area, | 188 bool in_nonclient_area, |
| 176 const ui::Event& event); | 189 const ui::Event& event); |
| 177 | 190 |
| 191 // Creates the set of WindowManagerStates from the |
| 192 // WindowManagerFactoryRegistry. |
| 193 void CreateWindowManagerStatesFromRegistry(); |
| 194 |
| 178 void UpdateNativeCursor(int32_t cursor_id); | 195 void UpdateNativeCursor(int32_t cursor_id); |
| 179 | 196 |
| 180 // DisplayManagerDelegate: | 197 // DisplayManagerDelegate: |
| 181 ServerWindow* GetRootWindow() override; | 198 ServerWindow* GetRootWindow() override; |
| 182 void OnEvent(const ui::Event& event) override; | 199 void OnEvent(const ui::Event& event) override; |
| 183 void OnNativeCaptureLost() override; | 200 void OnNativeCaptureLost() override; |
| 184 void OnDisplayClosed() override; | 201 void OnDisplayClosed() override; |
| 185 void OnViewportMetricsChanged( | 202 void OnViewportMetricsChanged( |
| 186 const mojom::ViewportMetrics& old_metrics, | 203 const mojom::ViewportMetrics& old_metrics, |
| 187 const mojom::ViewportMetrics& new_metrics) override; | 204 const mojom::ViewportMetrics& new_metrics) override; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 207 void OnServerWindowCaptureLost(ServerWindow* window) override; | 224 void OnServerWindowCaptureLost(ServerWindow* window) override; |
| 208 void DispatchInputEventToWindow(ServerWindow* target, | 225 void DispatchInputEventToWindow(ServerWindow* target, |
| 209 bool in_nonclient_area, | 226 bool in_nonclient_area, |
| 210 const ui::Event& event) override; | 227 const ui::Event& event) override; |
| 211 | 228 |
| 212 // ServerWindowObserver: | 229 // ServerWindowObserver: |
| 213 void OnWindowDestroyed(ServerWindow* window) override; | 230 void OnWindowDestroyed(ServerWindow* window) override; |
| 214 | 231 |
| 215 const uint32_t id_; | 232 const uint32_t id_; |
| 216 scoped_ptr<WindowTreeHostConnection> window_tree_host_connection_; | 233 scoped_ptr<WindowTreeHostConnection> window_tree_host_connection_; |
| 217 WindowTreeImpl* window_tree_ = nullptr; | 234 // Set once Init() has been called. |
| 235 bool init_called_ = false; |
| 218 ConnectionManager* const connection_manager_; | 236 ConnectionManager* const connection_manager_; |
| 219 EventDispatcher event_dispatcher_; | 237 EventDispatcher event_dispatcher_; |
| 220 scoped_ptr<ServerWindow> root_; | 238 scoped_ptr<ServerWindow> root_; |
| 221 scoped_ptr<DisplayManager> display_manager_; | 239 scoped_ptr<DisplayManager> display_manager_; |
| 222 scoped_ptr<FocusController> focus_controller_; | 240 scoped_ptr<FocusController> focus_controller_; |
| 223 mojom::WindowTree* tree_awaiting_input_ack_; | 241 mojom::WindowTree* tree_awaiting_input_ack_; |
| 224 | 242 |
| 225 // The last cursor set. Used to track whether we need to change the cursor. | 243 // The last cursor set. Used to track whether we need to change the cursor. |
| 226 int32_t last_cursor_; | 244 int32_t last_cursor_; |
| 227 | 245 |
| 228 ServerWindowTracker activation_parents_; | 246 ServerWindowTracker activation_parents_; |
| 229 | 247 |
| 230 // Set of windows with surfaces that need to be destroyed once the frame | 248 // Set of windows with surfaces that need to be destroyed once the frame |
| 231 // draws. | 249 // draws. |
| 232 std::set<ServerWindow*> windows_needing_frame_destruction_; | 250 std::set<ServerWindow*> windows_needing_frame_destruction_; |
| 233 | 251 |
| 234 std::queue<scoped_ptr<QueuedEvent>> event_queue_; | 252 std::queue<scoped_ptr<QueuedEvent>> event_queue_; |
| 235 base::OneShotTimer event_ack_timer_; | 253 base::OneShotTimer event_ack_timer_; |
| 236 | 254 |
| 255 WindowManagerStateMap window_manager_state_map_; |
| 256 |
| 237 mojom::FrameDecorationValuesPtr frame_decoration_values_; | 257 mojom::FrameDecorationValuesPtr frame_decoration_values_; |
| 238 | 258 |
| 239 DISALLOW_COPY_AND_ASSIGN(WindowTreeHostImpl); | 259 DISALLOW_COPY_AND_ASSIGN(WindowTreeHostImpl); |
| 240 }; | 260 }; |
| 241 | 261 |
| 242 } // namespace ws | 262 } // namespace ws |
| 243 } // namespace mus | 263 } // namespace mus |
| 244 | 264 |
| 245 #endif // COMPONENTS_MUS_WS_WINDOW_TREE_HOST_IMPL_H_ | 265 #endif // COMPONENTS_MUS_WS_WINDOW_TREE_HOST_IMPL_H_ |
| OLD | NEW |