Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(559)

Side by Side Diff: components/mus/ws/display.h

Issue 1775133003: Moves EventDispatcher from Display to WindowManagerState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: todo Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/mus/ws/connection_manager.cc ('k') | components/mus/ws/display.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_DISPLAY_H_ 5 #ifndef COMPONENTS_MUS_WS_DISPLAY_H_
6 #define COMPONENTS_MUS_WS_DISPLAY_H_ 6 #define COMPONENTS_MUS_WS_DISPLAY_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <queue> 11 #include <queue>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "components/mus/common/types.h" 16 #include "components/mus/common/types.h"
17 #include "components/mus/public/interfaces/window_manager_constants.mojom.h" 17 #include "components/mus/public/interfaces/window_manager_constants.mojom.h"
18 #include "components/mus/public/interfaces/window_tree_host.mojom.h" 18 #include "components/mus/public/interfaces/window_tree_host.mojom.h"
19 #include "components/mus/ws/event_dispatcher.h"
20 #include "components/mus/ws/event_dispatcher_delegate.h"
21 #include "components/mus/ws/focus_controller_delegate.h" 19 #include "components/mus/ws/focus_controller_delegate.h"
22 #include "components/mus/ws/focus_controller_observer.h" 20 #include "components/mus/ws/focus_controller_observer.h"
23 #include "components/mus/ws/platform_display.h" 21 #include "components/mus/ws/platform_display.h"
24 #include "components/mus/ws/server_window.h" 22 #include "components/mus/ws/server_window.h"
25 #include "components/mus/ws/server_window_observer.h" 23 #include "components/mus/ws/server_window_observer.h"
26 #include "components/mus/ws/server_window_tracker.h" 24 #include "components/mus/ws/server_window_tracker.h"
27 #include "components/mus/ws/user_id_tracker_observer.h" 25 #include "components/mus/ws/user_id_tracker_observer.h"
28 #include "components/mus/ws/window_manager_factory_registry_observer.h" 26 #include "components/mus/ws/window_manager_factory_registry_observer.h"
29 27
30 namespace mus { 28 namespace mus {
(...skipping 16 matching lines...) Expand all
47 // ways: 45 // ways:
48 // . with a DisplayBinding. In this mode there is only ever one WindowManager 46 // . with a DisplayBinding. In this mode there is only ever one WindowManager
49 // for the display, which comes from the client that created the 47 // for the display, which comes from the client that created the
50 // Display. 48 // Display.
51 // . without a DisplayBinding. In this mode a WindowManager is automatically 49 // . without a DisplayBinding. In this mode a WindowManager is automatically
52 // created per user. 50 // created per user.
53 class Display : public PlatformDisplayDelegate, 51 class Display : public PlatformDisplayDelegate,
54 public mojom::WindowTreeHost, 52 public mojom::WindowTreeHost,
55 public FocusControllerObserver, 53 public FocusControllerObserver,
56 public FocusControllerDelegate, 54 public FocusControllerDelegate,
57 public EventDispatcherDelegate,
58 public ServerWindowObserver, 55 public ServerWindowObserver,
59 public UserIdTrackerObserver, 56 public UserIdTrackerObserver,
60 public WindowManagerFactoryRegistryObserver { 57 public WindowManagerFactoryRegistryObserver {
61 public: 58 public:
62 // TODO(fsamuel): All these parameters are just plumbing for creating 59 // TODO(fsamuel): All these parameters are just plumbing for creating
63 // PlatformDisplays. We should probably just store these common parameters 60 // PlatformDisplays. We should probably just store these common parameters
64 // in the PlatformDisplayFactory and pass them along on 61 // in the PlatformDisplayFactory and pass them along on
65 // PlatformDisplay::Create. 62 // PlatformDisplay::Create.
66 Display(ConnectionManager* connection_manager, 63 Display(ConnectionManager* connection_manager,
67 mojo::Connector* connector, 64 mojo::Connector* connector,
(...skipping 22 matching lines...) Expand all
90 // drawn, otherwise destruction is immediate. 87 // drawn, otherwise destruction is immediate.
91 void ScheduleSurfaceDestruction(ServerWindow* window); 88 void ScheduleSurfaceDestruction(ServerWindow* window);
92 89
93 // Returns the metrics for this viewport. 90 // Returns the metrics for this viewport.
94 const mojom::ViewportMetrics& GetViewportMetrics() const; 91 const mojom::ViewportMetrics& GetViewportMetrics() const;
95 92
96 mojom::Rotation GetRotation() const; 93 mojom::Rotation GetRotation() const;
97 94
98 ConnectionManager* connection_manager() { return connection_manager_; } 95 ConnectionManager* connection_manager() { return connection_manager_; }
99 96
100 EventDispatcher* event_dispatcher() { return &event_dispatcher_; }
101
102 // Returns the root of the Display. The root's children are the roots 97 // Returns the root of the Display. The root's children are the roots
103 // of the corresponding WindowManagers. 98 // of the corresponding WindowManagers.
104 ServerWindow* root_window() { return root_.get(); } 99 ServerWindow* root_window() { return root_.get(); }
105 const ServerWindow* root_window() const { return root_.get(); } 100 const ServerWindow* root_window() const { return root_.get(); }
106 101
107 ServerWindow* GetRootWithId(const WindowId& id); 102 ServerWindow* GetRootWithId(const WindowId& id);
108 103
109 WindowManagerState* GetWindowManagerStateWithRoot(const ServerWindow* window); 104 WindowManagerState* GetWindowManagerStateWithRoot(const ServerWindow* window);
110 // TODO(sky): this is wrong, plumb through user_id. 105 // TODO(sky): this is wrong, plumb through user_id.
111 WindowManagerState* GetFirstWindowManagerState(); 106 WindowManagerState* GetFirstWindowManagerState();
112 WindowManagerState* GetWindowManagerStateForUser(const UserId& user_id) { 107 WindowManagerState* GetWindowManagerStateForUser(const UserId& user_id) {
113 return const_cast<WindowManagerState*>( 108 return const_cast<WindowManagerState*>(
114 const_cast<const Display*>(this)->GetWindowManagerStateForUser( 109 const_cast<const Display*>(this)->GetWindowManagerStateForUser(
115 user_id)); 110 user_id));
116 } 111 }
117 const WindowManagerState* GetWindowManagerStateForUser( 112 const WindowManagerState* GetWindowManagerStateForUser(
118 const UserId& user_id) const; 113 const UserId& user_id) const;
114 WindowManagerState* GetActiveWindowManagerState() {
115 return const_cast<WindowManagerState*>(
116 const_cast<const Display*>(this)->GetActiveWindowManagerState());
117 }
118 const WindowManagerState* GetActiveWindowManagerState() const;
119 size_t num_window_manger_states() const { 119 size_t num_window_manger_states() const {
120 return window_manager_state_map_.size(); 120 return window_manager_state_map_.size();
121 } 121 }
122 122
123 void SetCapture(ServerWindow* window, bool in_nonclient_area);
124
125 void SetFocusedWindow(ServerWindow* window); 123 void SetFocusedWindow(ServerWindow* window);
126 ServerWindow* GetFocusedWindow(); 124 ServerWindow* GetFocusedWindow();
127 void DestroyFocusController(); 125 void DestroyFocusController();
128 FocusController* focus_controller() { return focus_controller_.get(); } 126 FocusController* focus_controller() { return focus_controller_.get(); }
129 127
130 void AddActivationParent(ServerWindow* window); 128 void AddActivationParent(ServerWindow* window);
131 void RemoveActivationParent(ServerWindow* window); 129 void RemoveActivationParent(ServerWindow* window);
132 130
133 void UpdateTextInputState(ServerWindow* window, 131 void UpdateTextInputState(ServerWindow* window,
134 const ui::TextInputState& state); 132 const ui::TextInputState& state);
135 void SetImeVisibility(ServerWindow* window, bool visible); 133 void SetImeVisibility(ServerWindow* window, bool visible);
136 134
137 // Returns the window that has captured input.
138 ServerWindow* GetCaptureWindow() {
139 return event_dispatcher_.capture_window();
140 }
141 const ServerWindow* GetCaptureWindow() const {
142 return event_dispatcher_.capture_window();
143 }
144
145 // Called just before |tree| is destroyed. 135 // Called just before |tree| is destroyed.
146 void OnWillDestroyTree(WindowTree* tree); 136 void OnWillDestroyTree(WindowTree* tree);
147 137
138 void UpdateNativeCursor(int32_t cursor_id);
139
148 // Called when a client updates a cursor. This will update the cursor on the 140 // Called when a client updates a cursor. This will update the cursor on the
149 // native display if the cursor is currently under |window|. 141 // native display if the cursor is currently under |window|.
150 void OnCursorUpdated(ServerWindow* window); 142 void OnCursorUpdated(ServerWindow* window);
151 143
152 // Called when the window tree when stacking and bounds of a window 144 // Called when the window tree when stacking and bounds of a window
153 // change. This may update the cursor if the ServerWindow under the last 145 // change. This may update the cursor if the ServerWindow under the last
154 // known pointer location changed. 146 // known pointer location changed.
155 void MaybeChangeCursorOnWindowTreeChange(); 147 void MaybeChangeCursorOnWindowTreeChange();
156 148
157 // mojom::WindowTreeHost: 149 // mojom::WindowTreeHost:
158 void SetSize(mojo::SizePtr size) override; 150 void SetSize(mojo::SizePtr size) override;
159 void SetTitle(const mojo::String& title) override; 151 void SetTitle(const mojo::String& title) override;
160 152
161 void OnEventAck(mojom::WindowTree* tree);
162
163 private: 153 private:
164 class ProcessedEventTarget;
165 friend class test::DisplayTestApi; 154 friend class test::DisplayTestApi;
166 155
167 using WindowManagerStateMap = 156 using WindowManagerStateMap =
168 std::map<UserId, scoped_ptr<WindowManagerState>>; 157 std::map<UserId, scoped_ptr<WindowManagerState>>;
169 158
170 // There are two types of events that may be queued, both occur only when
171 // waiting for an ack from a client.
172 // . We get an event from the PlatformDisplay. This results in |event| being
173 // set, but |processed_target| is null.
174 // . We get an event from the EventDispatcher. In this case both |event| and
175 // |processed_target| are valid.
176 // The second case happens if EventDispatcher generates more than one event
177 // at a time.
178 struct QueuedEvent {
179 QueuedEvent();
180 ~QueuedEvent();
181
182 scoped_ptr<ui::Event> event;
183 scoped_ptr<ProcessedEventTarget> processed_target;
184 };
185
186 // Inits the necessary state once the display is ready. 159 // Inits the necessary state once the display is ready.
187 void InitWindowManagersIfNecessary(); 160 void InitWindowManagersIfNecessary();
188 161
189 void OnEventAckTimeout();
190
191 // Schedules an event to be processed later.
192 void QueueEvent(const ui::Event& event,
193 scoped_ptr<ProcessedEventTarget> processed_event_target);
194
195 // Processes the next valid event in |event_queue_|. If the event has already
196 // been processed it is dispatched, otherwise the event is passed to the
197 // EventDispatcher for processing.
198 void ProcessNextEventFromQueue();
199
200 // Dispatches the event to the appropriate client and starts the ack timer.
201 void DispatchInputEventToWindowImpl(ServerWindow* target,
202 bool in_nonclient_area,
203 const ui::Event& event);
204
205 // Creates the set of WindowManagerStates from the 162 // Creates the set of WindowManagerStates from the
206 // WindowManagerFactoryRegistry. 163 // WindowManagerFactoryRegistry.
207 void CreateWindowManagerStatesFromRegistry(); 164 void CreateWindowManagerStatesFromRegistry();
208 165
209 void CreateWindowManagerStateFromService( 166 void CreateWindowManagerStateFromService(
210 WindowManagerFactoryService* service); 167 WindowManagerFactoryService* service);
211 168
212 void UpdateNativeCursor(int32_t cursor_id);
213
214 // PlatformDisplayDelegate: 169 // PlatformDisplayDelegate:
215 ServerWindow* GetRootWindow() override; 170 ServerWindow* GetRootWindow() override;
216 void OnEvent(const ui::Event& event) override; 171 void OnEvent(const ui::Event& event) override;
217 void OnNativeCaptureLost() override; 172 void OnNativeCaptureLost() override;
218 void OnDisplayClosed() override; 173 void OnDisplayClosed() override;
219 void OnViewportMetricsChanged( 174 void OnViewportMetricsChanged(
220 const mojom::ViewportMetrics& old_metrics, 175 const mojom::ViewportMetrics& old_metrics,
221 const mojom::ViewportMetrics& new_metrics) override; 176 const mojom::ViewportMetrics& new_metrics) override;
222 void OnTopLevelSurfaceChanged(cc::SurfaceId surface_id) override; 177 void OnTopLevelSurfaceChanged(cc::SurfaceId surface_id) override;
223 void OnCompositorFrameDrawn() override; 178 void OnCompositorFrameDrawn() override;
224 179
225 // FocusControllerDelegate: 180 // FocusControllerDelegate:
226 bool CanHaveActiveChildren(ServerWindow* window) const override; 181 bool CanHaveActiveChildren(ServerWindow* window) const override;
227 182
228 // FocusControllerObserver: 183 // FocusControllerObserver:
229 void OnActivationChanged(ServerWindow* old_active_window, 184 void OnActivationChanged(ServerWindow* old_active_window,
230 ServerWindow* new_active_window) override; 185 ServerWindow* new_active_window) override;
231 void OnFocusChanged(FocusControllerChangeSource change_source, 186 void OnFocusChanged(FocusControllerChangeSource change_source,
232 ServerWindow* old_focused_window, 187 ServerWindow* old_focused_window,
233 ServerWindow* new_focused_window) override; 188 ServerWindow* new_focused_window) override;
234 189
235 // EventDispatcherDelegate:
236 void OnAccelerator(uint32_t accelerator_id, const ui::Event& event) override;
237 void SetFocusedWindowFromEventDispatcher(ServerWindow* window) override;
238 ServerWindow* GetFocusedWindowForEventDispatcher() override;
239 void SetNativeCapture() override;
240 void ReleaseNativeCapture() override;
241 void OnServerWindowCaptureLost(ServerWindow* window) override;
242 void DispatchInputEventToWindow(ServerWindow* target,
243 bool in_nonclient_area,
244 const ui::Event& event) override;
245
246 // ServerWindowObserver: 190 // ServerWindowObserver:
247 void OnWindowDestroyed(ServerWindow* window) override; 191 void OnWindowDestroyed(ServerWindow* window) override;
248 192
249 // UserIdTrackerObserver: 193 // UserIdTrackerObserver:
250 void OnActiveUserIdChanged(const UserId& id) override; 194 void OnActiveUserIdChanged(const UserId& previously_active_id,
195 const UserId& active_id) override;
251 void OnUserIdAdded(const UserId& id) override; 196 void OnUserIdAdded(const UserId& id) override;
252 void OnUserIdRemoved(const UserId& id) override; 197 void OnUserIdRemoved(const UserId& id) override;
253 198
254 // WindowManagerFactoryRegistryObserver: 199 // WindowManagerFactoryRegistryObserver:
255 void OnWindowManagerFactorySet(WindowManagerFactoryService* service) override; 200 void OnWindowManagerFactorySet(WindowManagerFactoryService* service) override;
256 201
257 const uint32_t id_; 202 const uint32_t id_;
258 scoped_ptr<DisplayBinding> binding_; 203 scoped_ptr<DisplayBinding> binding_;
259 // Set once Init() has been called. 204 // Set once Init() has been called.
260 bool init_called_ = false; 205 bool init_called_ = false;
261 ConnectionManager* const connection_manager_; 206 ConnectionManager* const connection_manager_;
262 EventDispatcher event_dispatcher_;
263 scoped_ptr<ServerWindow> root_; 207 scoped_ptr<ServerWindow> root_;
264 scoped_ptr<PlatformDisplay> platform_display_; 208 scoped_ptr<PlatformDisplay> platform_display_;
265 scoped_ptr<FocusController> focus_controller_; 209 scoped_ptr<FocusController> focus_controller_;
266 mojom::WindowTree* tree_awaiting_input_ack_;
267 210
268 // The last cursor set. Used to track whether we need to change the cursor. 211 // The last cursor set. Used to track whether we need to change the cursor.
269 int32_t last_cursor_; 212 int32_t last_cursor_;
270 213
271 ServerWindowTracker activation_parents_; 214 ServerWindowTracker activation_parents_;
272 215
273 // Set of windows with surfaces that need to be destroyed once the frame 216 // Set of windows with surfaces that need to be destroyed once the frame
274 // draws. 217 // draws.
275 std::set<ServerWindow*> windows_needing_frame_destruction_; 218 std::set<ServerWindow*> windows_needing_frame_destruction_;
276 219
277 std::queue<scoped_ptr<QueuedEvent>> event_queue_; 220 WindowManagerStateMap window_manager_state_map_;
278 base::OneShotTimer event_ack_timer_;
279 221
280 WindowManagerStateMap window_manager_state_map_; 222 cc::SurfaceId top_level_surface_id_;
281 223
282 DISALLOW_COPY_AND_ASSIGN(Display); 224 DISALLOW_COPY_AND_ASSIGN(Display);
283 }; 225 };
284 226
285 } // namespace ws 227 } // namespace ws
286 } // namespace mus 228 } // namespace mus
287 229
288 #endif // COMPONENTS_MUS_WS_DISPLAY_H_ 230 #endif // COMPONENTS_MUS_WS_DISPLAY_H_
OLDNEW
« no previous file with comments | « components/mus/ws/connection_manager.cc ('k') | components/mus/ws/display.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698