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 = |
| 47 base::OnceCallback<void(const PointerTarget&, |
| 48 const DeepestWindow&, |
| 49 const gfx::Point&, |
| 50 const int64_t)>; |
| 51 using HitTestCallback = base::OnceCallback< |
| 52 void(const DeepestWindow&, const gfx::Point&, const 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(EventDispatcherDelegate* event_dispatcher_delegate, | 57 EventTargeter(EventDispatcherDelegate* event_dispatcher_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 const 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 FindDeepestVisibleWindowForEvents(const gfx::Point& location, |
62 int64_t* display_id); | 71 const int64_t display_id, |
| 72 HitTestCallback callback); |
| 73 |
| 74 void ProcessNextHittesetRequestFromQueue(); |
| 75 |
| 76 bool IsHitTestInFlight() const; |
63 | 77 |
64 private: | 78 private: |
| 79 struct HitTestRequest { |
| 80 HitTestRequest(const gfx::Point& location, |
| 81 const int64_t display_id, |
| 82 HitTestCallback hittest_callback); |
| 83 ~HitTestRequest(); |
| 84 |
| 85 gfx::Point location; |
| 86 int64_t display_id; |
| 87 HitTestCallback callback; |
| 88 }; |
| 89 |
| 90 void PointerTargetForEventOnFoundWindow(const ui::PointerEvent& event, |
| 91 const DeepestWindow& deepest_window, |
| 92 const gfx::Point& location_in_display, |
| 93 const int64_t display_id); |
| 94 |
| 95 void FindDeepestVisibleWindowForEventsImpl(const gfx::Point& location, |
| 96 const int64_t display_id); |
| 97 |
| 98 void FindDeepestVisibleWindowForEventsAsync(const gfx::Point& location, |
| 99 const int64_t display_id); |
| 100 |
65 EventDispatcherDelegate* event_dispatcher_delegate_; | 101 EventDispatcherDelegate* event_dispatcher_delegate_; |
66 ModalWindowController* modal_window_controller_; | 102 ModalWindowController* modal_window_controller_; |
67 | 103 |
| 104 PointerTargetForEventCallback target_callback_; |
| 105 HitTestCallback hit_test_callback_; |
| 106 |
| 107 // True if we are waiting for the result of a hit-test. False otherwise. |
| 108 bool hit_test_in_flight_; |
| 109 |
| 110 // Request would go into this queue if it's coming from EventDispatcher:: |
| 111 // UpdateNonClientAreaForCurrentWindow() or EventDispatcher:: |
| 112 // UpdateCursorProviderByLastKnownLocation(). If it's an event that needs |
| 113 // targeting, it would only go to WindowManagerState::event_queue_ when it's |
| 114 // waiting for an active hit-test. |
| 115 std::queue<std::unique_ptr<HitTestRequest>> hit_test_request_queue_; |
| 116 |
| 117 base::WeakPtrFactory<EventTargeter> weak_ptr_factory_; |
| 118 |
68 DISALLOW_COPY_AND_ASSIGN(EventTargeter); | 119 DISALLOW_COPY_AND_ASSIGN(EventTargeter); |
69 }; | 120 }; |
70 | 121 |
71 } // namespace ws | 122 } // namespace ws |
72 } // namespace ui | 123 } // namespace ui |
73 | 124 |
74 #endif // SERVICES_UI_WS_EVENT_TARGETER_H_ | 125 #endif // SERVICES_UI_WS_EVENT_TARGETER_H_ |
OLD | NEW |