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

Side by Side Diff: ui/base/gestures/gesture_recognizer_impl.cc

Issue 10831240: Remove TouchEvent interface, and rename TouchEventImpl to TouchEvent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge-tot Created 8 years, 4 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
« no previous file with comments | « ui/base/gestures/gesture_point.cc ('k') | ui/base/gestures/gesture_sequence.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/gestures/gesture_recognizer_impl.h" 5 #include "ui/base/gestures/gesture_recognizer_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "ui/base/event.h"
10 #include "ui/base/events.h" 11 #include "ui/base/events.h"
11 #include "ui/base/gestures/gesture_configuration.h" 12 #include "ui/base/gestures/gesture_configuration.h"
12 #include "ui/base/gestures/gesture_sequence.h" 13 #include "ui/base/gestures/gesture_sequence.h"
13 #include "ui/base/gestures/gesture_types.h" 14 #include "ui/base/gestures/gesture_types.h"
14 15
15 namespace ui { 16 namespace ui {
16 17
17 namespace { 18 namespace {
18 19
19 // This is used to pop a std::queue when returning from a function. 20 // This is used to pop a std::queue when returning from a function.
20 class ScopedPop { 21 class ScopedPop {
21 public: 22 public:
22 explicit ScopedPop(std::queue<TouchEvent*>* queue) : queue_(queue) { 23 explicit ScopedPop(std::queue<TouchEvent*>* queue) : queue_(queue) {
23 } 24 }
24 25
25 ~ScopedPop() { 26 ~ScopedPop() {
26 delete queue_->front(); 27 delete queue_->front();
27 queue_->pop(); 28 queue_->pop();
28 } 29 }
29 30
30 private: 31 private:
31 std::queue<TouchEvent*>* queue_; 32 std::queue<TouchEvent*>* queue_;
32 DISALLOW_COPY_AND_ASSIGN(ScopedPop); 33 DISALLOW_COPY_AND_ASSIGN(ScopedPop);
33 }; 34 };
34 35
35 // CancelledTouchEvent mirrors a TouchEvent object. 36 // CancelledTouchEvent mirrors a TouchEvent object.
36 class MirroredTouchEvent : public TouchEvent { 37 class MirroredTouchEvent : public TouchEvent {
37 public: 38 public:
38 explicit MirroredTouchEvent(const TouchEvent* real) 39 explicit MirroredTouchEvent(const TouchEvent* real)
39 : type_(real->GetEventType()), 40 : TouchEvent(real->type(),
40 location_(real->GetLocation()), 41 real->location(),
41 touch_id_(real->GetTouchId()), 42 real->touch_id(),
42 flags_(real->GetEventFlags()), 43 real->time_stamp()) {
43 timestamp_(real->GetTimestamp()), 44 set_flags(real->flags());
44 radius_x_(real->RadiusX()), 45 set_radius(real->radius_x(), real->radius_y());
45 radius_y_(real->RadiusY()), 46 set_rotation_angle(real->rotation_angle());
46 rotation_angle_(real->RotationAngle()), 47 set_force(real->force());
47 force_(real->Force()) {
48 } 48 }
49 49
50 virtual ~MirroredTouchEvent() { 50 virtual ~MirroredTouchEvent() {
51 } 51 }
52 52
53 // Overridden from TouchEvent.
54 virtual EventType GetEventType() const OVERRIDE {
55 return type_;
56 }
57
58 virtual gfx::Point GetLocation() const OVERRIDE {
59 return location_;
60 }
61
62 virtual int GetTouchId() const OVERRIDE {
63 return touch_id_;
64 }
65
66 virtual int GetEventFlags() const OVERRIDE {
67 return flags_;
68 }
69
70 virtual base::TimeDelta GetTimestamp() const OVERRIDE {
71 return timestamp_;
72 }
73
74 virtual float RadiusX() const OVERRIDE {
75 return radius_x_;
76 }
77
78 virtual float RadiusY() const OVERRIDE {
79 return radius_y_;
80 }
81
82 virtual float RotationAngle() const OVERRIDE {
83 return rotation_angle_;
84 }
85
86 virtual float Force() const OVERRIDE {
87 return force_;
88 }
89
90 protected:
91 void set_type(const EventType type) { type_ = type; }
92
93 private: 53 private:
94 EventType type_;
95 gfx::Point location_;
96 int touch_id_;
97 int flags_;
98 base::TimeDelta timestamp_;
99 float radius_x_;
100 float radius_y_;
101 float rotation_angle_;
102 float force_;
103 54
104 DISALLOW_COPY_AND_ASSIGN(MirroredTouchEvent); 55 DISALLOW_COPY_AND_ASSIGN(MirroredTouchEvent);
105 }; 56 };
106 57
107 // A mirrored event, except for the type, which is always ET_TOUCH_CANCELLED. 58 // A mirrored event, except for the type, which is always ET_TOUCH_CANCELLED.
108 class CancelledTouchEvent : public MirroredTouchEvent { 59 class CancelledTouchEvent : public MirroredTouchEvent {
109 public: 60 public:
110 explicit CancelledTouchEvent(const TouchEvent* src) 61 explicit CancelledTouchEvent(const TouchEvent* src)
111 : MirroredTouchEvent(src) { 62 : MirroredTouchEvent(src) {
112 set_type(ET_TOUCH_CANCELLED); 63 set_type(ET_TOUCH_CANCELLED);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 122
172 GestureRecognizerImpl::~GestureRecognizerImpl() { 123 GestureRecognizerImpl::~GestureRecognizerImpl() {
173 STLDeleteValues(&consumer_sequence_); 124 STLDeleteValues(&consumer_sequence_);
174 STLDeleteValues(&event_queue_); 125 STLDeleteValues(&event_queue_);
175 } 126 }
176 127
177 // Checks if this finger is already down, if so, returns the current target. 128 // Checks if this finger is already down, if so, returns the current target.
178 // Otherwise, returns NULL. 129 // Otherwise, returns NULL.
179 GestureConsumer* GestureRecognizerImpl::GetTouchLockedTarget( 130 GestureConsumer* GestureRecognizerImpl::GetTouchLockedTarget(
180 TouchEvent* event) { 131 TouchEvent* event) {
181 return touch_id_target_[event->GetTouchId()]; 132 return touch_id_target_[event->touch_id()];
182 } 133 }
183 134
184 GestureConsumer* GestureRecognizerImpl::GetTargetForGestureEvent( 135 GestureConsumer* GestureRecognizerImpl::GetTargetForGestureEvent(
185 GestureEvent* event) { 136 GestureEvent* event) {
186 GestureConsumer* target = NULL; 137 GestureConsumer* target = NULL;
187 int touch_id = event->GetLowestTouchId(); 138 int touch_id = event->GetLowestTouchId();
188 target = touch_id_target_for_gestures_[touch_id]; 139 target = touch_id_target_for_gestures_[touch_id];
189 return target; 140 return target;
190 } 141 }
191 142
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 gesture_sequence = CreateSequence(helper_); 226 gesture_sequence = CreateSequence(helper_);
276 consumer_sequence_[consumer] = gesture_sequence; 227 consumer_sequence_[consumer] = gesture_sequence;
277 } 228 }
278 return gesture_sequence; 229 return gesture_sequence;
279 } 230 }
280 231
281 GestureSequence::Gestures* GestureRecognizerImpl::ProcessTouchEventForGesture( 232 GestureSequence::Gestures* GestureRecognizerImpl::ProcessTouchEventForGesture(
282 const TouchEvent& event, 233 const TouchEvent& event,
283 ui::TouchStatus status, 234 ui::TouchStatus status,
284 GestureConsumer* target) { 235 GestureConsumer* target) {
285 if (event.GetEventType() == ui::ET_TOUCH_RELEASED || 236 if (event.type() == ui::ET_TOUCH_RELEASED ||
286 event.GetEventType() == ui::ET_TOUCH_CANCELLED) { 237 event.type() == ui::ET_TOUCH_CANCELLED) {
287 touch_id_target_[event.GetTouchId()] = NULL; 238 touch_id_target_[event.touch_id()] = NULL;
288 } else { 239 } else {
289 touch_id_target_[event.GetTouchId()] = target; 240 touch_id_target_[event.touch_id()] = target;
290 if (target) 241 if (target)
291 touch_id_target_for_gestures_[event.GetTouchId()] = target; 242 touch_id_target_for_gestures_[event.touch_id()] = target;
292 } 243 }
293 244
294 GestureSequence* gesture_sequence = GetGestureSequenceForConsumer(target); 245 GestureSequence* gesture_sequence = GetGestureSequenceForConsumer(target);
295 return gesture_sequence->ProcessTouchEventForGesture(event, status); 246 return gesture_sequence->ProcessTouchEventForGesture(event, status);
296 } 247 }
297 248
298 void GestureRecognizerImpl::QueueTouchEventForGesture(GestureConsumer* consumer, 249 void GestureRecognizerImpl::QueueTouchEventForGesture(GestureConsumer* consumer,
299 const TouchEvent& event) { 250 const TouchEvent& event) {
300 if (!event_queue_[consumer]) 251 if (!event_queue_[consumer])
301 event_queue_[consumer] = new std::queue<TouchEvent*>(); 252 event_queue_[consumer] = new std::queue<TouchEvent*>();
302 event_queue_[consumer]->push(new MirroredTouchEvent(&event)); 253 event_queue_[consumer]->push(new MirroredTouchEvent(&event));
303 } 254 }
304 255
305 GestureSequence::Gestures* GestureRecognizerImpl::AdvanceTouchQueue( 256 GestureSequence::Gestures* GestureRecognizerImpl::AdvanceTouchQueue(
306 GestureConsumer* consumer, 257 GestureConsumer* consumer,
307 bool processed) { 258 bool processed) {
308 if (!event_queue_[consumer] || event_queue_[consumer]->empty()) { 259 if (!event_queue_[consumer] || event_queue_[consumer]->empty()) {
309 LOG(ERROR) << "Trying to advance an empty gesture queue for " << consumer; 260 LOG(ERROR) << "Trying to advance an empty gesture queue for " << consumer;
310 return NULL; 261 return NULL;
311 } 262 }
312 263
313 ScopedPop pop(event_queue_[consumer]); 264 ScopedPop pop(event_queue_[consumer]);
314 TouchEvent* event = event_queue_[consumer]->front(); 265 TouchEvent* event = event_queue_[consumer]->front();
315 266
316 GestureSequence* sequence = GetGestureSequenceForConsumer(consumer); 267 GestureSequence* sequence = GetGestureSequenceForConsumer(consumer);
317 268
318 if (processed && event->GetEventType() == ui::ET_TOUCH_RELEASED) { 269 if (processed && event->type() == ui::ET_TOUCH_RELEASED) {
319 // A touch release was was processed (e.g. preventDefault()ed by a 270 // A touch release was was processed (e.g. preventDefault()ed by a
320 // web-page), but we still need to process a touch cancel. 271 // web-page), but we still need to process a touch cancel.
321 CancelledTouchEvent cancelled(event); 272 CancelledTouchEvent cancelled(event);
322 return sequence->ProcessTouchEventForGesture(cancelled, 273 return sequence->ProcessTouchEventForGesture(cancelled,
323 ui::TOUCH_STATUS_UNKNOWN); 274 ui::TOUCH_STATUS_UNKNOWN);
324 } 275 }
325 276
326 return sequence->ProcessTouchEventForGesture( 277 return sequence->ProcessTouchEventForGesture(
327 *event, 278 *event,
328 processed ? ui::TOUCH_STATUS_CONTINUE : ui::TOUCH_STATUS_UNKNOWN); 279 processed ? ui::TOUCH_STATUS_CONTINUE : ui::TOUCH_STATUS_UNKNOWN);
(...skipping 13 matching lines...) Expand all
342 RemoveConsumerFromMap(consumer, &touch_id_target_); 293 RemoveConsumerFromMap(consumer, &touch_id_target_);
343 RemoveConsumerFromMap(consumer, &touch_id_target_for_gestures_); 294 RemoveConsumerFromMap(consumer, &touch_id_target_for_gestures_);
344 } 295 }
345 296
346 // GestureRecognizer, static 297 // GestureRecognizer, static
347 GestureRecognizer* GestureRecognizer::Create(GestureEventHelper* helper) { 298 GestureRecognizer* GestureRecognizer::Create(GestureEventHelper* helper) {
348 return new GestureRecognizerImpl(helper); 299 return new GestureRecognizerImpl(helper);
349 } 300 }
350 301
351 } // namespace ui 302 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/gestures/gesture_point.cc ('k') | ui/base/gestures/gesture_sequence.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698