OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "ui/aura/window_event_dispatcher.h" | 5 #include "ui/aura/window_event_dispatcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 Window* target = GetGestureTarget(event); | 143 Window* target = GetGestureTarget(event); |
144 if (target) { | 144 if (target) { |
145 event->ConvertLocationToTarget(window(), target); | 145 event->ConvertLocationToTarget(window(), target); |
146 DispatchDetails details = DispatchEvent(target, event); | 146 DispatchDetails details = DispatchEvent(target, event); |
147 if (details.dispatcher_destroyed) | 147 if (details.dispatcher_destroyed) |
148 return; | 148 return; |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 DispatchDetails WindowEventDispatcher::DispatchMouseExitAtPoint( | 152 DispatchDetails WindowEventDispatcher::DispatchMouseExitAtPoint( |
| 153 Window* window, |
153 const gfx::Point& point) { | 154 const gfx::Point& point) { |
154 ui::MouseEvent event(ui::ET_MOUSE_EXITED, point, point, ui::EF_NONE, | 155 ui::MouseEvent event(ui::ET_MOUSE_EXITED, point, point, ui::EF_NONE, |
155 ui::EF_NONE); | 156 ui::EF_NONE); |
156 return DispatchMouseEnterOrExit(event, ui::ET_MOUSE_EXITED); | 157 return DispatchMouseEnterOrExit(window, event, ui::ET_MOUSE_EXITED); |
157 } | 158 } |
158 | 159 |
159 void WindowEventDispatcher::ProcessedTouchEvent(ui::TouchEvent* event, | 160 void WindowEventDispatcher::ProcessedTouchEvent(ui::TouchEvent* event, |
160 Window* window, | 161 Window* window, |
161 ui::EventResult result) { | 162 ui::EventResult result) { |
162 // Once we've fully migrated to the eager gesture detector, we won't need to | 163 // Once we've fully migrated to the eager gesture detector, we won't need to |
163 // pass an event here. | 164 // pass an event here. |
164 scoped_ptr<ui::GestureRecognizer::Gestures> gestures( | 165 scoped_ptr<ui::GestureRecognizer::Gestures> gestures( |
165 ui::GestureRecognizer::Get()->AckAsyncTouchEvent( | 166 ui::GestureRecognizer::Get()->AckAsyncTouchEvent( |
166 *event, result, window)); | 167 *event, result, window)); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 236 |
236 void WindowEventDispatcher::DispatchMouseExitToHidingWindow(Window* window) { | 237 void WindowEventDispatcher::DispatchMouseExitToHidingWindow(Window* window) { |
237 // The mouse capture is intentionally ignored. Think that a mouse enters | 238 // The mouse capture is intentionally ignored. Think that a mouse enters |
238 // to a window, the window sets the capture, the mouse exits the window, | 239 // to a window, the window sets the capture, the mouse exits the window, |
239 // and then it releases the capture. In that case OnMouseExited won't | 240 // and then it releases the capture. In that case OnMouseExited won't |
240 // be called. So it is natural not to emit OnMouseExited even though | 241 // be called. So it is natural not to emit OnMouseExited even though |
241 // |window| is the capture window. | 242 // |window| is the capture window. |
242 gfx::Point last_mouse_location = GetLastMouseLocationInRoot(); | 243 gfx::Point last_mouse_location = GetLastMouseLocationInRoot(); |
243 if (window->Contains(mouse_moved_handler_) && | 244 if (window->Contains(mouse_moved_handler_) && |
244 window->ContainsPointInRoot(last_mouse_location)) { | 245 window->ContainsPointInRoot(last_mouse_location)) { |
245 DispatchDetails details = DispatchMouseExitAtPoint(last_mouse_location); | 246 DispatchDetails details = |
| 247 DispatchMouseExitAtPoint(window, last_mouse_location); |
246 if (details.dispatcher_destroyed) | 248 if (details.dispatcher_destroyed) |
247 return; | 249 return; |
248 } | 250 } |
249 } | 251 } |
250 | 252 |
251 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( | 253 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( |
| 254 Window* target, |
252 const ui::MouseEvent& event, | 255 const ui::MouseEvent& event, |
253 ui::EventType type) { | 256 ui::EventType type) { |
254 if (event.type() != ui::ET_MOUSE_CAPTURE_CHANGED && | 257 if (event.type() != ui::ET_MOUSE_CAPTURE_CHANGED && |
255 !(event.flags() & ui::EF_IS_SYNTHESIZED)) { | 258 !(event.flags() & ui::EF_IS_SYNTHESIZED)) { |
256 SetLastMouseLocation(window(), event.root_location()); | 259 SetLastMouseLocation(window(), event.root_location()); |
257 } | 260 } |
258 | 261 |
259 if (!mouse_moved_handler_ || !mouse_moved_handler_->delegate() || | 262 if (!mouse_moved_handler_ || !mouse_moved_handler_->delegate() || |
260 !window()->Contains(mouse_moved_handler_)) | 263 !window()->Contains(mouse_moved_handler_)) |
261 return DispatchDetails(); | 264 return DispatchDetails(); |
262 | 265 |
263 // |event| may be an event in the process of being dispatched to a target (in | 266 // |event| may be an event in the process of being dispatched to a target (in |
264 // which case its locations will be in the event's target's coordinate | 267 // which case its locations will be in the event's target's coordinate |
265 // system), or a synthetic event created in root-window (in which case, the | 268 // system), or a synthetic event created in root-window (in which case, the |
266 // event's target will be NULL, and the event will be in the root-window's | 269 // event's target will be NULL, and the event will be in the root-window's |
267 // coordinate system. | 270 // coordinate system. |
268 aura::Window* target = static_cast<Window*>(event.target()); | |
269 if (!target) | 271 if (!target) |
270 target = window(); | 272 target = window(); |
271 ui::MouseEvent translated_event(event, | 273 ui::MouseEvent translated_event(event, |
272 target, | 274 target, |
273 mouse_moved_handler_, | 275 mouse_moved_handler_, |
274 type, | 276 type, |
275 event.flags() | ui::EF_IS_SYNTHESIZED); | 277 event.flags() | ui::EF_IS_SYNTHESIZED); |
276 return DispatchEvent(mouse_moved_handler_, &translated_event); | 278 return DispatchEvent(mouse_moved_handler_, &translated_event); |
277 } | 279 } |
278 | 280 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 // OS to send us the mouse exit events (WM_MOUSELEAVE). Additionally on | 399 // OS to send us the mouse exit events (WM_MOUSELEAVE). Additionally on |
398 // desktop Windows, every top level window could potentially have its own | 400 // desktop Windows, every top level window could potentially have its own |
399 // root window, in which case this function will get called whenever those | 401 // root window, in which case this function will get called whenever those |
400 // windows grab mouse capture. Sending mouse exit messages in these cases | 402 // windows grab mouse capture. Sending mouse exit messages in these cases |
401 // causes subtle bugs like (crbug.com/394672). | 403 // causes subtle bugs like (crbug.com/394672). |
402 #if !defined(OS_WIN) | 404 #if !defined(OS_WIN) |
403 if (mouse_moved_handler_) { | 405 if (mouse_moved_handler_) { |
404 // Dispatch a mouse exit to reset any state associated with hover. This is | 406 // Dispatch a mouse exit to reset any state associated with hover. This is |
405 // important when going from no window having capture to a window having | 407 // important when going from no window having capture to a window having |
406 // capture because we do not dispatch ET_MOUSE_CAPTURE_CHANGED in this case. | 408 // capture because we do not dispatch ET_MOUSE_CAPTURE_CHANGED in this case. |
407 DispatchDetails details = DispatchMouseExitAtPoint( | 409 DispatchDetails details = |
408 GetLastMouseLocationInRoot()); | 410 DispatchMouseExitAtPoint(nullptr, GetLastMouseLocationInRoot()); |
409 if (details.dispatcher_destroyed) | 411 if (details.dispatcher_destroyed) |
410 return; | 412 return; |
411 } | 413 } |
412 #endif | 414 #endif |
413 | 415 |
414 mouse_moved_handler_ = NULL; | 416 mouse_moved_handler_ = NULL; |
415 mouse_pressed_handler_ = NULL; | 417 mouse_pressed_handler_ = NULL; |
416 } | 418 } |
417 | 419 |
418 void WindowEventDispatcher::SetNativeCapture() { | 420 void WindowEventDispatcher::SetNativeCapture() { |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 } | 780 } |
779 } | 781 } |
780 | 782 |
781 const int kMouseButtonFlagMask = ui::EF_LEFT_MOUSE_BUTTON | | 783 const int kMouseButtonFlagMask = ui::EF_LEFT_MOUSE_BUTTON | |
782 ui::EF_MIDDLE_MOUSE_BUTTON | | 784 ui::EF_MIDDLE_MOUSE_BUTTON | |
783 ui::EF_RIGHT_MOUSE_BUTTON; | 785 ui::EF_RIGHT_MOUSE_BUTTON; |
784 switch (event->type()) { | 786 switch (event->type()) { |
785 case ui::ET_MOUSE_EXITED: | 787 case ui::ET_MOUSE_EXITED: |
786 if (!target || target == window()) { | 788 if (!target || target == window()) { |
787 DispatchDetails details = | 789 DispatchDetails details = |
788 DispatchMouseEnterOrExit(*event, ui::ET_MOUSE_EXITED); | 790 DispatchMouseEnterOrExit(target, *event, ui::ET_MOUSE_EXITED); |
789 if (details.dispatcher_destroyed) { | 791 if (details.dispatcher_destroyed) { |
790 event->SetHandled(); | 792 event->SetHandled(); |
791 return; | 793 return; |
792 } | 794 } |
793 mouse_moved_handler_ = NULL; | 795 mouse_moved_handler_ = NULL; |
794 } | 796 } |
795 break; | 797 break; |
796 case ui::ET_MOUSE_MOVED: | 798 case ui::ET_MOUSE_MOVED: |
797 // Send an exit to the current |mouse_moved_handler_| and an enter to | 799 // Send an exit to the current |mouse_moved_handler_| and an enter to |
798 // |target|. Take care that both us and |target| aren't destroyed during | 800 // |target|. Take care that both us and |target| aren't destroyed during |
799 // dispatch. | 801 // dispatch. |
800 if (target != mouse_moved_handler_) { | 802 if (target != mouse_moved_handler_) { |
801 aura::Window* old_mouse_moved_handler = mouse_moved_handler_; | 803 aura::Window* old_mouse_moved_handler = mouse_moved_handler_; |
802 WindowTracker live_window; | 804 WindowTracker live_window; |
803 live_window.Add(target); | 805 live_window.Add(target); |
804 DispatchDetails details = | 806 DispatchDetails details = |
805 DispatchMouseEnterOrExit(*event, ui::ET_MOUSE_EXITED); | 807 DispatchMouseEnterOrExit(target, *event, ui::ET_MOUSE_EXITED); |
806 if (details.dispatcher_destroyed) { | 808 if (details.dispatcher_destroyed) { |
807 event->SetHandled(); | 809 event->SetHandled(); |
808 return; | 810 return; |
809 } | 811 } |
810 // If the |mouse_moved_handler_| changes out from under us, assume a | 812 // If the |mouse_moved_handler_| changes out from under us, assume a |
811 // nested message loop ran and we don't need to do anything. | 813 // nested message loop ran and we don't need to do anything. |
812 if (mouse_moved_handler_ != old_mouse_moved_handler) { | 814 if (mouse_moved_handler_ != old_mouse_moved_handler) { |
813 event->SetHandled(); | 815 event->SetHandled(); |
814 return; | 816 return; |
815 } | 817 } |
816 if (!live_window.Contains(target) || details.target_destroyed) { | 818 if (!live_window.Contains(target) || details.target_destroyed) { |
817 mouse_moved_handler_ = NULL; | 819 mouse_moved_handler_ = NULL; |
818 event->SetHandled(); | 820 event->SetHandled(); |
819 return; | 821 return; |
820 } | 822 } |
821 live_window.Remove(target); | 823 live_window.Remove(target); |
822 | 824 |
823 mouse_moved_handler_ = target; | 825 mouse_moved_handler_ = target; |
824 details = DispatchMouseEnterOrExit(*event, ui::ET_MOUSE_ENTERED); | 826 details = |
| 827 DispatchMouseEnterOrExit(target, *event, ui::ET_MOUSE_ENTERED); |
825 if (details.dispatcher_destroyed || details.target_destroyed) { | 828 if (details.dispatcher_destroyed || details.target_destroyed) { |
826 event->SetHandled(); | 829 event->SetHandled(); |
827 return; | 830 return; |
828 } | 831 } |
829 } | 832 } |
830 break; | 833 break; |
831 case ui::ET_MOUSE_PRESSED: | 834 case ui::ET_MOUSE_PRESSED: |
832 // Don't set the mouse pressed handler for non client mouse down events. | 835 // Don't set the mouse pressed handler for non client mouse down events. |
833 // These are only sent by Windows and are not always followed with non | 836 // These are only sent by Windows and are not always followed with non |
834 // client mouse up events which causes subsequent mouse events to be | 837 // client mouse up events which causes subsequent mouse events to be |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 } | 895 } |
893 | 896 |
894 // This flag is set depending on the gestures recognized in the call above, | 897 // This flag is set depending on the gestures recognized in the call above, |
895 // and needs to propagate with the forwarded event. | 898 // and needs to propagate with the forwarded event. |
896 event->set_may_cause_scrolling(orig_event.may_cause_scrolling()); | 899 event->set_may_cause_scrolling(orig_event.may_cause_scrolling()); |
897 | 900 |
898 PreDispatchLocatedEvent(target, event); | 901 PreDispatchLocatedEvent(target, event); |
899 } | 902 } |
900 | 903 |
901 } // namespace aura | 904 } // namespace aura |
OLD | NEW |