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> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 }; | 56 }; |
57 | 57 |
58 explicit EventDispatcher(EventDispatcherDelegate* delegate); | 58 explicit EventDispatcher(EventDispatcherDelegate* delegate); |
59 ~EventDispatcher() override; | 59 ~EventDispatcher() override; |
60 | 60 |
61 // Cancels capture and stops tracking any pointer events. This does not send | 61 // Cancels capture and stops tracking any pointer events. This does not send |
62 // any events to the delegate. | 62 // any events to the delegate. |
63 void Reset(); | 63 void Reset(); |
64 | 64 |
65 void SetMousePointerDisplayLocation(const gfx::Point& display_location, | 65 void SetMousePointerDisplayLocation(const gfx::Point& display_location, |
66 const int64_t display_id); | 66 int64_t display_id); |
67 const gfx::Point& mouse_pointer_last_location() const { | 67 const gfx::Point& mouse_pointer_last_location() const { |
68 return mouse_pointer_last_location_; | 68 return mouse_pointer_last_location_; |
69 } | 69 } |
70 int64_t mouse_pointer_display_id() const { return mouse_pointer_display_id_; } | 70 int64_t mouse_pointer_display_id() const { return mouse_pointer_display_id_; } |
71 | 71 |
72 // Returns the cursor for the current target, or POINTER if the mouse is not | 72 // Returns the cursor for the current target, or POINTER if the mouse is not |
73 // over a valid target. | 73 // over a valid target. |
74 ui::CursorData GetCurrentMouseCursor() const; | 74 ui::CursorData GetCurrentMouseCursor() const; |
75 | 75 |
76 // |capture_window_| will receive all input. See window_tree.mojom for | 76 // |capture_window_| will receive all input. See window_tree.mojom for |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 // ServerWindow* under it. | 135 // ServerWindow* under it. |
136 void UpdateCursorProviderByLastKnownLocation(); | 136 void UpdateCursorProviderByLastKnownLocation(); |
137 | 137 |
138 // Adds an accelerator with the given id and event-matcher. If an accelerator | 138 // Adds an accelerator with the given id and event-matcher. If an accelerator |
139 // already exists with the same id or the same matcher, then the accelerator | 139 // already exists with the same id or the same matcher, then the accelerator |
140 // is not added. Returns whether adding the accelerator was successful or not. | 140 // is not added. Returns whether adding the accelerator was successful or not. |
141 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); | 141 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); |
142 | 142 |
143 void RemoveAccelerator(uint32_t id); | 143 void RemoveAccelerator(uint32_t id); |
144 | 144 |
| 145 // True if we are actively finding a target for an event, false otherwise. |
| 146 bool IsProcessingEvent(); |
| 147 |
145 // Processes the supplied event, informing the delegate as approriate. This | 148 // Processes the supplied event, informing the delegate as approriate. This |
146 // may result in generating any number of events. If |match_phase| is | 149 // may result in generating any number of events. If |match_phase| is |
147 // ANY and there is a matching accelerator with PRE_TARGET found, than only | 150 // ANY and there is a matching accelerator with PRE_TARGET found, than only |
148 // OnAccelerator() is called. The expectation is after the PRE_TARGET has been | 151 // OnAccelerator() is called. The expectation is after the PRE_TARGET has been |
149 // handled this is again called with an AcceleratorMatchPhase of POST_ONLY. | 152 // handled this is again called with an AcceleratorMatchPhase of POST_ONLY. |
| 153 // This may be asynchronous if we need to find the target window for |event| |
| 154 // asynchronously. |
150 void ProcessEvent(const ui::Event& event, | 155 void ProcessEvent(const ui::Event& event, |
151 const int64_t display_id, | 156 int64_t display_id, |
152 AcceleratorMatchPhase match_phase); | 157 AcceleratorMatchPhase match_phase); |
153 | 158 |
154 // EventTargeterDelegate: | 159 // EventTargeterDelegate: |
155 ServerWindow* GetRootWindowContaining(gfx::Point* location_in_display, | 160 ServerWindow* GetRootWindowContaining(gfx::Point* location_in_display, |
156 int64_t* display_id) override; | 161 int64_t* display_id) override; |
| 162 void ProcessNextEventFromQueue() override; |
157 | 163 |
158 private: | 164 private: |
159 friend class test::EventDispatcherTestApi; | 165 friend class test::EventDispatcherTestApi; |
160 | 166 |
161 // Keeps track of state associated with an active pointer. | 167 // Keeps track of state associated with an active pointer. |
162 struct PointerTarget { | 168 struct PointerTarget { |
163 PointerTarget() | 169 PointerTarget() |
164 : window(nullptr), | 170 : window(nullptr), |
165 is_mouse_event(false), | 171 is_mouse_event(false), |
166 in_nonclient_area(false), | 172 in_nonclient_area(false), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 207 |
202 // EventDispatcher provides the following logic for pointer events: | 208 // EventDispatcher provides the following logic for pointer events: |
203 // . wheel events go to the current target of the associated pointer. If | 209 // . wheel events go to the current target of the associated pointer. If |
204 // there is no target, they go to the deepest window. | 210 // there is no target, they go to the deepest window. |
205 // . move (not drag) events go to the deepest window. | 211 // . move (not drag) events go to the deepest window. |
206 // . when a pointer goes down all events until the corresponding up or | 212 // . when a pointer goes down all events until the corresponding up or |
207 // cancel go to the deepest target. For mouse events the up only occurs | 213 // cancel go to the deepest target. For mouse events the up only occurs |
208 // when no buttons on the mouse are down. | 214 // when no buttons on the mouse are down. |
209 // This also generates exit events as appropriate. For example, if the mouse | 215 // This also generates exit events as appropriate. For example, if the mouse |
210 // moves between one window to another an exit is generated on the first. | 216 // moves between one window to another an exit is generated on the first. |
211 void ProcessPointerEvent(const ui::PointerEvent& event); | 217 // |pointer_target| is the PointerTarget for |event| based on the |
| 218 // |deepest_window|, the deepest visible window for the root_location |
| 219 // of the |event|. |location_in_display| and |display_id| are updated values |
| 220 // for root_location and |event_display_id_| (e.g. during drag-n-drop). |
| 221 void ProcessPointerEventOnFoundTarget(const ui::PointerEvent& event, |
| 222 const LocationTarget& location_target); |
| 223 |
| 224 void UpdateNonClientAreaForCurrentWindowOnFoundWindow( |
| 225 const LocationTarget& location_target); |
| 226 void UpdateCursorProviderByLastKnownLocationOnFoundWindow( |
| 227 const LocationTarget& location_target); |
212 | 228 |
213 // Adds |pointer_target| to |pointer_targets_|. | 229 // Adds |pointer_target| to |pointer_targets_|. |
214 void StartTrackingPointer(int32_t pointer_id, | 230 void StartTrackingPointer(int32_t pointer_id, |
215 const PointerTarget& pointer_target); | 231 const PointerTarget& pointer_target); |
216 | 232 |
217 // Removes a PointerTarget from |pointer_targets_|. | 233 // Removes a PointerTarget from |pointer_targets_|. |
218 void StopTrackingPointer(int32_t pointer_id); | 234 void StopTrackingPointer(int32_t pointer_id); |
219 | 235 |
220 // Starts tracking the pointer for |event|, or if already tracking the | 236 // Starts tracking the pointer for |event|, or if already tracking the |
221 // pointer sends the appropriate event to the delegate and updates the | 237 // pointer sends the appropriate event to the delegate and updates the |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 AcceleratorMatchPhase::ANY; | 327 AcceleratorMatchPhase::ANY; |
312 #endif | 328 #endif |
313 | 329 |
314 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | 330 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
315 }; | 331 }; |
316 | 332 |
317 } // namespace ws | 333 } // namespace ws |
318 } // namespace ui | 334 } // namespace ui |
319 | 335 |
320 #endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_ | 336 #endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_ |
OLD | NEW |