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

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

Issue 2884463002: Make event-targeting asynchronous in window server. (Closed)
Patch Set: rebase and comments 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_TARGETER_H_ 5 #ifndef SERVICES_UI_WS_EVENT_TARGETER_H_
6 #define SERVICES_UI_WS_EVENT_TARGETER_H_ 6 #define SERVICES_UI_WS_EVENT_TARGETER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <queue>
9 10
11 #include "base/callback.h"
10 #include "base/macros.h" 12 #include "base/macros.h"
11 13 #include "base/memory/weak_ptr.h"
12 namespace gfx { 14 #include "ui/gfx/geometry/point.h"
13 class Point;
14 }
15 15
16 namespace ui { 16 namespace ui {
17 class LocatedEvent; 17 class PointerEvent;
18 18
19 namespace ws { 19 namespace ws {
20 struct DeepestWindow; 20 struct DeepestWindow;
21 class EventTargeterDelegate; 21 class EventTargeterDelegate;
22 class ModalWindowController; 22 class ModalWindowController;
23 class ServerWindow; 23 class ServerWindow;
24 24
25 // Keeps track of state associated with an active pointer. 25 // Keeps track of state associated with an active pointer.
26 struct PointerTarget { 26 struct PointerTarget {
sky 2017/06/02 23:28:20 Sorry for not realizing this sooner, but PointerTa
riajiang 2017/06/05 23:56:15 Ah I see, makes sense. Moved PointerTarget back to
27 PointerTarget() 27 PointerTarget()
28 : window(nullptr), 28 : window(nullptr),
29 is_mouse_event(false), 29 is_mouse_event(false),
30 in_nonclient_area(false), 30 in_nonclient_area(false),
31 is_pointer_down(false) {} 31 is_pointer_down(false) {}
32 32
33 // The target window, which may be null. null is used in two situations: 33 // The target window, which may be null. null is used in two situations:
34 // when there is no valid window target, or there was a target but the 34 // when there is no valid window target, or there was a target but the
35 // window is destroyed before a corresponding release/cancel. 35 // window is destroyed before a corresponding release/cancel.
36 ServerWindow* window; 36 ServerWindow* window;
37 37
38 bool is_mouse_event; 38 bool is_mouse_event;
39 39
40 // Did the pointer event start in the non-client area. 40 // Did the pointer event start in the non-client area.
41 bool in_nonclient_area; 41 bool in_nonclient_area;
42 42
43 bool is_pointer_down; 43 bool is_pointer_down;
44 }; 44 };
45 45
46 using PointerTargetForEventCallback =
47 base::OnceCallback<void(const PointerTarget&,
48 const DeepestWindow&,
49 const gfx::Point&,
50 int64_t)>;
51 using HitTestCallback =
52 base::OnceCallback<void(const DeepestWindow&, const gfx::Point&, int64_t)>;
53
46 // Finds the PointerTarget for an event or the DeepestWindow for a location. 54 // Finds the PointerTarget for an event or the DeepestWindow for a location.
47 class EventTargeter { 55 class EventTargeter {
48 public: 56 public:
49 EventTargeter(EventTargeterDelegate* event_targeter_delegate, 57 EventTargeter(EventTargeterDelegate* event_targeter_delegate,
50 ModalWindowController* modal_window_controller); 58 ModalWindowController* modal_window_controller);
51 ~EventTargeter(); 59 ~EventTargeter();
52 60
53 // Returns a PointerTarget for the supplied |event|. If there is no valid 61 // |callback| is called with a PointerTarget for the supplied |event|. If
54 // event target for the specified location |window| in the returned value is 62 // there is no valid event target for the specified location |window| in the
55 // null. 63 // returned value is null.
56 PointerTarget PointerTargetForEvent(const ui::LocatedEvent& event, 64 void PointerTargetForEvent(const ui::PointerEvent& event,
57 int64_t* display_id); 65 int64_t display_id,
66 PointerTargetForEventCallback callback);
58 67
59 // Returns a DeepestWindow for the supplied |location|. If there is no valid 68 // Calls WindowFinder to find the deepest visible window for |location|.
60 // root window, |window| in the returned value is null. 69 // |callback| is called with the window found.
61 DeepestWindow FindDeepestVisibleWindowForEvents(gfx::Point* location, 70 void FindDeepestVisibleWindowForLocation(const gfx::Point& location,
62 int64_t* display_id); 71 int64_t display_id,
72 HitTestCallback callback);
73
74 bool IsHitTestInFlight() const;
63 75
64 private: 76 private:
77 struct HitTestRequest {
78 HitTestRequest(const gfx::Point& location,
79 int64_t display_id,
80 HitTestCallback hittest_callback);
81 ~HitTestRequest();
82
83 gfx::Point location;
84 int64_t display_id;
85 HitTestCallback callback;
86 };
87
88 void PointerTargetForEventOnFoundWindow(const ui::PointerEvent& event,
89 const DeepestWindow& deepest_window,
90 const gfx::Point& location_in_display,
91 int64_t display_id);
92
93 void FindDeepestVisibleWindowForLocationImpl(const gfx::Point& location,
94 int64_t display_id);
95
96 void FindDeepestVisibleWindowForLocationAsync(const gfx::Point& location,
97 int64_t display_id);
98
99 void ProcessNextHittesetRequestFromQueue();
100
65 EventTargeterDelegate* event_targeter_delegate_; 101 EventTargeterDelegate* event_targeter_delegate_;
102
66 ModalWindowController* modal_window_controller_; 103 ModalWindowController* modal_window_controller_;
67 104
105 PointerTargetForEventCallback target_callback_;
106 HitTestCallback hit_test_callback_;
107
108 // True if we are waiting for the result of a hit-test. False otherwise.
109 bool hit_test_in_flight_;
110
111 // Request would go into this queue if it's coming from EventDispatcher::
112 // UpdateNonClientAreaForCurrentWindow() or EventDispatcher::
113 // UpdateCursorProviderByLastKnownLocation(). If it's an event that needs
114 // targeting, it would only go to WindowManagerState::event_queue_ when it's
115 // waiting for an active hit-test.
116 std::queue<std::unique_ptr<HitTestRequest>> hit_test_request_queue_;
117
118 base::WeakPtrFactory<EventTargeter> weak_ptr_factory_;
119
68 DISALLOW_COPY_AND_ASSIGN(EventTargeter); 120 DISALLOW_COPY_AND_ASSIGN(EventTargeter);
69 }; 121 };
70 122
71 } // namespace ws 123 } // namespace ws
72 } // namespace ui 124 } // namespace ui
73 125
74 #endif // SERVICES_UI_WS_EVENT_TARGETER_H_ 126 #endif // SERVICES_UI_WS_EVENT_TARGETER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698