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

Unified Diff: ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.cc

Issue 193813003: ozone: evdev: Add libgestures bindings for touchpad & mouse support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moved 1 space by 1 character Created 6 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 side-by-side diff with in-line comments
Download patch
Index: ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.cc
diff --git a/ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.cc b/ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..92f15b77825ee1e0c073d1753b8763c8aca5e567
--- /dev/null
+++ b/ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.cc
@@ -0,0 +1,72 @@
+// Copyright 2014 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 "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h"
+
+#include <gestures/gestures.h>
+
+#include "base/timer/timer.h"
+
+// libgestures requires that this be in the top level namespace.
+class GesturesTimer {
+ public:
+ GesturesTimer() : callback_(NULL), callback_data_(NULL) {}
+ ~GesturesTimer() {}
+
+ void Set(stime_t delay, GesturesTimerCallback callback, void* callback_data) {
+ callback_ = callback;
+ callback_data_ = callback_data;
+ timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMicroseconds(
+ delay * base::Time::kMicrosecondsPerSecond),
+ this,
+ &GesturesTimer::OnTimerExpired);
+ }
+
+ void Cancel() { timer_.Stop(); }
+
+ private:
+ void OnTimerExpired() {
+ struct timespec ts;
+ CHECK(!clock_gettime(CLOCK_MONOTONIC, &ts));
+ stime_t next_delay = callback_(StimeFromTimespec(&ts), callback_data_);
+ if (next_delay >= 0) {
+ timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMicroseconds(
+ next_delay * base::Time::kMicrosecondsPerSecond),
+ this,
+ &GesturesTimer::OnTimerExpired);
+ }
+ }
+
+ GesturesTimerCallback callback_;
+ void* callback_data_;
+ base::OneShotTimer<GesturesTimer> timer_;
+};
+
+namespace ui {
+
+namespace {
+
+GesturesTimer* GesturesTimerCreate(void* data) { return new GesturesTimer; }
+
+void GesturesTimerSet(void* data,
+ GesturesTimer* timer,
+ stime_t delay,
+ GesturesTimerCallback callback,
+ void* callback_data) {
+ timer->Set(delay, callback, callback_data);
+}
+
+void GesturesTimerCancel(void* data, GesturesTimer* timer) { timer->Cancel(); }
+
+void GesturesTimerFree(void* data, GesturesTimer* timer) { delete timer; }
+
+} // namespace
+
+const GesturesTimerProvider kGestureTimerProvider = {
+ GesturesTimerCreate, GesturesTimerSet, GesturesTimerCancel,
+ GesturesTimerFree};
+
+} // namespace ui
« no previous file with comments | « ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h ('k') | ui/events/ozone/evdev/touch_event_converter_evdev.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698