Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: ui/aura/window_event_dispatcher.cc

Issue 754013007: Fix the wrong relative coordinates from EventDispatch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 return; 142 return;
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(Window* window,
153 const gfx::Point& point) { 153 const gfx::Point& point) {
154 ui::MouseEvent event(ui::ET_MOUSE_EXITED, point, point, ui::EF_NONE, 154 ui::MouseEvent event(ui::ET_MOUSE_EXITED, point, point, ui::EF_NONE,
155 ui::EF_NONE); 155 ui::EF_NONE);
156 return DispatchMouseEnterOrExit(event, ui::ET_MOUSE_EXITED); 156 return DispatchMouseEnterOrExit(window, event, ui::ET_MOUSE_EXITED);
157 } 157 }
158 158
159 void WindowEventDispatcher::ProcessedTouchEvent(ui::TouchEvent* event, 159 void WindowEventDispatcher::ProcessedTouchEvent(ui::TouchEvent* event,
160 Window* window, 160 Window* window,
161 ui::EventResult result) { 161 ui::EventResult result) {
162 // Once we've fully migrated to the eager gesture detector, we won't need to 162 // Once we've fully migrated to the eager gesture detector, we won't need to
163 // pass an event here. 163 // pass an event here.
164 scoped_ptr<ui::GestureRecognizer::Gestures> gestures( 164 scoped_ptr<ui::GestureRecognizer::Gestures> gestures(
165 ui::GestureRecognizer::Get()->AckAsyncTouchEvent( 165 ui::GestureRecognizer::Get()->AckAsyncTouchEvent(
166 *event, result, window)); 166 *event, result, window));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 235
236 void WindowEventDispatcher::DispatchMouseExitToHidingWindow(Window* window) { 236 void WindowEventDispatcher::DispatchMouseExitToHidingWindow(Window* window) {
237 // The mouse capture is intentionally ignored. Think that a mouse enters 237 // 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, 238 // 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 239 // 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 240 // be called. So it is natural not to emit OnMouseExited even though
241 // |window| is the capture window. 241 // |window| is the capture window.
242 gfx::Point last_mouse_location = GetLastMouseLocationInRoot(); 242 gfx::Point last_mouse_location = GetLastMouseLocationInRoot();
243 if (window->Contains(mouse_moved_handler_) && 243 if (window->Contains(mouse_moved_handler_) &&
244 window->ContainsPointInRoot(last_mouse_location)) { 244 window->ContainsPointInRoot(last_mouse_location)) {
245 DispatchDetails details = DispatchMouseExitAtPoint(last_mouse_location); 245 DispatchDetails details = DispatchMouseExitAtPoint(window,
246 last_mouse_location);
246 if (details.dispatcher_destroyed) 247 if (details.dispatcher_destroyed)
247 return; 248 return;
248 } 249 }
249 } 250 }
250 251
251 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( 252 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit(
253 Window* target,
252 const ui::MouseEvent& event, 254 const ui::MouseEvent& event,
253 ui::EventType type) { 255 ui::EventType type) {
254 if (event.type() != ui::ET_MOUSE_CAPTURE_CHANGED && 256 if (event.type() != ui::ET_MOUSE_CAPTURE_CHANGED &&
255 !(event.flags() & ui::EF_IS_SYNTHESIZED)) { 257 !(event.flags() & ui::EF_IS_SYNTHESIZED)) {
256 SetLastMouseLocation(window(), event.root_location()); 258 SetLastMouseLocation(window(), event.root_location());
257 } 259 }
258 260
259 if (!mouse_moved_handler_ || !mouse_moved_handler_->delegate() || 261 if (!mouse_moved_handler_ || !mouse_moved_handler_->delegate() ||
260 !window()->Contains(mouse_moved_handler_)) 262 !window()->Contains(mouse_moved_handler_))
261 return DispatchDetails(); 263 return DispatchDetails();
262 264
263 // |event| may be an event in the process of being dispatched to a target (in 265 // |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 266 // 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 267 // 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 268 // event's target will be NULL, and the event will be in the root-window's
267 // coordinate system. 269 // coordinate system.
268 aura::Window* target = static_cast<Window*>(event.target()); 270 if (event.target())
sky 2014/12/18 20:29:29 Why do we need both the supplied target and event.
Miyoung Shin 2014/12/19 14:39:42 You're right. I think I can use only target to con
sky 2015/01/05 17:23:02 You didn't quite end up with what I was suggesting
Miyoung Shin 2015/01/06 13:20:44 Sorry, I don't understand your point yet and why y
271 target = static_cast<Window*>(event.target());
269 if (!target) 272 if (!target)
270 target = window(); 273 target = window();
271 ui::MouseEvent translated_event(event, 274 ui::MouseEvent translated_event(event,
272 target, 275 target,
273 mouse_moved_handler_, 276 mouse_moved_handler_,
274 type, 277 type,
275 event.flags() | ui::EF_IS_SYNTHESIZED); 278 event.flags() | ui::EF_IS_SYNTHESIZED);
276 return DispatchEvent(mouse_moved_handler_, &translated_event); 279 return DispatchEvent(mouse_moved_handler_, &translated_event);
277 } 280 }
278 281
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 // OS to send us the mouse exit events (WM_MOUSELEAVE). Additionally on 400 // OS to send us the mouse exit events (WM_MOUSELEAVE). Additionally on
398 // desktop Windows, every top level window could potentially have its own 401 // desktop Windows, every top level window could potentially have its own
399 // root window, in which case this function will get called whenever those 402 // root window, in which case this function will get called whenever those
400 // windows grab mouse capture. Sending mouse exit messages in these cases 403 // windows grab mouse capture. Sending mouse exit messages in these cases
401 // causes subtle bugs like (crbug.com/394672). 404 // causes subtle bugs like (crbug.com/394672).
402 #if !defined(OS_WIN) 405 #if !defined(OS_WIN)
403 if (mouse_moved_handler_) { 406 if (mouse_moved_handler_) {
404 // Dispatch a mouse exit to reset any state associated with hover. This is 407 // 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 408 // 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. 409 // capture because we do not dispatch ET_MOUSE_CAPTURE_CHANGED in this case.
407 DispatchDetails details = DispatchMouseExitAtPoint( 410 DispatchDetails details = DispatchMouseExitAtPoint(NULL,
sky 2014/12/18 20:29:29 nullptr
Miyoung Shin 2014/12/19 14:39:42 ok
408 GetLastMouseLocationInRoot()); 411 GetLastMouseLocationInRoot());
409 if (details.dispatcher_destroyed) 412 if (details.dispatcher_destroyed)
410 return; 413 return;
411 } 414 }
412 #endif 415 #endif
413 416
414 mouse_moved_handler_ = NULL; 417 mouse_moved_handler_ = NULL;
415 mouse_pressed_handler_ = NULL; 418 mouse_pressed_handler_ = NULL;
416 } 419 }
417 420
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 } 781 }
779 } 782 }
780 783
781 const int kMouseButtonFlagMask = ui::EF_LEFT_MOUSE_BUTTON | 784 const int kMouseButtonFlagMask = ui::EF_LEFT_MOUSE_BUTTON |
782 ui::EF_MIDDLE_MOUSE_BUTTON | 785 ui::EF_MIDDLE_MOUSE_BUTTON |
783 ui::EF_RIGHT_MOUSE_BUTTON; 786 ui::EF_RIGHT_MOUSE_BUTTON;
784 switch (event->type()) { 787 switch (event->type()) {
785 case ui::ET_MOUSE_EXITED: 788 case ui::ET_MOUSE_EXITED:
786 if (!target || target == window()) { 789 if (!target || target == window()) {
787 DispatchDetails details = 790 DispatchDetails details =
788 DispatchMouseEnterOrExit(*event, ui::ET_MOUSE_EXITED); 791 DispatchMouseEnterOrExit(target, *event, ui::ET_MOUSE_EXITED);
789 if (details.dispatcher_destroyed) { 792 if (details.dispatcher_destroyed) {
790 event->SetHandled(); 793 event->SetHandled();
791 return; 794 return;
792 } 795 }
793 mouse_moved_handler_ = NULL; 796 mouse_moved_handler_ = NULL;
794 } 797 }
795 break; 798 break;
796 case ui::ET_MOUSE_MOVED: 799 case ui::ET_MOUSE_MOVED:
797 // Send an exit to the current |mouse_moved_handler_| and an enter to 800 // 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 801 // |target|. Take care that both us and |target| aren't destroyed during
799 // dispatch. 802 // dispatch.
800 if (target != mouse_moved_handler_) { 803 if (target != mouse_moved_handler_) {
801 aura::Window* old_mouse_moved_handler = mouse_moved_handler_; 804 aura::Window* old_mouse_moved_handler = mouse_moved_handler_;
802 WindowTracker live_window; 805 WindowTracker live_window;
803 live_window.Add(target); 806 live_window.Add(target);
804 DispatchDetails details = 807 DispatchDetails details =
805 DispatchMouseEnterOrExit(*event, ui::ET_MOUSE_EXITED); 808 DispatchMouseEnterOrExit(target, *event, ui::ET_MOUSE_EXITED);
806 if (details.dispatcher_destroyed) { 809 if (details.dispatcher_destroyed) {
807 event->SetHandled(); 810 event->SetHandled();
808 return; 811 return;
809 } 812 }
810 // If the |mouse_moved_handler_| changes out from under us, assume a 813 // 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. 814 // nested message loop ran and we don't need to do anything.
812 if (mouse_moved_handler_ != old_mouse_moved_handler) { 815 if (mouse_moved_handler_ != old_mouse_moved_handler) {
813 event->SetHandled(); 816 event->SetHandled();
814 return; 817 return;
815 } 818 }
816 if (!live_window.Contains(target) || details.target_destroyed) { 819 if (!live_window.Contains(target) || details.target_destroyed) {
817 mouse_moved_handler_ = NULL; 820 mouse_moved_handler_ = NULL;
818 event->SetHandled(); 821 event->SetHandled();
819 return; 822 return;
820 } 823 }
821 live_window.Remove(target); 824 live_window.Remove(target);
822 825
823 mouse_moved_handler_ = target; 826 mouse_moved_handler_ = target;
824 details = DispatchMouseEnterOrExit(*event, ui::ET_MOUSE_ENTERED); 827 details = DispatchMouseEnterOrExit(target, *event,
828 ui::ET_MOUSE_ENTERED);
825 if (details.dispatcher_destroyed || details.target_destroyed) { 829 if (details.dispatcher_destroyed || details.target_destroyed) {
826 event->SetHandled(); 830 event->SetHandled();
827 return; 831 return;
828 } 832 }
829 } 833 }
830 break; 834 break;
831 case ui::ET_MOUSE_PRESSED: 835 case ui::ET_MOUSE_PRESSED:
832 // Don't set the mouse pressed handler for non client mouse down events. 836 // 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 837 // 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 838 // client mouse up events which causes subsequent mouse events to be
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 // The event is invalid - ignore it. 892 // The event is invalid - ignore it.
889 event->StopPropagation(); 893 event->StopPropagation();
890 event->DisableSynchronousHandling(); 894 event->DisableSynchronousHandling();
891 return; 895 return;
892 } 896 }
893 897
894 PreDispatchLocatedEvent(target, event); 898 PreDispatchLocatedEvent(target, event);
895 } 899 }
896 900
897 } // namespace aura 901 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698