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