Chromium Code Reviews| Index: ui/events/gesture_detection/gesture_detector.cc |
| diff --git a/ui/events/gesture_detection/gesture_detector.cc b/ui/events/gesture_detection/gesture_detector.cc |
| index 8cf76e62394e31838e32ae2b44b01858107d72b1..393f6191c1780734af54343f9132d2d35d5d886d 100644 |
| --- a/ui/events/gesture_detection/gesture_detector.cc |
| +++ b/ui/events/gesture_detection/gesture_detector.cc |
| @@ -12,6 +12,11 @@ |
| namespace ui { |
| namespace { |
| +// Using a small epsilon when comparing slop distances allows pixel perfect |
| +// slop determination when using fractional DPI coordinates (assuming the slop |
|
tdresser
2014/04/09 14:00:01
fractional DPI -> fractional DIP
jdduke (slow)
2014/04/10 22:04:53
Done.
|
| +// region and DPI scale are reasonably proportioned). |
| +const float SLOP_EPSILON = .05f; |
| + |
| // Constants used by TimeoutGestureHandler. |
| enum TimeoutEvent { |
| SHOW_PRESS = 0, |
| @@ -28,10 +33,10 @@ GestureDetector::Config::Config() |
| : longpress_timeout(base::TimeDelta::FromMilliseconds(500)), |
| showpress_timeout(base::TimeDelta::FromMilliseconds(180)), |
| double_tap_timeout(base::TimeDelta::FromMilliseconds(300)), |
| - scaled_touch_slop(8), |
| - scaled_double_tap_slop(100), |
| - scaled_minimum_fling_velocity(50), |
| - scaled_maximum_fling_velocity(8000) {} |
| + touch_slop(8), |
| + double_tap_slop(100), |
| + minimum_fling_velocity(50), |
| + maximum_fling_velocity(8000) {} |
| GestureDetector::Config::~Config() {} |
| @@ -267,9 +272,9 @@ bool GestureDetector::OnTouchEvent(const MotionEvent& ev) { |
| DCHECK(double_tap_listener_); |
| handled |= double_tap_listener_->OnDoubleTapEvent(ev); |
| } else if (always_in_tap_region_) { |
| - const int delta_x = static_cast<int>(focus_x - down_focus_x_); |
| - const int delta_y = static_cast<int>(focus_y - down_focus_y_); |
| - int distance = (delta_x * delta_x) + (delta_y * delta_y); |
| + const float delta_x = focus_x - down_focus_x_; |
| + const float delta_y = focus_y - down_focus_y_; |
| + const float distance = delta_x * delta_x + delta_y * delta_y; |
|
tdresser
2014/04/09 14:00:01
Maybe rename |distance| to |distance_squared| or |
jdduke (slow)
2014/04/10 22:04:53
Done.
|
| if (distance > touch_slop_square_) { |
| handled = listener_->OnScroll( |
| *current_down_event_, ev, scroll_x, scroll_y); |
| @@ -280,7 +285,7 @@ bool GestureDetector::OnTouchEvent(const MotionEvent& ev) { |
| } |
| if (distance > double_tap_touch_slop_square_) |
| always_in_bigger_tap_region_ = false; |
| - } else if ((std::abs(scroll_x) >= 1) || (std::abs(scroll_y) >= 1)) { |
| + } else if (scroll_x || scroll_y) { |
|
tdresser
2014/04/09 14:00:01
Shouldn't there be some kind of epsilon check here
jdduke (slow)
2014/04/10 22:04:53
Ahh, of course.
|
| handled = |
| listener_->OnScroll(*current_down_event_, ev, scroll_x, scroll_y); |
| last_focus_x_ = focus_x; |
| @@ -340,15 +345,15 @@ bool GestureDetector::OnTouchEvent(const MotionEvent& ev) { |
| void GestureDetector::Init(const Config& config) { |
| DCHECK(listener_); |
| - const int touch_slop = config.scaled_touch_slop; |
| - const int double_tap_touch_slop = touch_slop; |
| - const int double_tap_slop = config.scaled_double_tap_slop; |
| - min_fling_velocity_ = config.scaled_minimum_fling_velocity; |
| - max_fling_velocity_ = config.scaled_maximum_fling_velocity; |
| + const float touch_slop = config.touch_slop + SLOP_EPSILON; |
| + const float double_tap_touch_slop = touch_slop; |
| + const float double_tap_slop = config.double_tap_slop + SLOP_EPSILON; |
| touch_slop_square_ = touch_slop * touch_slop; |
| double_tap_touch_slop_square_ = double_tap_touch_slop * double_tap_touch_slop; |
| double_tap_slop_square_ = double_tap_slop * double_tap_slop; |
| double_tap_timeout_ = config.double_tap_timeout; |
| + min_fling_velocity_ = config.minimum_fling_velocity; |
| + max_fling_velocity_ = config.maximum_fling_velocity; |
| } |
| void GestureDetector::OnShowPressTimeout() { |
| @@ -401,8 +406,8 @@ bool GestureDetector::IsConsideredDoubleTap( |
| double_tap_timeout_) |
| return false; |
| - int delta_x = static_cast<int>(first_down.GetX() - second_down.GetX()); |
| - int delta_y = static_cast<int>(first_down.GetY() - second_down.GetY()); |
| + const float delta_x = first_down.GetX() - second_down.GetX(); |
| + const float delta_y = first_down.GetY() - second_down.GetY(); |
| return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square_); |
| } |