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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "ui/aura/client/capture_client.h" | 14 #include "ui/aura/client/capture_client.h" |
15 #include "ui/aura/client/cursor_client.h" | 15 #include "ui/aura/client/cursor_client.h" |
16 #include "ui/aura/client/event_client.h" | 16 #include "ui/aura/client/event_client.h" |
17 #include "ui/aura/client/focus_client.h" | 17 #include "ui/aura/client/focus_client.h" |
18 #include "ui/aura/client/screen_position_client.h" | 18 #include "ui/aura/client/screen_position_client.h" |
19 #include "ui/aura/env.h" | 19 #include "ui/aura/env.h" |
20 #include "ui/aura/env_input_state_controller.h" | 20 #include "ui/aura/env_input_state_controller.h" |
21 #include "ui/aura/mus/mus_mouse_location_updater.h" | 21 #include "ui/aura/mus/mus_mouse_location_updater.h" |
22 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
23 #include "ui/aura/window_delegate.h" | 23 #include "ui/aura/window_delegate.h" |
24 #include "ui/aura/window_targeter.h" | 24 #include "ui/aura/window_targeter.h" |
25 #include "ui/aura/window_tracker.h" | 25 #include "ui/aura/window_tracker.h" |
26 #include "ui/aura/window_tree_host.h" | 26 #include "ui/aura/window_tree_host.h" |
27 #include "ui/base/hit_test.h" | 27 #include "ui/base/hit_test.h" |
28 #include "ui/compositor/dip_util.h" | 28 #include "ui/compositor/dip_util.h" |
29 #include "ui/events/event.h" | 29 #include "ui/events/event.h" |
| 30 #include "ui/events/event_targeter.h" |
30 #include "ui/events/event_utils.h" | 31 #include "ui/events/event_utils.h" |
31 #include "ui/events/gestures/gesture_recognizer.h" | 32 #include "ui/events/gestures/gesture_recognizer.h" |
32 #include "ui/events/gestures/gesture_types.h" | 33 #include "ui/events/gestures/gesture_types.h" |
33 | 34 |
34 typedef ui::EventDispatchDetails DispatchDetails; | 35 typedef ui::EventDispatchDetails DispatchDetails; |
35 | 36 |
36 namespace aura { | 37 namespace aura { |
37 | 38 |
38 namespace { | 39 namespace { |
39 | 40 |
(...skipping 29 matching lines...) Expand all Loading... |
69 : host_(host), | 70 : host_(host), |
70 mouse_pressed_handler_(NULL), | 71 mouse_pressed_handler_(NULL), |
71 mouse_moved_handler_(NULL), | 72 mouse_moved_handler_(NULL), |
72 event_dispatch_target_(NULL), | 73 event_dispatch_target_(NULL), |
73 old_dispatch_target_(NULL), | 74 old_dispatch_target_(NULL), |
74 synthesize_mouse_move_(false), | 75 synthesize_mouse_move_(false), |
75 move_hold_count_(0), | 76 move_hold_count_(0), |
76 dispatching_held_event_(nullptr), | 77 dispatching_held_event_(nullptr), |
77 observer_manager_(this), | 78 observer_manager_(this), |
78 env_controller_(new EnvInputStateController), | 79 env_controller_(new EnvInputStateController), |
| 80 event_targeter_(new WindowTargeter), |
79 repost_event_factory_(this), | 81 repost_event_factory_(this), |
80 held_event_factory_(this) { | 82 held_event_factory_(this) { |
81 ui::GestureRecognizer::Get()->AddGestureEventHelper(this); | 83 ui::GestureRecognizer::Get()->AddGestureEventHelper(this); |
82 Env::GetInstance()->AddObserver(this); | 84 Env::GetInstance()->AddObserver(this); |
83 if (Env::GetInstance()->mode() == Env::Mode::MUS) | 85 if (Env::GetInstance()->mode() == Env::Mode::MUS) |
84 mus_mouse_location_updater_ = base::MakeUnique<MusMouseLocationUpdater>(); | 86 mus_mouse_location_updater_ = base::MakeUnique<MusMouseLocationUpdater>(); |
85 } | 87 } |
86 | 88 |
87 WindowEventDispatcher::~WindowEventDispatcher() { | 89 WindowEventDispatcher::~WindowEventDispatcher() { |
88 TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor"); | 90 TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor"); |
89 Env::GetInstance()->RemoveObserver(this); | 91 Env::GetInstance()->RemoveObserver(this); |
90 ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this); | 92 ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this); |
91 } | 93 } |
92 | 94 |
| 95 ui::EventTargeter* WindowEventDispatcher::GetDefaultEventTargeter() { |
| 96 return event_targeter_.get(); |
| 97 } |
| 98 |
93 void WindowEventDispatcher::RepostEvent(const ui::LocatedEvent* event) { | 99 void WindowEventDispatcher::RepostEvent(const ui::LocatedEvent* event) { |
94 DCHECK(event->type() == ui::ET_MOUSE_PRESSED || | 100 DCHECK(event->type() == ui::ET_MOUSE_PRESSED || |
95 event->type() == ui::ET_GESTURE_TAP_DOWN || | 101 event->type() == ui::ET_GESTURE_TAP_DOWN || |
96 event->type() == ui::ET_TOUCH_PRESSED); | 102 event->type() == ui::ET_TOUCH_PRESSED); |
97 // We allow for only one outstanding repostable event. This is used | 103 // We allow for only one outstanding repostable event. This is used |
98 // in exiting context menus. A dropped repost request is allowed. | 104 // in exiting context menus. A dropped repost request is allowed. |
99 if (event->type() == ui::ET_MOUSE_PRESSED) { | 105 if (event->type() == ui::ET_MOUSE_PRESSED) { |
100 held_repostable_event_.reset(new ui::MouseEvent( | 106 held_repostable_event_.reset(new ui::MouseEvent( |
101 *event->AsMouseEvent(), static_cast<aura::Window*>(event->target()), | 107 *event->AsMouseEvent(), static_cast<aura::Window*>(event->target()), |
102 window())); | 108 window())); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 void WindowEventDispatcher::SetNativeCapture() { | 415 void WindowEventDispatcher::SetNativeCapture() { |
410 host_->SetCapture(); | 416 host_->SetCapture(); |
411 } | 417 } |
412 | 418 |
413 void WindowEventDispatcher::ReleaseNativeCapture() { | 419 void WindowEventDispatcher::ReleaseNativeCapture() { |
414 host_->ReleaseCapture(); | 420 host_->ReleaseCapture(); |
415 } | 421 } |
416 | 422 |
417 //////////////////////////////////////////////////////////////////////////////// | 423 //////////////////////////////////////////////////////////////////////////////// |
418 // WindowEventDispatcher, ui::EventProcessor implementation: | 424 // WindowEventDispatcher, ui::EventProcessor implementation: |
419 ui::EventTarget* WindowEventDispatcher::GetRootTarget() { | 425 ui::EventTarget* WindowEventDispatcher::GetRootForEvent(ui::Event* event) { |
420 return window(); | 426 if (Env::GetInstance()->mode() == Env::Mode::LOCAL) |
| 427 return window(); |
| 428 |
| 429 if (!event->target()) |
| 430 return window(); |
| 431 |
| 432 ui::EventTarget* target = event->target(); |
| 433 ui::EventTarget* ancestor_with_targeter = target; |
| 434 for (ui::EventTarget* ancestor = target->GetParentTarget(); ancestor; |
| 435 ancestor = ancestor->GetParentTarget()) { |
| 436 if (ancestor->GetEventTargeter()) |
| 437 ancestor_with_targeter = ancestor; |
| 438 if (ancestor == window()) |
| 439 break; |
| 440 } |
| 441 |
| 442 if (ancestor_with_targeter != target && event->IsLocatedEvent()) { |
| 443 gfx::Point location = event->AsLocatedEvent()->location(); |
| 444 gfx::Point root_location = event->AsLocatedEvent()->root_location(); |
| 445 Window::ConvertPointToTarget(static_cast<Window*>(target), |
| 446 static_cast<Window*>(ancestor_with_targeter), |
| 447 &location); |
| 448 Window::ConvertPointToTarget(static_cast<Window*>(target), |
| 449 static_cast<Window*>(ancestor_with_targeter), |
| 450 &root_location); |
| 451 event->AsLocatedEvent()->set_location(location); |
| 452 event->AsLocatedEvent()->set_root_location(root_location); |
| 453 } |
| 454 return ancestor_with_targeter; |
421 } | 455 } |
422 | 456 |
423 void WindowEventDispatcher::OnEventProcessingStarted(ui::Event* event) { | 457 void WindowEventDispatcher::OnEventProcessingStarted(ui::Event* event) { |
424 // The held events are already in |window()|'s coordinate system. So it is | 458 // The held events are already in |window()|'s coordinate system. So it is |
425 // not necessary to apply the transform to convert from the host's | 459 // not necessary to apply the transform to convert from the host's |
426 // coordinate system to |window()|'s coordinate system. | 460 // coordinate system to |window()|'s coordinate system. |
427 if (event->IsLocatedEvent() && !is_dispatched_held_event(*event)) | 461 if (event->IsLocatedEvent() && !is_dispatched_held_event(*event)) |
428 TransformEventForDeviceScaleFactor(static_cast<ui::LocatedEvent*>(event)); | 462 TransformEventForDeviceScaleFactor(static_cast<ui::LocatedEvent*>(event)); |
429 | 463 |
430 if (mus_mouse_location_updater_) | 464 if (mus_mouse_location_updater_) |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 } | 904 } |
871 | 905 |
872 // This flag is set depending on the gestures recognized in the call above, | 906 // This flag is set depending on the gestures recognized in the call above, |
873 // and needs to propagate with the forwarded event. | 907 // and needs to propagate with the forwarded event. |
874 event->set_may_cause_scrolling(orig_event.may_cause_scrolling()); | 908 event->set_may_cause_scrolling(orig_event.may_cause_scrolling()); |
875 | 909 |
876 return PreDispatchLocatedEvent(target, event); | 910 return PreDispatchLocatedEvent(target, event); |
877 } | 911 } |
878 | 912 |
879 } // namespace aura | 913 } // namespace aura |
OLD | NEW |