| 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 12 matching lines...) Expand all Loading... |
| 23 class PointerEvent; | 23 class PointerEvent; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace mus { | 26 namespace mus { |
| 27 namespace ws { | 27 namespace ws { |
| 28 | 28 |
| 29 class EventDispatcherDelegate; | 29 class EventDispatcherDelegate; |
| 30 class EventMatcher; | 30 class EventMatcher; |
| 31 class ServerWindow; | 31 class ServerWindow; |
| 32 | 32 |
| 33 namespace test { |
| 34 class EventDispatcherTestApi; |
| 35 } |
| 36 |
| 33 // Handles dispatching events to the right location as well as updating focus. | 37 // Handles dispatching events to the right location as well as updating focus. |
| 34 class EventDispatcher : public ServerWindowObserver { | 38 class EventDispatcher : public ServerWindowObserver { |
| 35 public: | 39 public: |
| 36 explicit EventDispatcher(EventDispatcherDelegate* delegate); | 40 explicit EventDispatcher(EventDispatcherDelegate* delegate); |
| 37 ~EventDispatcher() override; | 41 ~EventDispatcher() override; |
| 38 | 42 |
| 39 void set_root(ServerWindow* root) { root_ = root; } | 43 void set_root(ServerWindow* root) { root_ = root; } |
| 40 | 44 |
| 41 void set_surface_id(cc::SurfaceId surface_id) { surface_id_ = surface_id; } | 45 void set_surface_id(cc::SurfaceId surface_id) { surface_id_ = surface_id; } |
| 42 | 46 |
| 47 // Cancels capture and stops tracking any pointer events. This does not send |
| 48 // any events to the delegate. |
| 49 void Reset(); |
| 50 |
| 51 void SetMousePointerScreenLocation(const gfx::Point& screen_location); |
| 52 const gfx::Point& mouse_pointer_last_location() const { |
| 53 return mouse_pointer_last_location_; |
| 54 } |
| 55 |
| 43 // |capture_window_| will receive all input. See window_tree.mojom for | 56 // |capture_window_| will receive all input. See window_tree.mojom for |
| 44 // details. | 57 // details. |
| 45 ServerWindow* capture_window() { return capture_window_; } | 58 ServerWindow* capture_window() { return capture_window_; } |
| 46 const ServerWindow* capture_window() const { return capture_window_; } | 59 const ServerWindow* capture_window() const { return capture_window_; } |
| 47 void SetCaptureWindow(ServerWindow* capture_window, bool in_nonclient_area); | 60 void SetCaptureWindow(ServerWindow* capture_window, bool in_nonclient_area); |
| 48 | 61 |
| 49 // Retrieves the ServerWindow of the last mouse move. | 62 // Retrieves the ServerWindow of the last mouse move. |
| 50 ServerWindow* mouse_cursor_source_window() const { | 63 ServerWindow* mouse_cursor_source_window() const { |
| 51 return mouse_cursor_source_window_; | 64 return mouse_cursor_source_window_; |
| 52 } | 65 } |
| 53 | 66 |
| 54 // Possibly updates the cursor. If we aren't in an implicit capture, we take | 67 // Possibly updates the cursor. If we aren't in an implicit capture, we take |
| 55 // the last known location of the mouse pointer, and look for the | 68 // the last known location of the mouse pointer, and look for the |
| 56 // ServerWindow* under it. | 69 // ServerWindow* under it. |
| 57 void UpdateCursorProviderByLastKnownLocation(); | 70 void UpdateCursorProviderByLastKnownLocation(); |
| 58 | 71 |
| 59 // Adds an accelerator with the given id and event-matcher. If an accelerator | 72 // Adds an accelerator with the given id and event-matcher. If an accelerator |
| 60 // already exists with the same id or the same matcher, then the accelerator | 73 // already exists with the same id or the same matcher, then the accelerator |
| 61 // is not added. Returns whether adding the accelerator was successful or not. | 74 // is not added. Returns whether adding the accelerator was successful or not. |
| 62 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); | 75 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); |
| 63 void RemoveAccelerator(uint32_t id); | 76 void RemoveAccelerator(uint32_t id); |
| 64 | 77 |
| 65 // Processes the supplied event, informing the delegate as approriate. This | 78 // Processes the supplied event, informing the delegate as approriate. This |
| 66 // may result in generating any number of events. | 79 // may result in generating any number of events. |
| 67 void ProcessEvent(const ui::Event& event); | 80 void ProcessEvent(const ui::Event& event); |
| 68 | 81 |
| 69 private: | 82 private: |
| 70 friend class EventDispatcherTest; | 83 friend class test::EventDispatcherTestApi; |
| 71 | 84 |
| 72 // Keeps track of state associated with an active pointer. | 85 // Keeps track of state associated with an active pointer. |
| 73 struct PointerTarget { | 86 struct PointerTarget { |
| 74 PointerTarget() | 87 PointerTarget() |
| 75 : window(nullptr), | 88 : window(nullptr), |
| 76 is_mouse_event(false), | 89 is_mouse_event(false), |
| 77 in_nonclient_area(false), | 90 in_nonclient_area(false), |
| 78 is_pointer_down(false) {} | 91 is_pointer_down(false) {} |
| 79 | 92 |
| 80 // NOTE: this is set to null if the window is destroyed before a | 93 // NOTE: this is set to null if the window is destroyed before a |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // cancel or up. | 189 // cancel or up. |
| 177 PointerIdToTargetMap pointer_targets_; | 190 PointerIdToTargetMap pointer_targets_; |
| 178 | 191 |
| 179 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | 192 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
| 180 }; | 193 }; |
| 181 | 194 |
| 182 } // namespace ws | 195 } // namespace ws |
| 183 } // namespace mus | 196 } // namespace mus |
| 184 | 197 |
| 185 #endif // COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ | 198 #endif // COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ |
| OLD | NEW |