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 FindTargetForLocationImpl(const gfx::Point& location, | |
59 int64_t display_id, | |
60 HitTestCallback callback); | |
61 | |
62 void FindTargetForLocationAsync(const gfx::Point& location, | |
63 int64_t display_id, | |
64 HitTestCallback callback); | |
65 | |
66 void ProcessNextHittesetRequestFromQueue(); | |
sky
2017/06/07 17:05:07
HitTestRequest
riajiang
2017/06/07 18:15:04
Done.
| |
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 // Request would go into this queue if it's coming from EventDispatcher:: | |
sky
2017/06/07 17:05:07
Update description.
riajiang
2017/06/07 18:15:04
This is still valid? Even though we call FindTarge
sky
2017/06/07 19:46:41
This description is entirely in terms of other cla
riajiang
2017/06/07 21:46:25
Oh I see, done.
| |
74 // UpdateNonClientAreaForCurrentWindow() or EventDispatcher:: | |
75 // UpdateCursorProviderByLastKnownLocation(). If it's an event that needs | |
76 // targeting, it would only go to WindowManagerState::event_queue_ when it's | |
77 // waiting for an active hit-test. | |
78 std::queue<std::unique_ptr<HitTestRequest>> hit_test_request_queue_; | |
79 | |
80 base::WeakPtrFactory<EventTargeter> weak_ptr_factory_; | |
81 | |
41 DISALLOW_COPY_AND_ASSIGN(EventTargeter); | 82 DISALLOW_COPY_AND_ASSIGN(EventTargeter); |
42 }; | 83 }; |
43 | 84 |
44 } // namespace ws | 85 } // namespace ws |
45 } // namespace ui | 86 } // namespace ui |
46 | 87 |
47 #endif // SERVICES_UI_WS_EVENT_TARGETER_H_ | 88 #endif // SERVICES_UI_WS_EVENT_TARGETER_H_ |
OLD | NEW |