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 <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 max_diameter_before_show_press_ = event.GetTouchMajor(); | 114 max_diameter_before_show_press_ = event.GetTouchMajor(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 gesture_detector_.OnTouchEvent(event); | 117 gesture_detector_.OnTouchEvent(event); |
| 118 scale_gesture_detector_.OnTouchEvent(event); | 118 scale_gesture_detector_.OnTouchEvent(event); |
| 119 | 119 |
| 120 if (action == MotionEvent::ACTION_UP || | 120 if (action == MotionEvent::ACTION_UP || |
| 121 action == MotionEvent::ACTION_CANCEL) { | 121 action == MotionEvent::ACTION_CANCEL) { |
| 122 // Note: This call will have no effect if a fling was just generated, as | 122 // Note: This call will have no effect if a fling was just generated, as |
| 123 // |Fling()| will have already signalled an end to touch-scrolling. | 123 // |Fling()| will have already signalled an end to touch-scrolling. |
| 124 if (scroll_event_sent_) | 124 if (scroll_event_sent_) { |
|
tdresser
2015/04/16 17:33:34
No reason to add braces here.
lanwei
2015/04/20 19:58:59
Done.
| |
| 125 Send(CreateGesture(ET_GESTURE_SCROLL_END, event)); | 125 Send(CreateGesture(ET_GESTURE_SCROLL_END, event)); |
| 126 } | |
| 126 current_down_time_ = base::TimeTicks(); | 127 current_down_time_ = base::TimeTicks(); |
| 127 } else if (action == MotionEvent::ACTION_MOVE) { | 128 } else if (action == MotionEvent::ACTION_MOVE) { |
| 128 if (!show_press_event_sent_ && !scroll_event_sent_) { | 129 if (!show_press_event_sent_ && !scroll_event_sent_) { |
| 129 max_diameter_before_show_press_ = | 130 max_diameter_before_show_press_ = |
| 130 std::max(max_diameter_before_show_press_, event.GetTouchMajor()); | 131 std::max(max_diameter_before_show_press_, event.GetTouchMajor()); |
| 131 } | 132 } |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 | 135 |
| 135 void Send(GestureEventData gesture) { | 136 void Send(GestureEventData gesture) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 return; | 211 return; |
| 211 Send(CreateGesture(ET_GESTURE_PINCH_END, e)); | 212 Send(CreateGesture(ET_GESTURE_PINCH_END, e)); |
| 212 } | 213 } |
| 213 | 214 |
| 214 bool OnScale(const ScaleGestureDetector& detector, | 215 bool OnScale(const ScaleGestureDetector& detector, |
| 215 const MotionEvent& e) override { | 216 const MotionEvent& e) override { |
| 216 if (ignore_multitouch_zoom_events_ && !detector.InDoubleTapMode()) | 217 if (ignore_multitouch_zoom_events_ && !detector.InDoubleTapMode()) |
| 217 return false; | 218 return false; |
| 218 if (!pinch_event_sent_) { | 219 if (!pinch_event_sent_) { |
| 219 Send(CreateGesture(ET_GESTURE_PINCH_BEGIN, | 220 Send(CreateGesture(ET_GESTURE_PINCH_BEGIN, |
| 220 e.GetId(), | 221 e.GetPointerId(), |
| 221 e.GetToolType(), | 222 e.GetToolType(), |
| 222 detector.GetEventTime(), | 223 detector.GetEventTime(), |
| 223 detector.GetFocusX(), | 224 detector.GetFocusX(), |
| 224 detector.GetFocusY(), | 225 detector.GetFocusY(), |
| 225 detector.GetFocusX() + e.GetRawOffsetX(), | 226 detector.GetFocusX() + e.GetRawOffsetX(), |
| 226 detector.GetFocusY() + e.GetRawOffsetY(), | 227 detector.GetFocusY() + e.GetRawOffsetY(), |
| 227 e.GetPointerCount(), | 228 e.GetPointerCount(), |
| 228 GetBoundingBox(e, ET_GESTURE_PINCH_BEGIN), | 229 GetBoundingBox(e, ET_GESTURE_PINCH_BEGIN), |
| 229 e.GetFlags())); | 230 e.GetFlags())); |
| 230 } | 231 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 246 // the scale delta remains constant if the touch velocity is constant. | 247 // the scale delta remains constant if the touch velocity is constant. |
| 247 float dy = | 248 float dy = |
| 248 (detector.GetCurrentSpanY() - detector.GetPreviousSpanY()) * 0.5f; | 249 (detector.GetCurrentSpanY() - detector.GetPreviousSpanY()) * 0.5f; |
| 249 scale = std::pow(scale > 1 ? 1.0f + kDoubleTapDragZoomSpeed | 250 scale = std::pow(scale > 1 ? 1.0f + kDoubleTapDragZoomSpeed |
| 250 : 1.0f - kDoubleTapDragZoomSpeed, | 251 : 1.0f - kDoubleTapDragZoomSpeed, |
| 251 std::abs(dy)); | 252 std::abs(dy)); |
| 252 } | 253 } |
| 253 GestureEventDetails pinch_details(ET_GESTURE_PINCH_UPDATE); | 254 GestureEventDetails pinch_details(ET_GESTURE_PINCH_UPDATE); |
| 254 pinch_details.set_scale(scale); | 255 pinch_details.set_scale(scale); |
| 255 Send(CreateGesture(pinch_details, | 256 Send(CreateGesture(pinch_details, |
| 256 e.GetId(), | 257 e.GetPointerId(), |
| 257 e.GetToolType(), | 258 e.GetToolType(), |
| 258 detector.GetEventTime(), | 259 detector.GetEventTime(), |
| 259 detector.GetFocusX(), | 260 detector.GetFocusX(), |
| 260 detector.GetFocusY(), | 261 detector.GetFocusY(), |
| 261 detector.GetFocusX() + e.GetRawOffsetX(), | 262 detector.GetFocusX() + e.GetRawOffsetX(), |
| 262 detector.GetFocusY() + e.GetRawOffsetY(), | 263 detector.GetFocusY() + e.GetRawOffsetY(), |
| 263 e.GetPointerCount(), | 264 e.GetPointerCount(), |
| 264 GetBoundingBox(e, pinch_details.type()), | 265 GetBoundingBox(e, pinch_details.type()), |
| 265 e.GetFlags())); | 266 e.GetFlags())); |
| 266 return true; | 267 return true; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 297 } | 298 } |
| 298 | 299 |
| 299 // Note that scroll start hints are in distance traveled, where | 300 // Note that scroll start hints are in distance traveled, where |
| 300 // scroll deltas are in the opposite direction. | 301 // scroll deltas are in the opposite direction. |
| 301 GestureEventDetails scroll_details( | 302 GestureEventDetails scroll_details( |
| 302 ET_GESTURE_SCROLL_BEGIN, -raw_distance_x, -raw_distance_y); | 303 ET_GESTURE_SCROLL_BEGIN, -raw_distance_x, -raw_distance_y); |
| 303 | 304 |
| 304 // Use the co-ordinates from the touch down, as these co-ordinates are | 305 // Use the co-ordinates from the touch down, as these co-ordinates are |
| 305 // used to determine which layer the scroll should affect. | 306 // used to determine which layer the scroll should affect. |
| 306 Send(CreateGesture(scroll_details, | 307 Send(CreateGesture(scroll_details, |
| 307 e2.GetId(), | 308 e2.GetPointerId(), |
| 308 e2.GetToolType(), | 309 e2.GetToolType(), |
| 309 e2.GetEventTime(), | 310 e2.GetEventTime(), |
| 310 e1.GetX(), | 311 e1.GetX(), |
| 311 e1.GetY(), | 312 e1.GetY(), |
| 312 e1.GetRawX(), | 313 e1.GetRawX(), |
| 313 e1.GetRawY(), | 314 e1.GetRawY(), |
| 314 e2.GetPointerCount(), | 315 e2.GetPointerCount(), |
| 315 GetBoundingBox(e2, scroll_details.type()), | 316 GetBoundingBox(e2, scroll_details.type()), |
| 316 e2.GetFlags())); | 317 e2.GetFlags())); |
| 317 DCHECK(scroll_event_sent_); | 318 DCHECK(scroll_event_sent_); |
| 318 } | 319 } |
| 319 | 320 |
| 320 snap_scroll_controller_.UpdateSnapScrollMode(distance_x, distance_y); | 321 snap_scroll_controller_.UpdateSnapScrollMode(distance_x, distance_y); |
| 321 if (snap_scroll_controller_.IsSnappingScrolls()) { | 322 if (snap_scroll_controller_.IsSnappingScrolls()) { |
| 322 if (snap_scroll_controller_.IsSnapHorizontal()) | 323 if (snap_scroll_controller_.IsSnapHorizontal()) |
| 323 distance_y = 0; | 324 distance_y = 0; |
| 324 else | 325 else |
| 325 distance_x = 0; | 326 distance_x = 0; |
| 326 } | 327 } |
| 327 | 328 |
| 328 if (distance_x || distance_y) { | 329 if (distance_x || distance_y) { |
| 329 GestureEventDetails scroll_details( | 330 GestureEventDetails scroll_details( |
| 330 ET_GESTURE_SCROLL_UPDATE, -distance_x, -distance_y); | 331 ET_GESTURE_SCROLL_UPDATE, -distance_x, -distance_y); |
| 331 const gfx::RectF bounding_box = GetBoundingBox(e2, scroll_details.type()); | 332 const gfx::RectF bounding_box = GetBoundingBox(e2, scroll_details.type()); |
| 332 const gfx::PointF center = bounding_box.CenterPoint(); | 333 const gfx::PointF center = bounding_box.CenterPoint(); |
| 333 const gfx::PointF raw_center = | 334 const gfx::PointF raw_center = |
| 334 center + gfx::Vector2dF(e2.GetRawOffsetX(), e2.GetRawOffsetY()); | 335 center + gfx::Vector2dF(e2.GetRawOffsetX(), e2.GetRawOffsetY()); |
| 335 Send(CreateGesture(scroll_details, | 336 Send(CreateGesture(scroll_details, |
| 336 e2.GetId(), | 337 e2.GetPointerId(), |
| 337 e2.GetToolType(), | 338 e2.GetToolType(), |
| 338 e2.GetEventTime(), | 339 e2.GetEventTime(), |
| 339 center.x(), | 340 center.x(), |
| 340 center.y(), | 341 center.y(), |
| 341 raw_center.x(), | 342 raw_center.x(), |
| 342 raw_center.y(), | 343 raw_center.y(), |
| 343 e2.GetPointerCount(), | 344 e2.GetPointerCount(), |
| 344 bounding_box, | 345 bounding_box, |
| 345 e2.GetFlags())); | 346 e2.GetFlags())); |
| 346 } | 347 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 Send(CreateGesture(swipe_details, e2)); | 387 Send(CreateGesture(swipe_details, e2)); |
| 387 return true; | 388 return true; |
| 388 } | 389 } |
| 389 | 390 |
| 390 bool OnTwoFingerTap(const MotionEvent& e1, const MotionEvent& e2) override { | 391 bool OnTwoFingerTap(const MotionEvent& e1, const MotionEvent& e2) override { |
| 391 // The location of the two finger tap event should be the location of the | 392 // The location of the two finger tap event should be the location of the |
| 392 // primary pointer. | 393 // primary pointer. |
| 393 GestureEventDetails two_finger_tap_details( | 394 GestureEventDetails two_finger_tap_details( |
| 394 ET_GESTURE_TWO_FINGER_TAP, e1.GetTouchMajor(), e1.GetTouchMajor()); | 395 ET_GESTURE_TWO_FINGER_TAP, e1.GetTouchMajor(), e1.GetTouchMajor()); |
| 395 Send(CreateGesture(two_finger_tap_details, | 396 Send(CreateGesture(two_finger_tap_details, |
| 396 e2.GetId(), | 397 e2.GetPointerId(), |
| 397 e2.GetToolType(), | 398 e2.GetToolType(), |
| 398 e2.GetEventTime(), | 399 e2.GetEventTime(), |
| 399 e1.GetX(), | 400 e1.GetX(), |
| 400 e1.GetY(), | 401 e1.GetY(), |
| 401 e1.GetRawX(), | 402 e1.GetRawX(), |
| 402 e1.GetRawY(), | 403 e1.GetRawY(), |
| 403 e2.GetPointerCount(), | 404 e2.GetPointerCount(), |
| 404 GetBoundingBox(e2, two_finger_tap_details.type()), | 405 GetBoundingBox(e2, two_finger_tap_details.type()), |
| 405 e2.GetFlags())); | 406 e2.GetFlags())); |
| 406 return true; | 407 return true; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 raw_x, | 535 raw_x, |
| 535 raw_y, | 536 raw_y, |
| 536 touch_point_count, | 537 touch_point_count, |
| 537 bounding_box, | 538 bounding_box, |
| 538 flags); | 539 flags); |
| 539 } | 540 } |
| 540 | 541 |
| 541 GestureEventData CreateGesture(const GestureEventDetails& details, | 542 GestureEventData CreateGesture(const GestureEventDetails& details, |
| 542 const MotionEvent& event) { | 543 const MotionEvent& event) { |
| 543 return GestureEventData(details, | 544 return GestureEventData(details, |
| 544 event.GetId(), | 545 event.GetPointerId(), |
| 545 event.GetToolType(), | 546 event.GetToolType(), |
| 546 event.GetEventTime(), | 547 event.GetEventTime(), |
| 547 event.GetX(), | 548 event.GetX(), |
| 548 event.GetY(), | 549 event.GetY(), |
| 549 event.GetRawX(), | 550 event.GetRawX(), |
| 550 event.GetRawY(), | 551 event.GetRawY(), |
| 551 event.GetPointerCount(), | 552 event.GetPointerCount(), |
| 552 GetBoundingBox(event, details.type()), | 553 GetBoundingBox(event, details.type()), |
| 553 event.GetFlags()); | 554 event.GetFlags()); |
| 554 } | 555 } |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 current_down_event_ = event.Clone(); | 766 current_down_event_ = event.Clone(); |
| 766 if (gesture_begin_end_types_enabled_) | 767 if (gesture_begin_end_types_enabled_) |
| 767 gesture_listener_->Send( | 768 gesture_listener_->Send( |
| 768 gesture_listener_->CreateGesture(ET_GESTURE_BEGIN, event)); | 769 gesture_listener_->CreateGesture(ET_GESTURE_BEGIN, event)); |
| 769 break; | 770 break; |
| 770 case MotionEvent::ACTION_POINTER_DOWN: | 771 case MotionEvent::ACTION_POINTER_DOWN: |
| 771 if (gesture_begin_end_types_enabled_) { | 772 if (gesture_begin_end_types_enabled_) { |
| 772 const int action_index = event.GetActionIndex(); | 773 const int action_index = event.GetActionIndex(); |
| 773 gesture_listener_->Send(gesture_listener_->CreateGesture( | 774 gesture_listener_->Send(gesture_listener_->CreateGesture( |
| 774 ET_GESTURE_BEGIN, | 775 ET_GESTURE_BEGIN, |
| 775 event.GetId(), | 776 event.GetPointerId(), |
| 776 event.GetToolType(), | 777 event.GetToolType(), |
| 777 event.GetEventTime(), | 778 event.GetEventTime(), |
| 778 event.GetX(action_index), | 779 event.GetX(action_index), |
| 779 event.GetY(action_index), | 780 event.GetY(action_index), |
| 780 event.GetRawX(action_index), | 781 event.GetRawX(action_index), |
| 781 event.GetRawY(action_index), | 782 event.GetRawY(action_index), |
| 782 event.GetPointerCount(), | 783 event.GetPointerCount(), |
| 783 gesture_listener_->GetBoundingBox(event, ET_GESTURE_BEGIN), | 784 gesture_listener_->GetBoundingBox(event, ET_GESTURE_BEGIN), |
| 784 event.GetFlags())); | 785 event.GetFlags())); |
| 785 } | 786 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 823 // null'ing of the listener until the sequence has ended. | 824 // null'ing of the listener until the sequence has ended. |
| 824 if (current_down_event_) | 825 if (current_down_event_) |
| 825 return; | 826 return; |
| 826 | 827 |
| 827 const bool double_tap_enabled = | 828 const bool double_tap_enabled = |
| 828 double_tap_support_for_page_ && double_tap_support_for_platform_; | 829 double_tap_support_for_page_ && double_tap_support_for_platform_; |
| 829 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 830 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
| 830 } | 831 } |
| 831 | 832 |
| 832 } // namespace ui | 833 } // namespace ui |
| OLD | NEW |