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

Side by Side Diff: services/ui/ws/event_dispatcher.h

Issue 2905333002: Separate out event-targeting logic in EventDispatcher to EventTargeter. (Closed)
Patch Set: Created 3 years, 6 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
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 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // Processes the supplied event, informing the delegate as approriate. This 140 // Processes the supplied event, informing the delegate as approriate. This
141 // may result in generating any number of events. If |match_phase| is 141 // may result in generating any number of events. If |match_phase| is
142 // ANY and there is a matching accelerator with PRE_TARGET found, than only 142 // ANY and there is a matching accelerator with PRE_TARGET found, than only
143 // OnAccelerator() is called. The expectation is after the PRE_TARGET has been 143 // OnAccelerator() is called. The expectation is after the PRE_TARGET has been
144 // handled this is again called with an AcceleratorMatchPhase of POST_ONLY. 144 // handled this is again called with an AcceleratorMatchPhase of POST_ONLY.
145 void ProcessEvent(const ui::Event& event, AcceleratorMatchPhase match_phase); 145 void ProcessEvent(const ui::Event& event, AcceleratorMatchPhase match_phase);
146 146
147 private: 147 private:
148 friend class test::EventDispatcherTestApi; 148 friend class test::EventDispatcherTestApi;
149 149
150 // Keeps track of state associated with an active pointer.
151 struct PointerTarget {
152 PointerTarget()
153 : window(nullptr),
154 is_mouse_event(false),
155 in_nonclient_area(false),
156 is_pointer_down(false) {}
157
158 // The target window, which may be null. null is used in two situations:
159 // when there is no valid window target, or there was a target but the
160 // window is destroyed before a corresponding release/cancel.
161 ServerWindow* window;
162
163 bool is_mouse_event;
164
165 // Did the pointer event start in the non-client area.
166 bool in_nonclient_area;
167
168 bool is_pointer_down;
169 };
170
171 void SetMouseCursorSourceWindow(ServerWindow* window); 150 void SetMouseCursorSourceWindow(ServerWindow* window);
172 151
173 void ProcessKeyEvent(const ui::KeyEvent& event, 152 void ProcessKeyEvent(const ui::KeyEvent& event,
174 AcceleratorMatchPhase match_phase); 153 AcceleratorMatchPhase match_phase);
175 154
176 bool IsTrackingPointer(int32_t pointer_id) const { 155 bool IsTrackingPointer(int32_t pointer_id) const {
177 return pointer_targets_.count(pointer_id) > 0; 156 return pointer_targets_.count(pointer_id) > 0;
178 } 157 }
179 158
180 // EventDispatcher provides the following logic for pointer events: 159 // EventDispatcher provides the following logic for pointer events:
(...skipping 13 matching lines...) Expand all
194 173
195 // Removes a PointerTarget from |pointer_targets_|. 174 // Removes a PointerTarget from |pointer_targets_|.
196 void StopTrackingPointer(int32_t pointer_id); 175 void StopTrackingPointer(int32_t pointer_id);
197 176
198 // Starts tracking the pointer for |event|, or if already tracking the 177 // Starts tracking the pointer for |event|, or if already tracking the
199 // pointer sends the appropriate event to the delegate and updates the 178 // pointer sends the appropriate event to the delegate and updates the
200 // currently tracked PointerTarget appropriately. 179 // currently tracked PointerTarget appropriately.
201 void UpdateTargetForPointer(int32_t pointer_id, 180 void UpdateTargetForPointer(int32_t pointer_id,
202 const ui::LocatedEvent& event); 181 const ui::LocatedEvent& event);
203 182
204 // Returns a PointerTarget for the supplied event. If there is no valid
205 // event target for the specified location |window| in the returned value is
206 // null.
207 PointerTarget PointerTargetForEvent(const ui::LocatedEvent& event);
208
209 // Returns true if any pointers are in the pressed/down state. 183 // Returns true if any pointers are in the pressed/down state.
210 bool AreAnyPointersDown() const; 184 bool AreAnyPointersDown() const;
211 185
212 // If |target->window| is valid, then passes the event to the delegate. 186 // If |target->window| is valid, then passes the event to the delegate.
213 void DispatchToPointerTarget(const PointerTarget& target, 187 void DispatchToPointerTarget(const PointerTarget& target,
214 const ui::LocatedEvent& event); 188 const ui::LocatedEvent& event);
215 189
216 // Dispatch |event| to the delegate. 190 // Dispatch |event| to the delegate.
217 void DispatchToClient(ServerWindow* window, 191 void DispatchToClient(ServerWindow* window,
218 ClientSpecificId client_id, 192 ClientSpecificId client_id,
219 const ui::LocatedEvent& event); 193 const ui::LocatedEvent& event);
220 194
221 // Stops sending pointer events to |window|. This does not remove the entry 195 // Stops sending pointer events to |window|. This does not remove the entry
222 // for |window| from |pointer_targets_|, rather it nulls out the window. This 196 // for |window| from |pointer_targets_|, rather it nulls out the window. This
223 // way we continue to eat events until the up/cancel is received. 197 // way we continue to eat events until the up/cancel is received.
224 void CancelPointerEventsToTarget(ServerWindow* window); 198 void CancelPointerEventsToTarget(ServerWindow* window);
225 199
226 // Used to observe a window. Can be called multiple times on a window. To 200 // Used to observe a window. Can be called multiple times on a window. To
227 // unobserve a window, UnobserveWindow() should be called the same number of 201 // unobserve a window, UnobserveWindow() should be called the same number of
228 // times. 202 // times.
229 void ObserveWindow(ServerWindow* winodw); 203 void ObserveWindow(ServerWindow* winodw);
230 void UnobserveWindow(ServerWindow* winodw); 204 void UnobserveWindow(ServerWindow* winodw);
231 205
232 // Returns an Accelerator bound to the specified code/flags, and of the 206 // Returns an Accelerator bound to the specified code/flags, and of the
233 // matching |phase|. Otherwise returns null. 207 // matching |phase|. Otherwise returns null.
234 Accelerator* FindAccelerator(const ui::KeyEvent& event, 208 Accelerator* FindAccelerator(const ui::KeyEvent& event,
235 const ui::mojom::AcceleratorPhase phase); 209 const ui::mojom::AcceleratorPhase phase);
236 210
237 DeepestWindow FindDeepestVisibleWindowForEvents(const gfx::Point& location);
238
239 // Clears the implicit captures in |pointer_targets_|, with the exception of 211 // Clears the implicit captures in |pointer_targets_|, with the exception of
240 // |window|. |window| may be null. |client_id| is the target client of 212 // |window|. |window| may be null. |client_id| is the target client of
241 // |window|. 213 // |window|.
242 void CancelImplicitCaptureExcept(ServerWindow* window, 214 void CancelImplicitCaptureExcept(ServerWindow* window,
243 ClientSpecificId client_id); 215 ClientSpecificId client_id);
244 216
245 // ServerWindowObserver: 217 // ServerWindowObserver:
246 void OnWillChangeWindowHierarchy(ServerWindow* window, 218 void OnWillChangeWindowHierarchy(ServerWindow* window,
247 ServerWindow* new_parent, 219 ServerWindow* new_parent,
248 ServerWindow* old_parent) override; 220 ServerWindow* old_parent) override;
249 void OnWindowVisibilityChanged(ServerWindow* window) override; 221 void OnWindowVisibilityChanged(ServerWindow* window) override;
250 void OnWindowDestroyed(ServerWindow* window) override; 222 void OnWindowDestroyed(ServerWindow* window) override;
251 223
252 // DragCursorUpdater: 224 // DragCursorUpdater:
253 void OnDragCursorUpdated() override; 225 void OnDragCursorUpdated() override;
254 226
255 EventDispatcherDelegate* delegate_; 227 EventDispatcherDelegate* delegate_;
256 228
257 ServerWindow* capture_window_; 229 ServerWindow* capture_window_;
258 ClientSpecificId capture_window_client_id_; 230 ClientSpecificId capture_window_client_id_;
259 231
260 std::unique_ptr<DragController> drag_controller_; 232 std::unique_ptr<DragController> drag_controller_;
261 233
262 ModalWindowController modal_window_controller_; 234 ModalWindowController modal_window_controller_;
263 235
236 std::unique_ptr<EventTargeter> event_targeter_;
237
264 bool mouse_button_down_; 238 bool mouse_button_down_;
265 ServerWindow* mouse_cursor_source_window_; 239 ServerWindow* mouse_cursor_source_window_;
266 bool mouse_cursor_in_non_client_area_; 240 bool mouse_cursor_in_non_client_area_;
267 241
268 // The on screen location of the mouse pointer. This can be outside the 242 // The on screen location of the mouse pointer. This can be outside the
269 // bounds of |mouse_cursor_source_window_|, which can capture the cursor. 243 // bounds of |mouse_cursor_source_window_|, which can capture the cursor.
270 gfx::Point mouse_pointer_last_location_; 244 gfx::Point mouse_pointer_last_location_;
271 245
272 std::map<uint32_t, std::unique_ptr<Accelerator>> accelerators_; 246 std::map<uint32_t, std::unique_ptr<Accelerator>> accelerators_;
273 247
(...skipping 13 matching lines...) Expand all
287 AcceleratorMatchPhase::ANY; 261 AcceleratorMatchPhase::ANY;
288 #endif 262 #endif
289 263
290 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); 264 DISALLOW_COPY_AND_ASSIGN(EventDispatcher);
291 }; 265 };
292 266
293 } // namespace ws 267 } // namespace ws
294 } // namespace ui 268 } // namespace ui
295 269
296 #endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_ 270 #endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698