OLD | NEW |
---|---|
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 EventDispatcherDelegate; | 21 class EventDispatcherDelegate; |
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 { |
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 = base::OnceCallback<void(PointerTarget)>; | |
47 using HitTestCallback = base::OnceCallback<void(DeepestWindow)>; | |
48 | |
46 // Finds the PointerTarget for an event or the DeepestWindow for a location. | 49 // Finds the PointerTarget for an event or the DeepestWindow for a location. |
47 class EventTargeter { | 50 class EventTargeter { |
48 public: | 51 public: |
49 EventTargeter(EventDispatcherDelegate* event_dispatcher_delegate, | 52 EventTargeter(EventDispatcherDelegate* event_dispatcher_delegate, |
50 ModalWindowController* modal_window_controller); | 53 ModalWindowController* modal_window_controller); |
51 ~EventTargeter(); | 54 ~EventTargeter(); |
52 | 55 |
53 // Returns a PointerTarget for the supplied |event|. If there is no valid | 56 // |callback| is called with a PointerTarget for the supplied |event|. If |
54 // event target for the specified location |window| in the returned value is | 57 // there is no valid event target for the specified location |window| in the |
55 // null. | 58 // returned value is null. |
56 PointerTarget PointerTargetForEvent(const ui::LocatedEvent& event, | 59 void PointerTargetForEvent(const ui::PointerEvent& event, |
57 int64_t* display_id); | 60 int64_t* display_id, |
61 PointerTargetForEventCallback callback); | |
58 | 62 |
59 // Returns a DeepestWindow for the supplied |location|. If there is no valid | 63 // Calls WindowFinder to find the deepest visible window for |location|. |
60 // root window, |window| in the returned value is null. | 64 // |callback| is called with the window found. |
61 DeepestWindow FindDeepestVisibleWindowForEvents(gfx::Point* location, | 65 void FindDeepestVisibleWindowForEvents(gfx::Point* location, |
62 int64_t* display_id); | 66 int64_t* display_id, |
67 HitTestCallback callback); | |
68 | |
69 void ProcessNextHittesetRequestFromQueue(); | |
70 | |
71 bool IsHitTestInFlight() const; | |
63 | 72 |
64 private: | 73 private: |
74 struct HitTestRequest { | |
75 HitTestRequest(gfx::Point* location, | |
sky
2017/05/30 17:26:02
I'm nervous about keeping pointers to members from
riajiang
2017/05/31 22:44:03
Makes sense, changed to by value and return the up
| |
76 int64_t* display_id, | |
77 HitTestCallback hittest_callback); | |
78 ~HitTestRequest(); | |
79 | |
80 gfx::Point* hittest_location; | |
81 int64_t* hittest_display_id; | |
82 HitTestCallback hittest_callback; | |
83 }; | |
84 | |
85 void PointerTargetForEventOnFoundWindow(const ui::PointerEvent& event, | |
86 DeepestWindow deepest_window); | |
87 | |
88 void FindDeepestVisibleWindowForEventsImpl(gfx::Point* location, | |
89 int64_t* display_id); | |
90 | |
91 void FindDeepestVisibleWindowForEventsAsync(gfx::Point* location, | |
92 int64_t* display_id); | |
93 | |
65 EventDispatcherDelegate* event_dispatcher_delegate_; | 94 EventDispatcherDelegate* event_dispatcher_delegate_; |
66 ModalWindowController* modal_window_controller_; | 95 ModalWindowController* modal_window_controller_; |
67 | 96 |
97 PointerTargetForEventCallback target_callback_; | |
98 | |
99 std::unique_ptr<gfx::Point> current_hittest_location_; | |
100 HitTestCallback hittest_callback_; | |
101 | |
102 // True if we are waiting for the result of a hit-test. False otherwise. | |
103 bool hittest_in_flight_; | |
104 | |
105 // Request would go into this queue if it's coming from EventDispatcher:: | |
106 // UpdateNonClientAreaForCurrentWindow() or EventDispatcher:: | |
107 // UpdateCursorProviderByLastKnownLocation(). If it's an event that needs | |
108 // targeting, it would only go to WindowManagerState::event_queue_ when it's | |
109 // waiting for an active hit-test. | |
110 std::queue<std::unique_ptr<HitTestRequest>> hittest_request_queue_; | |
111 | |
112 base::WeakPtrFactory<EventTargeter> weak_ptr_factory_; | |
113 | |
68 DISALLOW_COPY_AND_ASSIGN(EventTargeter); | 114 DISALLOW_COPY_AND_ASSIGN(EventTargeter); |
69 }; | 115 }; |
70 | 116 |
71 } // namespace ws | 117 } // namespace ws |
72 } // namespace ui | 118 } // namespace ui |
73 | 119 |
74 #endif // SERVICES_UI_WS_EVENT_TARGETER_H_ | 120 #endif // SERVICES_UI_WS_EVENT_TARGETER_H_ |
OLD | NEW |