| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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 "ash/wm/user_activity_detector.h" |
| 6 |
| 7 #include "ash/wm/user_activity_observer.h" |
| 8 |
| 9 namespace ash { |
| 10 |
| 11 const double UserActivityDetector::kNotifyIntervalSec = 1.0; |
| 12 |
| 13 UserActivityDetector::UserActivityDetector() { |
| 14 } |
| 15 |
| 16 UserActivityDetector::~UserActivityDetector() { |
| 17 } |
| 18 |
| 19 void UserActivityDetector::AddObserver(UserActivityObserver* observer) { |
| 20 observers_.AddObserver(observer); |
| 21 } |
| 22 |
| 23 void UserActivityDetector::RemoveObserver(UserActivityObserver* observer) { |
| 24 observers_.RemoveObserver(observer); |
| 25 } |
| 26 |
| 27 bool UserActivityDetector::PreHandleKeyEvent(aura::Window* target, |
| 28 aura::KeyEvent* event) { |
| 29 MaybeNotify(); |
| 30 return false; |
| 31 } |
| 32 |
| 33 bool UserActivityDetector::PreHandleMouseEvent(aura::Window* target, |
| 34 aura::MouseEvent* event) { |
| 35 MaybeNotify(); |
| 36 return false; |
| 37 } |
| 38 |
| 39 ui::TouchStatus UserActivityDetector::PreHandleTouchEvent( |
| 40 aura::Window* target, |
| 41 aura::TouchEvent* event) { |
| 42 MaybeNotify(); |
| 43 return ui::TOUCH_STATUS_UNKNOWN; |
| 44 } |
| 45 |
| 46 ui::GestureStatus UserActivityDetector::PreHandleGestureEvent( |
| 47 aura::Window* target, |
| 48 aura::GestureEvent* event) { |
| 49 MaybeNotify(); |
| 50 return ui::GESTURE_STATUS_UNKNOWN; |
| 51 } |
| 52 |
| 53 void UserActivityDetector::MaybeNotify() { |
| 54 base::TimeTicks now = base::TimeTicks::Now(); |
| 55 if (last_observer_notification_time_.is_null() || |
| 56 (now - last_observer_notification_time_).InSecondsF() >= |
| 57 kNotifyIntervalSec) { |
| 58 FOR_EACH_OBSERVER(UserActivityObserver, observers_, OnUserActivity()); |
| 59 last_observer_notification_time_ = now; |
| 60 } |
| 61 } |
| 62 |
| 63 } // namespace ash |
| OLD | NEW |