| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host) | 84 WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host) |
| 85 : host_(host), | 85 : host_(host), |
| 86 mouse_pressed_handler_(NULL), | 86 mouse_pressed_handler_(NULL), |
| 87 mouse_moved_handler_(NULL), | 87 mouse_moved_handler_(NULL), |
| 88 event_dispatch_target_(NULL), | 88 event_dispatch_target_(NULL), |
| 89 old_dispatch_target_(NULL), | 89 old_dispatch_target_(NULL), |
| 90 synthesize_mouse_move_(false), | 90 synthesize_mouse_move_(false), |
| 91 move_hold_count_(0), | 91 move_hold_count_(0), |
| 92 dispatching_held_event_(nullptr), | 92 dispatching_held_event_(nullptr), |
| 93 observer_manager_(this), | 93 observer_manager_(this), |
| 94 env_controller_(new EnvInputStateController), | |
| 95 event_targeter_(new WindowTargeter), | 94 event_targeter_(new WindowTargeter), |
| 96 repost_event_factory_(this), | 95 repost_event_factory_(this), |
| 97 held_event_factory_(this) { | 96 held_event_factory_(this) { |
| 98 ui::GestureRecognizer::Get()->AddGestureEventHelper(this); | 97 ui::GestureRecognizer::Get()->AddGestureEventHelper(this); |
| 99 Env::GetInstance()->AddObserver(this); | 98 Env::GetInstance()->AddObserver(this); |
| 100 if (Env::GetInstance()->mode() == Env::Mode::MUS) | 99 if (Env::GetInstance()->mode() == Env::Mode::MUS) |
| 101 mus_mouse_location_updater_ = base::MakeUnique<MusMouseLocationUpdater>(); | 100 mus_mouse_location_updater_ = base::MakeUnique<MusMouseLocationUpdater>(); |
| 102 } | 101 } |
| 103 | 102 |
| 104 WindowEventDispatcher::~WindowEventDispatcher() { | 103 WindowEventDispatcher::~WindowEventDispatcher() { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 return location; | 222 return location; |
| 224 } | 223 } |
| 225 | 224 |
| 226 void WindowEventDispatcher::OnHostLostMouseGrab() { | 225 void WindowEventDispatcher::OnHostLostMouseGrab() { |
| 227 mouse_pressed_handler_ = NULL; | 226 mouse_pressed_handler_ = NULL; |
| 228 mouse_moved_handler_ = NULL; | 227 mouse_moved_handler_ = NULL; |
| 229 } | 228 } |
| 230 | 229 |
| 231 void WindowEventDispatcher::OnCursorMovedToRootLocation( | 230 void WindowEventDispatcher::OnCursorMovedToRootLocation( |
| 232 const gfx::Point& root_location) { | 231 const gfx::Point& root_location) { |
| 233 env_controller_->SetLastMouseLocation(window(), root_location); | 232 Env::GetInstance()->env_controller()->SetLastMouseLocation(window(), |
| 233 root_location); |
| 234 | 234 |
| 235 // Synthesize a mouse move in case the cursor's location in root coordinates | 235 // Synthesize a mouse move in case the cursor's location in root coordinates |
| 236 // changed but its position in WindowTreeHost coordinates did not. | 236 // changed but its position in WindowTreeHost coordinates did not. |
| 237 PostSynthesizeMouseMove(); | 237 PostSynthesizeMouseMove(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void WindowEventDispatcher::OnPostNotifiedWindowDestroying(Window* window) { | 240 void WindowEventDispatcher::OnPostNotifiedWindowDestroying(Window* window) { |
| 241 OnWindowHidden(window, WINDOW_DESTROYED); | 241 OnWindowHidden(window, WINDOW_DESTROYED); |
| 242 } | 242 } |
| 243 | 243 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 270 DispatchMouseExitAtPoint(this->window(), last_mouse_location); | 270 DispatchMouseExitAtPoint(this->window(), last_mouse_location); |
| 271 if (details.dispatcher_destroyed) | 271 if (details.dispatcher_destroyed) |
| 272 return; | 272 return; |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| 276 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( | 276 ui::EventDispatchDetails WindowEventDispatcher::DispatchMouseEnterOrExit( |
| 277 Window* target, | 277 Window* target, |
| 278 const ui::MouseEvent& event, | 278 const ui::MouseEvent& event, |
| 279 ui::EventType type) { | 279 ui::EventType type) { |
| 280 env_controller_->UpdateStateForMouseEvent(window(), event); | 280 Env::GetInstance()->env_controller()->UpdateStateForMouseEvent(window(), |
| 281 event); |
| 281 if (!mouse_moved_handler_ || !mouse_moved_handler_->delegate() || | 282 if (!mouse_moved_handler_ || !mouse_moved_handler_->delegate() || |
| 282 !window()->Contains(mouse_moved_handler_)) | 283 !window()->Contains(mouse_moved_handler_)) |
| 283 return DispatchDetails(); | 284 return DispatchDetails(); |
| 284 | 285 |
| 285 // |event| may be an event in the process of being dispatched to a target (in | 286 // |event| may be an event in the process of being dispatched to a target (in |
| 286 // which case its locations will be in the event's target's coordinate | 287 // which case its locations will be in the event's target's coordinate |
| 287 // system), or a synthetic event created in root-window (in which case, the | 288 // system), or a synthetic event created in root-window (in which case, the |
| 288 // event's target will be NULL, and the event will be in the root-window's | 289 // event's target will be NULL, and the event will be in the root-window's |
| 289 // coordinate system. | 290 // coordinate system. |
| 290 if (!target) | 291 if (!target) |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 // disabled. This ensures that hover state, etc on controls like buttons is | 807 // disabled. This ensures that hover state, etc on controls like buttons is |
| 807 // cleared. | 808 // cleared. |
| 808 if (cursor_client && | 809 if (cursor_client && |
| 809 !cursor_client->IsMouseEventsEnabled() && | 810 !cursor_client->IsMouseEventsEnabled() && |
| 810 (event->flags() & ui::EF_IS_SYNTHESIZED) && | 811 (event->flags() & ui::EF_IS_SYNTHESIZED) && |
| 811 (event->type() != ui::ET_MOUSE_EXITED)) { | 812 (event->type() != ui::ET_MOUSE_EXITED)) { |
| 812 event->SetHandled(); | 813 event->SetHandled(); |
| 813 return DispatchDetails(); | 814 return DispatchDetails(); |
| 814 } | 815 } |
| 815 | 816 |
| 816 env_controller_->UpdateStateForMouseEvent(window(), *event); | 817 Env::GetInstance()->env_controller()->UpdateStateForMouseEvent(window(), |
| 818 *event); |
| 817 | 819 |
| 818 if (IsEventCandidateForHold(*event) && !dispatching_held_event_) { | 820 if (IsEventCandidateForHold(*event) && !dispatching_held_event_) { |
| 819 if (move_hold_count_) { | 821 if (move_hold_count_) { |
| 820 held_move_event_.reset(new ui::MouseEvent(*event, target, window())); | 822 held_move_event_.reset(new ui::MouseEvent(*event, target, window())); |
| 821 event->SetHandled(); | 823 event->SetHandled(); |
| 822 return DispatchDetails(); | 824 return DispatchDetails(); |
| 823 } else { | 825 } else { |
| 824 // We may have a held event for a period between the time move_hold_count_ | 826 // We may have a held event for a period between the time move_hold_count_ |
| 825 // fell to 0 and the DispatchHeldEvents executes. Since we're going to | 827 // fell to 0 and the DispatchHeldEvents executes. Since we're going to |
| 826 // dispatch the new event directly below, we can reset the old one. | 828 // dispatch the new event directly below, we can reset the old one. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 DispatchDetails WindowEventDispatcher::PreDispatchTouchEvent( | 904 DispatchDetails WindowEventDispatcher::PreDispatchTouchEvent( |
| 903 Window* target, | 905 Window* target, |
| 904 ui::TouchEvent* event) { | 906 ui::TouchEvent* event) { |
| 905 if (event->type() == ui::ET_TOUCH_MOVED && move_hold_count_ && | 907 if (event->type() == ui::ET_TOUCH_MOVED && move_hold_count_ && |
| 906 !dispatching_held_event_) { | 908 !dispatching_held_event_) { |
| 907 held_move_event_.reset(new ui::TouchEvent(*event, target, window())); | 909 held_move_event_.reset(new ui::TouchEvent(*event, target, window())); |
| 908 event->SetHandled(); | 910 event->SetHandled(); |
| 909 return DispatchDetails(); | 911 return DispatchDetails(); |
| 910 } | 912 } |
| 911 | 913 |
| 912 env_controller_->UpdateStateForTouchEvent(*event); | 914 Env::GetInstance()->env_controller()->UpdateStateForTouchEvent(*event); |
| 913 | 915 |
| 914 ui::TouchEvent orig_event(*event, target, window()); | 916 ui::TouchEvent orig_event(*event, target, window()); |
| 915 if (!ui::GestureRecognizer::Get()->ProcessTouchEventPreDispatch(&orig_event, | 917 if (!ui::GestureRecognizer::Get()->ProcessTouchEventPreDispatch(&orig_event, |
| 916 target)) { | 918 target)) { |
| 917 // The event is invalid - ignore it. | 919 // The event is invalid - ignore it. |
| 918 event->StopPropagation(); | 920 event->StopPropagation(); |
| 919 event->DisableSynchronousHandling(); | 921 event->DisableSynchronousHandling(); |
| 920 return DispatchDetails(); | 922 return DispatchDetails(); |
| 921 } | 923 } |
| 922 | 924 |
| 923 // This flag is set depending on the gestures recognized in the call above, | 925 // This flag is set depending on the gestures recognized in the call above, |
| 924 // and needs to propagate with the forwarded event. | 926 // and needs to propagate with the forwarded event. |
| 925 event->set_may_cause_scrolling(orig_event.may_cause_scrolling()); | 927 event->set_may_cause_scrolling(orig_event.may_cause_scrolling()); |
| 926 | 928 |
| 927 return PreDispatchLocatedEvent(target, event); | 929 return PreDispatchLocatedEvent(target, event); |
| 928 } | 930 } |
| 929 | 931 |
| 930 } // namespace aura | 932 } // namespace aura |
| OLD | NEW |