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" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 bool IsEventCandidateForHold(const ui::Event& event) { | 53 bool IsEventCandidateForHold(const ui::Event& event) { |
54 if (event.type() == ui::ET_TOUCH_MOVED) | 54 if (event.type() == ui::ET_TOUCH_MOVED) |
55 return true; | 55 return true; |
56 if (event.type() == ui::ET_MOUSE_DRAGGED) | 56 if (event.type() == ui::ET_MOUSE_DRAGGED) |
57 return true; | 57 return true; |
58 if (event.IsMouseEvent() && (event.flags() & ui::EF_IS_SYNTHESIZED)) | 58 if (event.IsMouseEvent() && (event.flags() & ui::EF_IS_SYNTHESIZED)) |
59 return true; | 59 return true; |
60 return false; | 60 return false; |
61 } | 61 } |
62 | 62 |
63 void ConvertEventLocationToTarget(ui::EventTarget* event_target, | |
64 ui::EventTarget* target, | |
65 ui::Event* event) { | |
66 if (target != event_target && event->IsLocatedEvent()) { | |
sadrul
2017/03/03 02:33:20
early out instead.
riajiang
2017/03/03 04:53:08
Done.
| |
67 gfx::Point location = event->AsLocatedEvent()->location(); | |
68 gfx::Point root_location = event->AsLocatedEvent()->root_location(); | |
69 Window::ConvertPointToTarget(static_cast<Window*>(event_target), | |
70 static_cast<Window*>(target), &location); | |
71 Window::ConvertPointToTarget(static_cast<Window*>(event_target), | |
72 static_cast<Window*>(target), &root_location); | |
73 event->AsLocatedEvent()->set_location(location); | |
74 event->AsLocatedEvent()->set_root_location(root_location); | |
75 } | |
76 } | |
77 | |
63 } // namespace | 78 } // namespace |
64 | 79 |
65 //////////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////////// |
66 // WindowEventDispatcher, public: | 81 // WindowEventDispatcher, public: |
67 | 82 |
68 WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host) | 83 WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host) |
69 : host_(host), | 84 : host_(host), |
70 mouse_pressed_handler_(NULL), | 85 mouse_pressed_handler_(NULL), |
71 mouse_moved_handler_(NULL), | 86 mouse_moved_handler_(NULL), |
72 event_dispatch_target_(NULL), | 87 event_dispatch_target_(NULL), |
73 old_dispatch_target_(NULL), | 88 old_dispatch_target_(NULL), |
74 synthesize_mouse_move_(false), | 89 synthesize_mouse_move_(false), |
75 move_hold_count_(0), | 90 move_hold_count_(0), |
76 dispatching_held_event_(nullptr), | 91 dispatching_held_event_(nullptr), |
77 observer_manager_(this), | 92 observer_manager_(this), |
78 env_controller_(new EnvInputStateController), | 93 env_controller_(new EnvInputStateController), |
94 event_targeter_(new WindowTargeter), | |
79 repost_event_factory_(this), | 95 repost_event_factory_(this), |
80 held_event_factory_(this) { | 96 held_event_factory_(this) { |
81 ui::GestureRecognizer::Get()->AddGestureEventHelper(this); | 97 ui::GestureRecognizer::Get()->AddGestureEventHelper(this); |
82 Env::GetInstance()->AddObserver(this); | 98 Env::GetInstance()->AddObserver(this); |
83 if (Env::GetInstance()->mode() == Env::Mode::MUS) | 99 if (Env::GetInstance()->mode() == Env::Mode::MUS) |
84 mus_mouse_location_updater_ = base::MakeUnique<MusMouseLocationUpdater>(); | 100 mus_mouse_location_updater_ = base::MakeUnique<MusMouseLocationUpdater>(); |
85 } | 101 } |
86 | 102 |
87 WindowEventDispatcher::~WindowEventDispatcher() { | 103 WindowEventDispatcher::~WindowEventDispatcher() { |
88 TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor"); | 104 TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor"); |
89 Env::GetInstance()->RemoveObserver(this); | 105 Env::GetInstance()->RemoveObserver(this); |
90 ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this); | 106 ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this); |
91 } | 107 } |
92 | 108 |
109 ui::EventTargeter* WindowEventDispatcher::GetDefaultEventTargeter() { | |
110 return event_targeter_.get(); | |
111 } | |
112 | |
93 void WindowEventDispatcher::RepostEvent(const ui::LocatedEvent* event) { | 113 void WindowEventDispatcher::RepostEvent(const ui::LocatedEvent* event) { |
94 DCHECK(event->type() == ui::ET_MOUSE_PRESSED || | 114 DCHECK(event->type() == ui::ET_MOUSE_PRESSED || |
95 event->type() == ui::ET_GESTURE_TAP_DOWN || | 115 event->type() == ui::ET_GESTURE_TAP_DOWN || |
96 event->type() == ui::ET_TOUCH_PRESSED); | 116 event->type() == ui::ET_TOUCH_PRESSED); |
97 // We allow for only one outstanding repostable event. This is used | 117 // We allow for only one outstanding repostable event. This is used |
98 // in exiting context menus. A dropped repost request is allowed. | 118 // in exiting context menus. A dropped repost request is allowed. |
99 if (event->type() == ui::ET_MOUSE_PRESSED) { | 119 if (event->type() == ui::ET_MOUSE_PRESSED) { |
100 held_repostable_event_.reset(new ui::MouseEvent( | 120 held_repostable_event_.reset(new ui::MouseEvent( |
101 *event->AsMouseEvent(), static_cast<aura::Window*>(event->target()), | 121 *event->AsMouseEvent(), static_cast<aura::Window*>(event->target()), |
102 window())); | 122 window())); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 void WindowEventDispatcher::SetNativeCapture() { | 429 void WindowEventDispatcher::SetNativeCapture() { |
410 host_->SetCapture(); | 430 host_->SetCapture(); |
411 } | 431 } |
412 | 432 |
413 void WindowEventDispatcher::ReleaseNativeCapture() { | 433 void WindowEventDispatcher::ReleaseNativeCapture() { |
414 host_->ReleaseCapture(); | 434 host_->ReleaseCapture(); |
415 } | 435 } |
416 | 436 |
417 //////////////////////////////////////////////////////////////////////////////// | 437 //////////////////////////////////////////////////////////////////////////////// |
418 // WindowEventDispatcher, ui::EventProcessor implementation: | 438 // WindowEventDispatcher, ui::EventProcessor implementation: |
419 ui::EventTarget* WindowEventDispatcher::GetRootTarget() { | 439 ui::EventTarget* WindowEventDispatcher::GetRootForEvent(ui::Event* event) { |
420 return window(); | 440 if (Env::GetInstance()->mode() == Env::Mode::LOCAL) |
441 return window(); | |
442 | |
443 if (!event->target()) | |
444 return window(); | |
445 | |
446 ui::EventTarget* event_target = event->target(); | |
447 if (event->IsLocatedEvent()) { | |
448 ui::EventTarget* target = event_targeter_->FindTargetInRootWindow( | |
449 window(), *event->AsLocatedEvent()); | |
450 if (target) { | |
451 ConvertEventLocationToTarget(event_target, target, event); | |
452 return target; | |
453 } | |
454 } | |
455 | |
456 ui::EventTarget* ancestor_with_targeter = event_target; | |
457 for (ui::EventTarget* ancestor = event_target->GetParentTarget(); ancestor; | |
458 ancestor = ancestor->GetParentTarget()) { | |
459 if (ancestor->GetEventTargeter()) | |
460 ancestor_with_targeter = ancestor; | |
461 if (ancestor == window()) | |
462 break; | |
463 } | |
464 ConvertEventLocationToTarget(event_target, ancestor_with_targeter, event); | |
465 return ancestor_with_targeter; | |
421 } | 466 } |
422 | 467 |
423 void WindowEventDispatcher::OnEventProcessingStarted(ui::Event* event) { | 468 void WindowEventDispatcher::OnEventProcessingStarted(ui::Event* event) { |
424 // The held events are already in |window()|'s coordinate system. So it is | 469 // 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 | 470 // not necessary to apply the transform to convert from the host's |
426 // coordinate system to |window()|'s coordinate system. | 471 // coordinate system to |window()|'s coordinate system. |
427 if (event->IsLocatedEvent() && !is_dispatched_held_event(*event)) | 472 if (event->IsLocatedEvent() && !is_dispatched_held_event(*event)) |
428 TransformEventForDeviceScaleFactor(static_cast<ui::LocatedEvent*>(event)); | 473 TransformEventForDeviceScaleFactor(static_cast<ui::LocatedEvent*>(event)); |
429 | 474 |
430 if (mus_mouse_location_updater_) | 475 if (mus_mouse_location_updater_) |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
870 } | 915 } |
871 | 916 |
872 // This flag is set depending on the gestures recognized in the call above, | 917 // This flag is set depending on the gestures recognized in the call above, |
873 // and needs to propagate with the forwarded event. | 918 // and needs to propagate with the forwarded event. |
874 event->set_may_cause_scrolling(orig_event.may_cause_scrolling()); | 919 event->set_may_cause_scrolling(orig_event.may_cause_scrolling()); |
875 | 920 |
876 return PreDispatchLocatedEvent(target, event); | 921 return PreDispatchLocatedEvent(target, event); |
877 } | 922 } |
878 | 923 |
879 } // namespace aura | 924 } // namespace aura |
OLD | NEW |