Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 SERVICES_UI_WS_WINDOW_MANAGER_STATE_H_ | 5 #ifndef SERVICES_UI_WS_WINDOW_MANAGER_STATE_H_ |
| 6 #define SERVICES_UI_WS_WINDOW_MANAGER_STATE_H_ | 6 #define SERVICES_UI_WS_WINDOW_MANAGER_STATE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 // not be exposed. | 85 // not be exposed. |
| 86 EventDispatcher* event_dispatcher() { return &event_dispatcher_; } | 86 EventDispatcher* event_dispatcher() { return &event_dispatcher_; } |
| 87 | 87 |
| 88 // Returns true if this is the WindowManager of the active user. | 88 // Returns true if this is the WindowManager of the active user. |
| 89 bool IsActive() const; | 89 bool IsActive() const; |
| 90 | 90 |
| 91 void Activate(const gfx::Point& mouse_location_on_screen); | 91 void Activate(const gfx::Point& mouse_location_on_screen); |
| 92 void Deactivate(); | 92 void Deactivate(); |
| 93 | 93 |
| 94 // Processes an event from PlatformDisplay. | 94 // Processes an event from PlatformDisplay. |
| 95 void ProcessEvent(const ui::Event& event); | 95 void ProcessEvent(const Event& event, int64_t display_id); |
| 96 | 96 |
| 97 // Called when the ack from an event dispatched to WindowTree |tree| is | 97 // Called when the ack from an event dispatched to WindowTree |tree| is |
| 98 // received. | 98 // received. |
| 99 // TODO(sky): make this private and use a callback. | 99 // TODO(sky): make this private and use a callback. |
| 100 void OnEventAck(mojom::WindowTree* tree, mojom::EventResult result); | 100 void OnEventAck(mojom::WindowTree* tree, mojom::EventResult result); |
| 101 | 101 |
| 102 // Called when the WindowManager acks an accelerator. | 102 // Called when the WindowManager acks an accelerator. |
| 103 void OnAcceleratorAck(mojom::EventResult result); | 103 void OnAcceleratorAck(mojom::EventResult result); |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 class ProcessedEventTarget; | 106 class ProcessedEventTarget; |
| 107 friend class Display; | 107 friend class Display; |
| 108 friend class test::WindowManagerStateTestApi; | 108 friend class test::WindowManagerStateTestApi; |
| 109 | 109 |
| 110 // Set of display roots. This is a vector rather than a set to support removal | 110 // Set of display roots. This is a vector rather than a set to support removal |
| 111 // without deleting. | 111 // without deleting. |
| 112 using WindowManagerDisplayRoots = | 112 using WindowManagerDisplayRoots = |
| 113 std::vector<std::unique_ptr<WindowManagerDisplayRoot>>; | 113 std::vector<std::unique_ptr<WindowManagerDisplayRoot>>; |
| 114 | 114 |
| 115 enum class DebugAcceleratorType { | 115 enum class DebugAcceleratorType { |
| 116 PRINT_WINDOWS, | 116 PRINT_WINDOWS, |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 struct DebugAccelerator { | 119 struct DebugAccelerator { |
| 120 bool Matches(const ui::KeyEvent& event) const; | 120 bool Matches(const KeyEvent& event) const; |
| 121 | 121 |
| 122 DebugAcceleratorType type; | 122 DebugAcceleratorType type; |
| 123 ui::KeyboardCode key_code; | 123 KeyboardCode key_code; |
| 124 int event_flags; | 124 int event_flags; |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 enum class EventDispatchPhase { | 127 enum class EventDispatchPhase { |
| 128 // Not actively dispatching. | 128 // Not actively dispatching. |
| 129 NONE, | 129 NONE, |
| 130 | 130 |
| 131 // A PRE_TARGET accelerator has been encountered and we're awaiting the ack. | 131 // A PRE_TARGET accelerator has been encountered and we're awaiting the ack. |
| 132 PRE_TARGET_ACCELERATOR, | 132 PRE_TARGET_ACCELERATOR, |
| 133 | 133 |
| 134 // Dispatching to the target, awaiting the ack. | 134 // Dispatching to the target, awaiting the ack. |
| 135 TARGET, | 135 TARGET, |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 // There are two types of events that may be queued, both occur only when | 138 // There are two types of events that may be queued, both occur only when |
| 139 // waiting for an ack from a client. | 139 // waiting for an ack from a client. |
| 140 // . We get an event from the PlatformDisplay. This results in |event| being | 140 // . We get an event from the PlatformDisplay. This results in |event| being |
| 141 // set, but |processed_target| is null. | 141 // set, but |processed_target| is null. |
| 142 // . We get an event from the EventDispatcher. In this case both |event| and | 142 // . We get an event from the EventDispatcher. In this case both |event| and |
| 143 // |processed_target| are valid. | 143 // |processed_target| are valid. |
| 144 // The second case happens if EventDispatcher generates more than one event | 144 // The second case happens if EventDispatcher generates more than one event |
| 145 // at a time. | 145 // at a time. |
| 146 struct QueuedEvent { | 146 struct QueuedEvent { |
| 147 QueuedEvent(); | 147 QueuedEvent(); |
| 148 ~QueuedEvent(); | 148 ~QueuedEvent(); |
| 149 | 149 |
| 150 std::unique_ptr<ui::Event> event; | 150 std::unique_ptr<Event> event; |
| 151 std::unique_ptr<ProcessedEventTarget> processed_target; | 151 std::unique_ptr<ProcessedEventTarget> processed_target; |
| 152 int64_t display_id; | |
| 153 }; | |
| 154 | |
| 155 // Tracks state associated with an event being dispatched to a client. | |
| 156 struct InFlightEventDetails { | |
|
sadrul
2017/02/09 21:21:34
Btw: like this!
| |
| 157 InFlightEventDetails(WindowTree* tree, | |
| 158 int64_t display_id, | |
| 159 const Event& event, | |
| 160 EventDispatchPhase phase); | |
| 161 ~InFlightEventDetails(); | |
| 162 | |
| 163 base::OneShotTimer timer; | |
| 164 WindowTree* tree; | |
| 165 int64_t display_id; | |
| 166 std::unique_ptr<Event> event; | |
| 167 EventDispatchPhase phase; | |
| 152 }; | 168 }; |
| 153 | 169 |
| 154 const WindowServer* window_server() const; | 170 const WindowServer* window_server() const; |
| 155 WindowServer* window_server(); | 171 WindowServer* window_server(); |
| 156 | 172 |
| 157 DisplayManager* display_manager(); | 173 DisplayManager* display_manager(); |
| 158 const DisplayManager* display_manager() const; | 174 const DisplayManager* display_manager() const; |
| 159 | 175 |
| 160 // Adds |display_root| to the set of WindowManagerDisplayRoots owned by this | 176 // Adds |display_root| to the set of WindowManagerDisplayRoots owned by this |
| 161 // WindowManagerState. | 177 // WindowManagerState. |
| 162 void AddWindowManagerDisplayRoot( | 178 void AddWindowManagerDisplayRoot( |
| 163 std::unique_ptr<WindowManagerDisplayRoot> display_root); | 179 std::unique_ptr<WindowManagerDisplayRoot> display_root); |
| 164 | 180 |
| 165 // Called when a Display is deleted. | 181 // Called when a Display is deleted. |
| 166 void OnDisplayDestroying(Display* display); | 182 void OnDisplayDestroying(Display* display); |
| 167 | 183 |
| 168 // Sets the visibility of all window manager roots windows to |value|. | 184 // Sets the visibility of all window manager roots windows to |value|. |
| 169 void SetAllRootWindowsVisible(bool value); | 185 void SetAllRootWindowsVisible(bool value); |
| 170 | 186 |
| 171 // Returns the ServerWindow that is the root of the WindowManager for | 187 // Returns the ServerWindow that is the root of the WindowManager for |
| 172 // |window|. |window| corresponds to the root of a Display. | 188 // |window|. |window| corresponds to the root of a Display. |
| 173 ServerWindow* GetWindowManagerRoot(ServerWindow* window); | 189 ServerWindow* GetWindowManagerRoot(ServerWindow* window); |
| 174 | 190 |
| 175 // Called if the client doesn't ack an event in the appropriate amount of | 191 // Called if the client doesn't ack an event in the appropriate amount of |
| 176 // time. | 192 // time. |
| 177 void OnEventAckTimeout(ClientSpecificId client_id); | 193 void OnEventAckTimeout(ClientSpecificId client_id); |
| 178 | 194 |
| 179 // Implemenation of processing an event with a match phase of all. This | 195 // Implemenation of processing an event with a match phase of all. This |
| 180 // handles debug accelerators and forwards to EventDispatcher. | 196 // handles debug accelerators and forwards to EventDispatcher. |
| 181 void ProcessEventImpl(const ui::Event& event); | 197 void ProcessEventImpl(const Event& event, int64_t display_id); |
| 182 | 198 |
| 183 // Schedules an event to be processed later. | 199 // Schedules an event to be processed later. |
| 184 void QueueEvent(const ui::Event& event, | 200 void QueueEvent(const Event& event, |
| 185 std::unique_ptr<ProcessedEventTarget> processed_event_target); | 201 std::unique_ptr<ProcessedEventTarget> processed_event_target, |
| 202 int64_t display_id); | |
| 186 | 203 |
| 187 // Processes the next valid event in |event_queue_|. If the event has already | 204 // Processes the next valid event in |event_queue_|. If the event has already |
| 188 // been processed it is dispatched, otherwise the event is passed to the | 205 // been processed it is dispatched, otherwise the event is passed to the |
| 189 // EventDispatcher for processing. | 206 // EventDispatcher for processing. |
| 190 void ProcessNextEventFromQueue(); | 207 void ProcessNextEventFromQueue(); |
| 191 | 208 |
| 192 // Dispatches the event to the appropriate client and starts the ack timer. | 209 // Dispatches the event to the appropriate client and starts the ack timer. |
| 193 void DispatchInputEventToWindowImpl(ServerWindow* target, | 210 void DispatchInputEventToWindowImpl(ServerWindow* target, |
| 194 ClientSpecificId client_id, | 211 ClientSpecificId client_id, |
| 195 const ui::Event& event, | 212 const Event& event, |
| 196 base::WeakPtr<Accelerator> accelerator); | 213 base::WeakPtr<Accelerator> accelerator); |
| 197 | 214 |
| 198 // Registers accelerators used internally for debugging. | 215 // Registers accelerators used internally for debugging. |
| 199 void AddDebugAccelerators(); | 216 void AddDebugAccelerators(); |
| 200 | 217 |
| 201 // Finds the debug accelerator for |event| and if one is found calls | 218 // Finds the debug accelerator for |event| and if one is found calls |
| 202 // HandleDebugAccelerator(). | 219 // HandleDebugAccelerator(). |
| 203 void ProcessDebugAccelerator(const ui::Event& event); | 220 void ProcessDebugAccelerator(const Event& event); |
| 204 | 221 |
| 205 // Runs the specified debug accelerator. | 222 // Runs the specified debug accelerator. |
| 206 void HandleDebugAccelerator(DebugAcceleratorType type); | 223 void HandleDebugAccelerator(DebugAcceleratorType type); |
| 207 | 224 |
| 208 // Called when waiting for an event or accelerator to be processed by |tree|. | 225 // Called when waiting for an event or accelerator to be processed by |tree|. |
| 209 void ScheduleInputEventTimeout(WindowTree* tree); | 226 void ScheduleInputEventTimeout(WindowTree* tree, |
| 227 ServerWindow* target, | |
| 228 const Event& event, | |
| 229 EventDispatchPhase phase); | |
| 210 | 230 |
| 211 // EventDispatcherDelegate: | 231 // EventDispatcherDelegate: |
| 212 void OnAccelerator(uint32_t accelerator_id, | 232 void OnAccelerator(uint32_t accelerator_id, |
| 213 const ui::Event& event, | 233 const Event& event, |
| 214 AcceleratorPhase phase) override; | 234 AcceleratorPhase phase) override; |
| 215 void SetFocusedWindowFromEventDispatcher(ServerWindow* window) override; | 235 void SetFocusedWindowFromEventDispatcher(ServerWindow* window) override; |
| 216 ServerWindow* GetFocusedWindowForEventDispatcher() override; | 236 ServerWindow* GetFocusedWindowForEventDispatcher() override; |
| 217 void SetNativeCapture(ServerWindow* window) override; | 237 void SetNativeCapture(ServerWindow* window) override; |
| 218 void ReleaseNativeCapture() override; | 238 void ReleaseNativeCapture() override; |
| 219 void UpdateNativeCursorFromDispatcher() override; | 239 void UpdateNativeCursorFromDispatcher() override; |
| 220 void OnCaptureChanged(ServerWindow* new_capture, | 240 void OnCaptureChanged(ServerWindow* new_capture, |
| 221 ServerWindow* old_capture) override; | 241 ServerWindow* old_capture) override; |
| 222 void OnMouseCursorLocationChanged(const gfx::Point& point) override; | 242 void OnMouseCursorLocationChanged(const gfx::Point& point) override; |
| 223 void DispatchInputEventToWindow(ServerWindow* target, | 243 void DispatchInputEventToWindow(ServerWindow* target, |
| 224 ClientSpecificId client_id, | 244 ClientSpecificId client_id, |
| 225 const ui::Event& event, | 245 const Event& event, |
| 226 Accelerator* accelerator) override; | 246 Accelerator* accelerator) override; |
| 227 ClientSpecificId GetEventTargetClientId(const ServerWindow* window, | 247 ClientSpecificId GetEventTargetClientId(const ServerWindow* window, |
| 228 bool in_nonclient_area) override; | 248 bool in_nonclient_area) override; |
| 229 ServerWindow* GetRootWindowContaining(gfx::Point* location) override; | 249 ServerWindow* GetRootWindowContaining(gfx::Point* location) override; |
| 230 void OnEventTargetNotFound(const ui::Event& event) override; | 250 void OnEventTargetNotFound(const Event& event) override; |
| 231 | 251 |
| 232 // ServerWindowObserver: | 252 // ServerWindowObserver: |
| 233 void OnWindowEmbeddedAppDisconnected(ServerWindow* window) override; | 253 void OnWindowEmbeddedAppDisconnected(ServerWindow* window) override; |
| 234 | 254 |
| 235 // The single WindowTree this WindowManagerState is associated with. | 255 // The single WindowTree this WindowManagerState is associated with. |
| 236 // |window_tree_| owns this. | 256 // |window_tree_| owns this. |
| 237 WindowTree* window_tree_; | 257 WindowTree* window_tree_; |
| 238 | 258 |
| 239 // Set to true the first time SetFrameDecorationValues() is called. | 259 // Set to true the first time SetFrameDecorationValues() is called. |
| 240 bool got_frame_decoration_values_ = false; | 260 bool got_frame_decoration_values_ = false; |
| 241 mojom::FrameDecorationValuesPtr frame_decoration_values_; | 261 mojom::FrameDecorationValuesPtr frame_decoration_values_; |
| 242 | 262 |
| 243 EventDispatchPhase event_dispatch_phase_ = EventDispatchPhase::NONE; | |
| 244 // The tree we're waiting to process the current accelerator or event. | |
| 245 WindowTree* tree_awaiting_input_ack_ = nullptr; | |
| 246 // The event we're awaiting an accelerator or input ack from. | |
| 247 std::unique_ptr<ui::Event> event_awaiting_input_ack_; | |
| 248 base::WeakPtr<Accelerator> post_target_accelerator_; | 263 base::WeakPtr<Accelerator> post_target_accelerator_; |
| 249 std::queue<std::unique_ptr<QueuedEvent>> event_queue_; | 264 std::queue<std::unique_ptr<QueuedEvent>> event_queue_; |
| 250 base::OneShotTimer event_ack_timer_; | |
| 251 | 265 |
| 252 std::vector<DebugAccelerator> debug_accelerators_; | 266 std::vector<DebugAccelerator> debug_accelerators_; |
| 253 | 267 |
| 268 // If non-null we're actively waiting for a response from a client for an | |
| 269 // event. | |
| 270 std::unique_ptr<InFlightEventDetails> in_flight_event_details_; | |
| 271 | |
| 254 EventDispatcher event_dispatcher_; | 272 EventDispatcher event_dispatcher_; |
| 255 | 273 |
| 256 // PlatformDisplay that currently has capture. | 274 // PlatformDisplay that currently has capture. |
| 257 PlatformDisplay* platform_display_with_capture_ = nullptr; | 275 PlatformDisplay* platform_display_with_capture_ = nullptr; |
| 258 | 276 |
| 259 // All the active WindowManagerDisplayRoots. | 277 // All the active WindowManagerDisplayRoots. |
| 260 WindowManagerDisplayRoots window_manager_display_roots_; | 278 WindowManagerDisplayRoots window_manager_display_roots_; |
| 261 | 279 |
| 280 // Id of the display the current event being processed originated from. | |
| 281 int64_t event_processing_display_id_ = 0; | |
| 282 | |
| 262 // Set of WindowManagerDisplayRoots corresponding to Displays that have been | 283 // Set of WindowManagerDisplayRoots corresponding to Displays that have been |
| 263 // destroyed. WindowManagerDisplayRoots are not destroyed immediately when | 284 // destroyed. WindowManagerDisplayRoots are not destroyed immediately when |
| 264 // the Display is destroyed to allow the client to destroy the window when it | 285 // the Display is destroyed to allow the client to destroy the window when it |
| 265 // wants to. Once the client destroys the window WindowManagerDisplayRoots is | 286 // wants to. Once the client destroys the window WindowManagerDisplayRoots is |
| 266 // destroyed. | 287 // destroyed. |
| 267 WindowManagerDisplayRoots orphaned_window_manager_display_roots_; | 288 WindowManagerDisplayRoots orphaned_window_manager_display_roots_; |
| 268 | 289 |
| 269 base::WeakPtrFactory<WindowManagerState> weak_factory_; | 290 base::WeakPtrFactory<WindowManagerState> weak_factory_; |
| 270 | 291 |
| 271 DISALLOW_COPY_AND_ASSIGN(WindowManagerState); | 292 DISALLOW_COPY_AND_ASSIGN(WindowManagerState); |
| 272 }; | 293 }; |
| 273 | 294 |
| 274 } // namespace ws | 295 } // namespace ws |
| 275 } // namespace ui | 296 } // namespace ui |
| 276 | 297 |
| 277 #endif // SERVICES_UI_WS_WINDOW_MANAGER_STATE_H_ | 298 #endif // SERVICES_UI_WS_WINDOW_MANAGER_STATE_H_ |
| OLD | NEW |