Chromium Code Reviews| 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 | |
| 33 MusMouseLocationUpdater::~MusMouseLocationUpdater() { | |
| 34 // Should never be destroyed while in the middle of processing an event. | |
| 35 DCHECK(!observing_message_loop_); | |
| 36 } | |
| 37 | |
| 38 void MusMouseLocationUpdater::OnEventProcessingStarted(const ui::Event& event) { | |
| 39 // Should never process an event while processing another event, unless | |
| 40 // a nested message loop is spun, which sets |observing_message_loop_| to | |
| 41 // false. | |
| 42 DCHECK(!observing_message_loop_); | |
| 43 | |
| 44 if (!IsMouseEventWithLocation(event)) | |
| 45 return; | |
| 46 | |
| 47 Env::GetInstance()->set_last_mouse_location( | |
| 48 event.AsMouseEvent()->root_location()); | |
| 49 Env::GetInstance()->get_last_mouse_location_from_mus_ = false; | |
|
sadrul
2017/01/27 21:08:36
Maybe call this |last_mouse_location_is_valid_| (a
| |
| 50 observing_message_loop_ = true; | |
| 51 base::MessageLoop::current()->AddNestingObserver(this); | |
|
sadrul
2017/01/27 21:08:36
Is it better to just leave it always added as a ne
| |
| 52 } | |
| 53 | |
| 54 void MusMouseLocationUpdater::OnEventProcessingFinished() { | |
| 55 if (!observing_message_loop_) | |
| 56 return; | |
| 57 | |
| 58 StopObserving(); | |
| 59 } | |
| 60 | |
| 61 void MusMouseLocationUpdater::StopObserving() { | |
| 62 DCHECK(observing_message_loop_); | |
| 63 observing_message_loop_ = false; | |
| 64 base::MessageLoop::current()->RemoveNestingObserver(this); | |
| 65 Env::GetInstance()->get_last_mouse_location_from_mus_ = true; | |
| 66 } | |
| 67 | |
| 68 void MusMouseLocationUpdater::OnBeginNestedMessageLoop() { | |
| 69 StopObserving(); | |
| 70 } | |
| 71 | |
| 72 } // namespace aura | |
| OLD | NEW |