| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/aura/mus/mus_mouse_location_updater.h" |
| 6 |
| 7 #include "ui/aura/env.h" |
| 8 #include "ui/events/event.h" |
| 9 |
| 10 namespace aura { |
| 11 namespace { |
| 12 |
| 13 bool IsMouseEventWithLocation(const ui::Event& event) { |
| 14 // All mouse events except exited, capture, and wheel which mus doesn't |
| 15 // include locations for. |
| 16 switch (event.type()) { |
| 17 case ui::ET_MOUSE_PRESSED: |
| 18 case ui::ET_MOUSE_DRAGGED: |
| 19 case ui::ET_MOUSE_RELEASED: |
| 20 case ui::ET_MOUSE_MOVED: |
| 21 case ui::ET_MOUSE_ENTERED: |
| 22 return true; |
| 23 default: |
| 24 break; |
| 25 } |
| 26 return false; |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
| 31 MusMouseLocationUpdater::MusMouseLocationUpdater() { |
| 32 base::MessageLoop::current()->AddNestingObserver(this); |
| 33 } |
| 34 |
| 35 MusMouseLocationUpdater::~MusMouseLocationUpdater() { |
| 36 base::MessageLoop::current()->RemoveNestingObserver(this); |
| 37 } |
| 38 |
| 39 void MusMouseLocationUpdater::OnEventProcessingStarted(const ui::Event& event) { |
| 40 if (!IsMouseEventWithLocation(event) || |
| 41 Env::GetInstance()->always_use_last_mouse_location_) { |
| 42 return; |
| 43 } |
| 44 |
| 45 is_processing_trigger_event_ = true; |
| 46 Env::GetInstance()->set_last_mouse_location( |
| 47 event.AsMouseEvent()->root_location()); |
| 48 Env::GetInstance()->get_last_mouse_location_from_mus_ = false; |
| 49 } |
| 50 |
| 51 void MusMouseLocationUpdater::OnEventProcessingFinished() { |
| 52 UseCursorScreenPoint(); |
| 53 } |
| 54 |
| 55 void MusMouseLocationUpdater::UseCursorScreenPoint() { |
| 56 if (!is_processing_trigger_event_) |
| 57 return; |
| 58 |
| 59 is_processing_trigger_event_ = false; |
| 60 Env::GetInstance()->get_last_mouse_location_from_mus_ = true; |
| 61 } |
| 62 |
| 63 void MusMouseLocationUpdater::OnBeginNestedMessageLoop() { |
| 64 UseCursorScreenPoint(); |
| 65 } |
| 66 |
| 67 } // namespace aura |
| OLD | NEW |