| 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 23 matching lines...) Expand all Loading... |
| 34 namespace test { | 34 namespace test { |
| 35 class EventDispatcherTestApi; | 35 class EventDispatcherTestApi; |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Handles dispatching events to the right location as well as updating focus. | 38 // Handles dispatching events to the right location as well as updating focus. |
| 39 class EventDispatcher : public ServerWindowObserver { | 39 class EventDispatcher : public ServerWindowObserver { |
| 40 public: | 40 public: |
| 41 explicit EventDispatcher(EventDispatcherDelegate* delegate); | 41 explicit EventDispatcher(EventDispatcherDelegate* delegate); |
| 42 ~EventDispatcher() override; | 42 ~EventDispatcher() override; |
| 43 | 43 |
| 44 void set_root(ServerWindow* root) { root_ = root; } | |
| 45 | |
| 46 // Cancels capture and stops tracking any pointer events. This does not send | 44 // Cancels capture and stops tracking any pointer events. This does not send |
| 47 // any events to the delegate. | 45 // any events to the delegate. |
| 48 void Reset(); | 46 void Reset(); |
| 49 | 47 |
| 50 void SetMousePointerScreenLocation(const gfx::Point& screen_location); | 48 void SetMousePointerScreenLocation(const gfx::Point& screen_location); |
| 51 const gfx::Point& mouse_pointer_last_location() const { | 49 const gfx::Point& mouse_pointer_last_location() const { |
| 52 return mouse_pointer_last_location_; | 50 return mouse_pointer_last_location_; |
| 53 } | 51 } |
| 54 | 52 |
| 55 // If we still have the window of the last mouse move, returns true and sets | 53 // If we still have the window of the last mouse move, returns true and sets |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // Removes a PointerTarget from |pointer_targets_|. | 154 // Removes a PointerTarget from |pointer_targets_|. |
| 157 void StopTrackingPointer(int32_t pointer_id); | 155 void StopTrackingPointer(int32_t pointer_id); |
| 158 | 156 |
| 159 // Starts tracking the pointer for |event|, or if already tracking the | 157 // Starts tracking the pointer for |event|, or if already tracking the |
| 160 // pointer sends the appropriate event to the delegate and updates the | 158 // pointer sends the appropriate event to the delegate and updates the |
| 161 // currently tracked PointerTarget appropriately. | 159 // currently tracked PointerTarget appropriately. |
| 162 void UpdateTargetForPointer(int32_t pointer_id, | 160 void UpdateTargetForPointer(int32_t pointer_id, |
| 163 const ui::LocatedEvent& event); | 161 const ui::LocatedEvent& event); |
| 164 | 162 |
| 165 // Returns a PointerTarget from the supplied event. | 163 // Returns a PointerTarget from the supplied event. |
| 166 PointerTarget PointerTargetForEvent(const ui::LocatedEvent& event) const; | 164 PointerTarget PointerTargetForEvent(const ui::LocatedEvent& event); |
| 167 | 165 |
| 168 // Returns true if any pointers are in the pressed/down state. | 166 // Returns true if any pointers are in the pressed/down state. |
| 169 bool AreAnyPointersDown() const; | 167 bool AreAnyPointersDown() const; |
| 170 | 168 |
| 171 // If |target->window| is valid, then passes the event to the delegate. | 169 // If |target->window| is valid, then passes the event to the delegate. |
| 172 void DispatchToPointerTarget(const PointerTarget& target, | 170 void DispatchToPointerTarget(const PointerTarget& target, |
| 173 const ui::LocatedEvent& event); | 171 const ui::LocatedEvent& event); |
| 174 | 172 |
| 175 // Dispatch |event| to the delegate. | 173 // Dispatch |event| to the delegate. |
| 176 void DispatchToClient(ServerWindow* window, | 174 void DispatchToClient(ServerWindow* window, |
| 177 ClientSpecificId client_id, | 175 ClientSpecificId client_id, |
| 178 const ui::LocatedEvent& event); | 176 const ui::LocatedEvent& event); |
| 179 | 177 |
| 180 // Stops sending pointer events to |window|. This does not remove the entry | 178 // Stops sending pointer events to |window|. This does not remove the entry |
| 181 // for |window| from |pointer_targets_|, rather it nulls out the window. This | 179 // for |window| from |pointer_targets_|, rather it nulls out the window. This |
| 182 // way we continue to eat events until the up/cancel is received. | 180 // way we continue to eat events until the up/cancel is received. |
| 183 void CancelPointerEventsToTarget(ServerWindow* window); | 181 void CancelPointerEventsToTarget(ServerWindow* window); |
| 184 | 182 |
| 185 // Used to observe a window. Can be called multiple times on a window. To | 183 // Used to observe a window. Can be called multiple times on a window. To |
| 186 // unobserve a window, UnobserveWindow() should be called the same number of | 184 // unobserve a window, UnobserveWindow() should be called the same number of |
| 187 // times. | 185 // times. |
| 188 void ObserveWindow(ServerWindow* winodw); | 186 void ObserveWindow(ServerWindow* winodw); |
| 189 void UnobserveWindow(ServerWindow* winodw); | 187 void UnobserveWindow(ServerWindow* winodw); |
| 190 | 188 |
| 191 // Returns an Accelerator bound to the specified code/flags, and of the | 189 // Returns an Accelerator bound to the specified code/flags, and of the |
| 192 // matching |phase|. Otherwise returns null. | 190 // matching |phase|. Otherwise returns null. |
| 193 Accelerator* FindAccelerator(const ui::KeyEvent& event, | 191 Accelerator* FindAccelerator(const ui::KeyEvent& event, |
| 194 const ui::mojom::AcceleratorPhase phase); | 192 const ui::mojom::AcceleratorPhase phase); |
| 195 | 193 |
| 194 ServerWindow* FindDeepestVisibleWindowForEvents(gfx::Point* location); |
| 195 |
| 196 // ServerWindowObserver: | 196 // ServerWindowObserver: |
| 197 void OnWillChangeWindowHierarchy(ServerWindow* window, | 197 void OnWillChangeWindowHierarchy(ServerWindow* window, |
| 198 ServerWindow* new_parent, | 198 ServerWindow* new_parent, |
| 199 ServerWindow* old_parent) override; | 199 ServerWindow* old_parent) override; |
| 200 void OnWindowVisibilityChanged(ServerWindow* window) override; | 200 void OnWindowVisibilityChanged(ServerWindow* window) override; |
| 201 void OnWindowDestroyed(ServerWindow* window) override; | 201 void OnWindowDestroyed(ServerWindow* window) override; |
| 202 | 202 |
| 203 EventDispatcherDelegate* delegate_; | 203 EventDispatcherDelegate* delegate_; |
| 204 ServerWindow* root_; | |
| 205 | 204 |
| 206 ServerWindow* capture_window_; | 205 ServerWindow* capture_window_; |
| 207 ClientSpecificId capture_window_client_id_; | 206 ClientSpecificId capture_window_client_id_; |
| 208 | 207 |
| 209 ModalWindowController modal_window_controller_; | 208 ModalWindowController modal_window_controller_; |
| 210 | 209 |
| 211 bool mouse_button_down_; | 210 bool mouse_button_down_; |
| 212 ServerWindow* mouse_cursor_source_window_; | 211 ServerWindow* mouse_cursor_source_window_; |
| 213 bool mouse_cursor_in_non_client_area_; | 212 bool mouse_cursor_in_non_client_area_; |
| 214 | 213 |
| 215 // The on screen location of the mouse pointer. This can be outside the | 214 // The on screen location of the mouse pointer. This can be outside the |
| 216 // bounds of |mouse_cursor_source_window_|, which can capture the cursor. | 215 // bounds of |mouse_cursor_source_window_|, which can capture the cursor. |
| 217 gfx::Point mouse_pointer_last_location_; | 216 gfx::Point mouse_pointer_last_location_; |
| 218 | 217 |
| 219 using Entry = std::pair<uint32_t, std::unique_ptr<Accelerator>>; | |
| 220 std::map<uint32_t, std::unique_ptr<Accelerator>> accelerators_; | 218 std::map<uint32_t, std::unique_ptr<Accelerator>> accelerators_; |
| 221 | 219 |
| 222 using PointerIdToTargetMap = std::map<int32_t, PointerTarget>; | 220 using PointerIdToTargetMap = std::map<int32_t, PointerTarget>; |
| 223 // |pointer_targets_| contains the active pointers. For a mouse based pointer | 221 // |pointer_targets_| contains the active pointers. For a mouse based pointer |
| 224 // a PointerTarget is always active (and present in |pointer_targets_|). For | 222 // a PointerTarget is always active (and present in |pointer_targets_|). For |
| 225 // touch based pointers the pointer is active while down and removed on | 223 // touch based pointers the pointer is active while down and removed on |
| 226 // cancel or up. | 224 // cancel or up. |
| 227 PointerIdToTargetMap pointer_targets_; | 225 PointerIdToTargetMap pointer_targets_; |
| 228 | 226 |
| 229 // Keeps track of number of observe requests for each observed window. | 227 // Keeps track of number of observe requests for each observed window. |
| 230 std::map<const ServerWindow*, uint8_t> observed_windows_; | 228 std::map<const ServerWindow*, uint8_t> observed_windows_; |
| 231 | 229 |
| 232 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | 230 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
| 233 }; | 231 }; |
| 234 | 232 |
| 235 } // namespace ws | 233 } // namespace ws |
| 236 } // namespace mus | 234 } // namespace mus |
| 237 | 235 |
| 238 #endif // COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ | 236 #endif // COMPONENTS_MUS_WS_EVENT_DISPATCHER_H_ |
| OLD | NEW |