| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef ASH_WM_USER_ACTIVITY_DETECTOR_H_ | 5 #ifndef ASH_WM_USER_ACTIVITY_DETECTOR_H_ |
| 6 #define ASH_WM_USER_ACTIVITY_DETECTOR_H_ | 6 #define ASH_WM_USER_ACTIVITY_DETECTOR_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "ui/base/events/event_handler.h" | 13 #include "ui/base/events/event_handler.h" |
| 14 | 14 |
| 15 namespace ash { | 15 namespace ash { |
| 16 | 16 |
| 17 class UserActivityObserver; | 17 class UserActivityObserver; |
| 18 | 18 |
| 19 // Watches for input events and notifies observers that the user is active. | 19 // Watches for input events and notifies observers that the user is active. |
| 20 class ASH_EXPORT UserActivityDetector : public ui::EventHandler { | 20 class ASH_EXPORT UserActivityDetector : public ui::EventHandler { |
| 21 public: | 21 public: |
| 22 // Minimum amount of time between notifications to observers. | 22 // Minimum amount of time between notifications to observers. |
| 23 static const double kNotifyIntervalMs; | 23 static const int kNotifyIntervalMs; |
| 24 |
| 25 // Amount of time that mouse events should be ignored after notification |
| 26 // is received that displays' power states are being changed. |
| 27 static const int kDisplayPowerChangeIgnoreMouseMs; |
| 24 | 28 |
| 25 UserActivityDetector(); | 29 UserActivityDetector(); |
| 26 virtual ~UserActivityDetector(); | 30 virtual ~UserActivityDetector(); |
| 27 | 31 |
| 28 void set_now_for_test(base::TimeTicks now) { now_for_test_ = now; } | 32 void set_now_for_test(base::TimeTicks now) { now_for_test_ = now; } |
| 29 | 33 |
| 30 bool HasObserver(UserActivityObserver* observer) const; | 34 bool HasObserver(UserActivityObserver* observer) const; |
| 31 void AddObserver(UserActivityObserver* observer); | 35 void AddObserver(UserActivityObserver* observer); |
| 32 void RemoveObserver(UserActivityObserver* observer); | 36 void RemoveObserver(UserActivityObserver* observer); |
| 33 | 37 |
| 34 // Called when chrome has received a request to turn of all displays. | 38 // Called when displays are about to be turned on or off. |
| 35 void OnAllOutputsTurnedOff(); | 39 void OnDisplayPowerChanging(); |
| 36 | 40 |
| 37 // ui::EventHandler implementation. | 41 // ui::EventHandler implementation. |
| 38 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | 42 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
| 39 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; | 43 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
| 40 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; | 44 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; |
| 41 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; | 45 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; |
| 42 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 46 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
| 43 | 47 |
| 44 private: | 48 private: |
| 49 // Returns |now_for_test_| if set or base::TimeTicks::Now() otherwise. |
| 50 base::TimeTicks GetCurrentTime() const; |
| 51 |
| 45 // Notifies observers if enough time has passed since the last notification. | 52 // Notifies observers if enough time has passed since the last notification. |
| 46 void MaybeNotify(); | 53 void MaybeNotify(); |
| 47 | 54 |
| 48 ObserverList<UserActivityObserver> observers_; | 55 ObserverList<UserActivityObserver> observers_; |
| 49 | 56 |
| 50 // Last time at which we notified observers that the user was active. | 57 // Last time at which we notified observers that the user was active. |
| 51 base::TimeTicks last_observer_notification_time_; | 58 base::TimeTicks last_observer_notification_time_; |
| 52 | 59 |
| 53 // If set, used when the current time is needed. This can be set by tests to | 60 // If set, used when the current time is needed. This can be set by tests to |
| 54 // simulate the passage of time. | 61 // simulate the passage of time. |
| 55 base::TimeTicks now_for_test_; | 62 base::TimeTicks now_for_test_; |
| 56 | 63 |
| 57 // When this is true, the next mouse event is ignored. This is to | 64 // If set, mouse events will be ignored until this time is reached. This |
| 58 // avoid mis-detecting a mouse enter event that occurs when turning | 65 // is to avoid reporting mouse events that occur when displays are turned |
| 59 // off display as a user activity. | 66 // on or off as user activity. |
| 60 bool ignore_next_mouse_event_; | 67 base::TimeTicks honor_mouse_events_time_; |
| 61 | 68 |
| 62 DISALLOW_COPY_AND_ASSIGN(UserActivityDetector); | 69 DISALLOW_COPY_AND_ASSIGN(UserActivityDetector); |
| 63 }; | 70 }; |
| 64 | 71 |
| 65 } // namespace ash | 72 } // namespace ash |
| 66 | 73 |
| 67 #endif // ASH_WM_USER_ACTIVITY_DETECTOR_H_ | 74 #endif // ASH_WM_USER_ACTIVITY_DETECTOR_H_ |
| OLD | NEW |