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