| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 DCHECK(event.type() == ui::ET_GESTURE_TAP_DOWN); | 114 DCHECK(event.type() == ui::ET_GESTURE_TAP_DOWN); |
| 115 held_repostable_event_.reset(); | 115 held_repostable_event_.reset(); |
| 116 // TODO(rbyers): Reposing of gestures is tricky to get | 116 // TODO(rbyers): Reposing of gestures is tricky to get |
| 117 // right, so it's not yet supported. crbug.com/170987. | 117 // right, so it's not yet supported. crbug.com/170987. |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 void WindowEventDispatcher::OnMouseEventsEnableStateChanged(bool enabled) { | 121 void WindowEventDispatcher::OnMouseEventsEnableStateChanged(bool enabled) { |
| 122 // Send entered / exited so that visual state can be updated to match | 122 // Send entered / exited so that visual state can be updated to match |
| 123 // mouse events state. | 123 // mouse events state. |
| 124 PostSynthesizeMouseMove(); | 124 PostSynthesizeMouseMove(ui::EF_NONE); |
| 125 // TODO(mazda): Add code to disable mouse events when |enabled| == false. | 125 // TODO(mazda): Add code to disable mouse events when |enabled| == false. |
| 126 } | 126 } |
| 127 | 127 |
| 128 void WindowEventDispatcher::DispatchCancelModeEvent() { | 128 void WindowEventDispatcher::DispatchCancelModeEvent() { |
| 129 ui::CancelModeEvent event; | 129 ui::CancelModeEvent event; |
| 130 Window* focused_window = client::GetFocusClient(window())->GetFocusedWindow(); | 130 Window* focused_window = client::GetFocusClient(window())->GetFocusedWindow(); |
| 131 if (focused_window && !window()->Contains(focused_window)) | 131 if (focused_window && !window()->Contains(focused_window)) |
| 132 focused_window = NULL; | 132 focused_window = NULL; |
| 133 DispatchDetails details = | 133 DispatchDetails details = |
| 134 DispatchEvent(focused_window ? focused_window : window(), &event); | 134 DispatchEvent(focused_window ? focused_window : window(), &event); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 old_capture->delegate()->OnCaptureLost(); | 372 old_capture->delegate()->OnCaptureLost(); |
| 373 } | 373 } |
| 374 | 374 |
| 375 if (new_capture) { | 375 if (new_capture) { |
| 376 // Make all subsequent mouse events go to the capture window. We shouldn't | 376 // Make all subsequent mouse events go to the capture window. We shouldn't |
| 377 // need to send an event here as OnCaptureLost() should take care of that. | 377 // need to send an event here as OnCaptureLost() should take care of that. |
| 378 if (mouse_moved_handler_ || Env::GetInstance()->IsMouseButtonDown()) | 378 if (mouse_moved_handler_ || Env::GetInstance()->IsMouseButtonDown()) |
| 379 mouse_moved_handler_ = new_capture; | 379 mouse_moved_handler_ = new_capture; |
| 380 } else { | 380 } else { |
| 381 // Make sure mouse_moved_handler gets updated. | 381 // Make sure mouse_moved_handler gets updated. |
| 382 DispatchDetails details = SynthesizeMouseMoveEvent(); | 382 DispatchDetails details = SynthesizeMouseMoveEvent(ui::EF_NONE); |
| 383 if (details.dispatcher_destroyed) | 383 if (details.dispatcher_destroyed) |
| 384 return; | 384 return; |
| 385 } | 385 } |
| 386 mouse_pressed_handler_ = NULL; | 386 mouse_pressed_handler_ = NULL; |
| 387 } | 387 } |
| 388 | 388 |
| 389 void WindowEventDispatcher::OnOtherRootGotCapture() { | 389 void WindowEventDispatcher::OnOtherRootGotCapture() { |
| 390 mouse_moved_handler_ = NULL; | 390 mouse_moved_handler_ = NULL; |
| 391 mouse_pressed_handler_ = NULL; | 391 mouse_pressed_handler_ = NULL; |
| 392 } | 392 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 | 555 |
| 556 DispatchMouseExitToHidingWindow(window); | 556 DispatchMouseExitToHidingWindow(window); |
| 557 } | 557 } |
| 558 | 558 |
| 559 void WindowEventDispatcher::OnWindowVisibilityChanged(Window* window, | 559 void WindowEventDispatcher::OnWindowVisibilityChanged(Window* window, |
| 560 bool visible) { | 560 bool visible) { |
| 561 if (!host_->window()->Contains(window)) | 561 if (!host_->window()->Contains(window)) |
| 562 return; | 562 return; |
| 563 | 563 |
| 564 if (window->ContainsPointInRoot(GetLastMouseLocationInRoot())) | 564 if (window->ContainsPointInRoot(GetLastMouseLocationInRoot())) |
| 565 PostSynthesizeMouseMove(); | 565 PostSynthesizeMouseMove(ui::EF_NONE); |
| 566 | 566 |
| 567 // Hiding the window releases capture which can implicitly destroy the window | 567 // Hiding the window releases capture which can implicitly destroy the window |
| 568 // so the window may no longer be valid after this call. | 568 // so the window may no longer be valid after this call. |
| 569 if (!visible) | 569 if (!visible) |
| 570 OnWindowHidden(window, WINDOW_HIDDEN); | 570 OnWindowHidden(window, WINDOW_HIDDEN); |
| 571 } | 571 } |
| 572 | 572 |
| 573 void WindowEventDispatcher::OnWindowBoundsChanged(Window* window, | 573 void WindowEventDispatcher::OnWindowBoundsChanged(Window* window, |
| 574 const gfx::Rect& old_bounds, | 574 const gfx::Rect& old_bounds, |
| 575 const gfx::Rect& new_bounds) { | 575 const gfx::Rect& new_bounds) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 587 // Constrain the mouse position within the new root Window size. | 587 // Constrain the mouse position within the new root Window size. |
| 588 gfx::Point point; | 588 gfx::Point point; |
| 589 if (host_->QueryMouseLocation(&point)) { | 589 if (host_->QueryMouseLocation(&point)) { |
| 590 SetLastMouseLocation( | 590 SetLastMouseLocation( |
| 591 host_->window(), | 591 host_->window(), |
| 592 ui::ConvertPointToDIP(host_->window()->layer(), point)); | 592 ui::ConvertPointToDIP(host_->window()->layer(), point)); |
| 593 } | 593 } |
| 594 synthesize_mouse_move_ = false; | 594 synthesize_mouse_move_ = false; |
| 595 } | 595 } |
| 596 | 596 |
| 597 if (window->IsVisible()) { | 597 if (window->IsVisible() && !window->ignore_events()) { |
| 598 gfx::Rect old_bounds_in_root = old_bounds, new_bounds_in_root = new_bounds; | 598 gfx::Rect old_bounds_in_root = old_bounds, new_bounds_in_root = new_bounds; |
| 599 Window::ConvertRectToTarget(window->parent(), host_->window(), | 599 Window::ConvertRectToTarget(window->parent(), host_->window(), |
| 600 &old_bounds_in_root); | 600 &old_bounds_in_root); |
| 601 Window::ConvertRectToTarget(window->parent(), host_->window(), | 601 Window::ConvertRectToTarget(window->parent(), host_->window(), |
| 602 &new_bounds_in_root); | 602 &new_bounds_in_root); |
| 603 gfx::Point last_mouse_location = GetLastMouseLocationInRoot(); | 603 gfx::Point last_mouse_location = GetLastMouseLocationInRoot(); |
| 604 if (old_bounds_in_root.Contains(last_mouse_location) != | 604 if (old_bounds_in_root.Contains(last_mouse_location) != |
| 605 new_bounds_in_root.Contains(last_mouse_location)) { | 605 new_bounds_in_root.Contains(last_mouse_location)) { |
| 606 PostSynthesizeMouseMove(); | 606 PostSynthesizeMouseMove(Env::GetInstance()->mouse_button_flags()); |
| 607 } | 607 } |
| 608 } | 608 } |
| 609 } | 609 } |
| 610 | 610 |
| 611 void WindowEventDispatcher::OnWindowTransforming(Window* window) { | 611 void WindowEventDispatcher::OnWindowTransforming(Window* window) { |
| 612 if (!host_->window()->Contains(window)) | 612 if (!host_->window()->Contains(window)) |
| 613 return; | 613 return; |
| 614 | 614 |
| 615 SynthesizeMouseMoveAfterChangeToWindow(window); | 615 SynthesizeMouseMoveAfterChangeToWindow(window); |
| 616 } | 616 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 } | 662 } |
| 663 if (!dispatch_details.dispatcher_destroyed) | 663 if (!dispatch_details.dispatcher_destroyed) |
| 664 held_move_event_.reset(); | 664 held_move_event_.reset(); |
| 665 } | 665 } |
| 666 | 666 |
| 667 if (!dispatch_details.dispatcher_destroyed) | 667 if (!dispatch_details.dispatcher_destroyed) |
| 668 dispatching_held_event_ = false; | 668 dispatching_held_event_ = false; |
| 669 return dispatch_details; | 669 return dispatch_details; |
| 670 } | 670 } |
| 671 | 671 |
| 672 void WindowEventDispatcher::PostSynthesizeMouseMove() { | 672 void WindowEventDispatcher::PostSynthesizeMouseMove(int mouse_button_flags) { |
| 673 if (synthesize_mouse_move_) | 673 if (synthesize_mouse_move_) |
| 674 return; | 674 return; |
| 675 synthesize_mouse_move_ = true; | 675 synthesize_mouse_move_ = true; |
| 676 base::MessageLoop::current()->PostNonNestableTask( | 676 base::MessageLoop::current()->PostNonNestableTask( |
| 677 FROM_HERE, | 677 FROM_HERE, |
| 678 base::Bind(base::IgnoreResult( | 678 base::Bind(base::IgnoreResult( |
| 679 &WindowEventDispatcher::SynthesizeMouseMoveEvent), | 679 &WindowEventDispatcher::SynthesizeMouseMoveEvent), |
| 680 held_event_factory_.GetWeakPtr())); | 680 held_event_factory_.GetWeakPtr(), |
| 681 mouse_button_flags)); |
| 681 } | 682 } |
| 682 | 683 |
| 683 void WindowEventDispatcher::SynthesizeMouseMoveAfterChangeToWindow( | 684 void WindowEventDispatcher::SynthesizeMouseMoveAfterChangeToWindow( |
| 684 Window* window) { | 685 Window* window) { |
| 685 if (window->IsVisible() && | 686 if (window->IsVisible() && |
| 686 window->ContainsPointInRoot(GetLastMouseLocationInRoot())) { | 687 window->ContainsPointInRoot(GetLastMouseLocationInRoot())) { |
| 687 PostSynthesizeMouseMove(); | 688 PostSynthesizeMouseMove(ui::EF_NONE); |
| 688 } | 689 } |
| 689 } | 690 } |
| 690 | 691 |
| 691 ui::EventDispatchDetails WindowEventDispatcher::SynthesizeMouseMoveEvent() { | 692 ui::EventDispatchDetails WindowEventDispatcher::SynthesizeMouseMoveEvent( |
| 693 int mouse_button_flags) { |
| 692 DispatchDetails details; | 694 DispatchDetails details; |
| 693 if (!synthesize_mouse_move_) | 695 if (!synthesize_mouse_move_) |
| 694 return details; | 696 return details; |
| 695 synthesize_mouse_move_ = false; | 697 synthesize_mouse_move_ = false; |
| 696 gfx::Point root_mouse_location = GetLastMouseLocationInRoot(); | 698 gfx::Point root_mouse_location = GetLastMouseLocationInRoot(); |
| 697 if (!window()->bounds().Contains(root_mouse_location)) | 699 if (!window()->bounds().Contains(root_mouse_location)) |
| 698 return details; | 700 return details; |
| 699 gfx::Point host_mouse_location = root_mouse_location; | 701 gfx::Point host_mouse_location = root_mouse_location; |
| 700 host_->ConvertPointToHost(&host_mouse_location); | 702 host_->ConvertPointToHost(&host_mouse_location); |
| 701 ui::MouseEvent event(ui::ET_MOUSE_MOVED, | 703 ui::MouseEvent event( |
| 702 host_mouse_location, | 704 mouse_button_flags ? ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED, |
| 703 host_mouse_location, | 705 host_mouse_location, |
| 704 ui::EF_IS_SYNTHESIZED, | 706 host_mouse_location, |
| 705 0); | 707 ui::EF_IS_SYNTHESIZED | mouse_button_flags, |
| 708 0); |
| 706 return OnEventFromSource(&event); | 709 return OnEventFromSource(&event); |
| 707 } | 710 } |
| 708 | 711 |
| 709 void WindowEventDispatcher::PreDispatchLocatedEvent(Window* target, | 712 void WindowEventDispatcher::PreDispatchLocatedEvent(Window* target, |
| 710 ui::LocatedEvent* event) { | 713 ui::LocatedEvent* event) { |
| 711 int flags = event->flags(); | 714 int flags = event->flags(); |
| 712 if (IsNonClientLocation(target, event->location())) | 715 if (IsNonClientLocation(target, event->location())) |
| 713 flags |= ui::EF_IS_NON_CLIENT; | 716 flags |= ui::EF_IS_NON_CLIENT; |
| 714 event->set_flags(flags); | 717 event->set_flags(flags); |
| 715 | 718 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 break; | 856 break; |
| 854 | 857 |
| 855 default: | 858 default: |
| 856 NOTREACHED(); | 859 NOTREACHED(); |
| 857 break; | 860 break; |
| 858 } | 861 } |
| 859 PreDispatchLocatedEvent(target, event); | 862 PreDispatchLocatedEvent(target, event); |
| 860 } | 863 } |
| 861 | 864 |
| 862 } // namespace aura | 865 } // namespace aura |
| OLD | NEW |