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 20 matching lines...) Expand all Loading... | |
31 class EventDispatcherDelegate; | 31 class EventDispatcherDelegate; |
32 class ServerWindow; | 32 class ServerWindow; |
33 | 33 |
34 namespace test { | 34 namespace test { |
35 class EventDispatcherTestApi; | 35 class EventDispatcherTestApi; |
36 } | 36 } |
37 | 37 |
38 // Handles dispatching events to the right location as well as updating focus. | 38 // Handles dispatching events to the right location as well as updating focus. |
39 class EventDispatcher : public ServerWindowObserver { | 39 class EventDispatcher : public ServerWindowObserver { |
40 public: | 40 public: |
41 enum class AcceleratorMatchPhase { | |
42 // Both pre and post should be considered. | |
43 ANY, | |
44 | |
45 // PRE_TARGETs are not considered, only the actual target and any | |
46 // accelerators registered with POST_TARGET. | |
47 POST_ONLY, | |
48 }; | |
49 | |
sadrul
2016/07/08 15:40:44
Would it make sense to set Event::phase_ on the ev
sky
2016/07/08 16:23:51
Similar comment to the other type, ui::EventPhase
| |
41 explicit EventDispatcher(EventDispatcherDelegate* delegate); | 50 explicit EventDispatcher(EventDispatcherDelegate* delegate); |
42 ~EventDispatcher() override; | 51 ~EventDispatcher() override; |
43 | 52 |
44 // Cancels capture and stops tracking any pointer events. This does not send | 53 // Cancels capture and stops tracking any pointer events. This does not send |
45 // any events to the delegate. | 54 // any events to the delegate. |
46 void Reset(); | 55 void Reset(); |
47 | 56 |
48 void SetMousePointerScreenLocation(const gfx::Point& screen_location); | 57 void SetMousePointerScreenLocation(const gfx::Point& screen_location); |
49 const gfx::Point& mouse_pointer_last_location() const { | 58 const gfx::Point& mouse_pointer_last_location() const { |
50 return mouse_pointer_last_location_; | 59 return mouse_pointer_last_location_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 // ServerWindow* under it. | 106 // ServerWindow* under it. |
98 void UpdateCursorProviderByLastKnownLocation(); | 107 void UpdateCursorProviderByLastKnownLocation(); |
99 | 108 |
100 // Adds an accelerator with the given id and event-matcher. If an accelerator | 109 // 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 | 110 // 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. | 111 // is not added. Returns whether adding the accelerator was successful or not. |
103 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); | 112 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); |
104 void RemoveAccelerator(uint32_t id); | 113 void RemoveAccelerator(uint32_t id); |
105 | 114 |
106 // Processes the supplied event, informing the delegate as approriate. This | 115 // Processes the supplied event, informing the delegate as approriate. This |
107 // may result in generating any number of events. | 116 // may result in generating any number of events. If |match_phase| is |
108 void ProcessEvent(const ui::Event& event); | 117 // ANY and there is a matching accelerator with PRE_TARGET found, than only |
118 // OnAccelerator() is called. The expectation is after the PRE_TARGET has been | |
119 // handled this is again called with an AcceleratorMatchPhase of POST_ONLY. | |
120 void ProcessEvent(const ui::Event& event, AcceleratorMatchPhase match_phase); | |
109 | 121 |
110 private: | 122 private: |
111 friend class test::EventDispatcherTestApi; | 123 friend class test::EventDispatcherTestApi; |
112 | 124 |
113 // Keeps track of state associated with an active pointer. | 125 // Keeps track of state associated with an active pointer. |
114 struct PointerTarget { | 126 struct PointerTarget { |
115 PointerTarget() | 127 PointerTarget() |
116 : window(nullptr), | 128 : window(nullptr), |
117 is_mouse_event(false), | 129 is_mouse_event(false), |
118 in_nonclient_area(false), | 130 in_nonclient_area(false), |
119 is_pointer_down(false) {} | 131 is_pointer_down(false) {} |
120 | 132 |
121 // NOTE: this is set to null if the window is destroyed before a | 133 // NOTE: this is set to null if the window is destroyed before a |
122 // corresponding release/cancel. | 134 // corresponding release/cancel. |
123 ServerWindow* window; | 135 ServerWindow* window; |
124 | 136 |
125 bool is_mouse_event; | 137 bool is_mouse_event; |
126 | 138 |
127 // Did the pointer event start in the non-client area. | 139 // Did the pointer event start in the non-client area. |
128 bool in_nonclient_area; | 140 bool in_nonclient_area; |
129 | 141 |
130 bool is_pointer_down; | 142 bool is_pointer_down; |
131 }; | 143 }; |
132 | 144 |
133 void ProcessKeyEvent(const ui::KeyEvent& event); | 145 void ProcessKeyEvent(const ui::KeyEvent& event, |
146 AcceleratorMatchPhase match_phase); | |
134 | 147 |
135 bool IsTrackingPointer(int32_t pointer_id) const { | 148 bool IsTrackingPointer(int32_t pointer_id) const { |
136 return pointer_targets_.count(pointer_id) > 0; | 149 return pointer_targets_.count(pointer_id) > 0; |
137 } | 150 } |
138 | 151 |
139 // EventDispatcher provides the following logic for pointer events: | 152 // EventDispatcher provides the following logic for pointer events: |
140 // . wheel events go to the current target of the associated pointer. If | 153 // . wheel events go to the current target of the associated pointer. If |
141 // there is no target, they go to the deepest window. | 154 // there is no target, they go to the deepest window. |
142 // . move (not drag) events go to the deepest window. | 155 // . move (not drag) events go to the deepest window. |
143 // . when a pointer goes down all events until the corresponding up or | 156 // . when a pointer goes down all events until the corresponding up or |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 // Keeps track of number of observe requests for each observed window. | 240 // Keeps track of number of observe requests for each observed window. |
228 std::map<const ServerWindow*, uint8_t> observed_windows_; | 241 std::map<const ServerWindow*, uint8_t> observed_windows_; |
229 | 242 |
230 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | 243 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
231 }; | 244 }; |
232 | 245 |
233 } // namespace ws | 246 } // namespace ws |
234 } // namespace ui | 247 } // namespace ui |
235 | 248 |
236 #endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_ | 249 #endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_ |
OLD | NEW |