| 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 <vector> | |
| 8 | |
| 9 #include "base/bind.h" | 7 #include "base/bind.h" |
| 10 #include "base/command_line.h" | |
| 11 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 12 #include "base/logging.h" | 9 #include "base/logging.h" |
| 13 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 14 #include "ui/aura/client/capture_client.h" | 11 #include "ui/aura/client/capture_client.h" |
| 15 #include "ui/aura/client/cursor_client.h" | 12 #include "ui/aura/client/cursor_client.h" |
| 16 #include "ui/aura/client/event_client.h" | 13 #include "ui/aura/client/event_client.h" |
| 17 #include "ui/aura/client/focus_client.h" | 14 #include "ui/aura/client/focus_client.h" |
| 18 #include "ui/aura/client/screen_position_client.h" | 15 #include "ui/aura/client/screen_position_client.h" |
| 19 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
| 20 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_delegate.h" | 18 #include "ui/aura/window_delegate.h" |
| 22 #include "ui/aura/window_targeter.h" | 19 #include "ui/aura/window_targeter.h" |
| 23 #include "ui/aura/window_tracker.h" | 20 #include "ui/aura/window_tracker.h" |
| 24 #include "ui/aura/window_tree_host.h" | 21 #include "ui/aura/window_tree_host.h" |
| 25 #include "ui/base/hit_test.h" | 22 #include "ui/base/hit_test.h" |
| 26 #include "ui/compositor/dip_util.h" | 23 #include "ui/compositor/dip_util.h" |
| 27 #include "ui/compositor/layer.h" | |
| 28 #include "ui/compositor/layer_animator.h" | |
| 29 #include "ui/events/event.h" | 24 #include "ui/events/event.h" |
| 30 #include "ui/events/gestures/gesture_recognizer.h" | 25 #include "ui/events/gestures/gesture_recognizer.h" |
| 31 #include "ui/events/gestures/gesture_types.h" | 26 #include "ui/events/gestures/gesture_types.h" |
| 32 #include "ui/gfx/screen.h" | |
| 33 | |
| 34 using std::vector; | |
| 35 | 27 |
| 36 typedef ui::EventDispatchDetails DispatchDetails; | 28 typedef ui::EventDispatchDetails DispatchDetails; |
| 37 | 29 |
| 38 namespace aura { | 30 namespace aura { |
| 39 | 31 |
| 40 namespace { | 32 namespace { |
| 41 | 33 |
| 42 // Returns true if |target| has a non-client (frame) component at |location|, | 34 // Returns true if |target| has a non-client (frame) component at |location|, |
| 43 // in window coordinates. | 35 // in window coordinates. |
| 44 bool IsNonClientLocation(Window* target, const gfx::Point& location) { | 36 bool IsNonClientLocation(Window* target, const gfx::Point& location) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 base::IgnoreResult(&WindowEventDispatcher::DispatchHeldEvents), | 114 base::IgnoreResult(&WindowEventDispatcher::DispatchHeldEvents), |
| 123 repost_event_factory_.GetWeakPtr())); | 115 repost_event_factory_.GetWeakPtr())); |
| 124 } else { | 116 } else { |
| 125 DCHECK(event.type() == ui::ET_GESTURE_TAP_DOWN); | 117 DCHECK(event.type() == ui::ET_GESTURE_TAP_DOWN); |
| 126 held_repostable_event_.reset(); | 118 held_repostable_event_.reset(); |
| 127 // TODO(rbyers): Reposing of gestures is tricky to get | 119 // TODO(rbyers): Reposing of gestures is tricky to get |
| 128 // right, so it's not yet supported. crbug.com/170987. | 120 // right, so it's not yet supported. crbug.com/170987. |
| 129 } | 121 } |
| 130 } | 122 } |
| 131 | 123 |
| 132 WindowTreeHostDelegate* WindowEventDispatcher::AsWindowTreeHostDelegate() { | |
| 133 return this; | |
| 134 } | |
| 135 | |
| 136 void WindowEventDispatcher::OnMouseEventsEnableStateChanged(bool enabled) { | 124 void WindowEventDispatcher::OnMouseEventsEnableStateChanged(bool enabled) { |
| 137 // Send entered / exited so that visual state can be updated to match | 125 // Send entered / exited so that visual state can be updated to match |
| 138 // mouse events state. | 126 // mouse events state. |
| 139 PostMouseMoveEventAfterWindowChange(); | 127 PostMouseMoveEventAfterWindowChange(); |
| 140 // TODO(mazda): Add code to disable mouse events when |enabled| == false. | 128 // TODO(mazda): Add code to disable mouse events when |enabled| == false. |
| 141 } | 129 } |
| 142 | 130 |
| 131 void WindowEventDispatcher::DispatchCancelModeEvent() { |
| 132 ui::CancelModeEvent event; |
| 133 Window* focused_window = client::GetFocusClient(window())->GetFocusedWindow(); |
| 134 if (focused_window && !window()->Contains(focused_window)) |
| 135 focused_window = NULL; |
| 136 DispatchDetails details = |
| 137 DispatchEvent(focused_window ? focused_window : window(), &event); |
| 138 if (details.dispatcher_destroyed) |
| 139 return; |
| 140 } |
| 141 |
| 143 Window* WindowEventDispatcher::GetGestureTarget(ui::GestureEvent* event) { | 142 Window* WindowEventDispatcher::GetGestureTarget(ui::GestureEvent* event) { |
| 144 Window* target = NULL; | 143 Window* target = NULL; |
| 145 if (!event->IsEndingEvent()) { | 144 if (!event->IsEndingEvent()) { |
| 146 // The window that received the start event (e.g. scroll begin) needs to | 145 // The window that received the start event (e.g. scroll begin) needs to |
| 147 // receive the end event (e.g. scroll end). | 146 // receive the end event (e.g. scroll end). |
| 148 target = client::GetCaptureWindow(window()); | 147 target = client::GetCaptureWindow(window()); |
| 149 } | 148 } |
| 150 if (!target) { | 149 if (!target) { |
| 151 target = ConsumerToWindow( | 150 target = ConsumerToWindow( |
| 152 ui::GestureRecognizer::Get()->GetTargetForGestureEvent(*event)); | 151 ui::GestureRecognizer::Get()->GetTargetForGestureEvent(*event)); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 267 |
| 269 gfx::Point WindowEventDispatcher::GetLastMouseLocationInRoot() const { | 268 gfx::Point WindowEventDispatcher::GetLastMouseLocationInRoot() const { |
| 270 gfx::Point location = Env::GetInstance()->last_mouse_location(); | 269 gfx::Point location = Env::GetInstance()->last_mouse_location(); |
| 271 client::ScreenPositionClient* client = | 270 client::ScreenPositionClient* client = |
| 272 client::GetScreenPositionClient(window()); | 271 client::GetScreenPositionClient(window()); |
| 273 if (client) | 272 if (client) |
| 274 client->ConvertPointFromScreen(window(), &location); | 273 client->ConvertPointFromScreen(window(), &location); |
| 275 return location; | 274 return location; |
| 276 } | 275 } |
| 277 | 276 |
| 277 void WindowEventDispatcher::OnHostLostMouseGrab() { |
| 278 mouse_pressed_handler_ = NULL; |
| 279 mouse_moved_handler_ = NULL; |
| 280 } |
| 281 |
| 282 void WindowEventDispatcher::OnHostResized(const gfx::Size& size) { |
| 283 TRACE_EVENT1("ui", "WindowEventDispatcher::OnHostResized", |
| 284 "size", size.ToString()); |
| 285 |
| 286 DispatchDetails details = DispatchHeldEvents(); |
| 287 if (details.dispatcher_destroyed) |
| 288 return; |
| 289 |
| 290 // Constrain the mouse position within the new root Window size. |
| 291 gfx::Point point; |
| 292 if (host_->QueryMouseLocation(&point)) { |
| 293 SetLastMouseLocation(window(), |
| 294 ui::ConvertPointToDIP(window()->layer(), point)); |
| 295 } |
| 296 synthesize_mouse_move_ = false; |
| 297 } |
| 298 |
| 299 void WindowEventDispatcher::OnCursorMovedToRootLocation( |
| 300 const gfx::Point& root_location) { |
| 301 SetLastMouseLocation(window(), root_location); |
| 302 synthesize_mouse_move_ = false; |
| 303 } |
| 304 |
| 278 //////////////////////////////////////////////////////////////////////////////// | 305 //////////////////////////////////////////////////////////////////////////////// |
| 279 // WindowEventDispatcher, private: | 306 // WindowEventDispatcher, private: |
| 280 | 307 |
| 281 void WindowEventDispatcher::TransformEventForDeviceScaleFactor( | 308 void WindowEventDispatcher::TransformEventForDeviceScaleFactor( |
| 282 ui::LocatedEvent* event) { | 309 ui::LocatedEvent* event) { |
| 283 event->UpdateForRootTransform(host()->GetInverseRootTransform()); | 310 event->UpdateForRootTransform(host()->GetInverseRootTransform()); |
| 284 } | 311 } |
| 285 | 312 |
| 286 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( | 313 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( |
| 287 const ui::MouseEvent& event, | 314 const ui::MouseEvent& event, |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 DispatchGestureEvent(event); | 576 DispatchGestureEvent(event); |
| 550 } | 577 } |
| 551 | 578 |
| 552 void WindowEventDispatcher::DispatchCancelTouchEvent(ui::TouchEvent* event) { | 579 void WindowEventDispatcher::DispatchCancelTouchEvent(ui::TouchEvent* event) { |
| 553 DispatchDetails details = OnEventFromSource(event); | 580 DispatchDetails details = OnEventFromSource(event); |
| 554 if (details.dispatcher_destroyed) | 581 if (details.dispatcher_destroyed) |
| 555 return; | 582 return; |
| 556 } | 583 } |
| 557 | 584 |
| 558 //////////////////////////////////////////////////////////////////////////////// | 585 //////////////////////////////////////////////////////////////////////////////// |
| 559 // WindowEventDispatcher, ui::LayerAnimationObserver implementation: | |
| 560 | |
| 561 void WindowEventDispatcher::OnLayerAnimationEnded( | |
| 562 ui::LayerAnimationSequence* animation) { | |
| 563 host()->UpdateRootWindowSize(host_->GetBounds().size()); | |
| 564 } | |
| 565 | |
| 566 void WindowEventDispatcher::OnLayerAnimationScheduled( | |
| 567 ui::LayerAnimationSequence* animation) { | |
| 568 } | |
| 569 | |
| 570 void WindowEventDispatcher::OnLayerAnimationAborted( | |
| 571 ui::LayerAnimationSequence* animation) { | |
| 572 } | |
| 573 | |
| 574 //////////////////////////////////////////////////////////////////////////////// | |
| 575 // WindowEventDispatcher, WindowTreeHostDelegate implementation: | |
| 576 | |
| 577 void WindowEventDispatcher::OnHostCancelMode() { | |
| 578 ui::CancelModeEvent event; | |
| 579 Window* focused_window = client::GetFocusClient(window())->GetFocusedWindow(); | |
| 580 if (focused_window && !window()->Contains(focused_window)) | |
| 581 focused_window = NULL; | |
| 582 DispatchDetails details = | |
| 583 DispatchEvent(focused_window ? focused_window : window(), &event); | |
| 584 if (details.dispatcher_destroyed) | |
| 585 return; | |
| 586 } | |
| 587 | |
| 588 void WindowEventDispatcher::OnHostActivated() { | |
| 589 Env::GetInstance()->RootWindowActivated(this); | |
| 590 } | |
| 591 | |
| 592 void WindowEventDispatcher::OnHostLostWindowCapture() { | |
| 593 Window* capture_window = client::GetCaptureWindow(window()); | |
| 594 if (capture_window && capture_window->GetRootWindow() == window()) | |
| 595 capture_window->ReleaseCapture(); | |
| 596 } | |
| 597 | |
| 598 void WindowEventDispatcher::OnHostLostMouseGrab() { | |
| 599 mouse_pressed_handler_ = NULL; | |
| 600 mouse_moved_handler_ = NULL; | |
| 601 } | |
| 602 | |
| 603 void WindowEventDispatcher::OnHostResized(const gfx::Size& size) { | |
| 604 TRACE_EVENT1("ui", "WindowEventDispatcher::OnHostResized", | |
| 605 "size", size.ToString()); | |
| 606 | |
| 607 DispatchDetails details = DispatchHeldEvents(); | |
| 608 if (details.dispatcher_destroyed) | |
| 609 return; | |
| 610 | |
| 611 // Constrain the mouse position within the new root Window size. | |
| 612 gfx::Point point; | |
| 613 if (host_->QueryMouseLocation(&point)) { | |
| 614 SetLastMouseLocation(window(), | |
| 615 ui::ConvertPointToDIP(window()->layer(), point)); | |
| 616 } | |
| 617 synthesize_mouse_move_ = false; | |
| 618 } | |
| 619 | |
| 620 void WindowEventDispatcher::OnCursorMovedToRootLocation( | |
| 621 const gfx::Point& root_location) { | |
| 622 SetLastMouseLocation(window(), root_location); | |
| 623 synthesize_mouse_move_ = false; | |
| 624 } | |
| 625 | |
| 626 WindowEventDispatcher* WindowEventDispatcher::AsDispatcher() { | |
| 627 return this; | |
| 628 } | |
| 629 | |
| 630 const WindowEventDispatcher* WindowEventDispatcher::AsDispatcher() const { | |
| 631 return this; | |
| 632 } | |
| 633 | |
| 634 ui::EventProcessor* WindowEventDispatcher::GetEventProcessor() { | |
| 635 return this; | |
| 636 } | |
| 637 | |
| 638 //////////////////////////////////////////////////////////////////////////////// | |
| 639 // WindowEventDispatcher, private: | 586 // WindowEventDispatcher, private: |
| 640 | 587 |
| 641 ui::EventDispatchDetails WindowEventDispatcher::DispatchHeldEvents() { | 588 ui::EventDispatchDetails WindowEventDispatcher::DispatchHeldEvents() { |
| 642 if (!held_repostable_event_ && !held_move_event_) | 589 if (!held_repostable_event_ && !held_move_event_) |
| 643 return DispatchDetails(); | 590 return DispatchDetails(); |
| 644 | 591 |
| 645 CHECK(!dispatching_held_event_); | 592 CHECK(!dispatching_held_event_); |
| 646 dispatching_held_event_ = true; | 593 dispatching_held_event_ = true; |
| 647 | 594 |
| 648 DispatchDetails dispatch_details; | 595 DispatchDetails dispatch_details; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 break; | 794 break; |
| 848 | 795 |
| 849 default: | 796 default: |
| 850 NOTREACHED(); | 797 NOTREACHED(); |
| 851 break; | 798 break; |
| 852 } | 799 } |
| 853 PreDispatchLocatedEvent(target, event); | 800 PreDispatchLocatedEvent(target, event); |
| 854 } | 801 } |
| 855 | 802 |
| 856 } // namespace aura | 803 } // namespace aura |
| OLD | NEW |