Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1170)

Unified Diff: ui/events/gesture_detection/gesture_detector.cc

Issue 302463004: Implementing the dispatch of the swipe gesture for one-finger touch swipes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implementing review feedback. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/events/gesture_detection/gesture_detector.h ('k') | ui/events/gesture_detection/gesture_provider.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ca26b7e957cbe155e15f27999ccb06e32468d4c7..8ceffbaad64783f7a5a0231af436f657beda9927 100644
--- a/ui/events/gesture_detection/gesture_detector.cc
+++ b/ui/events/gesture_detection/gesture_detector.cc
@@ -272,29 +272,7 @@ bool GestureDetector::OnTouchEvent(const MotionEvent& ev) {
vy_total += vy2;
}
- if (swipe_enabled_ && (vx_total || vy_total)) {
- float vx = vx_total / count;
- float vy = vy_total / count;
- float vx_abs = std::abs(vx);
- float vy_abs = std::abs(vy);
-
- if (vx_abs < min_swipe_velocity_)
- vx_abs = vx = 0;
- if (vy_abs < min_swipe_velocity_)
- vy_abs = vy = 0;
-
- // Note that the ratio will be 0 if both velocites are below the min.
- float ratio = vx_abs > vy_abs ? vx_abs / std::max(vy_abs, 0.001f)
- : vy_abs / std::max(vx_abs, 0.001f);
- if (ratio > min_swipe_direction_component_ratio_) {
- if (vx_abs > vy_abs)
- vy = 0;
- else
- vx = 0;
-
- handled = listener_->OnSwipe(*current_down_event_, ev, vx, vy);
- }
- }
+ handled = HandleSwipeIfNeeded(ev, vx_total / count, vy_total / count);
if (two_finger_tap_allowed_for_gesture_ && ev.GetPointerCount() == 2 &&
(ev.GetEventTime() - secondary_pointer_down_event_->GetEventTime() <=
@@ -433,6 +411,8 @@ bool GestureDetector::OnTouchEvent(const MotionEvent& ev) {
handled = listener_->OnFling(
*current_down_event_, ev, velocity_x, velocity_y);
}
+
+ handled |= HandleSwipeIfNeeded(ev, velocity_x, velocity_y);
}
previous_up_event_ = ev.Clone();
@@ -549,4 +529,31 @@ bool GestureDetector::IsConsideredDoubleTap(
return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square_);
}
+bool GestureDetector::HandleSwipeIfNeeded(const MotionEvent& up,
+ float vx,
+ float vy) {
+ if (!swipe_enabled_ || (!vx && !vy))
+ return false;
+ float vx_abs = std::abs(vx);
+ float vy_abs = std::abs(vy);
+
+ if (vx_abs < min_swipe_velocity_)
+ vx_abs = vx = 0;
+ if (vy_abs < min_swipe_velocity_)
+ vy_abs = vy = 0;
+
+ // Note that the ratio will be 0 if both velocites are below the min.
+ float ratio = vx_abs > vy_abs ? vx_abs / std::max(vy_abs, 0.001f)
+ : vy_abs / std::max(vx_abs, 0.001f);
+
+ if (ratio < min_swipe_direction_component_ratio_)
+ return false;
+
+ if (vx_abs > vy_abs)
+ vy = 0;
+ else
+ vx = 0;
+ return listener_->OnSwipe(*current_down_event_, up, vx, vy);
+}
+
} // namespace ui
« no previous file with comments | « ui/events/gesture_detection/gesture_detector.h ('k') | ui/events/gesture_detection/gesture_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698