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

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

Issue 10937038: gesture recognizer: Recognizer rotation gestures. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/gestures/gesture_sequence.h ('k') | ui/base/gestures/gesture_types.h » ('j') | 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 2c3b599e78f8e7771aaaed6ac9084b66a27e6732..1f2a19afbb15b3df8c3fe7208cb8f8af550391b8 100644
--- a/ui/base/gestures/gesture_sequence.cc
+++ b/ui/base/gestures/gesture_sequence.cc
@@ -264,6 +264,12 @@ float BoundingBoxDiagonal(const gfx::Rect& rect) {
return sqrt(width + height);
}
+float BoundingBoxDiagonalAngle(const gfx::Rect& rect) {
+ float width = rect.width();
+ float height = rect.height();
+ return width == 0.f ? M_PI_2 : atan(height / width);
+}
+
unsigned int ComputeTouchBitmask(const GesturePoint* points) {
unsigned int touch_bitmask = 0;
for (int i = 0; i < GestureSequence::kMaxGesturePoints; ++i) {
@@ -291,6 +297,7 @@ float CalibrateFlingVelocity(float velocity) {
GestureSequence::GestureSequence(GestureEventHelper* helper)
: state_(GS_NO_GESTURE),
flags_(0),
+ bounding_box_diagonal_angle_(0.f),
pinch_distance_start_(0.f),
pinch_distance_current_(0.f),
scroll_type_(ST_FREE),
@@ -474,6 +481,7 @@ GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture(
case GST_PINCH_FIFTH_PRESSED:
pinch_distance_current_ = BoundingBoxDiagonal(bounding_box_);
pinch_distance_start_ = pinch_distance_current_;
+ bounding_box_diagonal_angle_ = BoundingBoxDiagonalAngle(bounding_box_);
break;
}
@@ -508,6 +516,7 @@ GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture(
if (state_ == GS_PINCH) {
pinch_distance_current_ = BoundingBoxDiagonal(bounding_box_);
pinch_distance_start_ = pinch_distance_current_;
+ bounding_box_diagonal_angle_ = BoundingBoxDiagonalAngle(bounding_box_);
}
}
return gestures.release();
@@ -752,11 +761,12 @@ void GestureSequence::AppendPinchGestureEnd(const GesturePoint& p1,
void GestureSequence::AppendPinchGestureUpdate(const GesturePoint& point,
float scale,
+ float rotation,
Gestures* gestures) {
// TODO(sad): Compute rotation and include it in delta_y.
// http://crbug.com/113145
gestures->push_back(CreateGestureEvent(
- GestureEventDetails(ui::ET_GESTURE_PINCH_UPDATE, scale, 0),
+ GestureEventDetails(ui::ET_GESTURE_PINCH_UPDATE, scale, rotation),
bounding_box_.CenterPoint(),
flags_,
base::Time::FromDoubleT(point.last_touch_time()),
@@ -932,6 +942,8 @@ bool GestureSequence::PinchStart(const TouchEvent& event,
pinch_distance_current_ = BoundingBoxDiagonal(bounding_box_);
pinch_distance_start_ = pinch_distance_current_;
+ bounding_box_diagonal_angle_ = BoundingBoxDiagonalAngle(bounding_box_);
+
AppendPinchGestureBegin(*point1, *point2, gestures);
if (state_ == GS_PENDING_SYNTHETIC_CLICK ||
@@ -968,9 +980,18 @@ bool GestureSequence::PinchUpdate(const TouchEvent& event,
if (abs(distance - pinch_distance_current_) >=
GestureConfiguration::min_pinch_update_distance_in_pixels()) {
- AppendPinchGestureUpdate(point,
- distance / pinch_distance_current_, gestures);
+ float scale = distance / pinch_distance_current_;
+ float angle = bounding_box_diagonal_angle_;
+ // Compute rotation only if the the bounding box remained of roughly the
+ // same size.
+ if (fabs(1.f - scale) < 0.15f)
+ angle = BoundingBoxDiagonalAngle(bounding_box_);
+ else
+ LOG(ERROR) << "Scale: " << scale;
+ AppendPinchGestureUpdate(point, scale, angle - bounding_box_diagonal_angle_,
+ gestures);
pinch_distance_current_ = distance;
+ bounding_box_diagonal_angle_ = angle;
} else {
gfx::Point center = bounding_box_.CenterPoint();
AppendScrollGestureUpdate(point, center, gestures);
« no previous file with comments | « ui/base/gestures/gesture_sequence.h ('k') | ui/base/gestures/gesture_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698