OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ | 5 #ifndef COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ |
6 #define COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ | 6 #define COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "cc/surfaces/surface_id.h" | 11 #include "cc/surfaces/surface_id.h" |
12 #include "components/mus/public/interfaces/input_event_constants.mojom.h" | 12 #include "components/mus/public/interfaces/input_event_constants.mojom.h" |
13 #include "components/mus/public/interfaces/input_event_matcher.mojom.h" | 13 #include "components/mus/public/interfaces/input_event_matcher.mojom.h" |
14 #include "components/mus/public/interfaces/input_events.mojom.h" | 14 #include "components/mus/public/interfaces/input_events.mojom.h" |
15 #include "components/mus/public/interfaces/input_key_codes.mojom.h" | 15 #include "components/mus/public/interfaces/input_key_codes.mojom.h" |
| 16 #include "components/mus/ws/server_window_observer.h" |
16 #include "ui/gfx/geometry/rect_f.h" | 17 #include "ui/gfx/geometry/rect_f.h" |
17 | 18 |
18 namespace mus { | 19 namespace mus { |
19 namespace ws { | 20 namespace ws { |
20 | 21 |
21 class EventDispatcherDelegate; | 22 class EventDispatcherDelegate; |
22 class EventMatcher; | 23 class EventMatcher; |
23 class ServerWindow; | 24 class ServerWindow; |
24 | 25 |
25 // Handles dispatching events to the right location as well as updating focus. | 26 // Handles dispatching events to the right location as well as updating focus. |
26 class EventDispatcher { | 27 class EventDispatcher : public ServerWindowObserver { |
27 public: | 28 public: |
28 explicit EventDispatcher(EventDispatcherDelegate* delegate); | 29 explicit EventDispatcher(EventDispatcherDelegate* delegate); |
29 ~EventDispatcher(); | 30 ~EventDispatcher() override; |
30 | 31 |
31 void set_root(ServerWindow* root) { root_ = root; } | 32 void set_root(ServerWindow* root) { root_ = root; } |
32 | 33 |
33 void set_surface_id(cc::SurfaceId surface_id) { surface_id_ = surface_id; } | 34 void set_surface_id(cc::SurfaceId surface_id) { surface_id_ = surface_id; } |
34 | 35 |
35 void AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); | 36 void AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); |
36 void RemoveAccelerator(uint32_t id); | 37 void RemoveAccelerator(uint32_t id); |
37 | 38 |
38 void OnEvent(mojom::EventPtr event); | 39 void OnEvent(mojom::EventPtr event); |
39 | 40 |
40 private: | 41 private: |
| 42 // Keeps track of state associated with a pointer down until the |
| 43 // corresponding up/cancel. |
| 44 struct PointerTarget { |
| 45 PointerTarget() : window(nullptr), in_nonclient_area(false) {} |
| 46 |
| 47 // NOTE: this is set to null if the window is destroyed before a |
| 48 // corresponding release/cancel. |
| 49 ServerWindow* window; |
| 50 |
| 51 // Did the pointer event start in the non-client area. |
| 52 bool in_nonclient_area; |
| 53 }; |
| 54 |
| 55 void ProcessKeyEvent(mojom::EventPtr event); |
| 56 |
| 57 // EventDispatcher provides the following logic for pointer events: |
| 58 // . wheel events go to the current target of the associated pointer. If |
| 59 // there is no target, they go to the deepest window. |
| 60 // . move (not drag) events go to the deepest window. |
| 61 // . when a pointer goes down all events until the corresponding up or |
| 62 // cancel go to the deepest target. For mouse events the up only occurs |
| 63 // when no buttons on the mouse are down. |
| 64 void ProcessPointerEvent(mojom::EventPtr event); |
| 65 |
| 66 // If |target->window| is valid, then passes the event to the delegate. |
| 67 void DispatchToPointerTarget(const PointerTarget& target, |
| 68 mojom::EventPtr event); |
| 69 |
| 70 // Stops sending pointer events to |window|. This does not remove the entry |
| 71 // for |window| from |pointer_targets_|, rather it nulls out the window. This |
| 72 // way we continue to eat events until the up/cancel is received. |
| 73 void CancelPointerEventsToTarget(ServerWindow* window); |
| 74 |
| 75 // Returns true if we're currently an observer for |window|. We are an |
| 76 // observer for a window if any pointer events are targeting it. |
| 77 bool IsObservingWindow(ServerWindow* window); |
| 78 |
41 // Looks to see if there is an accelerator bound to the specified code/flags. | 79 // Looks to see if there is an accelerator bound to the specified code/flags. |
42 // If there is one, sets |accelerator_id| to the id of the accelerator invoked | 80 // If there is one, sets |accelerator_id| to the id of the accelerator invoked |
43 // and returns true. If there is none, returns false so normal key event | 81 // and returns true. If there is none, returns false so normal key event |
44 // processing can continue. | 82 // processing can continue. |
45 bool FindAccelerator(const mojom::Event& event, uint32_t* accelerator_id); | 83 bool FindAccelerator(const mojom::Event& event, uint32_t* accelerator_id); |
46 | 84 |
47 // Returns the ServerWindow that should receive |event|. If |event| is a | 85 // ServerWindowObserver: |
48 // pointer-type event, then this function also updates the event location to | 86 void OnWillChangeWindowHierarchy(ServerWindow* window, |
49 // make sure it is in the returned target's coordinate space. | 87 ServerWindow* new_parent, |
50 ServerWindow* FindEventTarget(mojom::Event* event); | 88 ServerWindow* old_parent) override; |
| 89 void OnWindowVisibilityChanged(ServerWindow* window) override; |
| 90 void OnWindowDestroyed(ServerWindow* window) override; |
51 | 91 |
52 EventDispatcherDelegate* delegate_; | 92 EventDispatcherDelegate* delegate_; |
53 ServerWindow* root_; | 93 ServerWindow* root_; |
54 | 94 |
55 cc::SurfaceId surface_id_; | 95 cc::SurfaceId surface_id_; |
56 ServerWindow* capture_window_; | |
57 | |
58 // Was the capture the result of clicking in the non-client area? | |
59 bool capture_in_nonclient_area_; | |
60 | 96 |
61 using Entry = std::pair<uint32_t, EventMatcher>; | 97 using Entry = std::pair<uint32_t, EventMatcher>; |
62 std::map<uint32_t, EventMatcher> accelerators_; | 98 std::map<uint32_t, EventMatcher> accelerators_; |
63 | 99 |
| 100 using PointerIdToTargetMap = std::map<int32_t, PointerTarget>; |
| 101 PointerIdToTargetMap pointer_targets_; |
| 102 |
64 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | 103 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
65 }; | 104 }; |
66 | 105 |
67 } // namespace ws | 106 } // namespace ws |
68 } // namespace mus | 107 } // namespace mus |
69 | 108 |
70 #endif // COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ | 109 #endif // COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ |
OLD | NEW |