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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 18 matching lines...) Expand all Loading... | |
29 // Handles dispatching events to the right location as well as updating focus. | 29 // Handles dispatching events to the right location as well as updating focus. |
30 class EventDispatcher : public ServerWindowObserver { | 30 class EventDispatcher : public ServerWindowObserver { |
31 public: | 31 public: |
32 explicit EventDispatcher(EventDispatcherDelegate* delegate); | 32 explicit EventDispatcher(EventDispatcherDelegate* delegate); |
33 ~EventDispatcher() override; | 33 ~EventDispatcher() override; |
34 | 34 |
35 void set_root(ServerWindow* root) { root_ = root; } | 35 void set_root(ServerWindow* root) { root_ = root; } |
36 | 36 |
37 void set_surface_id(cc::SurfaceId surface_id) { surface_id_ = surface_id; } | 37 void set_surface_id(cc::SurfaceId surface_id) { surface_id_ = surface_id; } |
38 | 38 |
39 ServerWindow* capture_window() { return capture_window_; } | |
40 const ServerWindow* capture_window() const { return capture_window_; } | |
41 void SetCaptureWindow(ServerWindow* capture_window); | |
sky
2016/01/22 00:55:00
You should document what capturewindow means and w
jonross
2016/01/26 18:38:50
Done.
| |
42 | |
39 // Retrieves the ServerWindow of the last mouse move. | 43 // Retrieves the ServerWindow of the last mouse move. |
40 ServerWindow* mouse_cursor_source_window() const { | 44 ServerWindow* mouse_cursor_source_window() const { |
41 return mouse_cursor_source_window_; | 45 return mouse_cursor_source_window_; |
42 } | 46 } |
43 | 47 |
44 // Possibly updates the cursor. If we aren't in an implicit capture, we take | 48 // Possibly updates the cursor. If we aren't in an implicit capture, we take |
45 // the last known location of the mouse pointer, and look for the | 49 // the last known location of the mouse pointer, and look for the |
46 // ServerWindow* under it. | 50 // ServerWindow* under it. |
47 void UpdateCursorProviderByLastKnownLocation(); | 51 void UpdateCursorProviderByLastKnownLocation(); |
48 | 52 |
49 // Adds an accelerator with the given id and event-matcher. If an accelerator | 53 // Adds an accelerator with the given id and event-matcher. If an accelerator |
50 // already exists with the same id or the same matcher, then the accelerator | 54 // already exists with the same id or the same matcher, then the accelerator |
51 // is not added. Returns whether adding the accelerator was successful or not. | 55 // is not added. Returns whether adding the accelerator was successful or not. |
52 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); | 56 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); |
53 void RemoveAccelerator(uint32_t id); | 57 void RemoveAccelerator(uint32_t id); |
54 | 58 |
55 // Processes the supplied event, informing the delegate as approriate. This | 59 // Processes the supplied event, informing the delegate as approriate. This |
56 // may result in generating any number of events. | 60 // may result in generating any number of events. |
57 void ProcessEvent(mojom::EventPtr event); | 61 void ProcessEvent(mojom::EventPtr event); |
58 | 62 |
59 private: | 63 private: |
64 friend class EventDispatcherTest; | |
65 | |
60 // Keeps track of state associated with an active pointer. | 66 // Keeps track of state associated with an active pointer. |
61 struct PointerTarget { | 67 struct PointerTarget { |
62 PointerTarget() | 68 PointerTarget() |
63 : window(nullptr), in_nonclient_area(false), is_pointer_down(false) {} | 69 : window(nullptr), in_nonclient_area(false), is_pointer_down(false) {} |
64 | 70 |
65 // NOTE: this is set to null if the window is destroyed before a | 71 // NOTE: this is set to null if the window is destroyed before a |
66 // corresponding release/cancel. | 72 // corresponding release/cancel. |
67 ServerWindow* window; | 73 ServerWindow* window; |
68 | 74 |
69 // Did the pointer event start in the non-client area. | 75 // Did the pointer event start in the non-client area. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 | 134 |
129 // ServerWindowObserver: | 135 // ServerWindowObserver: |
130 void OnWillChangeWindowHierarchy(ServerWindow* window, | 136 void OnWillChangeWindowHierarchy(ServerWindow* window, |
131 ServerWindow* new_parent, | 137 ServerWindow* new_parent, |
132 ServerWindow* old_parent) override; | 138 ServerWindow* old_parent) override; |
133 void OnWindowVisibilityChanged(ServerWindow* window) override; | 139 void OnWindowVisibilityChanged(ServerWindow* window) override; |
134 void OnWindowDestroyed(ServerWindow* window) override; | 140 void OnWindowDestroyed(ServerWindow* window) override; |
135 | 141 |
136 EventDispatcherDelegate* delegate_; | 142 EventDispatcherDelegate* delegate_; |
137 ServerWindow* root_; | 143 ServerWindow* root_; |
144 ServerWindow* capture_window_; | |
138 | 145 |
139 bool mouse_button_down_; | 146 bool mouse_button_down_; |
140 ServerWindow* mouse_cursor_source_window_; | 147 ServerWindow* mouse_cursor_source_window_; |
141 | 148 |
142 // The on screen location of the mouse pointer. This can be outside the | 149 // The on screen location of the mouse pointer. This can be outside the |
143 // bounds of |mouse_cursor_source_window_|, which can capture the cursor. | 150 // bounds of |mouse_cursor_source_window_|, which can capture the cursor. |
144 gfx::Point mouse_pointer_last_location_; | 151 gfx::Point mouse_pointer_last_location_; |
145 | 152 |
146 cc::SurfaceId surface_id_; | 153 cc::SurfaceId surface_id_; |
147 | 154 |
148 using Entry = std::pair<uint32_t, EventMatcher>; | 155 using Entry = std::pair<uint32_t, EventMatcher>; |
149 std::map<uint32_t, EventMatcher> accelerators_; | 156 std::map<uint32_t, EventMatcher> accelerators_; |
150 | 157 |
151 using PointerIdToTargetMap = std::map<int32_t, PointerTarget>; | 158 using PointerIdToTargetMap = std::map<int32_t, PointerTarget>; |
152 // |pointer_targets_| contains the active pointers. For a mouse based pointer | 159 // |pointer_targets_| contains the active pointers. For a mouse based pointer |
153 // a PointerTarget is always active (and present in |pointer_targets_|). For | 160 // a PointerTarget is always active (and present in |pointer_targets_|). For |
154 // touch based pointers the pointer is active while down and removed on | 161 // touch based pointers the pointer is active while down and removed on |
155 // cancel or up. | 162 // cancel or up. |
156 PointerIdToTargetMap pointer_targets_; | 163 PointerIdToTargetMap pointer_targets_; |
157 | 164 |
158 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | 165 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
159 }; | 166 }; |
160 | 167 |
161 } // namespace ws | 168 } // namespace ws |
162 } // namespace mus | 169 } // namespace mus |
163 | 170 |
164 #endif // COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ | 171 #endif // COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ |
OLD | NEW |