| 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> |
| 11 #include <queue> | 11 #include <queue> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
| 16 #include "services/ui/public/interfaces/display.mojom.h" | 16 #include "services/ui/public/interfaces/display.mojom.h" |
| 17 #include "services/ui/ws/event_dispatcher.h" | 17 #include "services/ui/ws/event_dispatcher.h" |
| 18 #include "services/ui/ws/event_dispatcher_delegate.h" | 18 #include "services/ui/ws/event_dispatcher_delegate.h" |
| 19 #include "services/ui/ws/server_window_observer.h" |
| 19 #include "services/ui/ws/user_id.h" | 20 #include "services/ui/ws/user_id.h" |
| 20 #include "services/ui/ws/window_server.h" | 21 #include "services/ui/ws/window_server.h" |
| 21 | 22 |
| 22 namespace ui { | 23 namespace ui { |
| 23 namespace ws { | 24 namespace ws { |
| 24 | 25 |
| 25 class DisplayManager; | 26 class DisplayManager; |
| 27 class WindowManagerDisplayRoot; |
| 26 class WindowTree; | 28 class WindowTree; |
| 27 | 29 |
| 28 namespace test { | 30 namespace test { |
| 29 class WindowManagerStateTestApi; | 31 class WindowManagerStateTestApi; |
| 30 } | 32 } |
| 31 | 33 |
| 32 // Manages state specific to a WindowManager that is shared across displays. | 34 // Manages state specific to a WindowManager that is shared across displays. |
| 33 // WindowManagerState is owned by the WindowTree the window manager is | 35 // WindowManagerState is owned by the WindowTree the window manager is |
| 34 // associated with. | 36 // associated with. |
| 35 class WindowManagerState : public EventDispatcherDelegate { | 37 class WindowManagerState : public EventDispatcherDelegate, |
| 38 public ServerWindowObserver { |
| 36 public: | 39 public: |
| 37 explicit WindowManagerState(WindowTree* window_tree); | 40 explicit WindowManagerState(WindowTree* window_tree); |
| 38 ~WindowManagerState() override; | 41 ~WindowManagerState() override; |
| 39 | 42 |
| 40 const UserId& user_id() const; | 43 const UserId& user_id() const; |
| 41 | 44 |
| 42 WindowTree* window_tree() { return window_tree_; } | 45 WindowTree* window_tree() { return window_tree_; } |
| 43 const WindowTree* window_tree() const { return window_tree_; } | 46 const WindowTree* window_tree() const { return window_tree_; } |
| 44 | 47 |
| 45 void OnWillDestroyTree(WindowTree* tree); | 48 void OnWillDestroyTree(WindowTree* tree); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 65 DragSource* drag_source, | 68 DragSource* drag_source, |
| 66 ServerWindow* window, | 69 ServerWindow* window, |
| 67 DragTargetConnection* source_connection, | 70 DragTargetConnection* source_connection, |
| 68 int32_t drag_pointer, | 71 int32_t drag_pointer, |
| 69 mojo::Map<mojo::String, mojo::Array<uint8_t>> drag_data, | 72 mojo::Map<mojo::String, mojo::Array<uint8_t>> drag_data, |
| 70 uint32_t drag_operation); | 73 uint32_t drag_operation); |
| 71 void EndDragDrop(); | 74 void EndDragDrop(); |
| 72 | 75 |
| 73 void AddSystemModalWindow(ServerWindow* window); | 76 void AddSystemModalWindow(ServerWindow* window); |
| 74 | 77 |
| 78 // Returns the ServerWindow corresponding to an orphaned root with the |
| 79 // specified id. See |orphaned_window_manager_display_roots_| for details on |
| 80 // what on orphaned root is. |
| 81 ServerWindow* GetOrphanedRootWithId(const WindowId& id); |
| 82 |
| 75 // TODO(sky): EventDispatcher is really an implementation detail and should | 83 // TODO(sky): EventDispatcher is really an implementation detail and should |
| 76 // not be exposed. | 84 // not be exposed. |
| 77 EventDispatcher* event_dispatcher() { return &event_dispatcher_; } | 85 EventDispatcher* event_dispatcher() { return &event_dispatcher_; } |
| 78 | 86 |
| 79 // Returns true if this is the WindowManager of the active user. | 87 // Returns true if this is the WindowManager of the active user. |
| 80 bool IsActive() const; | 88 bool IsActive() const; |
| 81 | 89 |
| 82 void Activate(const gfx::Point& mouse_location_on_screen); | 90 void Activate(const gfx::Point& mouse_location_on_screen); |
| 83 void Deactivate(); | 91 void Deactivate(); |
| 84 | 92 |
| 85 // Processes an event from PlatformDisplay. | 93 // Processes an event from PlatformDisplay. |
| 86 void ProcessEvent(const ui::Event& event); | 94 void ProcessEvent(const ui::Event& event); |
| 87 | 95 |
| 88 // Called when the ack from an event dispatched to WindowTree |tree| is | 96 // Called when the ack from an event dispatched to WindowTree |tree| is |
| 89 // received. | 97 // received. |
| 90 // TODO(sky): make this private and use a callback. | 98 // TODO(sky): make this private and use a callback. |
| 91 void OnEventAck(mojom::WindowTree* tree, mojom::EventResult result); | 99 void OnEventAck(mojom::WindowTree* tree, mojom::EventResult result); |
| 92 | 100 |
| 93 // Called when the WindowManager acks an accelerator. | 101 // Called when the WindowManager acks an accelerator. |
| 94 void OnAcceleratorAck(mojom::EventResult result); | 102 void OnAcceleratorAck(mojom::EventResult result); |
| 95 | 103 |
| 96 private: | 104 private: |
| 97 class ProcessedEventTarget; | 105 class ProcessedEventTarget; |
| 98 friend class Display; | 106 friend class Display; |
| 99 friend class test::WindowManagerStateTestApi; | 107 friend class test::WindowManagerStateTestApi; |
| 100 | 108 |
| 109 // Set of display roots. This is a vector rather than a set to support removal |
| 110 // without deleting. |
| 111 using WindowManagerDisplayRoots = |
| 112 std::vector<std::unique_ptr<WindowManagerDisplayRoot>>; |
| 113 |
| 101 enum class DebugAcceleratorType { | 114 enum class DebugAcceleratorType { |
| 102 PRINT_WINDOWS, | 115 PRINT_WINDOWS, |
| 103 }; | 116 }; |
| 104 | 117 |
| 105 struct DebugAccelerator { | 118 struct DebugAccelerator { |
| 106 bool Matches(const ui::KeyEvent& event) const; | 119 bool Matches(const ui::KeyEvent& event) const; |
| 107 | 120 |
| 108 DebugAcceleratorType type; | 121 DebugAcceleratorType type; |
| 109 ui::KeyboardCode key_code; | 122 ui::KeyboardCode key_code; |
| 110 int event_flags; | 123 int event_flags; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 136 std::unique_ptr<ui::Event> event; | 149 std::unique_ptr<ui::Event> event; |
| 137 std::unique_ptr<ProcessedEventTarget> processed_target; | 150 std::unique_ptr<ProcessedEventTarget> processed_target; |
| 138 }; | 151 }; |
| 139 | 152 |
| 140 const WindowServer* window_server() const; | 153 const WindowServer* window_server() const; |
| 141 WindowServer* window_server(); | 154 WindowServer* window_server(); |
| 142 | 155 |
| 143 DisplayManager* display_manager(); | 156 DisplayManager* display_manager(); |
| 144 const DisplayManager* display_manager() const; | 157 const DisplayManager* display_manager() const; |
| 145 | 158 |
| 159 // Adds |display_root| to the set of WindowManagerDisplayRoots owned by this |
| 160 // WindowManagerState. |
| 161 void AddWindowManagerDisplayRoot( |
| 162 std::unique_ptr<WindowManagerDisplayRoot> display_root); |
| 163 |
| 164 // Called when a Display is deleted. |
| 165 void OnDisplayDestroying(Display* display); |
| 166 |
| 146 // Sets the visibility of all window manager roots windows to |value|. | 167 // Sets the visibility of all window manager roots windows to |value|. |
| 147 void SetAllRootWindowsVisible(bool value); | 168 void SetAllRootWindowsVisible(bool value); |
| 148 | 169 |
| 149 // Returns the ServerWindow that is the root of the WindowManager for | 170 // Returns the ServerWindow that is the root of the WindowManager for |
| 150 // |window|. |window| corresponds to the root of a Display. | 171 // |window|. |window| corresponds to the root of a Display. |
| 151 ServerWindow* GetWindowManagerRoot(ServerWindow* window); | 172 ServerWindow* GetWindowManagerRoot(ServerWindow* window); |
| 152 | 173 |
| 153 // Called if the client doesn't ack an event in the appropriate amount of | 174 // Called if the client doesn't ack an event in the appropriate amount of |
| 154 // time. | 175 // time. |
| 155 void OnEventAckTimeout(ClientSpecificId client_id); | 176 void OnEventAckTimeout(ClientSpecificId client_id); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 void OnMouseCursorLocationChanged(const gfx::Point& point) override; | 220 void OnMouseCursorLocationChanged(const gfx::Point& point) override; |
| 200 void DispatchInputEventToWindow(ServerWindow* target, | 221 void DispatchInputEventToWindow(ServerWindow* target, |
| 201 ClientSpecificId client_id, | 222 ClientSpecificId client_id, |
| 202 const ui::Event& event, | 223 const ui::Event& event, |
| 203 Accelerator* accelerator) override; | 224 Accelerator* accelerator) override; |
| 204 ClientSpecificId GetEventTargetClientId(const ServerWindow* window, | 225 ClientSpecificId GetEventTargetClientId(const ServerWindow* window, |
| 205 bool in_nonclient_area) override; | 226 bool in_nonclient_area) override; |
| 206 ServerWindow* GetRootWindowContaining(gfx::Point* location) override; | 227 ServerWindow* GetRootWindowContaining(gfx::Point* location) override; |
| 207 void OnEventTargetNotFound(const ui::Event& event) override; | 228 void OnEventTargetNotFound(const ui::Event& event) override; |
| 208 | 229 |
| 230 // ServerWindowObserver: |
| 231 void OnWindowEmbeddedAppDisconnected(ServerWindow* window) override; |
| 232 |
| 209 // The single WindowTree this WindowManagerState is associated with. | 233 // The single WindowTree this WindowManagerState is associated with. |
| 210 // |window_tree_| owns this. | 234 // |window_tree_| owns this. |
| 211 WindowTree* window_tree_; | 235 WindowTree* window_tree_; |
| 212 | 236 |
| 213 // Set to true the first time SetFrameDecorationValues() is called. | 237 // Set to true the first time SetFrameDecorationValues() is called. |
| 214 bool got_frame_decoration_values_ = false; | 238 bool got_frame_decoration_values_ = false; |
| 215 mojom::FrameDecorationValuesPtr frame_decoration_values_; | 239 mojom::FrameDecorationValuesPtr frame_decoration_values_; |
| 216 | 240 |
| 217 EventDispatchPhase event_dispatch_phase_ = EventDispatchPhase::NONE; | 241 EventDispatchPhase event_dispatch_phase_ = EventDispatchPhase::NONE; |
| 218 // The tree we're waiting to process the current accelerator or event. | 242 // The tree we're waiting to process the current accelerator or event. |
| 219 mojom::WindowTree* tree_awaiting_input_ack_ = nullptr; | 243 mojom::WindowTree* tree_awaiting_input_ack_ = nullptr; |
| 220 // The event we're awaiting an accelerator or input ack from. | 244 // The event we're awaiting an accelerator or input ack from. |
| 221 std::unique_ptr<ui::Event> event_awaiting_input_ack_; | 245 std::unique_ptr<ui::Event> event_awaiting_input_ack_; |
| 222 base::WeakPtr<Accelerator> post_target_accelerator_; | 246 base::WeakPtr<Accelerator> post_target_accelerator_; |
| 223 std::queue<std::unique_ptr<QueuedEvent>> event_queue_; | 247 std::queue<std::unique_ptr<QueuedEvent>> event_queue_; |
| 224 base::OneShotTimer event_ack_timer_; | 248 base::OneShotTimer event_ack_timer_; |
| 225 | 249 |
| 226 std::vector<DebugAccelerator> debug_accelerators_; | 250 std::vector<DebugAccelerator> debug_accelerators_; |
| 227 | 251 |
| 228 EventDispatcher event_dispatcher_; | 252 EventDispatcher event_dispatcher_; |
| 229 | 253 |
| 230 // PlatformDisplay that currently has capture. | 254 // PlatformDisplay that currently has capture. |
| 231 PlatformDisplay* platform_display_with_capture_ = nullptr; | 255 PlatformDisplay* platform_display_with_capture_ = nullptr; |
| 232 | 256 |
| 257 // All the active WindowManagerDisplayRoots. |
| 258 WindowManagerDisplayRoots window_manager_display_roots_; |
| 259 |
| 260 // Set of WindowManagerDisplayRoots corresponding to Displays that have been |
| 261 // destroyed. WindowManagerDisplayRoots are not destroyed immediately when |
| 262 // the Display is destroyed to allow the client to destroy the window when it |
| 263 // wants to. Once the client destroys the window WindowManagerDisplayRoots is |
| 264 // destroyed. |
| 265 WindowManagerDisplayRoots orphaned_window_manager_display_roots_; |
| 266 |
| 233 base::WeakPtrFactory<WindowManagerState> weak_factory_; | 267 base::WeakPtrFactory<WindowManagerState> weak_factory_; |
| 234 | 268 |
| 235 DISALLOW_COPY_AND_ASSIGN(WindowManagerState); | 269 DISALLOW_COPY_AND_ASSIGN(WindowManagerState); |
| 236 }; | 270 }; |
| 237 | 271 |
| 238 } // namespace ws | 272 } // namespace ws |
| 239 } // namespace ui | 273 } // namespace ui |
| 240 | 274 |
| 241 #endif // SERVICES_UI_WS_WINDOW_MANAGER_STATE_H_ | 275 #endif // SERVICES_UI_WS_WINDOW_MANAGER_STATE_H_ |
| OLD | NEW |