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/event_matcher.mojom.h" | 16 #include "services/ui/public/interfaces/event_matcher.mojom.h" |
17 #include "services/ui/ws/modal_window_controller.h" | 17 #include "services/ui/ws/modal_window_controller.h" |
18 #include "services/ui/ws/server_window_observer.h" | 18 #include "services/ui/ws/server_window_observer.h" |
19 #include "ui/gfx/geometry/rect_f.h" | 19 #include "ui/gfx/geometry/rect_f.h" |
20 | 20 |
21 namespace ui { | 21 namespace ui { |
22 class Event; | 22 class Event; |
23 class KeyEvent; | 23 class KeyEvent; |
24 class LocatedEvent; | 24 class LocatedEvent; |
25 } | |
26 | 25 |
27 namespace ui { | |
28 namespace ws { | 26 namespace ws { |
29 | 27 |
30 class Accelerator; | 28 class Accelerator; |
31 class EventDispatcherDelegate; | 29 class EventDispatcherDelegate; |
32 class ServerWindow; | 30 class ServerWindow; |
33 | 31 |
34 namespace test { | 32 namespace test { |
35 class EventDispatcherTestApi; | 33 class EventDispatcherTestApi; |
36 } | 34 } |
37 | 35 |
38 // Handles dispatching events to the right location as well as updating focus. | 36 // Handles dispatching events to the right location as well as updating focus. |
39 class EventDispatcher : public ServerWindowObserver { | 37 class EventDispatcher : public ServerWindowObserver { |
40 public: | 38 public: |
| 39 enum class AcceleratorMatchPhase { |
| 40 // Both pre and post should be considered. |
| 41 ANY, |
| 42 |
| 43 // PRE_TARGETs are not considered, only the actual target and any |
| 44 // accelerators registered with POST_TARGET. |
| 45 POST_ONLY, |
| 46 }; |
| 47 |
41 explicit EventDispatcher(EventDispatcherDelegate* delegate); | 48 explicit EventDispatcher(EventDispatcherDelegate* delegate); |
42 ~EventDispatcher() override; | 49 ~EventDispatcher() override; |
43 | 50 |
44 // Cancels capture and stops tracking any pointer events. This does not send | 51 // Cancels capture and stops tracking any pointer events. This does not send |
45 // any events to the delegate. | 52 // any events to the delegate. |
46 void Reset(); | 53 void Reset(); |
47 | 54 |
48 void SetMousePointerScreenLocation(const gfx::Point& screen_location); | 55 void SetMousePointerScreenLocation(const gfx::Point& screen_location); |
49 const gfx::Point& mouse_pointer_last_location() const { | 56 const gfx::Point& mouse_pointer_last_location() const { |
50 return mouse_pointer_last_location_; | 57 return mouse_pointer_last_location_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // ServerWindow* under it. | 104 // ServerWindow* under it. |
98 void UpdateCursorProviderByLastKnownLocation(); | 105 void UpdateCursorProviderByLastKnownLocation(); |
99 | 106 |
100 // Adds an accelerator with the given id and event-matcher. If an accelerator | 107 // Adds an accelerator with the given id and event-matcher. If an accelerator |
101 // already exists with the same id or the same matcher, then the accelerator | 108 // already exists with the same id or the same matcher, then the accelerator |
102 // is not added. Returns whether adding the accelerator was successful or not. | 109 // is not added. Returns whether adding the accelerator was successful or not. |
103 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); | 110 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); |
104 void RemoveAccelerator(uint32_t id); | 111 void RemoveAccelerator(uint32_t id); |
105 | 112 |
106 // Processes the supplied event, informing the delegate as approriate. This | 113 // Processes the supplied event, informing the delegate as approriate. This |
107 // may result in generating any number of events. | 114 // may result in generating any number of events. If |match_phase| is |
108 void ProcessEvent(const ui::Event& event); | 115 // ANY and there is a matching accelerator with PRE_TARGET found, than only |
| 116 // OnAccelerator() is called. The expectation is after the PRE_TARGET has been |
| 117 // handled this is again called with an AcceleratorMatchPhase of POST_ONLY. |
| 118 void ProcessEvent(const ui::Event& event, AcceleratorMatchPhase match_phase); |
109 | 119 |
110 private: | 120 private: |
111 friend class test::EventDispatcherTestApi; | 121 friend class test::EventDispatcherTestApi; |
112 | 122 |
113 // Keeps track of state associated with an active pointer. | 123 // Keeps track of state associated with an active pointer. |
114 struct PointerTarget { | 124 struct PointerTarget { |
115 PointerTarget() | 125 PointerTarget() |
116 : window(nullptr), | 126 : window(nullptr), |
117 is_mouse_event(false), | 127 is_mouse_event(false), |
118 in_nonclient_area(false), | 128 in_nonclient_area(false), |
119 is_pointer_down(false) {} | 129 is_pointer_down(false) {} |
120 | 130 |
121 // NOTE: this is set to null if the window is destroyed before a | 131 // NOTE: this is set to null if the window is destroyed before a |
122 // corresponding release/cancel. | 132 // corresponding release/cancel. |
123 ServerWindow* window; | 133 ServerWindow* window; |
124 | 134 |
125 bool is_mouse_event; | 135 bool is_mouse_event; |
126 | 136 |
127 // Did the pointer event start in the non-client area. | 137 // Did the pointer event start in the non-client area. |
128 bool in_nonclient_area; | 138 bool in_nonclient_area; |
129 | 139 |
130 bool is_pointer_down; | 140 bool is_pointer_down; |
131 }; | 141 }; |
132 | 142 |
133 void ProcessKeyEvent(const ui::KeyEvent& event); | 143 void ProcessKeyEvent(const ui::KeyEvent& event, |
| 144 AcceleratorMatchPhase match_phase); |
134 | 145 |
135 bool IsTrackingPointer(int32_t pointer_id) const { | 146 bool IsTrackingPointer(int32_t pointer_id) const { |
136 return pointer_targets_.count(pointer_id) > 0; | 147 return pointer_targets_.count(pointer_id) > 0; |
137 } | 148 } |
138 | 149 |
139 // EventDispatcher provides the following logic for pointer events: | 150 // EventDispatcher provides the following logic for pointer events: |
140 // . wheel events go to the current target of the associated pointer. If | 151 // . wheel events go to the current target of the associated pointer. If |
141 // there is no target, they go to the deepest window. | 152 // there is no target, they go to the deepest window. |
142 // . move (not drag) events go to the deepest window. | 153 // . move (not drag) events go to the deepest window. |
143 // . when a pointer goes down all events until the corresponding up or | 154 // . when a pointer goes down all events until the corresponding up or |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 using PointerIdToTargetMap = std::map<int32_t, PointerTarget>; | 231 using PointerIdToTargetMap = std::map<int32_t, PointerTarget>; |
221 // |pointer_targets_| contains the active pointers. For a mouse based pointer | 232 // |pointer_targets_| contains the active pointers. For a mouse based pointer |
222 // a PointerTarget is always active (and present in |pointer_targets_|). For | 233 // a PointerTarget is always active (and present in |pointer_targets_|). For |
223 // touch based pointers the pointer is active while down and removed on | 234 // touch based pointers the pointer is active while down and removed on |
224 // cancel or up. | 235 // cancel or up. |
225 PointerIdToTargetMap pointer_targets_; | 236 PointerIdToTargetMap pointer_targets_; |
226 | 237 |
227 // Keeps track of number of observe requests for each observed window. | 238 // Keeps track of number of observe requests for each observed window. |
228 std::map<const ServerWindow*, uint8_t> observed_windows_; | 239 std::map<const ServerWindow*, uint8_t> observed_windows_; |
229 | 240 |
| 241 #if !defined(NDEBUG) |
| 242 std::unique_ptr<ui::Event> previous_event_; |
| 243 AcceleratorMatchPhase previous_accelerator_match_phase_ = |
| 244 AcceleratorMatchPhase::ANY; |
| 245 #endif |
| 246 |
230 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | 247 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
231 }; | 248 }; |
232 | 249 |
233 } // namespace ws | 250 } // namespace ws |
234 } // namespace ui | 251 } // namespace ui |
235 | 252 |
236 #endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_ | 253 #endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_ |
OLD | NEW |