Commit 73a56652 authored by sadrul@chromium.org's avatar sadrul@chromium.org

gesture: Include velocity in scroll-update gestures.

BUG=143244

Review URL: https://chromiumcodereview.appspot.com/10837329

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152369 0039d316-1c4b-4281-b951-d872f2087c98
parent 0690883e
......@@ -50,6 +50,8 @@ class GestureEventConsumeDelegate : public TestWindowDelegate {
two_finger_tap_(false),
scroll_x_(0),
scroll_y_(0),
scroll_velocity_x_(0),
scroll_velocity_y_(0),
velocity_x_(0),
velocity_y_(0),
tap_count_(0) {
......@@ -78,6 +80,8 @@ class GestureEventConsumeDelegate : public TestWindowDelegate {
scroll_x_ = 0;
scroll_y_ = 0;
scroll_velocity_x_ = 0;
scroll_velocity_y_ = 0;
velocity_x_ = 0;
velocity_y_ = 0;
tap_count_ = 0;
......@@ -108,6 +112,8 @@ class GestureEventConsumeDelegate : public TestWindowDelegate {
float scroll_x() const { return scroll_x_; }
float scroll_y() const { return scroll_y_; }
float scroll_velocity_x() const { return scroll_velocity_x_; }
float scroll_velocity_y() const { return scroll_velocity_y_; }
int touch_id() const { return touch_id_; }
float velocity_x() const { return velocity_x_; }
float velocity_y() const { return velocity_y_; }
......@@ -143,6 +149,8 @@ class GestureEventConsumeDelegate : public TestWindowDelegate {
scroll_update_ = true;
scroll_x_ += gesture->details().scroll_x();
scroll_y_ += gesture->details().scroll_y();
scroll_velocity_x_ = gesture->details().velocity_x();
scroll_velocity_y_ = gesture->details().velocity_y();
break;
case ui::ET_GESTURE_SCROLL_END:
EXPECT_TRUE(velocity_x_ == 0 && velocity_y_ == 0);
......@@ -199,6 +207,8 @@ class GestureEventConsumeDelegate : public TestWindowDelegate {
float scroll_x_;
float scroll_y_;
float scroll_velocity_x_;
float scroll_velocity_y_;
float velocity_x_;
float velocity_y_;
int touch_id_;
......@@ -732,6 +742,8 @@ TEST_F(GestureRecognizerTest, GestureEventScroll) {
EXPECT_FALSE(delegate->scroll_end());
EXPECT_EQ(29, delegate->scroll_x());
EXPECT_EQ(29, delegate->scroll_y());
EXPECT_EQ(0, delegate->scroll_velocity_x());
EXPECT_EQ(0, delegate->scroll_velocity_y());
EXPECT_EQ(gfx::Point(1, 1).ToString(),
delegate->scroll_begin_position().ToString());
......@@ -860,6 +872,10 @@ TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) {
100, 10, kTouchId, 1,
ui::GestureConfiguration::points_buffered_for_velocity(),
delegate.get());
// The y-velocity during the scroll should be 0 since this is in a horizontal
// rail scroll.
EXPECT_GT(delegate->scroll_velocity_x(), 0);
EXPECT_EQ(0, delegate->scroll_velocity_y());
delegate->Reset();
ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
......@@ -891,12 +907,16 @@ TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) {
SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get());
EXPECT_EQ(20, delegate->scroll_y());
EXPECT_EQ(0, delegate->scroll_x());
EXPECT_EQ(0, delegate->scroll_velocity_x());
EXPECT_EQ(0, delegate->scroll_velocity_y());
// Get a high y velocity, while still staying on the rail
SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
10, 100, kTouchId, 1,
ui::GestureConfiguration::points_buffered_for_velocity(),
delegate.get());
EXPECT_EQ(0, delegate->scroll_velocity_x());
EXPECT_GT(delegate->scroll_velocity_y(), 0);
delegate->Reset();
ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
......@@ -1105,6 +1125,8 @@ TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) {
EXPECT_EQ(5, delegate->scroll_x());
// y shouldn't change, as we're on a horizontal rail.
EXPECT_EQ(0, delegate->scroll_y());
EXPECT_EQ(0, delegate->scroll_velocity_x());
EXPECT_EQ(0, delegate->scroll_velocity_y());
// Send enough information that a velocity can be calculated for the gesture,
// and we can break the rail
......@@ -1112,6 +1134,10 @@ TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) {
1, 100, kTouchId, 1,
ui::GestureConfiguration::points_buffered_for_velocity(),
delegate.get());
// Since the scroll is not longer railing, the velocity should be set for both
// axis.
EXPECT_GT(delegate->scroll_velocity_x(), 0);
EXPECT_GT(delegate->scroll_velocity_y(), 0);
SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get());
SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get());
......@@ -1147,6 +1173,8 @@ TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) {
EXPECT_EQ(5, delegate->scroll_y());
// x shouldn't change, as we're on a vertical rail.
EXPECT_EQ(0, delegate->scroll_x());
EXPECT_EQ(0, delegate->scroll_velocity_x());
EXPECT_EQ(0, delegate->scroll_velocity_y());
// Send enough information that a velocity can be calculated for the gesture,
// and we can break the rail
......@@ -1154,6 +1182,8 @@ TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) {
100, 1, kTouchId, 1,
ui::GestureConfiguration::points_buffered_for_velocity(),
delegate.get());
EXPECT_GT(delegate->scroll_velocity_x(), 0);
EXPECT_GT(delegate->scroll_velocity_y(), 0);
SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get());
SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get());
......
......@@ -273,6 +273,15 @@ unsigned int ComputeTouchBitmask(const GesturePoint* points) {
return touch_bitmask;
}
float CalibrateFlingVelocity(float velocity) {
// TODO(sad|rjkroege): fling-curve is currently configured to work well with
// touchpad scroll-events. This curve needs to be adjusted to work correctly
// with both touchpad and touchscreen. Until then, scale quadratically.
// http://crbug.com/120154
const float velocity_scaling = 1.f / 900.f;
return velocity_scaling * velocity * fabsf(velocity);
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
......@@ -655,16 +664,11 @@ void GestureSequence::AppendScrollGestureEnd(const GesturePoint& point,
railed_x_velocity = 0;
if (railed_x_velocity != 0 || railed_y_velocity != 0) {
// TODO(sad|rjkroege): fling-curve is currently configured to work well with
// touchpad scroll-events. This curve needs to be adjusted to work correctly
// with both touchpad and touchscreen. Until then, scale quadratically.
// http://crbug.com/120154
const float velocity_scaling = 1.f / 900.f;
gestures->push_back(CreateGestureEvent(
GestureEventDetails(ui::ET_SCROLL_FLING_START,
velocity_scaling * railed_x_velocity * fabsf(railed_x_velocity),
velocity_scaling * railed_y_velocity * fabsf(railed_y_velocity)),
CalibrateFlingVelocity(railed_x_velocity),
CalibrateFlingVelocity(railed_y_velocity)),
location,
flags_,
base::Time::FromDoubleT(point.last_touch_time()),
......@@ -679,7 +683,7 @@ void GestureSequence::AppendScrollGestureEnd(const GesturePoint& point,
}
}
void GestureSequence::AppendScrollGestureUpdate(const GesturePoint& point,
void GestureSequence::AppendScrollGestureUpdate(GesturePoint& point,
const gfx::Point& location,
Gestures* gestures) {
gfx::Point current_center = bounding_box_.CenterPoint();
......@@ -692,8 +696,12 @@ void GestureSequence::AppendScrollGestureUpdate(const GesturePoint& point,
if (dx == 0 && dy == 0)
return;
GestureEventDetails details(ui::ET_GESTURE_SCROLL_UPDATE, dx, dy);
details.SetScrollVelocity(
scroll_type_ == ST_VERTICAL ? 0 : point.XVelocity(),
scroll_type_ == ST_HORIZONTAL ? 0 : point.YVelocity());
gestures->push_back(CreateGestureEvent(
GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, dx, dy),
details,
location,
flags_,
base::Time::FromDoubleT(point.last_touch_time()),
......@@ -761,7 +769,8 @@ void GestureSequence::AppendTwoFingerTapGestureEvent(Gestures* gestures) {
}
bool GestureSequence::Click(const TouchEvent& event,
const GesturePoint& point, Gestures* gestures) {
const GesturePoint& point,
Gestures* gestures) {
DCHECK(state_ == GS_PENDING_SYNTHETIC_CLICK);
if (point.IsInClickWindow(event)) {
bool double_tap = point.IsInDoubleClickWindow(event);
......@@ -774,7 +783,8 @@ bool GestureSequence::Click(const TouchEvent& event,
}
bool GestureSequence::ScrollStart(const TouchEvent& event,
GesturePoint& point, Gestures* gestures) {
GesturePoint& point,
Gestures* gestures) {
DCHECK(state_ == GS_PENDING_SYNTHETIC_CLICK);
if (point.IsInClickWindow(event) ||
!point.IsInScrollWindow(event) ||
......@@ -791,7 +801,8 @@ bool GestureSequence::ScrollStart(const TouchEvent& event,
}
void GestureSequence::BreakRailScroll(const TouchEvent& event,
GesturePoint& point, Gestures* gestures) {
GesturePoint& point,
Gestures* gestures) {
DCHECK(state_ == GS_SCROLL);
if (scroll_type_ == ST_HORIZONTAL &&
point.BreaksHorizontalRail())
......@@ -802,7 +813,8 @@ void GestureSequence::BreakRailScroll(const TouchEvent& event,
}
bool GestureSequence::ScrollUpdate(const TouchEvent& event,
const GesturePoint& point, Gestures* gestures) {
GesturePoint& point,
Gestures* gestures) {
DCHECK(state_ == GS_SCROLL);
if (!point.DidScroll(event, 0))
return false;
......@@ -811,7 +823,8 @@ bool GestureSequence::ScrollUpdate(const TouchEvent& event,
}
bool GestureSequence::TouchDown(const TouchEvent& event,
const GesturePoint& point, Gestures* gestures) {
const GesturePoint& point,
Gestures* gestures) {
DCHECK(state_ == GS_NO_GESTURE);
AppendTapDownGestureEvent(point, gestures);
long_press_timer_->Start(
......@@ -824,7 +837,8 @@ bool GestureSequence::TouchDown(const TouchEvent& event,
}
bool GestureSequence::TwoFingerTouchDown(const TouchEvent& event,
const GesturePoint& point, Gestures* gestures) {
const GesturePoint& point,
Gestures* gestures) {
DCHECK(state_ == GS_PENDING_SYNTHETIC_CLICK || state_ == GS_SCROLL);
if (state_ == GS_SCROLL) {
AppendScrollGestureEnd(point, point.last_touch_position(), gestures,
......@@ -835,7 +849,8 @@ bool GestureSequence::TwoFingerTouchDown(const TouchEvent& event,
}
bool GestureSequence::TwoFingerTouchMove(const TouchEvent& event,
const GesturePoint& point, Gestures* gestures) {
const GesturePoint& point,
Gestures* gestures) {
DCHECK(state_ == GS_PENDING_TWO_FINGER_TAP);
base::TimeDelta time_delta = event.time_stamp() - second_touch_time_;
......@@ -849,7 +864,8 @@ bool GestureSequence::TwoFingerTouchMove(const TouchEvent& event,
}
bool GestureSequence::TwoFingerTouchReleased(const TouchEvent& event,
const GesturePoint& point, Gestures* gestures) {
const GesturePoint& point,
Gestures* gestures) {
DCHECK(state_ == GS_PENDING_TWO_FINGER_TAP);
base::TimeDelta time_delta = event.time_stamp() - second_touch_time_;
base::TimeDelta max_delta = base::TimeDelta::FromMilliseconds(1000 *
......@@ -871,7 +887,8 @@ void GestureSequence::AppendLongPressGestureEvent() {
}
bool GestureSequence::ScrollEnd(const TouchEvent& event,
GesturePoint& point, Gestures* gestures) {
GesturePoint& point,
Gestures* gestures) {
DCHECK(state_ == GS_SCROLL);
if (point.IsInFlickWindow(event)) {
AppendScrollGestureEnd(point, point.last_touch_position(), gestures,
......@@ -884,7 +901,8 @@ bool GestureSequence::ScrollEnd(const TouchEvent& event,
}
bool GestureSequence::PinchStart(const TouchEvent& event,
const GesturePoint& point, Gestures* gestures) {
const GesturePoint& point,
Gestures* gestures) {
DCHECK(state_ == GS_SCROLL ||
state_ == GS_PENDING_SYNTHETIC_CLICK ||
state_ == GS_PENDING_TWO_FINGER_TAP);
......@@ -909,7 +927,8 @@ bool GestureSequence::PinchStart(const TouchEvent& event,
}
bool GestureSequence::PinchUpdate(const TouchEvent& event,
const GesturePoint& point, Gestures* gestures) {
GesturePoint& point,
Gestures* gestures) {
DCHECK(state_ == GS_PINCH);
// It is possible that the none of the touch-points changed their position,
......@@ -944,7 +963,8 @@ bool GestureSequence::PinchUpdate(const TouchEvent& event,
}
bool GestureSequence::PinchEnd(const TouchEvent& event,
const GesturePoint& point, Gestures* gestures) {
const GesturePoint& point,
Gestures* gestures) {
DCHECK(state_ == GS_PINCH);
GesturePoint* point1 = GetPointByPointId(0);
......
......@@ -104,7 +104,7 @@ class UI_EXPORT GestureSequence {
Gestures* gestures,
float x_velocity,
float y_velocity);
void AppendScrollGestureUpdate(const GesturePoint& point,
void AppendScrollGestureUpdate(GesturePoint& point,
const gfx::Point& location,
Gestures* gestures);
......@@ -140,7 +140,7 @@ class UI_EXPORT GestureSequence {
GesturePoint& point,
Gestures* gestures);
bool ScrollUpdate(const TouchEvent& event,
const GesturePoint& point,
GesturePoint& point,
Gestures* gestures);
bool TouchDown(const TouchEvent& event,
const GesturePoint& point,
......@@ -161,7 +161,7 @@ class UI_EXPORT GestureSequence {
const GesturePoint& point,
Gestures* gestures);
bool PinchUpdate(const TouchEvent& event,
const GesturePoint& point,
GesturePoint& point,
Gestures* gestures);
bool PinchEnd(const TouchEvent& event,
const GesturePoint& point,
......
......@@ -13,13 +13,13 @@ GestureEventDetails::GestureEventDetails(ui::EventType type,
touch_points_(1) {
switch (type_) {
case ui::ET_GESTURE_SCROLL_UPDATE:
data.scroll.x = delta_x;
data.scroll.y = delta_y;
data.scroll_update.x = delta_x;
data.scroll_update.y = delta_y;
break;
case ui::ET_SCROLL_FLING_START:
data.velocity.x = delta_x;
data.velocity.y = delta_y;
data.fling_velocity.x = delta_x;
data.fling_velocity.y = delta_y;
break;
case ui::ET_GESTURE_LONG_PRESS:
......@@ -45,8 +45,6 @@ GestureEventDetails::GestureEventDetails(ui::EventType type,
break;
default:
data.generic.delta_x = delta_x;
data.generic.delta_y = delta_y;
if (delta_x != 0.f || delta_y != 0.f) {
DLOG(WARNING) << "A gesture event (" << type << ") had unknown data: ("
<< delta_x << "," << delta_y;
......@@ -55,4 +53,11 @@ GestureEventDetails::GestureEventDetails(ui::EventType type,
}
}
void GestureEventDetails::SetScrollVelocity(float velocity_x,
float velocity_y) {
CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_);
data.scroll_update.velocity_x = velocity_x;
data.scroll_update.velocity_y = velocity_y;
}
} // namespace ui
......@@ -27,22 +27,30 @@ struct UI_EXPORT GestureEventDetails {
const gfx::Rect& bounding_box() const { return bounding_box_; }
void set_bounding_box(const gfx::Rect& box) { bounding_box_ = box; }
void SetScrollVelocity(float velocity_x, float velocity_y);
float scroll_x() const {
CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_);
return data.scroll.x;
return data.scroll_update.x;
}
float scroll_y() const {
CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_);
return data.scroll.y;
return data.scroll_update.y;
}
float velocity_x() const {
CHECK_EQ(ui::ET_SCROLL_FLING_START, type_);
return data.velocity.x;
CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE ||
type_ == ui::ET_SCROLL_FLING_START);
return type_ == ui::ET_SCROLL_FLING_START ? data.fling_velocity.x :
data.scroll_update.velocity_x;
}
float velocity_y() const {
CHECK_EQ(ui::ET_SCROLL_FLING_START, type_);
return data.velocity.y;
CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE ||
type_ == ui::ET_SCROLL_FLING_START);
return type_ == ui::ET_SCROLL_FLING_START ? data.fling_velocity.y :
data.scroll_update.velocity_y;
}
int touch_id() const {
......@@ -59,14 +67,17 @@ struct UI_EXPORT GestureEventDetails {
CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
return data.swipe.left;
}
bool swipe_right() const {
CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
return data.swipe.right;
}
bool swipe_up() const {
CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
return data.swipe.up;
}
bool swipe_down() const {
CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_);
return data.swipe.down;
......@@ -83,14 +94,16 @@ struct UI_EXPORT GestureEventDetails {
struct { // SCROLL delta.
float x;
float y;
} scroll;
float velocity_x;
float velocity_y;
} scroll_update;
float scale; // PINCH scale.
struct { // FLING velocity.
float x;
float y;
} velocity;
} fling_velocity;
int touch_id; // LONG_PRESS touch-id.
......@@ -102,11 +115,6 @@ struct UI_EXPORT GestureEventDetails {
} swipe;
int tap_count; // TAP repeat count.
struct {
float delta_x;
float delta_y;
} generic;
} data;
int touch_points_; // Number of active touch points in the gesture.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment