diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-20 19:10:28 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-20 19:10:28 +0000 |
commit | 73a566529b4033837d37319c0e323ffa6c4b227f (patch) | |
tree | f4660e28b9f2306b33e96562526850bad82f787d /ui/base/gestures | |
parent | 0690883e566c4578f79e6abadd4be68ab50a64fb (diff) | |
download | chromium_src-73a566529b4033837d37319c0e323ffa6c4b227f.zip chromium_src-73a566529b4033837d37319c0e323ffa6c4b227f.tar.gz chromium_src-73a566529b4033837d37319c0e323ffa6c4b227f.tar.bz2 |
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
Diffstat (limited to 'ui/base/gestures')
-rw-r--r-- | ui/base/gestures/gesture_sequence.cc | 62 | ||||
-rw-r--r-- | ui/base/gestures/gesture_sequence.h | 6 | ||||
-rw-r--r-- | ui/base/gestures/gesture_types.cc | 17 | ||||
-rw-r--r-- | ui/base/gestures/gesture_types.h | 34 |
4 files changed, 76 insertions, 43 deletions
diff --git a/ui/base/gestures/gesture_sequence.cc b/ui/base/gestures/gesture_sequence.cc index f29e244..5039bc4 100644 --- a/ui/base/gestures/gesture_sequence.cc +++ b/ui/base/gestures/gesture_sequence.cc @@ -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); diff --git a/ui/base/gestures/gesture_sequence.h b/ui/base/gestures/gesture_sequence.h index 3933ef7..9827eb3 100644 --- a/ui/base/gestures/gesture_sequence.h +++ b/ui/base/gestures/gesture_sequence.h @@ -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, diff --git a/ui/base/gestures/gesture_types.cc b/ui/base/gestures/gesture_types.cc index 55dc7a1..ba659c5 100644 --- a/ui/base/gestures/gesture_types.cc +++ b/ui/base/gestures/gesture_types.cc @@ -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 diff --git a/ui/base/gestures/gesture_types.h b/ui/base/gestures/gesture_types.h index 0407954..14b73cd 100644 --- a/ui/base/gestures/gesture_types.h +++ b/ui/base/gestures/gesture_types.h @@ -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. |