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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/events/ozone/evdev/libgestures_glue/gesture_timer_provider.h"
6
7 #include <gestures/gestures.h>
8
9 #include "base/timer/timer.h"
10
11 // libgestures requires that this be in the top level namespace.
12 class GesturesTimer {
13 public:
14 GesturesTimer() : callback_(NULL), callback_data_(NULL) {}
15 ~GesturesTimer() {}
16
17 void Set(stime_t delay, GesturesTimerCallback callback, void* callback_data) {
18 callback_ = callback;
19 callback_data_ = callback_data;
20 timer_.Start(FROM_HERE,
21 base::TimeDelta::FromMicroseconds(
22 delay * base::Time::kMicrosecondsPerSecond),
23 this,
24 &GesturesTimer::OnTimerExpired);
25 }
26
27 void Cancel() { timer_.Stop(); }
28
29 private:
30 void OnTimerExpired() {
31 struct timespec ts;
32 CHECK(!clock_gettime(CLOCK_MONOTONIC, &ts));
33 stime_t next_delay = callback_(StimeFromTimespec(&ts), callback_data_);
34 if (next_delay >= 0) {
35 timer_.Start(FROM_HERE,
36 base::TimeDelta::FromMicroseconds(
37 next_delay * base::Time::kMicrosecondsPerSecond),
38 this,
39 &GesturesTimer::OnTimerExpired);
40 }
41 }
42
43 GesturesTimerCallback callback_;
44 void* callback_data_;
45 base::OneShotTimer<GesturesTimer> timer_;
46 };
47
48 namespace ui {
49
50 namespace {
51
52 GesturesTimer* GesturesTimerCreate(void* data) { return new GesturesTimer; }
53
54 void GesturesTimerSet(void* data,
55 GesturesTimer* timer,
56 stime_t delay,
57 GesturesTimerCallback callback,
58 void* callback_data) {
59 timer->Set(delay, callback, callback_data);
60 }
61
62 void GesturesTimerCancel(void* data, GesturesTimer* timer) { timer->Cancel(); }
63
64 void GesturesTimerFree(void* data, GesturesTimer* timer) { delete timer; }
65
66 } // namespace
67
68 const GesturesTimerProvider kGestureTimerProvider = {
69 GesturesTimerCreate, GesturesTimerSet, GesturesTimerCancel,
70 GesturesTimerFree};
71
72 } // namespace ui
OLDNEW
« 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