Commit d72f9100 authored by rjkroege@chromium.org's avatar rjkroege@chromium.org

Refactor access to scroll deltas in GesturePoint

Clean up some code in the GesturePoint to provide centralized
access to the scroll deltas so that smoothing of scroll start
is easier to implement.

BUG=141653


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171116 0039d316-1c4b-4281-b951-d872f2087c98
parent 62a5fd61
......@@ -931,12 +931,13 @@ TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) {
// Release the touch. This should end the scroll.
delegate->Reset();
ui::TouchEvent release(ui::ET_TOUCH_RELEASED,
gfx::Point(kPositionX, kPositionY),
gfx::Point(kPositionX + kScrollAmount,
kPositionY + kScrollAmount),
kTouchId, press.time_stamp() +
base::TimeDelta::FromMilliseconds(50));
root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
EXPECT_EQ(gfx::Rect(kPositionX - radius,
kPositionY - radius,
EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius,
kPositionY + kScrollAmount - radius,
radius * 2,
radius * 2).ToString(),
delegate->bounding_box().ToString());
......
......@@ -17,6 +17,7 @@ namespace ui {
GesturePoint::GesturePoint()
: first_touch_time_(0.0),
second_last_touch_time_(0.0),
last_touch_time_(0.0),
last_tap_time_(0.0),
velocity_calculator_(
......@@ -28,7 +29,7 @@ GesturePoint::GesturePoint()
GesturePoint::~GesturePoint() {}
void GesturePoint::Reset() {
first_touch_time_ = last_touch_time_ = 0.0;
first_touch_time_ = second_last_touch_time_ = last_touch_time_ = 0.0;
velocity_calculator_.ClearHistory();
point_id_ = -1;
clear_enclosing_rectangle();
......@@ -38,6 +39,10 @@ void GesturePoint::ResetVelocity() {
velocity_calculator_.ClearHistory();
}
gfx::Vector2d GesturePoint::ScrollDelta() {
return last_touch_position_ - second_last_touch_position_;
}
void GesturePoint::UpdateValues(const TouchEvent& event) {
const int64 event_timestamp_microseconds =
event.time_stamp().InMicroseconds();
......@@ -53,6 +58,9 @@ void GesturePoint::UpdateValues(const TouchEvent& event) {
if (event.type() == ui::ET_TOUCH_PRESSED) {
first_touch_time_ = last_touch_time_;
first_touch_position_ = event.location();
second_last_touch_position_ = last_touch_position_;
second_last_touch_time_ = last_touch_time_;
velocity_calculator_.ClearHistory();
velocity_calculator_.PointSeen(event.location().x(),
event.location().y(),
......@@ -70,11 +78,8 @@ void GesturePoint::UpdateForTap() {
}
void GesturePoint::UpdateForScroll() {
// Update the first-touch position and time so that the scroll-delta and
// scroll-velocity can be computed correctly for the next scroll gesture
// event.
first_touch_position_ = last_touch_position_;
first_touch_time_ = last_touch_time_;
second_last_touch_position_ = last_touch_position_;
second_last_touch_time_ = last_touch_time_;
}
bool GesturePoint::IsInClickWindow(const TouchEvent& event) const {
......@@ -97,28 +102,26 @@ bool GesturePoint::IsInFlickWindow(const TouchEvent& event) {
}
bool GesturePoint::DidScroll(const TouchEvent& event, int dist) const {
return abs(last_touch_position_.x() - first_touch_position_.x()) > dist ||
abs(last_touch_position_.y() - first_touch_position_.y()) > dist;
gfx::Vector2d d = last_touch_position_ - second_last_touch_position_;
return abs(d.x()) > dist || abs(d.y()) > dist;
}
bool GesturePoint::HasEnoughDataToEstablishRail() const {
int dx = x_delta();
int dy = y_delta();
int delta_squared = dx * dx + dy * dy;
gfx::Vector2d d = last_touch_position_ - first_touch_position_;
int64 delta_squared = d.LengthSquared();
return delta_squared > GestureConfiguration::min_scroll_delta_squared();
}
bool GesturePoint::IsInHorizontalRailWindow() const {
int dx = x_delta();
int dy = y_delta();
return abs(dx) > GestureConfiguration::rail_start_proportion() * abs(dy);
gfx::Vector2d d = last_touch_position_ - second_last_touch_position_;
return abs(d.x()) >
GestureConfiguration::rail_start_proportion() * abs(d.y());
}
bool GesturePoint::IsInVerticalRailWindow() const {
int dx = x_delta();
int dy = y_delta();
return abs(dy) > GestureConfiguration::rail_start_proportion() * abs(dx);
gfx::Vector2d d = last_touch_position_ - second_last_touch_position_;
return abs(d.y()) >
GestureConfiguration::rail_start_proportion() * abs(d.x());
}
bool GesturePoint::BreaksHorizontalRail() {
......
......@@ -72,13 +72,7 @@ class GesturePoint {
bool in_use() const { return point_id_ >= 0; }
double x_delta() const {
return last_touch_position_.x() - first_touch_position_.x();
}
double y_delta() const {
return last_touch_position_.y() - first_touch_position_.y();
}
gfx::Vector2d ScrollDelta();
float XVelocity() { return velocity_calculator_.XVelocity(); }
float YVelocity() { return velocity_calculator_.YVelocity(); }
......@@ -101,11 +95,13 @@ class GesturePoint {
void UpdateEnclosingRectangle(const TouchEvent& event);
void clear_enclosing_rectangle() { enclosing_rect_ = gfx::Rect(); }
// The position of touchdown event, or of the last scroll gesture event.
// We may want to consider tracking these two things in separate variables.
// The position of the first touchdown event.
gfx::Point first_touch_position_;
double first_touch_time_;
gfx::Point second_last_touch_position_;
double second_last_touch_time_;
gfx::Point last_touch_position_;
double last_touch_time_;
......
......@@ -733,26 +733,24 @@ void GestureSequence::AppendScrollGestureEnd(const GesturePoint& point,
void GestureSequence::AppendScrollGestureUpdate(GesturePoint& point,
Gestures* gestures) {
float dx, dy;
gfx::Vector2d d;
gfx::Point location;
if (point_count_ == 1) {
dx = point.x_delta();
dy = point.y_delta();
d = point.ScrollDelta();
location = point.last_touch_position();
} else {
location = bounding_box_.CenterPoint();
dx = location.x() - latest_multi_scroll_update_location_.x();
dy = location.y() - latest_multi_scroll_update_location_.y();
d = location - latest_multi_scroll_update_location_;
latest_multi_scroll_update_location_ = location;
}
if (scroll_type_ == ST_HORIZONTAL)
dy = 0;
d.set_y(0);
else if (scroll_type_ == ST_VERTICAL)
dx = 0;
if (dx == 0 && dy == 0)
d.set_x(0);
if (d.IsZero())
return;
GestureEventDetails details(ui::ET_GESTURE_SCROLL_UPDATE, dx, dy);
GestureEventDetails details(ui::ET_GESTURE_SCROLL_UPDATE, d.x(), d.y());
details.SetScrollVelocity(
scroll_type_ == ST_VERTICAL ? 0 : point.XVelocity(),
scroll_type_ == ST_HORIZONTAL ? 0 : point.YVelocity());
......
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