summaryrefslogtreecommitdiffstats
path: root/chromium/ash/wm/user_activity_detector.cc
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@digia.com>2014-03-18 13:16:26 +0100
committerFrederik Gladhorn <frederik.gladhorn@digia.com>2014-03-20 15:55:39 +0100
commit3f0f86b0caed75241fa71c95a5d73bc0164348c5 (patch)
tree92b9fb00f2e9e90b0be2262093876d4f43b6cd13 /chromium/ash/wm/user_activity_detector.cc
parente90d7c4b152c56919d963987e2503f9909a666d2 (diff)
Update to new stable branch 1750
This also includes an updated ninja and chromium dependencies needed on Windows. Change-Id: Icd597d80ed3fa4425933c9f1334c3c2e31291c42 Reviewed-by: Zoltan Arvai <zarvai@inf.u-szeged.hu> Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
Diffstat (limited to 'chromium/ash/wm/user_activity_detector.cc')
-rw-r--r--chromium/ash/wm/user_activity_detector.cc112
1 files changed, 112 insertions, 0 deletions
diff --git a/chromium/ash/wm/user_activity_detector.cc b/chromium/ash/wm/user_activity_detector.cc
new file mode 100644
index 00000000000..2809bb5b2a5
--- /dev/null
+++ b/chromium/ash/wm/user_activity_detector.cc
@@ -0,0 +1,112 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/wm/user_activity_detector.h"
+
+#include "ash/wm/user_activity_observer.h"
+#include "base/format_macros.h"
+#include "base/logging.h"
+#include "base/strings/stringprintf.h"
+#include "ui/events/event.h"
+
+namespace ash {
+
+namespace {
+
+// Returns a string describing |event|.
+std::string GetEventDebugString(const ui::Event* event) {
+ std::string details = base::StringPrintf(
+ "type=%d name=%s flags=%d time=%" PRId64,
+ event->type(), event->name().c_str(), event->flags(),
+ event->time_stamp().InMilliseconds());
+
+ if (event->IsKeyEvent()) {
+ details += base::StringPrintf(" key_code=%d",
+ static_cast<const ui::KeyEvent*>(event)->key_code());
+ } else if (event->IsMouseEvent() || event->IsTouchEvent() ||
+ event->IsGestureEvent()) {
+ details += base::StringPrintf(" location=%s",
+ static_cast<const ui::LocatedEvent*>(
+ event)->location().ToString().c_str());
+ }
+
+ return details;
+}
+
+} // namespace
+
+const int UserActivityDetector::kNotifyIntervalMs = 200;
+
+// Too low and mouse events generated at the tail end of reconfiguration
+// will be reported as user activity and turn the screen back on; too high
+// and we'll ignore legitimate activity.
+const int UserActivityDetector::kDisplayPowerChangeIgnoreMouseMs = 1000;
+
+UserActivityDetector::UserActivityDetector() {
+}
+
+UserActivityDetector::~UserActivityDetector() {
+}
+
+bool UserActivityDetector::HasObserver(UserActivityObserver* observer) const {
+ return observers_.HasObserver(observer);
+}
+
+void UserActivityDetector::AddObserver(UserActivityObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void UserActivityDetector::RemoveObserver(UserActivityObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void UserActivityDetector::OnDisplayPowerChanging() {
+ honor_mouse_events_time_ = GetCurrentTime() +
+ base::TimeDelta::FromMilliseconds(kDisplayPowerChangeIgnoreMouseMs);
+}
+
+void UserActivityDetector::OnKeyEvent(ui::KeyEvent* event) {
+ HandleActivity(event);
+}
+
+void UserActivityDetector::OnMouseEvent(ui::MouseEvent* event) {
+ if (event->flags() & ui::EF_IS_SYNTHESIZED)
+ return;
+ if (!honor_mouse_events_time_.is_null() &&
+ GetCurrentTime() < honor_mouse_events_time_)
+ return;
+
+ HandleActivity(event);
+}
+
+void UserActivityDetector::OnScrollEvent(ui::ScrollEvent* event) {
+ HandleActivity(event);
+}
+
+void UserActivityDetector::OnTouchEvent(ui::TouchEvent* event) {
+ HandleActivity(event);
+}
+
+void UserActivityDetector::OnGestureEvent(ui::GestureEvent* event) {
+ HandleActivity(event);
+}
+
+base::TimeTicks UserActivityDetector::GetCurrentTime() const {
+ return !now_for_test_.is_null() ? now_for_test_ : base::TimeTicks::Now();
+}
+
+void UserActivityDetector::HandleActivity(const ui::Event* event) {
+ base::TimeTicks now = GetCurrentTime();
+ last_activity_time_ = now;
+ if (last_observer_notification_time_.is_null() ||
+ (now - last_observer_notification_time_).InMillisecondsF() >=
+ kNotifyIntervalMs) {
+ if (VLOG_IS_ON(1))
+ VLOG(1) << "Reporting user activity: " << GetEventDebugString(event);
+ FOR_EACH_OBSERVER(UserActivityObserver, observers_, OnUserActivity(event));
+ last_observer_notification_time_ = now;
+ }
+}
+
+} // namespace ash