Roll src/third_party/skia b14e4a0:3c29c4d
[chromium-blink-merge.git] / ui / wm / core / user_activity_detector.h
blob851f07ac325d7323791f3564ed8622c41260ca0a
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
3 // found in the LICENSE file.
5 #ifndef UI_WM_CORE_USER_ACTIVITY_DETECTOR_H_
6 #define UI_WM_CORE_USER_ACTIVITY_DETECTOR_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/observer_list.h"
11 #include "base/time/time.h"
12 #include "ui/events/event_handler.h"
13 #include "ui/wm/wm_export.h"
15 namespace wm {
17 class UserActivityObserver;
19 // Watches for input events and notifies observers that the user is active.
20 class WM_EXPORT UserActivityDetector : public ui::EventHandler {
21 public:
22 // Minimum amount of time between notifications to observers.
23 static const int kNotifyIntervalMs;
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;
29 UserActivityDetector();
30 virtual ~UserActivityDetector();
32 base::TimeTicks last_activity_time() const { return last_activity_time_; }
34 void set_now_for_test(base::TimeTicks now) { now_for_test_ = now; }
36 bool HasObserver(UserActivityObserver* observer) const;
37 void AddObserver(UserActivityObserver* observer);
38 void RemoveObserver(UserActivityObserver* observer);
40 // Called when displays are about to be turned on or off.
41 void OnDisplayPowerChanging();
43 // ui::EventHandler implementation.
44 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
45 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
46 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
47 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
48 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
50 private:
51 // Returns |now_for_test_| if set or base::TimeTicks::Now() otherwise.
52 base::TimeTicks GetCurrentTime() const;
54 // Updates |last_activity_time_|. Additionally notifies observers and
55 // updates |last_observer_notification_time_| if enough time has passed
56 // since the last notification.
57 void HandleActivity(const ui::Event* event);
59 ObserverList<UserActivityObserver> observers_;
61 // Last time at which user activity was observed.
62 base::TimeTicks last_activity_time_;
64 // Last time at which we notified observers that the user was active.
65 base::TimeTicks last_observer_notification_time_;
67 // If set, used when the current time is needed. This can be set by tests to
68 // simulate the passage of time.
69 base::TimeTicks now_for_test_;
71 // If set, mouse events will be ignored until this time is reached. This
72 // is to avoid reporting mouse events that occur when displays are turned
73 // on or off as user activity.
74 base::TimeTicks honor_mouse_events_time_;
76 DISALLOW_COPY_AND_ASSIGN(UserActivityDetector);
79 } // namespace wm
81 #endif // UI_WM_CORE_USER_ACTIVITY_DETECTOR_H_