| 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 COMPONENTS_MUS_WS_WINDOW_MANAGER_STATE_H_ | 5 #ifndef COMPONENTS_MUS_WS_WINDOW_MANAGER_STATE_H_ |
| 6 #define COMPONENTS_MUS_WS_WINDOW_MANAGER_STATE_H_ | 6 #define COMPONENTS_MUS_WS_WINDOW_MANAGER_STATE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "components/mus/public/interfaces/display.mojom.h" | 14 #include "components/mus/public/interfaces/display.mojom.h" |
| 15 #include "components/mus/ws/event_dispatcher.h" | 15 #include "components/mus/ws/event_dispatcher.h" |
| 16 #include "components/mus/ws/event_dispatcher_delegate.h" | 16 #include "components/mus/ws/event_dispatcher_delegate.h" |
| 17 #include "components/mus/ws/user_id.h" | 17 #include "components/mus/ws/user_id.h" |
| 18 #include "components/mus/ws/window_server.h" | 18 #include "components/mus/ws/window_server.h" |
| 19 | 19 |
| 20 namespace mus { | 20 namespace mus { |
| 21 namespace ws { | 21 namespace ws { |
| 22 | 22 |
| 23 class Accelerator; | 23 class DisplayManager; |
| 24 class Display; | |
| 25 class PlatformDisplay; | |
| 26 class ServerWindow; | |
| 27 class WindowTree; | 24 class WindowTree; |
| 28 | 25 |
| 29 namespace test { | 26 namespace test { |
| 30 class WindowManagerStateTestApi; | 27 class WindowManagerStateTestApi; |
| 31 } | 28 } |
| 32 | 29 |
| 33 // Manages the state associated with a connection to a WindowManager for | 30 // Manages state specific to a WindowManager that is shared across displays. |
| 34 // a specific user. | 31 // WindowManagerState is owned by the WindowTree the window manager is |
| 32 // associated with. |
| 35 class WindowManagerState : public EventDispatcherDelegate { | 33 class WindowManagerState : public EventDispatcherDelegate { |
| 36 public: | 34 public: |
| 37 // Creates a WindowManagerState that can host content from any user. | 35 explicit WindowManagerState(WindowTree* window_tree); |
| 38 WindowManagerState(Display* display, PlatformDisplay* platform_display); | |
| 39 WindowManagerState(Display* display, | |
| 40 PlatformDisplay* platform_display, | |
| 41 const UserId& user_id); | |
| 42 ~WindowManagerState() override; | 36 ~WindowManagerState() override; |
| 43 | 37 |
| 44 bool is_user_id_valid() const { return is_user_id_valid_; } | 38 const UserId& user_id() const; |
| 45 | 39 |
| 46 const UserId& user_id() const { return user_id_; } | 40 WindowTree* window_tree() { return window_tree_; } |
| 41 const WindowTree* window_tree() const { return window_tree_; } |
| 47 | 42 |
| 48 ServerWindow* root() { return root_.get(); } | 43 void OnWillDestroyTree(WindowTree* tree); |
| 49 const ServerWindow* root() const { return root_.get(); } | |
| 50 | 44 |
| 51 WindowTree* tree() { return tree_; } | 45 void SetFrameDecorationValues(mojom::FrameDecorationValuesPtr values); |
| 52 const WindowTree* tree() const { return tree_; } | 46 const mojom::FrameDecorationValues& frame_decoration_values() const { |
| 53 | 47 return *frame_decoration_values_; |
| 54 Display* display() { return display_; } | 48 } |
| 55 const Display* display() const { return display_; } | 49 bool got_frame_decoration_values() const { |
| 50 return got_frame_decoration_values_; |
| 51 } |
| 56 | 52 |
| 57 bool SetCapture(ServerWindow* window, ClientSpecificId client_id); | 53 bool SetCapture(ServerWindow* window, ClientSpecificId client_id); |
| 58 ServerWindow* capture_window() { return event_dispatcher_.capture_window(); } | 54 ServerWindow* capture_window() { return event_dispatcher_.capture_window(); } |
| 59 const ServerWindow* capture_window() const { | 55 const ServerWindow* capture_window() const { |
| 60 return event_dispatcher_.capture_window(); | 56 return event_dispatcher_.capture_window(); |
| 61 } | 57 } |
| 62 | 58 |
| 63 void ReleaseCaptureBlockedByModalWindow(const ServerWindow* modal_window); | 59 void ReleaseCaptureBlockedByModalWindow(const ServerWindow* modal_window); |
| 64 void ReleaseCaptureBlockedByAnyModalWindow(); | 60 void ReleaseCaptureBlockedByAnyModalWindow(); |
| 65 | 61 |
| 66 void AddSystemModalWindow(ServerWindow* window); | 62 void AddSystemModalWindow(ServerWindow* window); |
| 67 | 63 |
| 68 // Returns true if this is the WindowManager of the active user. | |
| 69 bool IsActive() const; | |
| 70 | |
| 71 // TODO(sky): EventDispatcher is really an implementation detail and should | 64 // TODO(sky): EventDispatcher is really an implementation detail and should |
| 72 // not be exposed. | 65 // not be exposed. |
| 73 EventDispatcher* event_dispatcher() { return &event_dispatcher_; } | 66 EventDispatcher* event_dispatcher() { return &event_dispatcher_; } |
| 74 | 67 |
| 68 // Returns true if this is the WindowManager of the active user. |
| 69 bool IsActive() const; |
| 70 |
| 75 void Activate(const gfx::Point& mouse_location_on_screen); | 71 void Activate(const gfx::Point& mouse_location_on_screen); |
| 76 void Deactivate(); | 72 void Deactivate(); |
| 77 | 73 |
| 78 // Processes an event from PlatformDisplay. | 74 // Processes an event from PlatformDisplay. |
| 79 void ProcessEvent(const ui::Event& event); | 75 void ProcessEvent(const ui::Event& event); |
| 80 | 76 |
| 81 // Called when the ack from an event dispatched to WindowTree |tree| is | 77 // Called when the ack from an event dispatched to WindowTree |tree| is |
| 82 // received. | 78 // received. |
| 83 // TODO(sky): make this private and use a callback. | 79 // TODO(sky): make this private and use a callback. |
| 84 void OnEventAck(mojom::WindowTree* tree, mojom::EventResult result); | 80 void OnEventAck(mojom::WindowTree* tree, mojom::EventResult result); |
| 85 | 81 |
| 86 void OnWillDestroyTree(WindowTree* tree); | |
| 87 | |
| 88 private: | 82 private: |
| 89 class ProcessedEventTarget; | 83 class ProcessedEventTarget; |
| 90 friend class Display; | 84 friend class Display; |
| 91 friend class test::WindowManagerStateTestApi; | 85 friend class test::WindowManagerStateTestApi; |
| 92 | 86 |
| 93 // There are two types of events that may be queued, both occur only when | 87 // There are two types of events that may be queued, both occur only when |
| 94 // waiting for an ack from a client. | 88 // waiting for an ack from a client. |
| 95 // . We get an event from the PlatformDisplay. This results in |event| being | 89 // . We get an event from the PlatformDisplay. This results in |event| being |
| 96 // set, but |processed_target| is null. | 90 // set, but |processed_target| is null. |
| 97 // . We get an event from the EventDispatcher. In this case both |event| and | 91 // . We get an event from the EventDispatcher. In this case both |event| and |
| 98 // |processed_target| are valid. | 92 // |processed_target| are valid. |
| 99 // The second case happens if EventDispatcher generates more than one event | 93 // The second case happens if EventDispatcher generates more than one event |
| 100 // at a time. | 94 // at a time. |
| 101 struct QueuedEvent { | 95 struct QueuedEvent { |
| 102 QueuedEvent(); | 96 QueuedEvent(); |
| 103 ~QueuedEvent(); | 97 ~QueuedEvent(); |
| 104 | 98 |
| 105 std::unique_ptr<ui::Event> event; | 99 std::unique_ptr<ui::Event> event; |
| 106 std::unique_ptr<ProcessedEventTarget> processed_target; | 100 std::unique_ptr<ProcessedEventTarget> processed_target; |
| 107 }; | 101 }; |
| 108 | 102 |
| 109 WindowManagerState(Display* display, | 103 const WindowServer* window_server() const; |
| 110 PlatformDisplay* platform_display, | 104 WindowServer* window_server(); |
| 111 bool is_user_id_valid, | |
| 112 const UserId& user_id); | |
| 113 | 105 |
| 114 WindowServer* window_server(); | 106 DisplayManager* display_manager(); |
| 107 const DisplayManager* display_manager() const; |
| 108 |
| 109 // Sets the visibility of all window manager roots windows to |value|. |
| 110 void SetAllRootWindowsVisible(bool value); |
| 111 |
| 112 // Returns the ServerWindow that is the root of the WindowManager for |
| 113 // |window|. |window| corresponds to the root of a Display. |
| 114 ServerWindow* GetWindowManagerRoot(ServerWindow* window); |
| 115 | 115 |
| 116 void OnEventAckTimeout(ClientSpecificId client_id); | 116 void OnEventAckTimeout(ClientSpecificId client_id); |
| 117 | 117 |
| 118 // Schedules an event to be processed later. | 118 // Schedules an event to be processed later. |
| 119 void QueueEvent(const ui::Event& event, | 119 void QueueEvent(const ui::Event& event, |
| 120 std::unique_ptr<ProcessedEventTarget> processed_event_target); | 120 std::unique_ptr<ProcessedEventTarget> processed_event_target); |
| 121 | 121 |
| 122 // Processes the next valid event in |event_queue_|. If the event has already | 122 // Processes the next valid event in |event_queue_|. If the event has already |
| 123 // been processed it is dispatched, otherwise the event is passed to the | 123 // been processed it is dispatched, otherwise the event is passed to the |
| 124 // EventDispatcher for processing. | 124 // EventDispatcher for processing. |
| 125 void ProcessNextEventFromQueue(); | 125 void ProcessNextEventFromQueue(); |
| 126 | 126 |
| 127 // Dispatches the event to the appropriate client and starts the ack timer. | 127 // Dispatches the event to the appropriate client and starts the ack timer. |
| 128 void DispatchInputEventToWindowImpl(ServerWindow* target, | 128 void DispatchInputEventToWindowImpl(ServerWindow* target, |
| 129 ClientSpecificId client_id, | 129 ClientSpecificId client_id, |
| 130 const ui::Event& event, | 130 const ui::Event& event, |
| 131 base::WeakPtr<Accelerator> accelerator); | 131 base::WeakPtr<Accelerator> accelerator); |
| 132 | 132 |
| 133 // Registers accelerators used internally for debugging. | 133 // Registers accelerators used internally for debugging. |
| 134 void AddDebugAccelerators(); | 134 void AddDebugAccelerators(); |
| 135 | 135 |
| 136 // Returns true if the accelerator was handled. | 136 // Returns true if the accelerator was handled. |
| 137 bool HandleDebugAccelerator(uint32_t accelerator_id); | 137 bool HandleDebugAccelerator(uint32_t accelerator_id); |
| 138 | 138 |
| 139 // EventDispatcherDelegate: | 139 // EventDispatcherDelegate: |
| 140 void OnAccelerator(uint32_t accelerator_id, const ui::Event& event) override; | 140 void OnAccelerator(uint32_t accelerator_id, const ui::Event& event) override; |
| 141 void SetFocusedWindowFromEventDispatcher(ServerWindow* window) override; | 141 void SetFocusedWindowFromEventDispatcher(ServerWindow* window) override; |
| 142 ServerWindow* GetFocusedWindowForEventDispatcher() override; | 142 ServerWindow* GetFocusedWindowForEventDispatcher() override; |
| 143 void SetNativeCapture() override; | 143 void SetNativeCapture(ServerWindow* window) override; |
| 144 void ReleaseNativeCapture() override; | 144 void ReleaseNativeCapture() override; |
| 145 void OnServerWindowCaptureLost(ServerWindow* window) override; | 145 void OnServerWindowCaptureLost(ServerWindow* window) override; |
| 146 void OnMouseCursorLocationChanged(const gfx::Point& point) override; | 146 void OnMouseCursorLocationChanged(const gfx::Point& point) override; |
| 147 void DispatchInputEventToWindow(ServerWindow* target, | 147 void DispatchInputEventToWindow(ServerWindow* target, |
| 148 ClientSpecificId client_id, | 148 ClientSpecificId client_id, |
| 149 const ui::Event& event, | 149 const ui::Event& event, |
| 150 Accelerator* accelerator) override; | 150 Accelerator* accelerator) override; |
| 151 ClientSpecificId GetEventTargetClientId(const ServerWindow* window, | 151 ClientSpecificId GetEventTargetClientId(const ServerWindow* window, |
| 152 bool in_nonclient_area) override; | 152 bool in_nonclient_area) override; |
| 153 | 153 ServerWindow* GetRootWindowContaining(const gfx::Point& location) override; |
| 154 void OnEventTargetNotFound(const ui::Event& event) override; | 154 void OnEventTargetNotFound(const ui::Event& event) override; |
| 155 | 155 |
| 156 Display* display_; | 156 // The single WindowTree this WindowManagerState is associated with. |
| 157 PlatformDisplay* platform_display_; | 157 // |window_tree_| owns this. |
| 158 // If this was created implicitly by a call | 158 WindowTree* window_tree_; |
| 159 // WindowTreeHostFactory::CreateWindowTreeHost(), then |is_user_id_valid_| | 159 |
| 160 // is false. | 160 // Set to true the first time SetFrameDecorationValues() is called. |
| 161 const bool is_user_id_valid_; | 161 bool got_frame_decoration_values_ = false; |
| 162 const UserId user_id_; | 162 mojom::FrameDecorationValuesPtr frame_decoration_values_; |
| 163 // Root ServerWindow of this WindowManagerState. |root_| has a parent, the | |
| 164 // root ServerWindow of the Display. | |
| 165 std::unique_ptr<ServerWindow> root_; | |
| 166 WindowTree* tree_ = nullptr; | |
| 167 | 163 |
| 168 mojom::WindowTree* tree_awaiting_input_ack_ = nullptr; | 164 mojom::WindowTree* tree_awaiting_input_ack_ = nullptr; |
| 169 std::unique_ptr<ui::Event> event_awaiting_input_ack_; | 165 std::unique_ptr<ui::Event> event_awaiting_input_ack_; |
| 170 base::WeakPtr<Accelerator> post_target_accelerator_; | 166 base::WeakPtr<Accelerator> post_target_accelerator_; |
| 171 std::queue<std::unique_ptr<QueuedEvent>> event_queue_; | 167 std::queue<std::unique_ptr<QueuedEvent>> event_queue_; |
| 172 base::OneShotTimer event_ack_timer_; | 168 base::OneShotTimer event_ack_timer_; |
| 173 | 169 |
| 174 EventDispatcher event_dispatcher_; | 170 EventDispatcher event_dispatcher_; |
| 175 | 171 |
| 172 // PlatformDisplay that currently has capture. |
| 173 PlatformDisplay* platform_display_with_capture_ = nullptr; |
| 174 |
| 176 base::WeakPtrFactory<WindowManagerState> weak_factory_; | 175 base::WeakPtrFactory<WindowManagerState> weak_factory_; |
| 177 | 176 |
| 178 DISALLOW_COPY_AND_ASSIGN(WindowManagerState); | 177 DISALLOW_COPY_AND_ASSIGN(WindowManagerState); |
| 179 }; | 178 }; |
| 180 | 179 |
| 181 } // namespace ws | 180 } // namespace ws |
| 182 } // namespace mus | 181 } // namespace mus |
| 183 | 182 |
| 184 #endif // COMPONENTS_MUS_WS_WINDOW_MANAGER_STATE_H_ | 183 #endif // COMPONENTS_MUS_WS_WINDOW_MANAGER_STATE_H_ |
| OLD | NEW |