OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 UI_WM_CORE_USER_ACTIVITY_DETECTOR_H_ | 5 #ifndef UI_WM_CORE_USER_ACTIVITY_DETECTOR_H_ |
6 #define UI_WM_CORE_USER_ACTIVITY_DETECTOR_H_ | 6 #define UI_WM_CORE_USER_ACTIVITY_DETECTOR_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "ui/events/event_handler.h" | 12 #include "ui/events/event_handler.h" |
13 #include "ui/wm/wm_export.h" | 13 #include "ui/wm/wm_export.h" |
14 | 14 |
15 namespace wm { | 15 namespace wm { |
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 WM_EXPORT UserActivityDetector : public ui::EventHandler { | 20 class WM_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 int kNotifyIntervalMs; | 23 static const int kNotifyIntervalMs; |
24 | 24 |
25 // Amount of time that mouse events should be ignored after notification | 25 // Amount of time that mouse events should be ignored after notification |
26 // is received that displays' power states are being changed. | 26 // is received that displays' power states are being changed. |
27 static const int kDisplayPowerChangeIgnoreMouseMs; | 27 static const int kDisplayPowerChangeIgnoreMouseMs; |
28 | 28 |
29 UserActivityDetector(); | 29 // Creates a UserActivityDetector instance. |
30 ~UserActivityDetector() override; | 30 static void Create(); |
31 | |
32 // Deletes the UserActivityDetector instance. | |
33 static void Shutdown(); | |
oshima
2014/10/31 16:53:31
Can you keep ctor/dtor, and creation in shell. Jus
pkotwicz
2014/10/31 16:58:29
For the sake of interest, which other classes have
| |
34 | |
35 // Returns the UserActivityDetector instance if one was created. | |
36 static UserActivityDetector* Get(); | |
31 | 37 |
32 base::TimeTicks last_activity_time() const { return last_activity_time_; } | 38 base::TimeTicks last_activity_time() const { return last_activity_time_; } |
33 | 39 |
34 void set_now_for_test(base::TimeTicks now) { now_for_test_ = now; } | 40 void set_now_for_test(base::TimeTicks now) { now_for_test_ = now; } |
35 | 41 |
36 bool HasObserver(UserActivityObserver* observer) const; | 42 bool HasObserver(UserActivityObserver* observer) const; |
37 void AddObserver(UserActivityObserver* observer); | 43 void AddObserver(UserActivityObserver* observer); |
38 void RemoveObserver(UserActivityObserver* observer); | 44 void RemoveObserver(UserActivityObserver* observer); |
39 | 45 |
40 // Called when displays are about to be turned on or off. | 46 // Called when displays are about to be turned on or off. |
41 void OnDisplayPowerChanging(); | 47 void OnDisplayPowerChanging(); |
42 | 48 |
43 // ui::EventHandler implementation. | 49 // ui::EventHandler implementation. |
44 void OnKeyEvent(ui::KeyEvent* event) override; | 50 void OnKeyEvent(ui::KeyEvent* event) override; |
45 void OnMouseEvent(ui::MouseEvent* event) override; | 51 void OnMouseEvent(ui::MouseEvent* event) override; |
46 void OnScrollEvent(ui::ScrollEvent* event) override; | 52 void OnScrollEvent(ui::ScrollEvent* event) override; |
47 void OnTouchEvent(ui::TouchEvent* event) override; | 53 void OnTouchEvent(ui::TouchEvent* event) override; |
48 void OnGestureEvent(ui::GestureEvent* event) override; | 54 void OnGestureEvent(ui::GestureEvent* event) override; |
49 | 55 |
50 private: | 56 private: |
57 UserActivityDetector(); | |
58 ~UserActivityDetector() override; | |
59 | |
51 // Returns |now_for_test_| if set or base::TimeTicks::Now() otherwise. | 60 // Returns |now_for_test_| if set or base::TimeTicks::Now() otherwise. |
52 base::TimeTicks GetCurrentTime() const; | 61 base::TimeTicks GetCurrentTime() const; |
53 | 62 |
54 // Updates |last_activity_time_|. Additionally notifies observers and | 63 // Updates |last_activity_time_|. Additionally notifies observers and |
55 // updates |last_observer_notification_time_| if enough time has passed | 64 // updates |last_observer_notification_time_| if enough time has passed |
56 // since the last notification. | 65 // since the last notification. |
57 void HandleActivity(const ui::Event* event); | 66 void HandleActivity(const ui::Event* event); |
58 | 67 |
59 ObserverList<UserActivityObserver> observers_; | 68 ObserverList<UserActivityObserver> observers_; |
60 | 69 |
(...skipping 11 matching lines...) Expand all Loading... | |
72 // is to avoid reporting mouse events that occur when displays are turned | 81 // is to avoid reporting mouse events that occur when displays are turned |
73 // on or off as user activity. | 82 // on or off as user activity. |
74 base::TimeTicks honor_mouse_events_time_; | 83 base::TimeTicks honor_mouse_events_time_; |
75 | 84 |
76 DISALLOW_COPY_AND_ASSIGN(UserActivityDetector); | 85 DISALLOW_COPY_AND_ASSIGN(UserActivityDetector); |
77 }; | 86 }; |
78 | 87 |
79 } // namespace wm | 88 } // namespace wm |
80 | 89 |
81 #endif // UI_WM_CORE_USER_ACTIVITY_DETECTOR_H_ | 90 #endif // UI_WM_CORE_USER_ACTIVITY_DETECTOR_H_ |
OLD | NEW |