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

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

Issue 10964051: events: Clean up dispatching code for touch-events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 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
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_sequence.h" 5 #include "ui/base/gestures/gesture_sequence.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 12 matching lines...) Expand all
23 // Signature. 23 // Signature.
24 enum TouchState { 24 enum TouchState {
25 TS_RELEASED, 25 TS_RELEASED,
26 TS_PRESSED, 26 TS_PRESSED,
27 TS_MOVED, 27 TS_MOVED,
28 TS_STATIONARY, 28 TS_STATIONARY,
29 TS_CANCELLED, 29 TS_CANCELLED,
30 TS_UNKNOWN, 30 TS_UNKNOWN,
31 }; 31 };
32 32
33 // ui::TouchStatus is mapped to TouchStatusInternal to simply indicate whether a 33 // ui::EventResult is mapped to TouchStatusInternal to simply indicate whether a
34 // processed touch-event should affect gesture-recognition or not. 34 // processed touch-event should affect gesture-recognition or not.
35 enum TouchStatusInternal { 35 enum TouchStatusInternal {
36 TSI_NOT_PROCESSED, // The touch-event should take-part into 36 TSI_NOT_PROCESSED, // The touch-event should take-part into
37 // gesture-recognition only if the touch-event has not 37 // gesture-recognition only if the touch-event has not
38 // been processed. 38 // been processed.
39 39
40 TSI_PROCESSED, // The touch-event should affect gesture-recognition only 40 TSI_PROCESSED, // The touch-event should affect gesture-recognition only
41 // if the touch-event has been processed. 41 // if the touch-event has been processed.
42 42
43 TSI_ALWAYS // The touch-event should always affect gesture 43 TSI_ALWAYS // The touch-event should always affect gesture
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 long_press_timer_(CreateTimer()), 297 long_press_timer_(CreateTimer()),
298 point_count_(0), 298 point_count_(0),
299 helper_(helper) { 299 helper_(helper) {
300 } 300 }
301 301
302 GestureSequence::~GestureSequence() { 302 GestureSequence::~GestureSequence() {
303 } 303 }
304 304
305 GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture( 305 GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture(
306 const TouchEvent& event, 306 const TouchEvent& event,
307 ui::TouchStatus status) { 307 EventResult result) {
308 StopLongPressTimerIfRequired(event); 308 StopLongPressTimerIfRequired(event);
309 last_touch_location_ = event.location(); 309 last_touch_location_ = event.location();
310 if (status == ui::TOUCH_STATUS_QUEUED || 310 if (result & ER_ASYNC)
311 status == ui::TOUCH_STATUS_QUEUED_END)
312 return NULL; 311 return NULL;
313 312
314 // Set a limit on the number of simultaneous touches in a gesture. 313 // Set a limit on the number of simultaneous touches in a gesture.
315 if (event.touch_id() >= kMaxGesturePoints) 314 if (event.touch_id() >= kMaxGesturePoints)
316 return NULL; 315 return NULL;
317 316
318 if (event.type() == ui::ET_TOUCH_PRESSED) { 317 if (event.type() == ui::ET_TOUCH_PRESSED) {
319 if (point_count_ == kMaxGesturePoints) 318 if (point_count_ == kMaxGesturePoints)
320 return NULL; 319 return NULL;
321 GesturePoint* new_point = &points_[event.touch_id()]; 320 GesturePoint* new_point = &points_[event.touch_id()];
(...skipping 19 matching lines...) Expand all
341 RecreateBoundingBox(); 340 RecreateBoundingBox();
342 flags_ = event.flags(); 341 flags_ = event.flags();
343 const int point_id = point.point_id(); 342 const int point_id = point.point_id();
344 if (point_id < 0) 343 if (point_id < 0)
345 return NULL; 344 return NULL;
346 345
347 // Send GESTURE_BEGIN for any touch pressed. 346 // Send GESTURE_BEGIN for any touch pressed.
348 if (event.type() == ui::ET_TOUCH_PRESSED) 347 if (event.type() == ui::ET_TOUCH_PRESSED)
349 AppendBeginGestureEvent(point, gestures.get()); 348 AppendBeginGestureEvent(point, gestures.get());
350 349
351 TouchStatusInternal status_internal = (status == ui::TOUCH_STATUS_UNKNOWN) ? 350 CHECK_NE(ER_ASYNC, result);
351 TouchStatusInternal status_internal = (result == ER_UNHANDLED) ?
352 TSI_NOT_PROCESSED : TSI_PROCESSED; 352 TSI_NOT_PROCESSED : TSI_PROCESSED;
353 353
354 EdgeStateSignatureType signature = Signature(state_, point_id, 354 EdgeStateSignatureType signature = Signature(state_, point_id,
355 event.type(), status_internal); 355 event.type(), status_internal);
356 356
357 if (signature == GST_INVALID) 357 if (signature == GST_INVALID)
358 signature = Signature(state_, point_id, event.type(), TSI_ALWAYS); 358 signature = Signature(state_, point_id, event.type(), TSI_ALWAYS);
359 359
360 switch (signature) { 360 switch (signature) {
361 case GST_INVALID: 361 case GST_INVALID:
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 return &point; 564 return &point;
565 } 565 }
566 NOTREACHED(); 566 NOTREACHED();
567 return NULL; 567 return NULL;
568 } 568 }
569 569
570 bool GestureSequence::IsSecondTouchDownCloseEnoughForTwoFingerTap() { 570 bool GestureSequence::IsSecondTouchDownCloseEnoughForTwoFingerTap() {
571 gfx::Point p1 = GetPointByPointId(0)->last_touch_position(); 571 gfx::Point p1 = GetPointByPointId(0)->last_touch_position();
572 gfx::Point p2 = GetPointByPointId(1)->last_touch_position(); 572 gfx::Point p2 = GetPointByPointId(1)->last_touch_position();
573 double max_distance = 573 double max_distance =
574 ui::GestureConfiguration::max_distance_for_two_finger_tap_in_pixels(); 574 GestureConfiguration::max_distance_for_two_finger_tap_in_pixels();
575 double distance = (p1.x() - p2.x()) * (p1.x() - p2.x()) + 575 double distance = (p1.x() - p2.x()) * (p1.x() - p2.x()) +
576 (p1.y() - p2.y()) * (p1.y() - p2.y()); 576 (p1.y() - p2.y()) * (p1.y() - p2.y());
577 if (distance < max_distance * max_distance) 577 if (distance < max_distance * max_distance)
578 return true; 578 return true;
579 return false; 579 return false;
580 } 580 }
581 581
582 GestureEvent* GestureSequence::CreateGestureEvent( 582 GestureEvent* GestureSequence::CreateGestureEvent(
583 const GestureEventDetails& details, 583 const GestureEventDetails& details,
584 const gfx::Point& location, 584 const gfx::Point& location,
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 return; 1069 return;
1070 1070
1071 // Since long press timer has been started, there should be a non-NULL point. 1071 // Since long press timer has been started, there should be a non-NULL point.
1072 const GesturePoint* point = GetPointByPointId(0); 1072 const GesturePoint* point = GetPointByPointId(0);
1073 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), 1073 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(),
1074 event.location())) 1074 event.location()))
1075 long_press_timer_->Stop(); 1075 long_press_timer_->Stop();
1076 } 1076 }
1077 1077
1078 } // namespace ui 1078 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698