Chromium Code Reviews| 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 SERVICES_UI_WS_EVENT_DISPATCHER_H_ | 5 #ifndef SERVICES_UI_WS_EVENT_DISPATCHER_H_ |
| 6 #define SERVICES_UI_WS_EVENT_DISPATCHER_H_ | 6 #define SERVICES_UI_WS_EVENT_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 return mouse_cursor_source_window_; | 115 return mouse_cursor_source_window_; |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Returns the window the mouse cursor is taken from. This does not take | 118 // Returns the window the mouse cursor is taken from. This does not take |
| 119 // into account drags. In other words if there is a drag on going the mouse | 119 // into account drags. In other words if there is a drag on going the mouse |
| 120 // comes comes from a different window. | 120 // comes comes from a different window. |
| 121 const ServerWindow* GetWindowForMouseCursor() const; | 121 const ServerWindow* GetWindowForMouseCursor() const; |
| 122 | 122 |
| 123 // If the mouse cursor is still over |mouse_cursor_source_window_|, updates | 123 // If the mouse cursor is still over |mouse_cursor_source_window_|, updates |
| 124 // whether we are in the non-client area. Used when | 124 // whether we are in the non-client area. Used when |
| 125 // |mouse_cursor_source_window_| has changed its properties. | 125 // |mouse_cursor_source_window_| has changed its properties. |callback| is |
| 126 void UpdateNonClientAreaForCurrentWindow(); | 126 // called after the update is finished. |
| 127 void UpdateNonClientAreaForCurrentWindow(const base::Closure& callback); | |
| 127 | 128 |
| 128 // Possibly updates the cursor. If we aren't in an implicit capture, we take | 129 // Possibly updates the cursor. If we aren't in an implicit capture, we take |
| 129 // the last known location of the mouse pointer, and look for the | 130 // the last known location of the mouse pointer, and look for the |
| 130 // ServerWindow* under it. | 131 // ServerWindow* under it. |callback| is called after the update is finished. |
| 131 void UpdateCursorProviderByLastKnownLocation(); | 132 void UpdateCursorProviderByLastKnownLocation(const base::Closure& callback); |
| 132 | 133 |
| 133 // Adds an accelerator with the given id and event-matcher. If an accelerator | 134 // Adds an accelerator with the given id and event-matcher. If an accelerator |
| 134 // already exists with the same id or the same matcher, then the accelerator | 135 // already exists with the same id or the same matcher, then the accelerator |
| 135 // is not added. Returns whether adding the accelerator was successful or not. | 136 // is not added. Returns whether adding the accelerator was successful or not. |
| 136 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); | 137 bool AddAccelerator(uint32_t id, mojom::EventMatcherPtr event_matcher); |
| 137 | 138 |
| 138 void RemoveAccelerator(uint32_t id); | 139 void RemoveAccelerator(uint32_t id); |
| 139 | 140 |
| 140 // Processes the supplied event, informing the delegate as approriate. This | 141 // Processes the supplied event, informing the delegate as approriate. This |
| 141 // may result in generating any number of events. If |match_phase| is | 142 // may result in generating any number of events. If |match_phase| is |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 161 ServerWindow* window; | 162 ServerWindow* window; |
| 162 | 163 |
| 163 bool is_mouse_event; | 164 bool is_mouse_event; |
| 164 | 165 |
| 165 // Did the pointer event start in the non-client area. | 166 // Did the pointer event start in the non-client area. |
| 166 bool in_nonclient_area; | 167 bool in_nonclient_area; |
| 167 | 168 |
| 168 bool is_pointer_down; | 169 bool is_pointer_down; |
| 169 }; | 170 }; |
| 170 | 171 |
| 172 using PointerTargetForEventCallback = base::OnceCallback<void(PointerTarget)>; | |
| 173 using HittestCallback = base::OnceCallback<void(DeepestWindow)>; | |
| 174 | |
| 175 struct HittestRequest { | |
| 176 HittestRequest(gfx::Point location, HittestCallback hittest_callback); | |
|
sky
2017/05/14 15:59:05
const gfx::Point&
riajiang
2017/05/15 18:34:41
Done.
| |
| 177 ~HittestRequest(); | |
| 178 | |
| 179 gfx::Point hittest_location; | |
| 180 HittestCallback hittest_callback; | |
| 181 }; | |
| 182 | |
| 171 void SetMouseCursorSourceWindow(ServerWindow* window); | 183 void SetMouseCursorSourceWindow(ServerWindow* window); |
| 172 | 184 |
| 173 void ProcessKeyEvent(const ui::KeyEvent& event, | 185 void ProcessKeyEvent(const ui::KeyEvent& event, |
| 174 AcceleratorMatchPhase match_phase); | 186 AcceleratorMatchPhase match_phase); |
| 175 | 187 |
| 176 bool IsTrackingPointer(int32_t pointer_id) const { | 188 bool IsTrackingPointer(int32_t pointer_id) const { |
| 177 return pointer_targets_.count(pointer_id) > 0; | 189 return pointer_targets_.count(pointer_id) > 0; |
| 178 } | 190 } |
| 179 | 191 |
| 180 // EventDispatcher provides the following logic for pointer events: | 192 // EventDispatcher provides the following logic for pointer events: |
| 181 // . wheel events go to the current target of the associated pointer. If | 193 // . wheel events go to the current target of the associated pointer. If |
| 182 // there is no target, they go to the deepest window. | 194 // there is no target, they go to the deepest window. |
| 183 // . move (not drag) events go to the deepest window. | 195 // . move (not drag) events go to the deepest window. |
| 184 // . when a pointer goes down all events until the corresponding up or | 196 // . when a pointer goes down all events until the corresponding up or |
| 185 // cancel go to the deepest target. For mouse events the up only occurs | 197 // cancel go to the deepest target. For mouse events the up only occurs |
| 186 // when no buttons on the mouse are down. | 198 // when no buttons on the mouse are down. |
| 187 // This also generates exit events as appropriate. For example, if the mouse | 199 // This also generates exit events as appropriate. For example, if the mouse |
| 188 // moves between one window to another an exit is generated on the first. | 200 // moves between one window to another an exit is generated on the first. |
| 189 void ProcessPointerEvent(const ui::PointerEvent& event); | 201 void ProcessPointerEvent(const ui::PointerEvent& event); |
| 202 void ProcessPointerEventOnFoundTarget(const ui::PointerEvent& event, | |
| 203 PointerTarget pointer_target_found); | |
| 190 | 204 |
| 191 // Adds |pointer_target| to |pointer_targets_|. | 205 // Adds |pointer_target| to |pointer_targets_|. |
| 192 void StartTrackingPointer(int32_t pointer_id, | 206 void StartTrackingPointer(int32_t pointer_id, |
| 193 const PointerTarget& pointer_target); | 207 const PointerTarget& pointer_target); |
| 194 | 208 |
| 195 // Removes a PointerTarget from |pointer_targets_|. | 209 // Removes a PointerTarget from |pointer_targets_|. |
| 196 void StopTrackingPointer(int32_t pointer_id); | 210 void StopTrackingPointer(int32_t pointer_id); |
| 197 | 211 |
| 198 // Starts tracking the pointer for |event|, or if already tracking the | 212 // Starts tracking the pointer for |event|, or if already tracking the |
| 199 // pointer sends the appropriate event to the delegate and updates the | 213 // pointer sends the appropriate event to the delegate and updates the |
| 200 // currently tracked PointerTarget appropriately. | 214 // currently tracked PointerTarget appropriately. |
| 201 void UpdateTargetForPointer(int32_t pointer_id, | 215 void UpdateTargetForPointer(int32_t pointer_id, |
| 202 const ui::LocatedEvent& event); | 216 const ui::PointerEvent& event, |
| 217 const PointerTarget& pointer_target_found); | |
| 203 | 218 |
| 204 // Returns a PointerTarget for the supplied event. If there is no valid | 219 // |callback| is called with a PointerTarget for the supplied event. If there |
| 205 // event target for the specified location |window| in the returned value is | 220 // is no valid event target for the specified location |window| in the |
| 206 // null. | 221 // returned value is null. |
| 207 PointerTarget PointerTargetForEvent(const ui::LocatedEvent& event); | 222 void PointerTargetForEvent(const ui::PointerEvent& event, |
| 223 PointerTargetForEventCallback callback); | |
| 224 void PointerTargetForEventOnFoundWindow( | |
| 225 const ui::PointerEvent& event, | |
| 226 PointerTargetForEventCallback callback, | |
| 227 DeepestWindow deepest_window); | |
| 208 | 228 |
| 209 // Returns true if any pointers are in the pressed/down state. | 229 // Returns true if any pointers are in the pressed/down state. |
| 210 bool AreAnyPointersDown() const; | 230 bool AreAnyPointersDown() const; |
| 211 | 231 |
| 212 // If |target->window| is valid, then passes the event to the delegate. | 232 // If |target->window| is valid, then passes the event to the delegate. |
| 213 void DispatchToPointerTarget(const PointerTarget& target, | 233 void DispatchToPointerTarget(const PointerTarget& target, |
| 214 const ui::LocatedEvent& event); | 234 const ui::LocatedEvent& event); |
| 215 | 235 |
| 216 // Dispatch |event| to the delegate. | 236 // Dispatch |event| to the delegate. |
| 217 void DispatchToClient(ServerWindow* window, | 237 void DispatchToClient(ServerWindow* window, |
| 218 ClientSpecificId client_id, | 238 ClientSpecificId client_id, |
| 219 const ui::LocatedEvent& event); | 239 const ui::LocatedEvent& event); |
| 220 | 240 |
| 221 // Stops sending pointer events to |window|. This does not remove the entry | 241 // Stops sending pointer events to |window|. This does not remove the entry |
| 222 // for |window| from |pointer_targets_|, rather it nulls out the window. This | 242 // for |window| from |pointer_targets_|, rather it nulls out the window. This |
| 223 // way we continue to eat events until the up/cancel is received. | 243 // way we continue to eat events until the up/cancel is received. |
| 224 void CancelPointerEventsToTarget(ServerWindow* window); | 244 void CancelPointerEventsToTarget(ServerWindow* window); |
| 225 | 245 |
| 226 // Used to observe a window. Can be called multiple times on a window. To | 246 // Used to observe a window. Can be called multiple times on a window. To |
| 227 // unobserve a window, UnobserveWindow() should be called the same number of | 247 // unobserve a window, UnobserveWindow() should be called the same number of |
| 228 // times. | 248 // times. |
| 229 void ObserveWindow(ServerWindow* winodw); | 249 void ObserveWindow(ServerWindow* winodw); |
| 230 void UnobserveWindow(ServerWindow* winodw); | 250 void UnobserveWindow(ServerWindow* winodw); |
| 231 | 251 |
| 232 // Returns an Accelerator bound to the specified code/flags, and of the | 252 // Returns an Accelerator bound to the specified code/flags, and of the |
| 233 // matching |phase|. Otherwise returns null. | 253 // matching |phase|. Otherwise returns null. |
| 234 Accelerator* FindAccelerator(const ui::KeyEvent& event, | 254 Accelerator* FindAccelerator(const ui::KeyEvent& event, |
| 235 const ui::mojom::AcceleratorPhase phase); | 255 const ui::mojom::AcceleratorPhase phase); |
| 236 | 256 |
| 237 DeepestWindow FindDeepestVisibleWindowForEvents(const gfx::Point& location); | 257 // Call WindowFinder to find the deepest visible window for |location|. |
| 258 // |callback| is called with the window found. | |
| 259 void FindDeepestVisibleWindowForEvents(const gfx::Point& location, | |
| 260 HittestCallback callback); | |
| 261 void FindDeepestVisibleWindowForEventsImpl(const gfx::Point& location, | |
| 262 HittestCallback callback); | |
| 263 void FindDeepestVisibleWindowForEventsAsync(const gfx::Point& location, | |
| 264 HittestCallback callback); | |
| 265 | |
| 266 void UpdateNonClientAreaForCurrentWindowOnFoundWindow( | |
| 267 const base::Closure& callback, | |
| 268 DeepestWindow deepest_window); | |
| 269 void UpdateCursorProviderByLastKnownLocationOnFoundWindow( | |
| 270 const base::Closure& callback, | |
| 271 DeepestWindow deepest_window); | |
| 272 | |
| 273 void ProcessNextHittesetRequestFromQueue(); | |
| 238 | 274 |
| 239 // Clears the implicit captures in |pointer_targets_|, with the exception of | 275 // Clears the implicit captures in |pointer_targets_|, with the exception of |
| 240 // |window|. |window| may be null. |client_id| is the target client of | 276 // |window|. |window| may be null. |client_id| is the target client of |
| 241 // |window|. | 277 // |window|. |
| 242 void CancelImplicitCaptureExcept(ServerWindow* window, | 278 void CancelImplicitCaptureExcept(ServerWindow* window, |
| 243 ClientSpecificId client_id); | 279 ClientSpecificId client_id); |
| 244 | 280 |
| 245 // ServerWindowObserver: | 281 // ServerWindowObserver: |
| 246 void OnWillChangeWindowHierarchy(ServerWindow* window, | 282 void OnWillChangeWindowHierarchy(ServerWindow* window, |
| 247 ServerWindow* new_parent, | 283 ServerWindow* new_parent, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 264 bool mouse_button_down_; | 300 bool mouse_button_down_; |
| 265 ServerWindow* mouse_cursor_source_window_; | 301 ServerWindow* mouse_cursor_source_window_; |
| 266 bool mouse_cursor_in_non_client_area_; | 302 bool mouse_cursor_in_non_client_area_; |
| 267 | 303 |
| 268 // The on screen location of the mouse pointer. This can be outside the | 304 // The on screen location of the mouse pointer. This can be outside the |
| 269 // bounds of |mouse_cursor_source_window_|, which can capture the cursor. | 305 // bounds of |mouse_cursor_source_window_|, which can capture the cursor. |
| 270 gfx::Point mouse_pointer_last_location_; | 306 gfx::Point mouse_pointer_last_location_; |
| 271 | 307 |
| 272 std::map<uint32_t, std::unique_ptr<Accelerator>> accelerators_; | 308 std::map<uint32_t, std::unique_ptr<Accelerator>> accelerators_; |
| 273 | 309 |
| 310 // True if we are waiting for the result of a hit-test. False otherwise. | |
| 311 bool hittest_in_flight_; | |
| 312 std::queue<std::unique_ptr<HittestRequest>> hittest_request_queue_; | |
| 313 | |
| 274 using PointerIdToTargetMap = std::map<int32_t, PointerTarget>; | 314 using PointerIdToTargetMap = std::map<int32_t, PointerTarget>; |
| 275 // |pointer_targets_| contains the active pointers. For a mouse based pointer | 315 // |pointer_targets_| contains the active pointers. For a mouse based pointer |
| 276 // a PointerTarget is always active (and present in |pointer_targets_|). For | 316 // a PointerTarget is always active (and present in |pointer_targets_|). For |
| 277 // touch based pointers the pointer is active while down and removed on | 317 // touch based pointers the pointer is active while down and removed on |
| 278 // cancel or up. | 318 // cancel or up. |
| 279 PointerIdToTargetMap pointer_targets_; | 319 PointerIdToTargetMap pointer_targets_; |
| 280 | 320 |
| 281 // Keeps track of number of observe requests for each observed window. | 321 // Keeps track of number of observe requests for each observed window. |
| 282 std::map<const ServerWindow*, uint8_t> observed_windows_; | 322 std::map<const ServerWindow*, uint8_t> observed_windows_; |
| 283 | 323 |
| 284 #if !defined(NDEBUG) | 324 #if !defined(NDEBUG) |
| 285 std::unique_ptr<ui::Event> previous_event_; | 325 std::unique_ptr<ui::Event> previous_event_; |
| 286 AcceleratorMatchPhase previous_accelerator_match_phase_ = | 326 AcceleratorMatchPhase previous_accelerator_match_phase_ = |
| 287 AcceleratorMatchPhase::ANY; | 327 AcceleratorMatchPhase::ANY; |
| 288 #endif | 328 #endif |
| 289 | 329 |
| 290 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); | 330 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
| 291 }; | 331 }; |
| 292 | 332 |
| 293 } // namespace ws | 333 } // namespace ws |
| 294 } // namespace ui | 334 } // namespace ui |
| 295 | 335 |
| 296 #endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_ | 336 #endif // SERVICES_UI_WS_EVENT_DISPATCHER_H_ |
| OLD | NEW |