Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: ui/wm/core/user_activity_detector.h

Issue 833893003: Move UserActivityDetector to ui/base/user_activity/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: don't build test on android Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/wm/BUILD.gn ('k') | ui/wm/core/user_activity_detector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef UI_WM_CORE_USER_ACTIVITY_DETECTOR_H_
6 #define UI_WM_CORE_USER_ACTIVITY_DETECTOR_H_
7
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"
14
15 namespace wm {
16
17 class UserActivityObserver;
18
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;
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;
28
29 UserActivityDetector();
30 ~UserActivityDetector() override;
31
32 // Returns the UserActivityDetector instance if one was created.
33 static UserActivityDetector* Get();
34
35 base::TimeTicks last_activity_time() const { return last_activity_time_; }
36
37 void set_now_for_test(base::TimeTicks now) { now_for_test_ = now; }
38
39 bool HasObserver(const UserActivityObserver* observer) const;
40 void AddObserver(UserActivityObserver* observer);
41 void RemoveObserver(UserActivityObserver* observer);
42
43 // Called when displays are about to be turned on or off.
44 void OnDisplayPowerChanging();
45
46 // ui::EventHandler implementation.
47 void OnKeyEvent(ui::KeyEvent* event) override;
48 void OnMouseEvent(ui::MouseEvent* event) override;
49 void OnScrollEvent(ui::ScrollEvent* event) override;
50 void OnTouchEvent(ui::TouchEvent* event) override;
51 void OnGestureEvent(ui::GestureEvent* event) override;
52
53 private:
54 // Returns |now_for_test_| if set or base::TimeTicks::Now() otherwise.
55 base::TimeTicks GetCurrentTime() const;
56
57 // Updates |last_activity_time_|. Additionally notifies observers and
58 // updates |last_observer_notification_time_| if enough time has passed
59 // since the last notification.
60 void HandleActivity(const ui::Event* event);
61
62 ObserverList<UserActivityObserver> observers_;
63
64 // Last time at which user activity was observed.
65 base::TimeTicks last_activity_time_;
66
67 // Last time at which we notified observers that the user was active.
68 base::TimeTicks last_observer_notification_time_;
69
70 // If set, used when the current time is needed. This can be set by tests to
71 // simulate the passage of time.
72 base::TimeTicks now_for_test_;
73
74 // If set, mouse events will be ignored until this time is reached. This
75 // is to avoid reporting mouse events that occur when displays are turned
76 // on or off as user activity.
77 base::TimeTicks honor_mouse_events_time_;
78
79 DISALLOW_COPY_AND_ASSIGN(UserActivityDetector);
80 };
81
82 } // namespace wm
83
84 #endif // UI_WM_CORE_USER_ACTIVITY_DETECTOR_H_
OLDNEW
« no previous file with comments | « ui/wm/BUILD.gn ('k') | ui/wm/core/user_activity_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698