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" |
| 13 #include "base/memory/weak_ptr.h" |
11 #include "services/ui/ws/window_finder.h" | 14 #include "services/ui/ws/window_finder.h" |
12 #include "ui/display/types/display_constants.h" | 15 #include "ui/display/types/display_constants.h" |
13 #include "ui/gfx/geometry/point.h" | 16 #include "ui/gfx/geometry/point.h" |
14 | 17 |
15 namespace ui { | 18 namespace ui { |
16 namespace ws { | 19 namespace ws { |
17 class EventTargeterDelegate; | 20 class EventTargeterDelegate; |
18 | 21 |
19 // The target |window| for a given location, |location| and |display_id| are | 22 // The target |window| for a given location, |location| and |display_id| are |
20 // associated with the display |window| is on. | 23 // associated with the display |window| is on. |
21 struct LocationTarget { | 24 struct LocationTarget { |
22 DeepestWindow deepest_window; | 25 DeepestWindow deepest_window; |
23 gfx::Point location_in_root; | 26 gfx::Point location_in_root; |
24 int64_t display_id = display::kInvalidDisplayId; | 27 int64_t display_id = display::kInvalidDisplayId; |
25 }; | 28 }; |
26 | 29 |
| 30 using HitTestCallback = base::OnceCallback<void(const LocationTarget&)>; |
| 31 |
27 // Finds the target window for a location. | 32 // Finds the target window for a location. |
28 class EventTargeter { | 33 class EventTargeter { |
29 public: | 34 public: |
30 explicit EventTargeter(EventTargeterDelegate* event_targeter_delegate); | 35 explicit EventTargeter(EventTargeterDelegate* event_targeter_delegate); |
31 ~EventTargeter(); | 36 ~EventTargeter(); |
32 | 37 |
33 // Returns a LocationTarget for the supplied |location|. If there is no valid | 38 // Calls WindowFinder to find the target for |location|. |
34 // root window, |window| in the returned value is null. | 39 // |callback| is called with the LocationTarget found. |
35 LocationTarget FindTargetForLocation(const gfx::Point& location, | 40 void FindTargetForLocation(const gfx::Point& location, |
36 int64_t display_id); | 41 int64_t display_id, |
| 42 HitTestCallback callback); |
| 43 |
| 44 bool IsHitTestInFlight() const; |
37 | 45 |
38 private: | 46 private: |
| 47 struct HitTestRequest { |
| 48 HitTestRequest(const gfx::Point& location, |
| 49 int64_t display_id, |
| 50 HitTestCallback hittest_callback); |
| 51 ~HitTestRequest(); |
| 52 |
| 53 gfx::Point location; |
| 54 int64_t display_id; |
| 55 HitTestCallback callback; |
| 56 }; |
| 57 |
| 58 void ProcessFindTarget(const gfx::Point& location, |
| 59 int64_t display_id, |
| 60 HitTestCallback callback); |
| 61 |
| 62 void FindTargetForLocationNow(const gfx::Point& location, |
| 63 int64_t display_id, |
| 64 HitTestCallback callback); |
| 65 |
| 66 void ProcessNextHitTestRequestFromQueue(); |
| 67 |
39 EventTargeterDelegate* event_targeter_delegate_; | 68 EventTargeterDelegate* event_targeter_delegate_; |
40 | 69 |
| 70 // True if we are waiting for the result of a hit-test. False otherwise. |
| 71 bool hit_test_in_flight_; |
| 72 |
| 73 // Requests for a new location while waiting on an existing request are added |
| 74 // here. |
| 75 std::queue<std::unique_ptr<HitTestRequest>> hit_test_request_queue_; |
| 76 |
| 77 base::WeakPtrFactory<EventTargeter> weak_ptr_factory_; |
| 78 |
41 DISALLOW_COPY_AND_ASSIGN(EventTargeter); | 79 DISALLOW_COPY_AND_ASSIGN(EventTargeter); |
42 }; | 80 }; |
43 | 81 |
44 } // namespace ws | 82 } // namespace ws |
45 } // namespace ui | 83 } // namespace ui |
46 | 84 |
47 #endif // SERVICES_UI_WS_EVENT_TARGETER_H_ | 85 #endif // SERVICES_UI_WS_EVENT_TARGETER_H_ |
OLD | NEW |