OLD | NEW |
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 SERVICES_UI_WS_EVENT_DISPATCHER_H_ | 5 #ifndef SERVICES_UI_WS_EVENT_DISPATCHER_H_ |
6 #define SERVICES_UI_WS_EVENT_DISPATCHER_H_ | 6 #define SERVICES_UI_WS_EVENT_DISPATCHER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "services/ui/common/types.h" | 15 #include "services/ui/common/types.h" |
16 #include "services/ui/public/interfaces/cursor/cursor.mojom.h" | 16 #include "services/ui/public/interfaces/cursor/cursor.mojom.h" |
17 #include "services/ui/public/interfaces/window_manager.mojom.h" | 17 #include "services/ui/public/interfaces/window_manager.mojom.h" |
18 #include "services/ui/ws/drag_cursor_updater.h" | 18 #include "services/ui/ws/drag_cursor_updater.h" |
| 19 #include "services/ui/ws/event_targeter.h" |
19 #include "services/ui/ws/modal_window_controller.h" | 20 #include "services/ui/ws/modal_window_controller.h" |
20 #include "services/ui/ws/server_window_observer.h" | 21 #include "services/ui/ws/server_window_observer.h" |
21 #include "ui/gfx/geometry/rect_f.h" | 22 #include "ui/gfx/geometry/rect_f.h" |
22 | 23 |
23 namespace ui { | 24 namespace ui { |
24 class Event; | 25 class Event; |
25 class KeyEvent; | 26 class KeyEvent; |
26 class LocatedEvent; | 27 class LocatedEvent; |
27 class PointerEvent; | 28 class PointerEvent; |
28 | 29 |
29 namespace ws { | 30 namespace ws { |
30 | 31 |
31 class Accelerator; | 32 class Accelerator; |
32 struct DeepestWindow; | |
33 class DragController; | 33 class DragController; |
34 class DragSource; | 34 class DragSource; |
35 class DragTargetConnection; | 35 class DragTargetConnection; |
36 class EventDispatcherDelegate; | 36 class EventDispatcherDelegate; |
37 class ServerWindow; | 37 class ServerWindow; |
38 | 38 |
39 namespace test { | 39 namespace test { |
40 class EventDispatcherTestApi; | 40 class EventDispatcherTestApi; |
41 } | 41 } |
42 | 42 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // ANY and there is a matching accelerator with PRE_TARGET found, than only | 144 // ANY and there is a matching accelerator with PRE_TARGET found, than only |
145 // OnAccelerator() is called. The expectation is after the PRE_TARGET has been | 145 // OnAccelerator() is called. The expectation is after the PRE_TARGET has been |
146 // handled this is again called with an AcceleratorMatchPhase of POST_ONLY. | 146 // handled this is again called with an AcceleratorMatchPhase of POST_ONLY. |
147 void ProcessEvent(const ui::Event& event, | 147 void ProcessEvent(const ui::Event& event, |
148 const int64_t display_id, | 148 const int64_t display_id, |
149 AcceleratorMatchPhase match_phase); | 149 AcceleratorMatchPhase match_phase); |
150 | 150 |
151 private: | 151 private: |
152 friend class test::EventDispatcherTestApi; | 152 friend class test::EventDispatcherTestApi; |
153 | 153 |
154 // Keeps track of state associated with an active pointer. | |
155 struct PointerTarget { | |
156 PointerTarget() | |
157 : window(nullptr), | |
158 is_mouse_event(false), | |
159 in_nonclient_area(false), | |
160 is_pointer_down(false) {} | |
161 | |
162 // The target window, which may be null. null is used in two situations: | |
163 // when there is no valid window target, or there was a target but the | |
164 // window is destroyed before a corresponding release/cancel. | |
165 ServerWindow* window; | |
166 | |
167 bool is_mouse_event; | |
168 | |
169 // Did the pointer event start in the non-client area. | |
170 bool in_nonclient_area; | |
171 | |
172 bool is_pointer_down; | |
173 }; | |
174 | |
175 void SetMouseCursorSourceWindow(ServerWindow* window); | 154 void SetMouseCursorSourceWindow(ServerWindow* window); |
176 | 155 |
177 void ProcessKeyEvent(const ui::KeyEvent& event, | 156 void ProcessKeyEvent(const ui::KeyEvent& event, |
178 AcceleratorMatchPhase match_phase); | 157 AcceleratorMatchPhase match_phase); |
179 | 158 |
180 bool IsTrackingPointer(int32_t pointer_id) const { | 159 bool IsTrackingPointer(int32_t pointer_id) const { |
181 return pointer_targets_.count(pointer_id) > 0; | 160 return pointer_targets_.count(pointer_id) > 0; |
182 } | 161 } |
183 | 162 |
184 // EventDispatcher provides the following logic for pointer events: | 163 // EventDispatcher provides the following logic for pointer events: |
(...skipping 13 matching lines...) Expand all Loading... |
198 | 177 |
199 // Removes a PointerTarget from |pointer_targets_|. | 178 // Removes a PointerTarget from |pointer_targets_|. |
200 void StopTrackingPointer(int32_t pointer_id); | 179 void StopTrackingPointer(int32_t pointer_id); |
201 | 180 |
202 // Starts tracking the pointer for |event|, or if already tracking the | 181 // Starts tracking the pointer for |event|, or if already tracking the |
203 // pointer sends the appropriate event to the delegate and updates the | 182 // pointer sends the appropriate event to the delegate and updates the |
204 // currently tracked PointerTarget appropriately. | 183 // currently tracked PointerTarget appropriately. |
205 void UpdateTargetForPointer(int32_t pointer_id, | 184 void UpdateTargetForPointer(int32_t pointer_id, |
206 const ui::LocatedEvent& event); | 185 const ui::LocatedEvent& event); |
207 | 186 |
208 // Returns a PointerTarget for the supplied event. If there is no valid | |
209 // event target for the specified location |window| in the returned value is | |
210 // null. | |
211 PointerTarget PointerTargetForEvent(const ui::LocatedEvent& event); | |
212 | |
213 // Returns true if any pointers are in the pressed/down state. | 187 // Returns true if any pointers are in the pressed/down state. |
214 bool AreAnyPointersDown() const; | 188 bool AreAnyPointersDown() const; |
215 | 189 |
216 // If |target->window| is valid, then passes the event to the delegate. | 190 // If |target->window| is valid, then passes the event to the delegate. |
217 void DispatchToPointerTarget(const PointerTarget& target, | 191 void DispatchToPointerTarget(const PointerTarget& target, |
218 const ui::LocatedEvent& event); | 192 const ui::LocatedEvent& event); |
219 | 193 |
220 // Dispatch |event| to the delegate. | 194 // Dispatch |event| to the delegate. |
221 void DispatchToClient(ServerWindow* window, | 195 void DispatchToClient(ServerWindow* window, |
222 ClientSpecificId client_id, | 196 ClientSpecificId client_id, |
223 const ui::LocatedEvent& event); | 197 const ui::LocatedEvent& event); |
224 | 198 |
225 // Stops sending pointer events to |window|. This does not remove the entry | 199 // Stops sending pointer events to |window|. This does not remove the entry |
226 // for |window| from |pointer_targets_|, rather it nulls out the window. This | 200 // for |window| from |pointer_targets_|, rather it nulls out the window. This |
227 // way we continue to eat events until the up/cancel is received. | 201 // way we continue to eat events until the up/cancel is received. |
228 void CancelPointerEventsToTarget(ServerWindow* window); | 202 void CancelPointerEventsToTarget(ServerWindow* window); |
229 | 203 |
230 // Used to observe a window. Can be called multiple times on a window. To | 204 // Used to observe a window. Can be called multiple times on a window. To |
231 // unobserve a window, UnobserveWindow() should be called the same number of | 205 // unobserve a window, UnobserveWindow() should be called the same number of |
232 // times. | 206 // times. |
233 void ObserveWindow(ServerWindow* winodw); | 207 void ObserveWindow(ServerWindow* winodw); |
234 void UnobserveWindow(ServerWindow* winodw); | 208 void UnobserveWindow(ServerWindow* winodw); |
235 | 209 |
236 // Returns an Accelerator bound to the specified code/flags, and of the | 210 // Returns an Accelerator bound to the specified code/flags, and of the |
237 // matching |phase|. Otherwise returns null. | 211 // matching |phase|. Otherwise returns null. |
238 Accelerator* FindAccelerator(const ui::KeyEvent& event, | 212 Accelerator* FindAccelerator(const ui::KeyEvent& event, |
239 const ui::mojom::AcceleratorPhase phase); | 213 const ui::mojom::AcceleratorPhase phase); |
240 | 214 |
241 DeepestWindow FindDeepestVisibleWindowForEvents(gfx::Point* location, | |
242 int64_t* display_id); | |
243 | |
244 // Clears the implicit captures in |pointer_targets_|, with the exception of | 215 // Clears the implicit captures in |pointer_targets_|, with the exception of |
245 // |window|. |window| may be null. |client_id| is the target client of | 216 // |window|. |window| may be null. |client_id| is the target client of |
246 // |window|. | 217 // |window|. |
247 void CancelImplicitCaptureExcept(ServerWindow* window, | 218 void CancelImplicitCaptureExcept(ServerWindow* window, |
248 ClientSpecificId client_id); | 219 ClientSpecificId client_id); |
249 | 220 |
250 // ServerWindowObserver: | 221 // ServerWindowObserver: |
251 void OnWillChangeWindowHierarchy(ServerWindow* window, | 222 void OnWillChangeWindowHierarchy(ServerWindow* window, |
252 ServerWindow* new_parent, | 223 ServerWindow* new_parent, |
253 ServerWindow* old_parent) override; | 224 ServerWindow* old_parent) override; |
254 void OnWindowVisibilityChanged(ServerWindow* window) override; | 225 void OnWindowVisibilityChanged(ServerWindow* window) override; |
255 void OnWindowDestroyed(ServerWindow* window) override; | 226 void OnWindowDestroyed(ServerWindow* window) override; |
256 | 227 |
257 // DragCursorUpdater: | 228 // DragCursorUpdater: |
258 void OnDragCursorUpdated() override; | 229 void OnDragCursorUpdated() override; |
259 | 230 |
260 EventDispatcherDelegate* delegate_; | 231 EventDispatcherDelegate* delegate_; |
261 | 232 |
262 ServerWindow* capture_window_; | 233 ServerWindow* capture_window_; |
263 ClientSpecificId capture_window_client_id_; | 234 ClientSpecificId capture_window_client_id_; |
264 | 235 |
265 std::unique_ptr<DragController> drag_controller_; | 236 std::unique_ptr<DragController> drag_controller_; |
266 | 237 |
267 ModalWindowController modal_window_controller_; | 238 ModalWindowController modal_window_controller_; |
268 | 239 |
| 240 std::unique_ptr<EventTargeter> event_targeter_; |
| 241 |
269 bool mouse_button_down_; | 242 bool mouse_button_down_; |
270 ServerWindow* mouse_cursor_source_window_; | 243 ServerWindow* mouse_cursor_source_window_; |
271 bool mouse_cursor_in_non_client_area_; | 244 bool mouse_cursor_in_non_client_area_; |
272 | 245 |
273 // The location of the mouse pointer in display coordinates. This can be | 246 // The location of the mouse pointer in display coordinates. This can be |
274 // outside the bounds of |mouse_cursor_source_window_|, which can capture the | 247 // outside the bounds of |mouse_cursor_source_window_|, which can capture the |
275 // cursor. | 248 // cursor. |
276 gfx::Point mouse_pointer_last_location_; | 249 gfx::Point mouse_pointer_last_location_; |
277 // Id of the display |mouse_pointer_last_location_| is on. | 250 // Id of the display |mouse_pointer_last_location_| is on. |
278 int64_t mouse_pointer_display_id_ = display::kInvalidDisplayId; | 251 int64_t mouse_pointer_display_id_ = display::kInvalidDisplayId; |
(...skipping 19 matching lines...) Expand all Loading... |
298 AcceleratorMatchPhase::ANY; | 271 AcceleratorMatchPhase::ANY; |
299 #endif | 272 #endif |
300 | 273 |
301 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | 274 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
302 }; | 275 }; |
303 | 276 |
304 } // namespace ws | 277 } // namespace ws |
305 } // namespace ui | 278 } // namespace ui |
306 | 279 |
307 #endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_ | 280 #endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_ |
OLD | NEW |