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

Side by Side Diff: ui/base/user_activity/user_activity_detector.h

Issue 1016173002: Revert of Fix for menus blocking user activity detection (Retry). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
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_BASE_USER_ACTIVITY_USER_ACTIVITY_DETECTOR_H_ 5 #ifndef UI_BASE_USER_ACTIVITY_USER_ACTIVITY_DETECTOR_H_
6 #define UI_BASE_USER_ACTIVITY_USER_ACTIVITY_DETECTOR_H_ 6 #define UI_BASE_USER_ACTIVITY_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/base/ui_base_export.h" 12 #include "ui/base/ui_base_export.h"
13 #include "ui/events/event.h" 13 #include "ui/events/event_handler.h"
14 #include "ui/events/platform/platform_event_observer.h"
15 14
16 namespace ui { 15 namespace ui {
17 16
18 class UserActivityObserver; 17 class UserActivityObserver;
19 18
20 // 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.
21 class UI_BASE_EXPORT UserActivityDetector : public ui::PlatformEventObserver { 20 class UI_BASE_EXPORT UserActivityDetector : public ui::EventHandler {
22 public: 21 public:
23 // Minimum amount of time between notifications to observers. 22 // Minimum amount of time between notifications to observers.
24 static const int kNotifyIntervalMs; 23 static const int kNotifyIntervalMs;
25 24
26 // Amount of time that mouse events should be ignored after notification 25 // Amount of time that mouse events should be ignored after notification
27 // is received that displays' power states are being changed. 26 // is received that displays' power states are being changed.
28 static const int kDisplayPowerChangeIgnoreMouseMs; 27 static const int kDisplayPowerChangeIgnoreMouseMs;
29 28
30 UserActivityDetector(); 29 UserActivityDetector();
31 ~UserActivityDetector() override; 30 ~UserActivityDetector() override;
32 31
33 // Returns the UserActivityDetector instance if one was created. 32 // Returns the UserActivityDetector instance if one was created.
34 static UserActivityDetector* Get(); 33 static UserActivityDetector* Get();
35 34
36 base::TimeTicks last_activity_time() const { return last_activity_time_; } 35 base::TimeTicks last_activity_time() const { return last_activity_time_; }
37 36
38 void set_now_for_test(base::TimeTicks now) { now_for_test_ = now; } 37 void set_now_for_test(base::TimeTicks now) { now_for_test_ = now; }
39 38
40 bool HasObserver(const UserActivityObserver* observer) const; 39 bool HasObserver(const UserActivityObserver* observer) const;
41 void AddObserver(UserActivityObserver* observer); 40 void AddObserver(UserActivityObserver* observer);
42 void RemoveObserver(UserActivityObserver* observer); 41 void RemoveObserver(UserActivityObserver* observer);
43 42
44 // Called when displays are about to be turned on or off. 43 // Called when displays are about to be turned on or off.
45 void OnDisplayPowerChanging(); 44 void OnDisplayPowerChanging();
46 45
47 // ui::PlatformEventObserver: 46 // ui::EventHandler implementation.
48 void WillProcessEvent(const PlatformEvent& platform_event) override; 47 void OnKeyEvent(ui::KeyEvent* event) override;
49 void DidProcessEvent(const PlatformEvent& platform_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;
50 52
51 private: 53 private:
52 friend class UserActivityDetectorTest;
53
54 // Returns |now_for_test_| if set or base::TimeTicks::Now() otherwise. 54 // Returns |now_for_test_| if set or base::TimeTicks::Now() otherwise.
55 base::TimeTicks GetCurrentTime() const; 55 base::TimeTicks GetCurrentTime() const;
56 56
57 // Processes the event after it has been converted from a PlatformEvent.
58 void ProcessReceivedEvent(const ui::Event* event);
59
60 // Updates |last_activity_time_|. Additionally notifies observers and 57 // Updates |last_activity_time_|. Additionally notifies observers and
61 // updates |last_observer_notification_time_| if enough time has passed 58 // updates |last_observer_notification_time_| if enough time has passed
62 // since the last notification. 59 // since the last notification.
63 void HandleActivity(const ui::Event* event); 60 void HandleActivity(const ui::Event* event);
64 61
65 ObserverList<UserActivityObserver> observers_; 62 ObserverList<UserActivityObserver> observers_;
66 63
67 // Last time at which user activity was observed. 64 // Last time at which user activity was observed.
68 base::TimeTicks last_activity_time_; 65 base::TimeTicks last_activity_time_;
69 66
70 // Last time at which we notified observers that the user was active. 67 // Last time at which we notified observers that the user was active.
71 base::TimeTicks last_observer_notification_time_; 68 base::TimeTicks last_observer_notification_time_;
72 69
73 // If set, used when the current time is needed. This can be set by tests to 70 // If set, used when the current time is needed. This can be set by tests to
74 // simulate the passage of time. 71 // simulate the passage of time.
75 base::TimeTicks now_for_test_; 72 base::TimeTicks now_for_test_;
76 73
77 // If set, mouse events will be ignored until this time is reached. This 74 // If set, mouse events will be ignored until this time is reached. This
78 // is to avoid reporting mouse events that occur when displays are turned 75 // is to avoid reporting mouse events that occur when displays are turned
79 // on or off as user activity. 76 // on or off as user activity.
80 base::TimeTicks honor_mouse_events_time_; 77 base::TimeTicks honor_mouse_events_time_;
81 78
82 DISALLOW_COPY_AND_ASSIGN(UserActivityDetector); 79 DISALLOW_COPY_AND_ASSIGN(UserActivityDetector);
83 }; 80 };
84 81
85 } // namespace ui 82 } // namespace ui
86 83
87 #endif // UI_BASE_USER_ACTIVITY_USER_ACTIVITY_DETECTOR_H_ 84 #endif // UI_BASE_USER_ACTIVITY_USER_ACTIVITY_DETECTOR_H_
OLDNEW
« no previous file with comments | « extensions/shell/browser/shell_desktop_controller_aura.cc ('k') | ui/base/user_activity/user_activity_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698