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

Unified Diff: ui/base/gestures/gesture_sequence.cc

Issue 10834283: gesture recognizer: Some cleanup and workaround for a crash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/gestures/gesture_sequence.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/gestures/gesture_sequence.cc
diff --git a/ui/base/gestures/gesture_sequence.cc b/ui/base/gestures/gesture_sequence.cc
index 59d32edac8d54c19e554942d4f2cf3147c149121..1806e699f647e38aec97d828670b13582bb23b48 100644
--- a/ui/base/gestures/gesture_sequence.cc
+++ b/ui/base/gestures/gesture_sequence.cc
@@ -298,8 +298,14 @@ GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture(
return NULL;
GesturePoint* new_point = &points_[event.touch_id()];
// We shouldn't be able to get two PRESSED events from the same
- // finger without either a RELEASE or CANCEL in between.
- DCHECK(!new_point->in_use());
+ // finger without either a RELEASE or CANCEL in between. But let's not crash
+ // in a release build.
+ if (new_point->in_use()) {
+ LOG(ERROR) << "Received a second press for a point: " << event.touch_id();
+ new_point->ResetVelocity();
+ new_point->UpdateValues(event);
+ return NULL;
+ }
new_point->set_point_id(point_count_++);
new_point->set_touch_id(event.touch_id());
}
@@ -351,7 +357,7 @@ GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture(
}
break;
case GST_PENDING_SYNTHETIC_CLICK_FIRST_CANCELLED:
- NoGesture(event, point, gestures.get());
+ set_state(GS_NO_GESTURE);
break;
case GST_SCROLL_FIRST_MOVED:
if (scroll_type_ == ST_VERTICAL ||
@@ -458,35 +464,24 @@ GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture(
// could end up with gaps.
if (event.type() == ui::ET_TOUCH_RELEASED ||
event.type() == ui::ET_TOUCH_CANCELLED) {
- GesturePoint& old_point = points_[event.touch_id()];
for (int i = 0; i < kMaxGesturePoints; ++i) {
- GesturePoint& point = points_[i];
- if (point.point_id() > old_point.point_id())
- point.set_point_id(point.point_id() - 1);
+ GesturePoint& iter_point = points_[i];
+ if (iter_point.point_id() > point.point_id())
+ iter_point.set_point_id(iter_point.point_id() - 1);
}
- if (old_point.in_use()) {
- old_point.Reset();
- --point_count_;
- DCHECK_GE(point_count_, 0);
- RecreateBoundingBox();
- if (state_ == GS_PINCH) {
- pinch_distance_current_ = BoundingBoxDiagonal(bounding_box_);
- pinch_distance_start_ = pinch_distance_current_;
- }
+ point.Reset();
+ --point_count_;
+ CHECK_GE(point_count_, 0);
+ RecreateBoundingBox();
+ if (state_ == GS_PINCH) {
+ pinch_distance_current_ = BoundingBoxDiagonal(bounding_box_);
+ pinch_distance_start_ = pinch_distance_current_;
}
}
-
return gestures.release();
}
-void GestureSequence::Reset() {
- set_state(GS_NO_GESTURE);
- for (int i = 0; i < kMaxGesturePoints; ++i)
- points_[i].Reset();
- point_count_ = 0;
-}
-
void GestureSequence::RecreateBoundingBox() {
// TODO(sad): Recreating the bounding box at every touch-event is not very
// efficient. This should be made better.
@@ -800,12 +795,6 @@ bool GestureSequence::ScrollUpdate(const TouchEvent& event,
return true;
}
-bool GestureSequence::NoGesture(const TouchEvent&,
- const GesturePoint& point, Gestures*) {
- Reset();
- return false;
-}
-
bool GestureSequence::TouchDown(const TouchEvent& event,
const GesturePoint& point, Gestures* gestures) {
DCHECK(state_ == GS_NO_GESTURE);
« no previous file with comments | « ui/base/gestures/gesture_sequence.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698