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