Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, |
| 287 float raw_distance_x, | 286 float raw_distance_x, |
| 288 float raw_distance_y) override { | 287 float raw_distance_y) override { |
| 289 float distance_x = raw_distance_x; | 288 float distance_x = raw_distance_x; |
| 290 float distance_y = raw_distance_y; | 289 float distance_y = raw_distance_y; |
| 291 if (!scroll_event_sent_ && e2.GetPointerCount() == 1) { | 290 if (!scroll_event_sent_ && e2.GetPointerCount() < 3) { |
| 292 // Remove the touch slop region from the first scroll event to | 291 // 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 | 292 // 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. | 293 // pointers down, in those cases we don't subtract the slop. |
| 295 float distance = | 294 float distance = |
| 296 std::sqrt(distance_x * distance_x + distance_y * distance_y); | 295 std::sqrt(distance_x * distance_x + distance_y * distance_y); |
| 297 float epsilon = 1e-3f; | 296 float epsilon = 1e-3f; |
| 298 if (distance > epsilon) { | 297 if (distance > epsilon) { |
| 299 float ratio = | 298 float subtraction_value = config_.gesture_detector_config.touch_slop / |
| 300 std::max(0.f, | 299 e2.GetPointerCount(); |
| 301 distance - config_.gesture_detector_config.touch_slop) / | 300 float ratio = std::max(0.f, distance - subtraction_value ) / distance; |
|
tdresser
2016/06/10 19:34:57
Is this logic correct? If the two pointers move in
sahel
2016/06/23 22:34:44
Done.
| |
| 302 distance; | |
| 303 distance_x *= ratio; | 301 distance_x *= ratio; |
| 304 distance_y *= ratio; | 302 distance_y *= ratio; |
| 305 } | 303 } |
| 306 } | 304 } |
| 307 | 305 |
| 308 snap_scroll_controller_.UpdateSnapScrollMode(distance_x, distance_y); | 306 snap_scroll_controller_.UpdateSnapScrollMode(distance_x, distance_y); |
| 309 if (snap_scroll_controller_.IsSnappingScrolls()) { | 307 if (snap_scroll_controller_.IsSnappingScrolls()) { |
| 310 if (snap_scroll_controller_.IsSnapHorizontal()) | 308 if (snap_scroll_controller_.IsSnapHorizontal()) |
| 311 distance_y = 0; | 309 distance_y = 0; |
| 312 else | 310 else |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 // null'ing of the listener until the sequence has ended. | 836 // null'ing of the listener until the sequence has ended. |
| 839 if (current_down_event_) | 837 if (current_down_event_) |
| 840 return; | 838 return; |
| 841 | 839 |
| 842 const bool double_tap_enabled = | 840 const bool double_tap_enabled = |
| 843 double_tap_support_for_page_ && double_tap_support_for_platform_; | 841 double_tap_support_for_page_ && double_tap_support_for_platform_; |
| 844 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 842 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
| 845 } | 843 } |
| 846 | 844 |
| 847 } // namespace ui | 845 } // namespace ui |
| OLD | NEW |