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

Side by Side Diff: ui/events/gesture_detection/gesture_provider.cc

Issue 2058723003: Slop region check for multi-finger scroll (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/events/gesture_detection/gesture_provider.h" 5 #include "ui/events/gesture_detection/gesture_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 10
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 current_down_time_ = event.GetEventTime(); 111 current_down_time_ = event.GetEventTime();
112 current_longpress_time_ = base::TimeTicks(); 112 current_longpress_time_ = base::TimeTicks();
113 ignore_single_tap_ = false; 113 ignore_single_tap_ = false;
114 scroll_event_sent_ = false; 114 scroll_event_sent_ = false;
115 pinch_event_sent_ = false; 115 pinch_event_sent_ = false;
116 show_press_event_sent_ = false; 116 show_press_event_sent_ = false;
117 gesture_detector_.set_longpress_enabled(true); 117 gesture_detector_.set_longpress_enabled(true);
118 tap_down_point_ = gfx::PointF(event.GetX(), event.GetY()); 118 tap_down_point_ = gfx::PointF(event.GetX(), event.GetY());
119 max_diameter_before_show_press_ = event.GetTouchMajor(); 119 max_diameter_before_show_press_ = event.GetTouchMajor();
120 } 120 }
121
122 gesture_detector_.OnTouchEvent(event); 121 gesture_detector_.OnTouchEvent(event);
123 scale_gesture_detector_.OnTouchEvent(event); 122 scale_gesture_detector_.OnTouchEvent(event);
124 123
125 if (action == MotionEvent::ACTION_UP || 124 if (action == MotionEvent::ACTION_UP ||
126 action == MotionEvent::ACTION_CANCEL) { 125 action == MotionEvent::ACTION_CANCEL) {
127 // Note: This call will have no effect if a fling was just generated, as 126 // Note: This call will have no effect if a fling was just generated, as
128 // |Fling()| will have already signalled an end to touch-scrolling. 127 // |Fling()| will have already signalled an end to touch-scrolling.
129 if (scroll_event_sent_) 128 if (scroll_event_sent_)
130 Send(CreateGesture(ET_GESTURE_SCROLL_END, event)); 129 Send(CreateGesture(ET_GESTURE_SCROLL_END, event));
131 current_down_time_ = base::TimeTicks(); 130 current_down_time_ = base::TimeTicks();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 GestureEventDetails tap_details(ET_GESTURE_TAP_DOWN); 276 GestureEventDetails tap_details(ET_GESTURE_TAP_DOWN);
278 tap_details.set_device_type(GestureDeviceType::DEVICE_TOUCHSCREEN); 277 tap_details.set_device_type(GestureDeviceType::DEVICE_TOUCHSCREEN);
279 Send(CreateGesture(tap_details, e)); 278 Send(CreateGesture(tap_details, e));
280 279
281 // Return true to indicate that we want to handle touch. 280 // Return true to indicate that we want to handle touch.
282 return true; 281 return true;
283 } 282 }
284 283
285 bool OnScroll(const MotionEvent& e1, 284 bool OnScroll(const MotionEvent& e1,
286 const MotionEvent& e2, 285 const MotionEvent& e2,
286 const MotionEvent& secondary_pointer_down_event,
287 float raw_distance_x, 287 float raw_distance_x,
288 float raw_distance_y) override { 288 float raw_distance_y) override {
289 float distance_x = raw_distance_x; 289 float distance_x = raw_distance_x;
290 float distance_y = raw_distance_y; 290 float distance_y = raw_distance_y;
291 if (!scroll_event_sent_ && e2.GetPointerCount() == 1) { 291 if (!scroll_event_sent_ && e2.GetPointerCount() < 3) {
292 // Remove the touch slop region from the first scroll event to 292 // Remove the touch slop region from the first scroll event to avoid a
293 // avoid a jump. Touch slop isn't used for multi-finger 293 // jump. Touch slop isn't used for scroll gestures with greater than 2
294 // gestures, so in those cases we don't subtract the slop. 294 // pointers down, in those cases we don't subtract the slop.
295 float distance = 295 SetScrollValues(e1, e2, secondary_pointer_down_event,
296 std::sqrt(distance_x * distance_x + distance_y * distance_y); 296 distance_x, distance_y);
297 float epsilon = 1e-3f;
298 if (distance > epsilon) {
299 float ratio =
300 std::max(0.f,
301 distance - config_.gesture_detector_config.touch_slop) /
302 distance;
303 distance_x *= ratio;
304 distance_y *= ratio;
305 }
306 } 297 }
307 298
308 snap_scroll_controller_.UpdateSnapScrollMode(distance_x, distance_y); 299 snap_scroll_controller_.UpdateSnapScrollMode(distance_x, distance_y);
309 if (snap_scroll_controller_.IsSnappingScrolls()) { 300 if (snap_scroll_controller_.IsSnappingScrolls()) {
310 if (snap_scroll_controller_.IsSnapHorizontal()) 301 if (snap_scroll_controller_.IsSnapHorizontal())
311 distance_y = 0; 302 distance_y = 0;
312 else 303 else
313 distance_x = 0; 304 distance_x = 0;
314 } 305 }
315 306
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 bool InAnchoredScaleMode() const { 640 bool InAnchoredScaleMode() const {
650 return scale_gesture_detector_.InAnchoredScaleMode(); 641 return scale_gesture_detector_.InAnchoredScaleMode();
651 } 642 }
652 643
653 bool IsDoubleTapEnabled() const { 644 bool IsDoubleTapEnabled() const {
654 return gesture_detector_.has_doubletap_listener(); 645 return gesture_detector_.has_doubletap_listener();
655 } 646 }
656 647
657 void SetIgnoreSingleTap(bool value) { ignore_single_tap_ = value; } 648 void SetIgnoreSingleTap(bool value) { ignore_single_tap_ = value; }
658 649
650 // Calculate the subtraction value for touch scrolls
tdresser 2016/06/28 15:24:19 Missing period.
sahel 2016/06/29 16:26:19 Done.
651 void SetScrollValues(const MotionEvent& ev1,
652 const MotionEvent& ev2, const MotionEvent& secondary_pointer_down_event,
653 float& scroll_x, float& scroll_y) {
tdresser 2016/06/28 15:24:19 Maybe return a Point instead of using out paramete
sahel 2016/06/29 16:26:19 Done.
654
655 // If there are more than two down pointers, tapping is not possible.
656 // Slop region is not deducted.
tdresser 2016/06/28 15:24:19 "tapping is not possible, so the slop region is no
sahel 2016/06/29 16:26:19 Done.
657 if (ev2.GetPointerCount() > 2)
658 return;
659
660 const int id0 = ev1.GetPointerId(0);
661 const int ev_idx0 = ev2.GetPointerId(0) == id0 ? 0 : 1;
662
663 // Subtract the slop region from the first pointer move.
664 float dx0 = ev1.GetX() - ev2.GetX(ev_idx0);
665 float dy0 = ev1.GetY() - ev2.GetY(ev_idx0);
666 float distance0 = std::sqrt(dx0 * dx0 + dy0 * dy0);
667 float epsilon = 1e-3f;
668 if (distance0 > epsilon) {
669 float ratio = std::max(0.f, distance0 -
670 config_.gesture_detector_config.touch_slop ) / distance0;
671 dx0 *= ratio;
672 dy0 *= ratio;
673 }
674 float dx1 = 0;
675 float dy1 = 0;
676 // Subtract the slop region from the second pointer move.
677 if (ev2.GetPointerCount() == 2 ) {
678 const int ev_idx1 = ev_idx0 == 0 ? 1 : 0;
679 const int idx1 = secondary_pointer_down_event.GetActionIndex();
680 dx1 = secondary_pointer_down_event.GetX(idx1) - ev2.GetX(ev_idx1);
681 dy1 = secondary_pointer_down_event.GetY(idx1) - ev2.GetY(ev_idx1);
682 float distance1 = std::sqrt(dx1 * dx1 + dy1 * dy1);
683 if (distance1 > epsilon) {
684 float ratio = std::max(0.f, distance1 -
685 config_.gesture_detector_config.touch_slop ) / distance1;
686 dx1 *= ratio;
687 dy1 *= ratio;
688 }
689 }
690 scroll_x = (dx0 + dx1) / ev2.GetPointerCount();
691 scroll_y = (dy0 + dy1) / ev2.GetPointerCount();
tdresser 2016/06/28 15:24:19 This makes sense to me, but we should definitely t
sahel 2016/06/29 16:26:19 Sure, I'll play with the code, with a massive slop
692 }
693
659 const GestureProvider::Config config_; 694 const GestureProvider::Config config_;
660 GestureProviderClient* const client_; 695 GestureProviderClient* const client_;
661 696
662 GestureDetector gesture_detector_; 697 GestureDetector gesture_detector_;
663 ScaleGestureDetector scale_gesture_detector_; 698 ScaleGestureDetector scale_gesture_detector_;
664 SnapScrollController snap_scroll_controller_; 699 SnapScrollController snap_scroll_controller_;
665 700
666 base::TimeTicks current_down_time_; 701 base::TimeTicks current_down_time_;
667 702
668 // Keeps track of the current GESTURE_LONG_PRESS event. If a context menu is 703 // Keeps track of the current GESTURE_LONG_PRESS event. If a context menu is
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 // null'ing of the listener until the sequence has ended. 884 // null'ing of the listener until the sequence has ended.
850 if (current_down_event_) 885 if (current_down_event_)
851 return; 886 return;
852 887
853 const bool double_tap_enabled = 888 const bool double_tap_enabled =
854 double_tap_support_for_page_ && double_tap_support_for_platform_; 889 double_tap_support_for_page_ && double_tap_support_for_platform_;
855 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); 890 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled);
856 } 891 }
857 892
858 } // namespace ui 893 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698