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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 seen_first_scroll_event_ = true; | 311 seen_first_scroll_event_ = true; |
312 double distance = | 312 double distance = |
313 std::sqrt(distance_x * distance_x + distance_y * distance_y); | 313 std::sqrt(distance_x * distance_x + distance_y * distance_y); |
314 double epsilon = 1e-3; | 314 double epsilon = 1e-3; |
315 if (distance > epsilon) { | 315 if (distance > epsilon) { |
316 double ratio = std::max(0., distance - touch_slop_) / distance; | 316 double ratio = std::max(0., distance - touch_slop_) / distance; |
317 distance_x *= ratio; | 317 distance_x *= ratio; |
318 distance_y *= ratio; | 318 distance_y *= ratio; |
319 } | 319 } |
320 } | 320 } |
321 | |
322 float ordinal_distance_x = distance_x; | |
jdduke (slow)
2014/04/24 19:58:53
Nit: Let's make these const above and below sugges
| |
323 float ordinal_distance_y = distance_y; | |
324 | |
321 snap_scroll_controller_.UpdateSnapScrollMode(distance_x, distance_y); | 325 snap_scroll_controller_.UpdateSnapScrollMode(distance_x, distance_y); |
322 if (snap_scroll_controller_.IsSnappingScrolls()) { | 326 if (snap_scroll_controller_.IsSnappingScrolls()) { |
323 if (snap_scroll_controller_.IsSnapHorizontal()) { | 327 if (snap_scroll_controller_.IsSnapHorizontal()) { |
324 distance_y = 0; | 328 distance_y = 0; |
325 } else { | 329 } else { |
326 distance_x = 0; | 330 distance_x = 0; |
327 } | 331 } |
328 } | 332 } |
329 | 333 |
330 if (!provider_->IsScrollInProgress()) { | 334 if (!provider_->IsScrollInProgress()) { |
331 // Note that scroll start hints are in distance traveled, where | 335 // Note that scroll start hints are in distance traveled, where |
332 // scroll deltas are in the opposite direction. | 336 // scroll deltas are in the opposite direction. |
333 GestureEventDetails scroll_details( | 337 GestureEventDetails scroll_details( |
334 ET_GESTURE_SCROLL_BEGIN, -raw_distance_x, -raw_distance_y); | 338 ET_GESTURE_SCROLL_BEGIN, -raw_distance_x, -raw_distance_y); |
335 | 339 |
336 // Use the co-ordinates from the touch down, as these co-ordinates are | 340 // Use the co-ordinates from the touch down, as these co-ordinates are |
337 // used to determine which layer the scroll should affect. | 341 // used to determine which layer the scroll should affect. |
338 provider_->Send(CreateGesture(ET_GESTURE_SCROLL_BEGIN, | 342 provider_->Send(CreateGesture(ET_GESTURE_SCROLL_BEGIN, |
339 e2.GetId(), | 343 e2.GetId(), |
340 e2.GetEventTime(), | 344 e2.GetEventTime(), |
341 e1.GetX(), | 345 e1.GetX(), |
342 e1.GetY(), | 346 e1.GetY(), |
343 e2.GetPointerCount(), | 347 e2.GetPointerCount(), |
344 GetBoundingBox(e2), | 348 GetBoundingBox(e2), |
345 scroll_details)); | 349 scroll_details)); |
346 } | 350 } |
347 | 351 |
348 if (distance_x || distance_y) { | 352 if (distance_x || distance_y) { |
349 GestureEventDetails scroll_details( | 353 GestureEventDetails scroll_details(ET_GESTURE_SCROLL_UPDATE, |
350 ET_GESTURE_SCROLL_UPDATE, -distance_x, -distance_y); | 354 -distance_x, |
355 -distance_y, | |
356 -ordinal_distance_x, | |
357 -ordinal_distance_y); | |
351 provider_->Send( | 358 provider_->Send( |
352 CreateGesture(ET_GESTURE_SCROLL_UPDATE, e2, scroll_details)); | 359 CreateGesture(ET_GESTURE_SCROLL_UPDATE, e2, scroll_details)); |
353 } | 360 } |
354 | 361 |
355 return true; | 362 return true; |
356 } | 363 } |
357 | 364 |
358 virtual bool OnFling(const MotionEvent& e1, | 365 virtual bool OnFling(const MotionEvent& e1, |
359 const MotionEvent& e2, | 366 const MotionEvent& e2, |
360 float velocity_x, | 367 float velocity_x, |
361 float velocity_y) OVERRIDE { | 368 float velocity_y) OVERRIDE { |
369 float ordinal_velocity_x = velocity_x; | |
370 float ordinal_velocity_y = velocity_y; | |
371 | |
362 if (snap_scroll_controller_.IsSnappingScrolls()) { | 372 if (snap_scroll_controller_.IsSnappingScrolls()) { |
363 if (snap_scroll_controller_.IsSnapHorizontal()) { | 373 if (snap_scroll_controller_.IsSnapHorizontal()) { |
364 velocity_y = 0; | 374 velocity_y = 0; |
365 } else { | 375 } else { |
366 velocity_x = 0; | 376 velocity_x = 0; |
367 } | 377 } |
368 } | 378 } |
369 | 379 |
370 provider_->Fling(e2, velocity_x, velocity_y); | 380 provider_->Fling( |
381 e2, velocity_x, velocity_y, ordinal_velocity_x, ordinal_velocity_y); | |
371 return true; | 382 return true; |
372 } | 383 } |
373 | 384 |
374 virtual void OnShowPress(const MotionEvent& e) OVERRIDE { | 385 virtual void OnShowPress(const MotionEvent& e) OVERRIDE { |
375 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS, 0, 0); | 386 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS, 0, 0); |
376 provider_->Send( | 387 provider_->Send( |
377 CreateGesture(ET_GESTURE_SHOW_PRESS, e, show_press_details)); | 388 CreateGesture(ET_GESTURE_SHOW_PRESS, e, show_press_details)); |
378 } | 389 } |
379 | 390 |
380 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE { | 391 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 | 591 |
581 UpdateDoubleTapDetectionSupport(); | 592 UpdateDoubleTapDetectionSupport(); |
582 } | 593 } |
583 | 594 |
584 bool GestureProvider::CanHandle(const MotionEvent& event) const { | 595 bool GestureProvider::CanHandle(const MotionEvent& event) const { |
585 return event.GetAction() == MotionEvent::ACTION_DOWN || current_down_event_; | 596 return event.GetAction() == MotionEvent::ACTION_DOWN || current_down_event_; |
586 } | 597 } |
587 | 598 |
588 void GestureProvider::Fling(const MotionEvent& event, | 599 void GestureProvider::Fling(const MotionEvent& event, |
589 float velocity_x, | 600 float velocity_x, |
590 float velocity_y) { | 601 float velocity_y, |
602 float ordinal_velocity_x, | |
603 float ordinal_velocity_y) { | |
591 if (!velocity_x && !velocity_y) { | 604 if (!velocity_x && !velocity_y) { |
592 EndTouchScrollIfNecessary(event, true); | 605 EndTouchScrollIfNecessary(event, true); |
593 return; | 606 return; |
594 } | 607 } |
595 | 608 |
596 if (!touch_scroll_in_progress_) { | 609 if (!touch_scroll_in_progress_) { |
597 // The native side needs a ET_GESTURE_SCROLL_BEGIN before | 610 // The native side needs a ET_GESTURE_SCROLL_BEGIN before |
598 // ET_SCROLL_FLING_START to send the fling to the correct target. Send if it | 611 // ET_SCROLL_FLING_START to send the fling to the correct target. Send if it |
599 // has not sent. The distance traveled in one second is a reasonable scroll | 612 // has not sent. The distance traveled in one second is a reasonable scroll |
600 // start hint. | 613 // start hint. |
601 GestureEventDetails scroll_details( | 614 GestureEventDetails scroll_details( |
602 ET_GESTURE_SCROLL_BEGIN, velocity_x, velocity_y); | 615 ET_GESTURE_SCROLL_BEGIN, velocity_x, velocity_y); |
603 Send(CreateGesture(ET_GESTURE_SCROLL_BEGIN, event, scroll_details)); | 616 Send(CreateGesture(ET_GESTURE_SCROLL_BEGIN, event, scroll_details)); |
604 } | 617 } |
605 EndTouchScrollIfNecessary(event, false); | 618 EndTouchScrollIfNecessary(event, false); |
606 | 619 |
607 GestureEventDetails fling_details( | 620 GestureEventDetails fling_details(ET_SCROLL_FLING_START, |
608 ET_SCROLL_FLING_START, velocity_x, velocity_y); | 621 velocity_x, |
622 velocity_y, | |
623 ordinal_velocity_x, | |
624 ordinal_velocity_y); | |
609 Send(CreateGesture( | 625 Send(CreateGesture( |
610 ET_SCROLL_FLING_START, event, fling_details)); | 626 ET_SCROLL_FLING_START, event, fling_details)); |
611 } | 627 } |
612 | 628 |
613 void GestureProvider::Send(const GestureEventData& gesture) { | 629 void GestureProvider::Send(const GestureEventData& gesture) { |
614 DCHECK(!gesture.time.is_null()); | 630 DCHECK(!gesture.time.is_null()); |
615 // The only valid events that should be sent without an active touch sequence | 631 // The only valid events that should be sent without an active touch sequence |
616 // are SHOW_PRESS and TAP, potentially triggered by the double-tap | 632 // are SHOW_PRESS and TAP, potentially triggered by the double-tap |
617 // delay timing out. | 633 // delay timing out. |
618 DCHECK(current_down_event_ || gesture.type == ET_GESTURE_TAP || | 634 DCHECK(current_down_event_ || gesture.type == ET_GESTURE_TAP || |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
746 if (current_down_event_) | 762 if (current_down_event_) |
747 return; | 763 return; |
748 | 764 |
749 const bool double_tap_enabled = double_tap_support_for_page_ && | 765 const bool double_tap_enabled = double_tap_support_for_page_ && |
750 double_tap_support_for_platform_; | 766 double_tap_support_for_platform_; |
751 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 767 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
752 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 768 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
753 } | 769 } |
754 | 770 |
755 } // namespace ui | 771 } // namespace ui |
OLD | NEW |