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 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" |
8 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 12 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
11 #include "ui/aura/client/capture_client.h" | 14 #include "ui/aura/client/capture_client.h" |
12 #include "ui/aura/client/cursor_client.h" | 15 #include "ui/aura/client/cursor_client.h" |
13 #include "ui/aura/client/event_client.h" | 16 #include "ui/aura/client/event_client.h" |
14 #include "ui/aura/client/focus_client.h" | 17 #include "ui/aura/client/focus_client.h" |
15 #include "ui/aura/client/screen_position_client.h" | 18 #include "ui/aura/client/screen_position_client.h" |
16 #include "ui/aura/env.h" | 19 #include "ui/aura/env.h" |
17 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
18 #include "ui/aura/window_delegate.h" | 21 #include "ui/aura/window_delegate.h" |
19 #include "ui/aura/window_targeter.h" | 22 #include "ui/aura/window_targeter.h" |
20 #include "ui/aura/window_tracker.h" | 23 #include "ui/aura/window_tracker.h" |
21 #include "ui/aura/window_tree_host.h" | 24 #include "ui/aura/window_tree_host.h" |
22 #include "ui/base/hit_test.h" | 25 #include "ui/base/hit_test.h" |
23 #include "ui/compositor/dip_util.h" | 26 #include "ui/compositor/dip_util.h" |
| 27 #include "ui/compositor/layer.h" |
| 28 #include "ui/compositor/layer_animator.h" |
24 #include "ui/events/event.h" | 29 #include "ui/events/event.h" |
25 #include "ui/events/gestures/gesture_recognizer.h" | 30 #include "ui/events/gestures/gesture_recognizer.h" |
26 #include "ui/events/gestures/gesture_types.h" | 31 #include "ui/events/gestures/gesture_types.h" |
| 32 #include "ui/gfx/screen.h" |
| 33 |
| 34 using std::vector; |
27 | 35 |
28 typedef ui::EventDispatchDetails DispatchDetails; | 36 typedef ui::EventDispatchDetails DispatchDetails; |
29 | 37 |
30 namespace aura { | 38 namespace aura { |
31 | 39 |
32 namespace { | 40 namespace { |
33 | 41 |
34 // Returns true if |target| has a non-client (frame) component at |location|, | 42 // Returns true if |target| has a non-client (frame) component at |location|, |
35 // in window coordinates. | 43 // in window coordinates. |
36 bool IsNonClientLocation(Window* target, const gfx::Point& location) { | 44 bool IsNonClientLocation(Window* target, const gfx::Point& location) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 base::IgnoreResult(&WindowEventDispatcher::DispatchHeldEvents), | 122 base::IgnoreResult(&WindowEventDispatcher::DispatchHeldEvents), |
115 repost_event_factory_.GetWeakPtr())); | 123 repost_event_factory_.GetWeakPtr())); |
116 } else { | 124 } else { |
117 DCHECK(event.type() == ui::ET_GESTURE_TAP_DOWN); | 125 DCHECK(event.type() == ui::ET_GESTURE_TAP_DOWN); |
118 held_repostable_event_.reset(); | 126 held_repostable_event_.reset(); |
119 // TODO(rbyers): Reposing of gestures is tricky to get | 127 // TODO(rbyers): Reposing of gestures is tricky to get |
120 // right, so it's not yet supported. crbug.com/170987. | 128 // right, so it's not yet supported. crbug.com/170987. |
121 } | 129 } |
122 } | 130 } |
123 | 131 |
| 132 WindowTreeHostDelegate* WindowEventDispatcher::AsWindowTreeHostDelegate() { |
| 133 return this; |
| 134 } |
| 135 |
124 void WindowEventDispatcher::OnMouseEventsEnableStateChanged(bool enabled) { | 136 void WindowEventDispatcher::OnMouseEventsEnableStateChanged(bool enabled) { |
125 // Send entered / exited so that visual state can be updated to match | 137 // Send entered / exited so that visual state can be updated to match |
126 // mouse events state. | 138 // mouse events state. |
127 PostMouseMoveEventAfterWindowChange(); | 139 PostMouseMoveEventAfterWindowChange(); |
128 // TODO(mazda): Add code to disable mouse events when |enabled| == false. | 140 // TODO(mazda): Add code to disable mouse events when |enabled| == false. |
129 } | 141 } |
130 | 142 |
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 | |
142 Window* WindowEventDispatcher::GetGestureTarget(ui::GestureEvent* event) { | 143 Window* WindowEventDispatcher::GetGestureTarget(ui::GestureEvent* event) { |
143 Window* target = NULL; | 144 Window* target = NULL; |
144 if (!event->IsEndingEvent()) { | 145 if (!event->IsEndingEvent()) { |
145 // The window that received the start event (e.g. scroll begin) needs to | 146 // The window that received the start event (e.g. scroll begin) needs to |
146 // receive the end event (e.g. scroll end). | 147 // receive the end event (e.g. scroll end). |
147 target = client::GetCaptureWindow(window()); | 148 target = client::GetCaptureWindow(window()); |
148 } | 149 } |
149 if (!target) { | 150 if (!target) { |
150 target = ConsumerToWindow( | 151 target = ConsumerToWindow( |
151 ui::GestureRecognizer::Get()->GetTargetForGestureEvent(*event)); | 152 ui::GestureRecognizer::Get()->GetTargetForGestureEvent(*event)); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 268 |
268 gfx::Point WindowEventDispatcher::GetLastMouseLocationInRoot() const { | 269 gfx::Point WindowEventDispatcher::GetLastMouseLocationInRoot() const { |
269 gfx::Point location = Env::GetInstance()->last_mouse_location(); | 270 gfx::Point location = Env::GetInstance()->last_mouse_location(); |
270 client::ScreenPositionClient* client = | 271 client::ScreenPositionClient* client = |
271 client::GetScreenPositionClient(window()); | 272 client::GetScreenPositionClient(window()); |
272 if (client) | 273 if (client) |
273 client->ConvertPointFromScreen(window(), &location); | 274 client->ConvertPointFromScreen(window(), &location); |
274 return location; | 275 return location; |
275 } | 276 } |
276 | 277 |
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 | |
305 //////////////////////////////////////////////////////////////////////////////// | 278 //////////////////////////////////////////////////////////////////////////////// |
306 // WindowEventDispatcher, private: | 279 // WindowEventDispatcher, private: |
307 | 280 |
308 void WindowEventDispatcher::TransformEventForDeviceScaleFactor( | 281 void WindowEventDispatcher::TransformEventForDeviceScaleFactor( |
309 ui::LocatedEvent* event) { | 282 ui::LocatedEvent* event) { |
310 event->UpdateForRootTransform(host()->GetInverseRootTransform()); | 283 event->UpdateForRootTransform(host()->GetInverseRootTransform()); |
311 } | 284 } |
312 | 285 |
313 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( | 286 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( |
314 const ui::MouseEvent& event, | 287 const ui::MouseEvent& event, |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 DispatchGestureEvent(event); | 549 DispatchGestureEvent(event); |
577 } | 550 } |
578 | 551 |
579 void WindowEventDispatcher::DispatchCancelTouchEvent(ui::TouchEvent* event) { | 552 void WindowEventDispatcher::DispatchCancelTouchEvent(ui::TouchEvent* event) { |
580 DispatchDetails details = OnEventFromSource(event); | 553 DispatchDetails details = OnEventFromSource(event); |
581 if (details.dispatcher_destroyed) | 554 if (details.dispatcher_destroyed) |
582 return; | 555 return; |
583 } | 556 } |
584 | 557 |
585 //////////////////////////////////////////////////////////////////////////////// | 558 //////////////////////////////////////////////////////////////////////////////// |
| 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 //////////////////////////////////////////////////////////////////////////////// |
586 // WindowEventDispatcher, private: | 639 // WindowEventDispatcher, private: |
587 | 640 |
588 ui::EventDispatchDetails WindowEventDispatcher::DispatchHeldEvents() { | 641 ui::EventDispatchDetails WindowEventDispatcher::DispatchHeldEvents() { |
589 if (!held_repostable_event_ && !held_move_event_) | 642 if (!held_repostable_event_ && !held_move_event_) |
590 return DispatchDetails(); | 643 return DispatchDetails(); |
591 | 644 |
592 CHECK(!dispatching_held_event_); | 645 CHECK(!dispatching_held_event_); |
593 dispatching_held_event_ = true; | 646 dispatching_held_event_ = true; |
594 | 647 |
595 DispatchDetails dispatch_details; | 648 DispatchDetails dispatch_details; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 break; | 847 break; |
795 | 848 |
796 default: | 849 default: |
797 NOTREACHED(); | 850 NOTREACHED(); |
798 break; | 851 break; |
799 } | 852 } |
800 PreDispatchLocatedEvent(target, event); | 853 PreDispatchLocatedEvent(target, event); |
801 } | 854 } |
802 | 855 |
803 } // namespace aura | 856 } // namespace aura |
OLD | NEW |