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