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