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

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

Issue 344793013: Dispatch a synthetic mouse exit to the widget handling mouse events when a widget grabs capture (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « ui/aura/window_event_dispatcher.h ('k') | ui/views/widget/widget_interactive_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 143
144 Window* target = GetGestureTarget(event); 144 Window* target = GetGestureTarget(event);
145 if (target) { 145 if (target) {
146 event->ConvertLocationToTarget(window(), target); 146 event->ConvertLocationToTarget(window(), target);
147 DispatchDetails details = DispatchEvent(target, event); 147 DispatchDetails details = DispatchEvent(target, event);
148 if (details.dispatcher_destroyed) 148 if (details.dispatcher_destroyed)
149 return; 149 return;
150 } 150 }
151 } 151 }
152 152
153 void WindowEventDispatcher::DispatchMouseExitAtPoint(const gfx::Point& point) { 153 DispatchDetails WindowEventDispatcher::DispatchMouseExitAtPoint(
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 DispatchDetails details = 157 return DispatchMouseEnterOrExit(event, ui::ET_MOUSE_EXITED);
157 DispatchMouseEnterOrExit(event, ui::ET_MOUSE_EXITED);
158 if (details.dispatcher_destroyed)
159 return;
160 } 158 }
161 159
162 void WindowEventDispatcher::ProcessedTouchEvent(ui::TouchEvent* event, 160 void WindowEventDispatcher::ProcessedTouchEvent(ui::TouchEvent* event,
163 Window* window, 161 Window* window,
164 ui::EventResult result) { 162 ui::EventResult result) {
165 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; 163 scoped_ptr<ui::GestureRecognizer::Gestures> gestures;
166 gestures.reset(ui::GestureRecognizer::Get()-> 164 gestures.reset(ui::GestureRecognizer::Get()->
167 ProcessTouchEventForGesture(*event, result, window)); 165 ProcessTouchEventForGesture(*event, result, window));
168 DispatchDetails details = ProcessGestures(gestures.get()); 166 DispatchDetails details = ProcessGestures(gestures.get());
169 if (details.dispatcher_destroyed) 167 if (details.dispatcher_destroyed)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 233 }
236 234
237 void WindowEventDispatcher::DispatchMouseExitToHidingWindow(Window* window) { 235 void WindowEventDispatcher::DispatchMouseExitToHidingWindow(Window* window) {
238 // The mouse capture is intentionally ignored. Think that a mouse enters 236 // The mouse capture is intentionally ignored. Think that a mouse enters
239 // to a window, the window sets the capture, the mouse exits the window, 237 // to a window, the window sets the capture, the mouse exits the window,
240 // and then it releases the capture. In that case OnMouseExited won't 238 // and then it releases the capture. In that case OnMouseExited won't
241 // be called. So it is natural not to emit OnMouseExited even though 239 // be called. So it is natural not to emit OnMouseExited even though
242 // |window| is the capture window. 240 // |window| is the capture window.
243 gfx::Point last_mouse_location = GetLastMouseLocationInRoot(); 241 gfx::Point last_mouse_location = GetLastMouseLocationInRoot();
244 if (window->Contains(mouse_moved_handler_) && 242 if (window->Contains(mouse_moved_handler_) &&
245 window->ContainsPointInRoot(last_mouse_location)) 243 window->ContainsPointInRoot(last_mouse_location)) {
246 DispatchMouseExitAtPoint(last_mouse_location); 244 DispatchDetails details = DispatchMouseExitAtPoint(last_mouse_location);
245 if (details.dispatcher_destroyed)
246 return;
247 }
247 } 248 }
248 249
249 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( 250 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit(
250 const ui::MouseEvent& event, 251 const ui::MouseEvent& event,
251 ui::EventType type) { 252 ui::EventType type) {
252 if (event.type() != ui::ET_MOUSE_CAPTURE_CHANGED && 253 if (event.type() != ui::ET_MOUSE_CAPTURE_CHANGED &&
253 !(event.flags() & ui::EF_IS_SYNTHESIZED)) { 254 !(event.flags() & ui::EF_IS_SYNTHESIZED)) {
254 SetLastMouseLocation(window(), event.root_location()); 255 SetLastMouseLocation(window(), event.root_location());
255 } 256 }
256 257
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 if (mouse_moved_handler_ && !window()->Contains(mouse_moved_handler_)) 360 if (mouse_moved_handler_ && !window()->Contains(mouse_moved_handler_))
360 mouse_moved_handler_ = NULL; 361 mouse_moved_handler_ = NULL;
361 362
362 if (old_capture && old_capture->GetRootWindow() == window() && 363 if (old_capture && old_capture->GetRootWindow() == window() &&
363 old_capture->delegate()) { 364 old_capture->delegate()) {
364 // Send a capture changed event with bogus location data. 365 // Send a capture changed event with bogus location data.
365 ui::MouseEvent event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), 366 ui::MouseEvent event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(),
366 gfx::Point(), 0, 0); 367 gfx::Point(), 0, 0);
367 368
368 DispatchDetails details = DispatchEvent(old_capture, &event); 369 DispatchDetails details = DispatchEvent(old_capture, &event);
369 if (details.dispatcher_destroyed) 370 if (details.dispatcher_destroyed || details.target_destroyed)
370 return; 371 return;
371 372
372 old_capture->delegate()->OnCaptureLost(); 373 old_capture->delegate()->OnCaptureLost();
374
375 if (!new_capture) {
376 // Make sure |mouse_moved_handler_| gets updated.
377 DispatchDetails details = SynthesizeMouseMoveEvent();
378 if (details.dispatcher_destroyed)
379 return;
380 }
381 } else if (mouse_moved_handler_ &&
382 mouse_moved_handler_ != new_capture) {
sadrul 2014/06/24 18:33:09 Should you check for a non-null |new_capture| here
383 // Dispatch a mouse exit to reset any state associated with hover. This is
384 // important when going from no window having capture to a window having
385 // capture because we do not dispatch ET_MOUSE_CAPTURE_CHANGED in this case.
386 DispatchDetails details = DispatchMouseExitAtPoint(
387 GetLastMouseLocationInRoot());
388 if (details.dispatcher_destroyed)
389 return;
373 } 390 }
374 391
375 if (new_capture) { 392 if (new_capture) {
376 // Make all subsequent mouse events go to the capture window. We shouldn't 393 // Make all subsequent mouse events go to the capture window.
377 // need to send an event here as OnCaptureLost() should take care of that.
378 if (mouse_moved_handler_ || Env::GetInstance()->IsMouseButtonDown()) 394 if (mouse_moved_handler_ || Env::GetInstance()->IsMouseButtonDown())
379 mouse_moved_handler_ = new_capture; 395 mouse_moved_handler_ = new_capture;
380 } else {
381 // Make sure mouse_moved_handler gets updated.
382 DispatchDetails details = SynthesizeMouseMoveEvent();
383 if (details.dispatcher_destroyed)
384 return;
385 } 396 }
386 mouse_pressed_handler_ = NULL; 397 mouse_pressed_handler_ = NULL;
387 } 398 }
388 399
389 void WindowEventDispatcher::OnOtherRootGotCapture() { 400 void WindowEventDispatcher::OnOtherRootGotCapture() {
401 if (mouse_moved_handler_) {
402 // Dispatch a mouse exit to reset any state associated with hover. This is
403 // important when going from no window having capture to a window having
404 // capture because we do not dispatch ET_MOUSE_CAPTURE_CHANGED in this case.
405 DispatchDetails details = DispatchMouseExitAtPoint(
406 GetLastMouseLocationInRoot());
407 if (details.dispatcher_destroyed)
408 return;
409 }
410
390 mouse_moved_handler_ = NULL; 411 mouse_moved_handler_ = NULL;
391 mouse_pressed_handler_ = NULL; 412 mouse_pressed_handler_ = NULL;
392 } 413 }
393 414
394 void WindowEventDispatcher::SetNativeCapture() { 415 void WindowEventDispatcher::SetNativeCapture() {
395 host_->SetCapture(); 416 host_->SetCapture();
396 } 417 }
397 418
398 void WindowEventDispatcher::ReleaseNativeCapture() { 419 void WindowEventDispatcher::ReleaseNativeCapture() {
399 host_->ReleaseCapture(); 420 host_->ReleaseCapture();
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 break; 864 break;
844 865
845 default: 866 default:
846 NOTREACHED(); 867 NOTREACHED();
847 break; 868 break;
848 } 869 }
849 PreDispatchLocatedEvent(target, event); 870 PreDispatchLocatedEvent(target, event);
850 } 871 }
851 872
852 } // namespace aura 873 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window_event_dispatcher.h ('k') | ui/views/widget/widget_interactive_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698