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 13 matching lines...) Expand all Loading... |
24 case MotionEvent::ACTION_POINTER_UP: return "ACTION_POINTER_UP"; | 24 case MotionEvent::ACTION_POINTER_UP: return "ACTION_POINTER_UP"; |
25 case MotionEvent::ACTION_DOWN: return "ACTION_DOWN"; | 25 case MotionEvent::ACTION_DOWN: return "ACTION_DOWN"; |
26 case MotionEvent::ACTION_UP: return "ACTION_UP"; | 26 case MotionEvent::ACTION_UP: return "ACTION_UP"; |
27 case MotionEvent::ACTION_CANCEL: return "ACTION_CANCEL"; | 27 case MotionEvent::ACTION_CANCEL: return "ACTION_CANCEL"; |
28 case MotionEvent::ACTION_MOVE: return "ACTION_MOVE"; | 28 case MotionEvent::ACTION_MOVE: return "ACTION_MOVE"; |
29 } | 29 } |
30 return ""; | 30 return ""; |
31 } | 31 } |
32 | 32 |
33 GestureEventData CreateGesture(EventType type, | 33 GestureEventData CreateGesture(EventType type, |
| 34 int motion_event_id, |
34 base::TimeTicks time, | 35 base::TimeTicks time, |
35 float x, | 36 float x, |
36 float y, | 37 float y, |
37 const GestureEventDetails& details) { | 38 const GestureEventDetails& details) { |
38 return GestureEventData(type, time, x, y, details); | 39 return GestureEventData(type, motion_event_id, time, x, y, details); |
39 } | 40 } |
40 | 41 |
41 GestureEventData CreateGesture(EventType type, | 42 GestureEventData CreateGesture(EventType type, |
| 43 int motion_event_id, |
42 base::TimeTicks time, | 44 base::TimeTicks time, |
43 float x, | 45 float x, |
44 float y) { | 46 float y) { |
45 return GestureEventData(type, time, x, y); | 47 return GestureEventData(type, motion_event_id, time, x, y); |
46 } | 48 } |
47 | 49 |
48 GestureEventData CreateGesture(EventType type, | 50 GestureEventData CreateGesture(EventType type, |
49 const MotionEvent& event, | 51 const MotionEvent& event, |
50 const GestureEventDetails& details) { | 52 const GestureEventDetails& details) { |
51 return CreateGesture( | 53 return CreateGesture(type, |
52 type, event.GetEventTime(), event.GetX(), event.GetY(), details); | 54 event.GetId(), |
| 55 event.GetEventTime(), |
| 56 event.GetX(), |
| 57 event.GetY(), |
| 58 details); |
53 } | 59 } |
54 | 60 |
55 GestureEventData CreateGesture(EventType type, | 61 GestureEventData CreateGesture(EventType type, |
56 const MotionEvent& event) { | 62 const MotionEvent& event) { |
57 return CreateGesture(type, event.GetEventTime(), event.GetX(), event.GetY()); | 63 return CreateGesture( |
| 64 type, event.GetId(), event.GetEventTime(), event.GetX(), event.GetY()); |
58 } | 65 } |
59 | 66 |
60 GestureEventDetails CreateTapGestureDetails(EventType type, | 67 GestureEventDetails CreateTapGestureDetails(EventType type, |
61 const MotionEvent& event) { | 68 const MotionEvent& event) { |
62 // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be | 69 // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be |
63 // consistent with double tap behavior on a mobile viewport. See | 70 // consistent with double tap behavior on a mobile viewport. See |
64 // crbug.com/234986 for context. | 71 // crbug.com/234986 for context. |
65 GestureEventDetails tap_details(type, 1, 0); | 72 GestureEventDetails tap_details(type, 1, 0); |
66 tap_details.set_bounding_box( | 73 tap_details.set_bounding_box( |
67 gfx::RectF(event.GetTouchMajor(), event.GetTouchMajor())); | 74 gfx::RectF(event.GetTouchMajor(), event.GetTouchMajor())); |
(...skipping 28 matching lines...) Expand all Loading... |
96 bool handled = scale_gesture_detector_.OnTouchEvent(event); | 103 bool handled = scale_gesture_detector_.OnTouchEvent(event); |
97 if (!in_scale_gesture && | 104 if (!in_scale_gesture && |
98 (event.GetAction() == MotionEvent::ACTION_UP || | 105 (event.GetAction() == MotionEvent::ACTION_UP || |
99 event.GetAction() == MotionEvent::ACTION_CANCEL)) { | 106 event.GetAction() == MotionEvent::ACTION_CANCEL)) { |
100 return false; | 107 return false; |
101 } | 108 } |
102 return handled; | 109 return handled; |
103 } | 110 } |
104 | 111 |
105 // ScaleGestureDetector::ScaleGestureListener implementation. | 112 // ScaleGestureDetector::ScaleGestureListener implementation. |
106 virtual bool OnScaleBegin(const ScaleGestureDetector& detector) OVERRIDE { | 113 virtual bool OnScaleBegin(const ScaleGestureDetector& detector, |
| 114 const MotionEvent& e) OVERRIDE { |
107 if (ignore_multitouch_events_ && !detector.InDoubleTapMode()) | 115 if (ignore_multitouch_events_ && !detector.InDoubleTapMode()) |
108 return false; | 116 return false; |
109 pinch_event_sent_ = false; | 117 pinch_event_sent_ = false; |
110 return true; | 118 return true; |
111 } | 119 } |
112 | 120 |
113 virtual void OnScaleEnd(const ScaleGestureDetector& detector) OVERRIDE { | 121 virtual void OnScaleEnd(const ScaleGestureDetector& detector, |
| 122 const MotionEvent& e) OVERRIDE { |
114 if (!pinch_event_sent_) | 123 if (!pinch_event_sent_) |
115 return; | 124 return; |
116 provider_->Send( | 125 provider_->Send(CreateGesture( |
117 CreateGesture(ET_GESTURE_PINCH_END, detector.GetEventTime(), 0, 0)); | 126 ET_GESTURE_PINCH_END, e.GetId(), detector.GetEventTime(), 0, 0)); |
118 pinch_event_sent_ = false; | 127 pinch_event_sent_ = false; |
119 } | 128 } |
120 | 129 |
121 virtual bool OnScale(const ScaleGestureDetector& detector) OVERRIDE { | 130 virtual bool OnScale(const ScaleGestureDetector& detector, |
| 131 const MotionEvent& e) OVERRIDE { |
122 if (ignore_multitouch_events_ && !detector.InDoubleTapMode()) | 132 if (ignore_multitouch_events_ && !detector.InDoubleTapMode()) |
123 return false; | 133 return false; |
124 if (!pinch_event_sent_) { | 134 if (!pinch_event_sent_) { |
125 pinch_event_sent_ = true; | 135 pinch_event_sent_ = true; |
126 provider_->Send(CreateGesture(ET_GESTURE_PINCH_BEGIN, | 136 provider_->Send(CreateGesture(ET_GESTURE_PINCH_BEGIN, |
| 137 e.GetId(), |
127 detector.GetEventTime(), | 138 detector.GetEventTime(), |
128 detector.GetFocusX(), | 139 detector.GetFocusX(), |
129 detector.GetFocusY())); | 140 detector.GetFocusY())); |
130 } | 141 } |
131 | 142 |
132 float scale = detector.GetScaleFactor(); | 143 float scale = detector.GetScaleFactor(); |
133 if (scale == 1) | 144 if (scale == 1) |
134 return true; | 145 return true; |
135 | 146 |
136 if (detector.InDoubleTapMode()) { | 147 if (detector.InDoubleTapMode()) { |
137 // Relative changes in the double-tap scale factor computed by |detector| | 148 // Relative changes in the double-tap scale factor computed by |detector| |
138 // diminish as the touch moves away from the original double-tap focus. | 149 // diminish as the touch moves away from the original double-tap focus. |
139 // For historical reasons, Chrome has instead adopted a scale factor | 150 // For historical reasons, Chrome has instead adopted a scale factor |
140 // computation that is invariant to the focal distance, where | 151 // computation that is invariant to the focal distance, where |
141 // the scale delta remains constant if the touch velocity is constant. | 152 // the scale delta remains constant if the touch velocity is constant. |
142 float dy = | 153 float dy = |
143 (detector.GetCurrentSpanY() - detector.GetPreviousSpanY()) * 0.5f; | 154 (detector.GetCurrentSpanY() - detector.GetPreviousSpanY()) * 0.5f; |
144 scale = std::pow(scale > 1 ? 1.0f + kDoubleTapDragZoomSpeed | 155 scale = std::pow(scale > 1 ? 1.0f + kDoubleTapDragZoomSpeed |
145 : 1.0f - kDoubleTapDragZoomSpeed, | 156 : 1.0f - kDoubleTapDragZoomSpeed, |
146 std::abs(dy * px_to_dp_)); | 157 std::abs(dy * px_to_dp_)); |
147 } | 158 } |
148 GestureEventDetails pinch_details(ET_GESTURE_PINCH_UPDATE, scale, 0); | 159 GestureEventDetails pinch_details(ET_GESTURE_PINCH_UPDATE, scale, 0); |
149 provider_->Send(CreateGesture(ET_GESTURE_PINCH_UPDATE, | 160 provider_->Send(CreateGesture(ET_GESTURE_PINCH_UPDATE, |
| 161 e.GetId(), |
150 detector.GetEventTime(), | 162 detector.GetEventTime(), |
151 detector.GetFocusX(), | 163 detector.GetFocusX(), |
152 detector.GetFocusY(), | 164 detector.GetFocusY(), |
153 pinch_details)); | 165 pinch_details)); |
154 return true; | 166 return true; |
155 } | 167 } |
156 | 168 |
157 void SetDoubleTapEnabled(bool enabled) { | 169 void SetDoubleTapEnabled(bool enabled) { |
158 DCHECK(!IsDoubleTapInProgress()); | 170 DCHECK(!IsDoubleTapInProgress()); |
159 scale_gesture_detector_.SetQuickScaleEnabled(enabled); | 171 scale_gesture_detector_.SetQuickScaleEnabled(enabled); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 } | 298 } |
287 | 299 |
288 last_raw_x_ = e2.GetRawX(); | 300 last_raw_x_ = e2.GetRawX(); |
289 last_raw_y_ = e2.GetRawY(); | 301 last_raw_y_ = e2.GetRawY(); |
290 if (!provider_->IsScrollInProgress()) { | 302 if (!provider_->IsScrollInProgress()) { |
291 // Note that scroll start hints are in distance traveled, where | 303 // Note that scroll start hints are in distance traveled, where |
292 // scroll deltas are in the opposite direction. | 304 // scroll deltas are in the opposite direction. |
293 GestureEventDetails scroll_details( | 305 GestureEventDetails scroll_details( |
294 ET_GESTURE_SCROLL_BEGIN, -raw_distance_x, -raw_distance_y); | 306 ET_GESTURE_SCROLL_BEGIN, -raw_distance_x, -raw_distance_y); |
295 provider_->Send(CreateGesture(ET_GESTURE_SCROLL_BEGIN, | 307 provider_->Send(CreateGesture(ET_GESTURE_SCROLL_BEGIN, |
| 308 e2.GetId(), |
296 e2.GetEventTime(), | 309 e2.GetEventTime(), |
297 e1.GetX(), | 310 e1.GetX(), |
298 e1.GetY(), | 311 e1.GetY(), |
299 scroll_details)); | 312 scroll_details)); |
300 } | 313 } |
301 | 314 |
302 // distance_x and distance_y is the scrolling offset since last OnScroll. | 315 // distance_x and distance_y is the scrolling offset since last OnScroll. |
303 // Because we are passing integers to Blink, this could introduce | 316 // Because we are passing integers to Blink, this could introduce |
304 // rounding errors. The rounding errors will accumulate overtime. | 317 // rounding errors. The rounding errors will accumulate overtime. |
305 // To solve this, we should be adding back the rounding errors each time | 318 // To solve this, we should be adding back the rounding errors each time |
(...skipping 19 matching lines...) Expand all Loading... |
325 float velocity_x, | 338 float velocity_x, |
326 float velocity_y) OVERRIDE { | 339 float velocity_y) OVERRIDE { |
327 if (snap_scroll_controller_.IsSnappingScrolls()) { | 340 if (snap_scroll_controller_.IsSnappingScrolls()) { |
328 if (snap_scroll_controller_.IsSnapHorizontal()) { | 341 if (snap_scroll_controller_.IsSnapHorizontal()) { |
329 velocity_y = 0; | 342 velocity_y = 0; |
330 } else { | 343 } else { |
331 velocity_x = 0; | 344 velocity_x = 0; |
332 } | 345 } |
333 } | 346 } |
334 | 347 |
335 provider_->Fling( | 348 provider_->Fling(e2, velocity_x, velocity_y); |
336 e2.GetEventTime(), e1.GetX(), e1.GetY(), velocity_x, velocity_y); | |
337 return true; | 349 return true; |
338 } | 350 } |
339 | 351 |
340 virtual void OnShowPress(const MotionEvent& e) OVERRIDE { | 352 virtual void OnShowPress(const MotionEvent& e) OVERRIDE { |
341 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS, 0, 0); | 353 GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS, 0, 0); |
342 // TODO(jdduke): Expose minor axis length and rotation in |MotionEvent|. | 354 // TODO(jdduke): Expose minor axis length and rotation in |MotionEvent|. |
343 show_press_details.set_bounding_box( | 355 show_press_details.set_bounding_box( |
344 gfx::RectF(e.GetTouchMajor(), e.GetTouchMajor())); | 356 gfx::RectF(e.GetTouchMajor(), e.GetTouchMajor())); |
345 provider_->Send( | 357 provider_->Send( |
346 CreateGesture(ET_GESTURE_SHOW_PRESS, e, show_press_details)); | 358 CreateGesture(ET_GESTURE_SHOW_PRESS, e, show_press_details)); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 SendTapCancelIfNecessary(event); | 556 SendTapCancelIfNecessary(event); |
545 } | 557 } |
546 | 558 |
547 bool handled = gesture_listener_->OnTouchEvent(event, in_scale_gesture); | 559 bool handled = gesture_listener_->OnTouchEvent(event, in_scale_gesture); |
548 handled |= scale_gesture_listener_->OnTouchEvent(event); | 560 handled |= scale_gesture_listener_->OnTouchEvent(event); |
549 | 561 |
550 if (event.GetAction() == MotionEvent::ACTION_UP || | 562 if (event.GetAction() == MotionEvent::ACTION_UP || |
551 event.GetAction() == MotionEvent::ACTION_CANCEL) { | 563 event.GetAction() == MotionEvent::ACTION_CANCEL) { |
552 // Note: This call will have no effect if a fling was just generated, as | 564 // Note: This call will have no effect if a fling was just generated, as |
553 // |Fling()| will have already signalled an end to touch-scrolling. | 565 // |Fling()| will have already signalled an end to touch-scrolling. |
554 EndTouchScrollIfNecessary(event.GetEventTime(), true); | 566 EndTouchScrollIfNecessary(event, true); |
555 | 567 |
556 // We shouldn't necessarily cancel a tap on ACTION_UP, as the double-tap | 568 // We shouldn't necessarily cancel a tap on ACTION_UP, as the double-tap |
557 // timeout may yet trigger a SINGLE_TAP. | 569 // timeout may yet trigger a SINGLE_TAP. |
558 if (event.GetAction() == MotionEvent::ACTION_CANCEL) | 570 if (event.GetAction() == MotionEvent::ACTION_CANCEL) |
559 SendTapCancelIfNecessary(event); | 571 SendTapCancelIfNecessary(event); |
560 | 572 |
561 UpdateDoubleTapDetectionSupport(); | 573 UpdateDoubleTapDetectionSupport(); |
562 | 574 |
563 current_down_event_.reset(); | 575 current_down_event_.reset(); |
564 } | 576 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 config.snap_scroll_controller_config.device_scale_factor, | 634 config.snap_scroll_controller_config.device_scale_factor, |
623 this)); | 635 this)); |
624 | 636 |
625 UpdateDoubleTapDetectionSupport(); | 637 UpdateDoubleTapDetectionSupport(); |
626 } | 638 } |
627 | 639 |
628 bool GestureProvider::CanHandle(const MotionEvent& event) const { | 640 bool GestureProvider::CanHandle(const MotionEvent& event) const { |
629 return event.GetAction() == MotionEvent::ACTION_DOWN || current_down_event_; | 641 return event.GetAction() == MotionEvent::ACTION_DOWN || current_down_event_; |
630 } | 642 } |
631 | 643 |
632 void GestureProvider::Fling(base::TimeTicks time, | 644 void GestureProvider::Fling(const MotionEvent& event, |
633 float x, | |
634 float y, | |
635 float velocity_x, | 645 float velocity_x, |
636 float velocity_y) { | 646 float velocity_y) { |
637 if (!velocity_x && !velocity_y) { | 647 if (!velocity_x && !velocity_y) { |
638 EndTouchScrollIfNecessary(time, true); | 648 EndTouchScrollIfNecessary(event, true); |
639 return; | 649 return; |
640 } | 650 } |
641 | 651 |
642 if (!touch_scroll_in_progress_) { | 652 if (!touch_scroll_in_progress_) { |
643 // The native side needs a ET_GESTURE_SCROLL_BEGIN before | 653 // The native side needs a ET_GESTURE_SCROLL_BEGIN before |
644 // ET_SCROLL_FLING_START to send the fling to the correct target. Send if it | 654 // ET_SCROLL_FLING_START to send the fling to the correct target. Send if it |
645 // has not sent. The distance traveled in one second is a reasonable scroll | 655 // has not sent. The distance traveled in one second is a reasonable scroll |
646 // start hint. | 656 // start hint. |
647 GestureEventDetails scroll_details( | 657 GestureEventDetails scroll_details( |
648 ET_GESTURE_SCROLL_BEGIN, velocity_x, velocity_y); | 658 ET_GESTURE_SCROLL_BEGIN, velocity_x, velocity_y); |
649 Send(CreateGesture(ET_GESTURE_SCROLL_BEGIN, time, x, y, scroll_details)); | 659 Send(CreateGesture(ET_GESTURE_SCROLL_BEGIN, event, scroll_details)); |
650 } | 660 } |
651 EndTouchScrollIfNecessary(time, false); | 661 EndTouchScrollIfNecessary(event, false); |
652 | 662 |
653 GestureEventDetails fling_details( | 663 GestureEventDetails fling_details( |
654 ET_SCROLL_FLING_START, velocity_x, velocity_y); | 664 ET_SCROLL_FLING_START, velocity_x, velocity_y); |
655 Send(CreateGesture(ET_SCROLL_FLING_START, time, x, y, fling_details)); | 665 Send(CreateGesture( |
| 666 ET_SCROLL_FLING_START, event, fling_details)); |
656 } | 667 } |
657 | 668 |
658 void GestureProvider::Send(const GestureEventData& gesture) { | 669 void GestureProvider::Send(const GestureEventData& gesture) { |
659 DCHECK(!gesture.time.is_null()); | 670 DCHECK(!gesture.time.is_null()); |
660 // The only valid events that should be sent without an active touch sequence | 671 // The only valid events that should be sent without an active touch sequence |
661 // are SHOW_PRESS and TAP, potentially triggered by the double-tap | 672 // are SHOW_PRESS and TAP, potentially triggered by the double-tap |
662 // delay timing out. | 673 // delay timing out. |
663 DCHECK(current_down_event_ || gesture.type == ET_GESTURE_TAP || | 674 DCHECK(current_down_event_ || gesture.type == ET_GESTURE_TAP || |
664 gesture.type == ET_GESTURE_SHOW_PRESS); | 675 gesture.type == ET_GESTURE_SHOW_PRESS); |
665 | 676 |
666 switch (gesture.type) { | 677 switch (gesture.type) { |
667 case ET_GESTURE_TAP_DOWN: | 678 case ET_GESTURE_TAP_DOWN: |
668 needs_tap_ending_event_ = true; | 679 needs_tap_ending_event_ = true; |
669 break; | 680 break; |
670 case ET_GESTURE_TAP_UNCONFIRMED: | 681 case ET_GESTURE_TAP_UNCONFIRMED: |
671 needs_show_press_event_ = false; | 682 needs_show_press_event_ = false; |
672 break; | 683 break; |
673 case ET_GESTURE_TAP: | 684 case ET_GESTURE_TAP: |
674 if (needs_show_press_event_) | 685 if (needs_show_press_event_) |
675 Send(CreateGesture( | 686 Send(CreateGesture(ET_GESTURE_SHOW_PRESS, |
676 ET_GESTURE_SHOW_PRESS, gesture.time, gesture.x, gesture.y)); | 687 gesture.motion_event_id, |
| 688 gesture.time, |
| 689 gesture.x, |
| 690 gesture.y)); |
677 needs_tap_ending_event_ = false; | 691 needs_tap_ending_event_ = false; |
678 break; | 692 break; |
679 case ET_GESTURE_DOUBLE_TAP: | 693 case ET_GESTURE_DOUBLE_TAP: |
680 needs_tap_ending_event_ = false; | 694 needs_tap_ending_event_ = false; |
681 break; | 695 break; |
682 case ET_GESTURE_TAP_CANCEL: | 696 case ET_GESTURE_TAP_CANCEL: |
683 if (!needs_tap_ending_event_) | 697 if (!needs_tap_ending_event_) |
684 return; | 698 return; |
685 needs_tap_ending_event_ = false; | 699 needs_tap_ending_event_ = false; |
686 break; | 700 break; |
687 case ET_GESTURE_SHOW_PRESS: | 701 case ET_GESTURE_SHOW_PRESS: |
688 needs_show_press_event_ = false; | 702 needs_show_press_event_ = false; |
689 break; | 703 break; |
690 case ET_GESTURE_LONG_PRESS: | 704 case ET_GESTURE_LONG_PRESS: |
691 DCHECK(!scale_gesture_listener_->IsScaleGestureDetectionInProgress()); | 705 DCHECK(!scale_gesture_listener_->IsScaleGestureDetectionInProgress()); |
692 current_longpress_time_ = gesture.time; | 706 current_longpress_time_ = gesture.time; |
693 break; | 707 break; |
694 case ET_GESTURE_LONG_TAP: | 708 case ET_GESTURE_LONG_TAP: |
695 needs_tap_ending_event_ = false; | 709 needs_tap_ending_event_ = false; |
696 current_longpress_time_ = base::TimeTicks(); | 710 current_longpress_time_ = base::TimeTicks(); |
697 break; | 711 break; |
698 case ET_GESTURE_SCROLL_BEGIN: | 712 case ET_GESTURE_SCROLL_BEGIN: |
699 touch_scroll_in_progress_ = true; | 713 touch_scroll_in_progress_ = true; |
700 SendTapCancelIfNecessary(*current_down_event_); | 714 SendTapCancelIfNecessary(gesture); |
701 break; | 715 break; |
702 case ET_GESTURE_SCROLL_END: | 716 case ET_GESTURE_SCROLL_END: |
703 touch_scroll_in_progress_ = false; | 717 touch_scroll_in_progress_ = false; |
704 break; | 718 break; |
705 case ET_GESTURE_PINCH_BEGIN: | 719 case ET_GESTURE_PINCH_BEGIN: |
706 if (!touch_scroll_in_progress_) | 720 if (!touch_scroll_in_progress_) |
707 Send(CreateGesture( | 721 Send(CreateGesture(ET_GESTURE_SCROLL_BEGIN, |
708 ET_GESTURE_SCROLL_BEGIN, gesture.time, gesture.x, gesture.y)); | 722 gesture.motion_event_id, |
| 723 gesture.time, |
| 724 gesture.x, |
| 725 gesture.y)); |
709 pinch_in_progress_ = true; | 726 pinch_in_progress_ = true; |
710 break; | 727 break; |
711 case ET_GESTURE_PINCH_END: | 728 case ET_GESTURE_PINCH_END: |
712 pinch_in_progress_ = false; | 729 pinch_in_progress_ = false; |
713 break; | 730 break; |
714 default: | 731 default: |
715 break; | 732 break; |
716 }; | 733 }; |
717 | 734 |
718 client_->OnGestureEvent(gesture); | 735 client_->OnGestureEvent(gesture); |
719 } | 736 } |
720 | 737 |
721 void GestureProvider::SendTapCancelIfNecessary(const MotionEvent& event) { | 738 void GestureProvider::SendTapCancelIfNecessary(const MotionEvent& event) { |
722 if (!needs_tap_ending_event_) | 739 if (!needs_tap_ending_event_) |
723 return; | 740 return; |
724 current_longpress_time_ = base::TimeTicks(); | 741 current_longpress_time_ = base::TimeTicks(); |
725 Send(CreateGesture(ET_GESTURE_TAP_CANCEL, event)); | 742 Send(CreateGesture(ET_GESTURE_TAP_CANCEL, event)); |
726 } | 743 } |
727 | 744 |
| 745 void GestureProvider::SendTapCancelIfNecessary( |
| 746 const GestureEventData& gesture) { |
| 747 if (!needs_tap_ending_event_) |
| 748 return; |
| 749 current_longpress_time_ = base::TimeTicks(); |
| 750 Send(CreateGesture(ET_GESTURE_TAP_CANCEL, |
| 751 gesture.motion_event_id, |
| 752 gesture.time, |
| 753 gesture.x, |
| 754 gesture.y)); |
| 755 } |
| 756 |
728 bool GestureProvider::SendLongTapIfNecessary(const MotionEvent& event) { | 757 bool GestureProvider::SendLongTapIfNecessary(const MotionEvent& event) { |
729 if (event.GetAction() == MotionEvent::ACTION_UP && | 758 if (event.GetAction() == MotionEvent::ACTION_UP && |
730 !current_longpress_time_.is_null() && | 759 !current_longpress_time_.is_null() && |
731 !scale_gesture_listener_->IsScaleGestureDetectionInProgress()) { | 760 !scale_gesture_listener_->IsScaleGestureDetectionInProgress()) { |
732 SendTapCancelIfNecessary(event); | 761 SendTapCancelIfNecessary(event); |
733 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP, 0, 0); | 762 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP, 0, 0); |
734 long_tap_details.set_bounding_box( | 763 long_tap_details.set_bounding_box( |
735 gfx::RectF(event.GetTouchMajor(), event.GetTouchMajor())); | 764 gfx::RectF(event.GetTouchMajor(), event.GetTouchMajor())); |
736 Send(CreateGesture(ET_GESTURE_LONG_TAP, event, long_tap_details)); | 765 Send(CreateGesture(ET_GESTURE_LONG_TAP, event, long_tap_details)); |
737 return true; | 766 return true; |
738 } | 767 } |
739 return false; | 768 return false; |
740 } | 769 } |
741 | 770 |
742 void GestureProvider::EndTouchScrollIfNecessary(base::TimeTicks time, | 771 void GestureProvider::EndTouchScrollIfNecessary(const MotionEvent& event, |
743 bool send_scroll_end_event) { | 772 bool send_scroll_end_event) { |
744 if (!touch_scroll_in_progress_) | 773 if (!touch_scroll_in_progress_) |
745 return; | 774 return; |
746 touch_scroll_in_progress_ = false; | 775 touch_scroll_in_progress_ = false; |
747 if (send_scroll_end_event) | 776 if (send_scroll_end_event) |
748 Send(CreateGesture(ET_GESTURE_SCROLL_END, time, 0, 0)); | 777 Send(CreateGesture(ET_GESTURE_SCROLL_END, event)); |
749 } | 778 } |
750 | 779 |
751 void GestureProvider::UpdateDoubleTapDetectionSupport() { | 780 void GestureProvider::UpdateDoubleTapDetectionSupport() { |
752 if (IsDoubleTapInProgress()) | 781 if (IsDoubleTapInProgress()) |
753 return; | 782 return; |
754 | 783 |
755 const bool supports_double_tap = IsDoubleTapSupported(); | 784 const bool supports_double_tap = IsDoubleTapSupported(); |
756 gesture_listener_->SetDoubleTapEnabled(supports_double_tap); | 785 gesture_listener_->SetDoubleTapEnabled(supports_double_tap); |
757 scale_gesture_listener_->SetDoubleTapEnabled(supports_double_tap); | 786 scale_gesture_listener_->SetDoubleTapEnabled(supports_double_tap); |
758 } | 787 } |
759 | 788 |
760 } // namespace ui | 789 } // namespace ui |
OLD | NEW |