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

Side by Side Diff: ui/events/gestures/touch_point_state.cc

Issue 101933004: Eager Gesture Recognizer (WIP) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Starting work on Android. Created 6 years, 11 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 2013 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/gestures/touch_point_state.h"
6
7 #include "ui/events/event.h"
8 #include "ui/events/event_constants.h"
9
10 namespace ui {
11
12 TouchPointState::TouchPointState(int touch_id)
13 : touch_id_(touch_id),
14 has_press_(false),
15 has_release_(false),
16 move_count_(0),
17 timer_count_(0) {
18 }
19
20 TouchPointState::TouchPointState(int touch_id,
21 bool has_press,
22 bool has_release,
23 int move_count,
24 int timer_count)
25 : touch_id_(touch_id),
26 has_press_(has_press),
27 has_release_(has_release),
28 move_count_(move_count),
29 timer_count_(timer_count) {
30 }
31
32 TouchPointState::~TouchPointState() {}
33
34 void TouchPointState::Update(const TouchEvent& event) {
35 DCHECK(touch_id_ == event.touch_id());
36 switch(event.type()) {
37 case ET_TOUCH_PRESSED:
38 has_press_ = true;
39 break;
40 case ET_TOUCH_MOVED:
41 case ET_TOUCH_STATIONARY:
42 ++move_count_;
43 break;
44 case ET_TOUCH_RELEASED:
45 case ET_TOUCH_CANCELLED:
46 has_release_ = true;
47 break;
48 default:
49 // Should only be passed touch events.
50 NOTREACHED();
51 }
52 }
53
54 void TouchPointState::TimerFired() {
55 timer_count_++;
56 }
57
58 TouchPointState* TouchPointState::CopyForGestureType(
59 EventType type, RequiresAck requires_ack) const {
60 bool new_has_press = has_press_;
61 bool new_has_release = has_release_;
62 int new_move_count = move_count_;
63 int new_timer_count = 0;
64
65 switch(type) {
66 case ET_GESTURE_SHOW_PRESS:
67 // Only wait for show press timer.
68 new_timer_count = 1;
69 break;
70 case ET_GESTURE_LONG_PRESS:
71 // Wait for both long press and show press timers.
72 new_timer_count = 2;
73 break;
74 default:
75 break;
76 }
77
78 switch(type) {
79 case ET_GESTURE_SCROLL_BEGIN:
80 case ET_GESTURE_PINCH_BEGIN:
81 case ET_GESTURE_SCROLL_UPDATE:
82 case ET_GESTURE_PINCH_UPDATE:
83 case ET_GESTURE_SCROLL_END:
84 case ET_GESTURE_PINCH_END:
85 case ET_GESTURE_MULTIFINGER_SWIPE:
86 case ET_SCROLL_FLING_START:
87 case ET_SCROLL_FLING_CANCEL:
88 new_has_release = false;
89 break;
90 case ET_GESTURE_TAP:
91 case ET_GESTURE_LONG_TAP:
92 case ET_GESTURE_TWO_FINGER_TAP:
93 break;
94 case ET_GESTURE_BEGIN:
95 case ET_GESTURE_END:
96 case ET_GESTURE_SHOW_PRESS:
97 case ET_GESTURE_LONG_PRESS:
98 case ET_GESTURE_TAP_DOWN:
99 case ET_GESTURE_TAP_CANCEL:
100 new_has_release = false;
101 new_move_count = 0;
102 break;
103 default:
104 NOTREACHED() << "TouchPointState doesn't know about gesture type "
105 << type;
106 }
107
108 if (requires_ack == NO_ACK) {
109 new_has_press = false;
110 new_has_release = false;
111 new_move_count = false;
112 }
113
114 return new TouchPointState(touch_id_,
115 new_has_press,
116 new_has_release,
117 new_move_count,
118 new_timer_count);
119 }
120
121 bool TouchPointState::HasEmptyIntersection(const TouchPointState& tps) const {
122 DCHECK(touch_id_ == tps.touch_id());
123 return Intersect(tps) == TouchPointState(touch_id_, 0, false, false, false);
124 }
125
126 bool TouchPointState::Contains(const TouchPointState& tps) const {
127 DCHECK(touch_id_ == tps.touch_id());
128 return Intersect(tps) == tps;
129 }
130
131 void TouchPointState::Reset() {
132 has_press_ = false;
133 has_release_ = false;
134 move_count_ = 0;
135 timer_count_ = 0;
136 }
137
138 TouchPointState::TouchPointState(const TouchPointState& tps)
139 : touch_id_(tps.touch_id()),
140 has_press_(tps.has_press()),
141 has_release_(tps.has_release()),
142 move_count_(tps.move_count()),
143 timer_count_(tps.timer_count()) {
144 }
145
146 TouchPointState TouchPointState::Intersect(const TouchPointState& tps) const {
147 DCHECK(touch_id_ == tps.touch_id());
148 return TouchPointState(
149 touch_id_,
150 has_press() && tps.has_press(),
151 has_release() && tps.has_release(),
152 std::min(move_count(), tps.move_count()),
153 std::min(timer_count(), tps.timer_count()));
154 }
155
156 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gestures/touch_point_state.h ('k') | ui/events/gestures/touch_point_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698