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

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

Issue 1074543002: Prevent menus from blocking user activity detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: The new slight change Created 5 years, 8 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_handler.h" 13 #include "ui/events/event.h"
14 #include "ui/events/platform/platform_event_observer.h"
14 15
15 namespace ui { 16 namespace ui {
16 17
17 class UserActivityObserver; 18 class UserActivityObserver;
18 19
19 // Watches for input events and notifies observers that the user is active. 20 // Watches for input events and notifies observers that the user is active.
20 class UI_BASE_EXPORT UserActivityDetector : public ui::EventHandler { 21 class UI_BASE_EXPORT UserActivityDetector : public ui::PlatformEventObserver {
21 public: 22 public:
22 // Minimum amount of time between notifications to observers. 23 // Minimum amount of time between notifications to observers.
23 static const int kNotifyIntervalMs; 24 static const int kNotifyIntervalMs;
24 25
25 // Amount of time that mouse events should be ignored after notification 26 // Amount of time that mouse events should be ignored after notification
26 // is received that displays' power states are being changed. 27 // is received that displays' power states are being changed.
27 static const int kDisplayPowerChangeIgnoreMouseMs; 28 static const int kDisplayPowerChangeIgnoreMouseMs;
28 29
29 UserActivityDetector(); 30 UserActivityDetector();
30 ~UserActivityDetector() override; 31 ~UserActivityDetector() override;
31 32
32 // Returns the UserActivityDetector instance if one was created. 33 // Returns the UserActivityDetector instance if one was created.
33 static UserActivityDetector* Get(); 34 static UserActivityDetector* Get();
34 35
35 base::TimeTicks last_activity_time() const { return last_activity_time_; } 36 base::TimeTicks last_activity_time() const { return last_activity_time_; }
36 37
37 void set_now_for_test(base::TimeTicks now) { now_for_test_ = now; } 38 void set_now_for_test(base::TimeTicks now) { now_for_test_ = now; }
38 39
39 bool HasObserver(const UserActivityObserver* observer) const; 40 bool HasObserver(const UserActivityObserver* observer) const;
40 void AddObserver(UserActivityObserver* observer); 41 void AddObserver(UserActivityObserver* observer);
41 void RemoveObserver(UserActivityObserver* observer); 42 void RemoveObserver(UserActivityObserver* observer);
42 43
43 // Called when displays are about to be turned on or off. 44 // Called when displays are about to be turned on or off.
44 void OnDisplayPowerChanging(); 45 void OnDisplayPowerChanging();
45 46
46 // ui::EventHandler implementation. 47 // ui::PlatformEventObserver:
47 void OnKeyEvent(ui::KeyEvent* event) override; 48 void WillProcessEvent(const PlatformEvent& platform_event) override {}
48 void OnMouseEvent(ui::MouseEvent* event) override; 49 void DidProcessEvent(const PlatformEvent& platform_event) override;
49 void OnScrollEvent(ui::ScrollEvent* event) override;
50 void OnTouchEvent(ui::TouchEvent* event) override;
51 void OnGestureEvent(ui::GestureEvent* event) override;
52 50
53 private: 51 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
57 // Updates |last_activity_time_|. Additionally notifies observers and 60 // Updates |last_activity_time_|. Additionally notifies observers and
58 // updates |last_observer_notification_time_| if enough time has passed 61 // updates |last_observer_notification_time_| if enough time has passed
59 // since the last notification. 62 // since the last notification.
60 void HandleActivity(const ui::Event* event); 63 void HandleActivity(const ui::Event* event);
61 64
62 ObserverList<UserActivityObserver> observers_; 65 ObserverList<UserActivityObserver> observers_;
63 66
64 // Last time at which user activity was observed. 67 // Last time at which user activity was observed.
65 base::TimeTicks last_activity_time_; 68 base::TimeTicks last_activity_time_;
66 69
67 // Last time at which we notified observers that the user was active. 70 // Last time at which we notified observers that the user was active.
68 base::TimeTicks last_observer_notification_time_; 71 base::TimeTicks last_observer_notification_time_;
69 72
70 // If set, used when the current time is needed. This can be set by tests to 73 // If set, used when the current time is needed. This can be set by tests to
71 // simulate the passage of time. 74 // simulate the passage of time.
72 base::TimeTicks now_for_test_; 75 base::TimeTicks now_for_test_;
73 76
74 // If set, mouse events will be ignored until this time is reached. This 77 // 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 78 // is to avoid reporting mouse events that occur when displays are turned
76 // on or off as user activity. 79 // on or off as user activity.
77 base::TimeTicks honor_mouse_events_time_; 80 base::TimeTicks honor_mouse_events_time_;
78 81
79 DISALLOW_COPY_AND_ASSIGN(UserActivityDetector); 82 DISALLOW_COPY_AND_ASSIGN(UserActivityDetector);
80 }; 83 };
81 84
82 } // namespace ui 85 } // namespace ui
83 86
84 #endif // UI_BASE_USER_ACTIVITY_USER_ACTIVITY_DETECTOR_H_ 87 #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