| Index: ui/base/user_activity/user_activity_detector.cc
|
| diff --git a/ui/base/user_activity/user_activity_detector.cc b/ui/base/user_activity/user_activity_detector.cc
|
| index d6a4e4385278ab04012bdd158f96f62f1a6b335e..41256fc8583659598bf8c575691ac95f42b41101 100644
|
| --- a/ui/base/user_activity/user_activity_detector.cc
|
| +++ b/ui/base/user_activity/user_activity_detector.cc
|
| @@ -8,7 +8,8 @@
|
| #include "base/logging.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "ui/base/user_activity/user_activity_observer.h"
|
| -#include "ui/events/event.h"
|
| +#include "ui/events/event_utils.h"
|
| +#include "ui/events/platform/platform_event_source.h"
|
|
|
| namespace ui {
|
|
|
| @@ -48,9 +49,24 @@ const int UserActivityDetector::kDisplayPowerChangeIgnoreMouseMs = 1000;
|
| UserActivityDetector::UserActivityDetector() {
|
| CHECK(!g_instance);
|
| g_instance = this;
|
| +
|
| + ui::PlatformEventSource* platform_event_source =
|
| + ui::PlatformEventSource::GetInstance();
|
| +#if defined(OS_CHROMEOS) || defined(OS_LINUX)
|
| + CHECK(platform_event_source);
|
| +#endif
|
| + if (platform_event_source)
|
| + platform_event_source->AddPlatformEventObserver(this);
|
| }
|
|
|
| UserActivityDetector::~UserActivityDetector() {
|
| + ui::PlatformEventSource* platform_event_source =
|
| + ui::PlatformEventSource::GetInstance();
|
| +#if defined(OS_CHROMEOS) || defined(OS_LINUX)
|
| + CHECK(platform_event_source);
|
| +#endif
|
| + if (platform_event_source)
|
| + platform_event_source->RemovePlatformEventObserver(this);
|
| g_instance = nullptr;
|
| }
|
|
|
| @@ -77,36 +93,31 @@ void UserActivityDetector::OnDisplayPowerChanging() {
|
| base::TimeDelta::FromMilliseconds(kDisplayPowerChangeIgnoreMouseMs);
|
| }
|
|
|
| -void UserActivityDetector::OnKeyEvent(ui::KeyEvent* event) {
|
| - HandleActivity(event);
|
| +void UserActivityDetector::WillProcessEvent(
|
| + const PlatformEvent& platform_event) {
|
| + scoped_ptr<ui::Event> event(ui::EventFromNative(platform_event));
|
| + ProcessReceivedEvent(event.get());
|
| }
|
|
|
| -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);
|
| +base::TimeTicks UserActivityDetector::GetCurrentTime() const {
|
| + return !now_for_test_.is_null() ? now_for_test_ : base::TimeTicks::Now();
|
| }
|
|
|
| -void UserActivityDetector::OnScrollEvent(ui::ScrollEvent* event) {
|
| - HandleActivity(event);
|
| -}
|
| +void UserActivityDetector::ProcessReceivedEvent(const ui::Event* event) {
|
| + if (!event)
|
| + return;
|
|
|
| -void UserActivityDetector::OnTouchEvent(ui::TouchEvent* event) {
|
| - HandleActivity(event);
|
| -}
|
| + if (event->IsMouseEvent() || event->IsMouseWheelEvent()) {
|
| + if (event->flags() & ui::EF_IS_SYNTHESIZED)
|
| + return;
|
| + if (!honor_mouse_events_time_.is_null()
|
| + && GetCurrentTime() < honor_mouse_events_time_)
|
| + return;
|
| + }
|
|
|
| -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;
|
|
|