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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 100 } |
101 | 101 |
102 GestureEventDetails CreateTapGestureDetails(EventType type) { | 102 GestureEventDetails CreateTapGestureDetails(EventType type) { |
103 // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be | 103 // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be |
104 // consistent with double tap behavior on a mobile viewport. See | 104 // consistent with double tap behavior on a mobile viewport. See |
105 // crbug.com/234986 for context. | 105 // crbug.com/234986 for context. |
106 GestureEventDetails tap_details(type, 1, 0); | 106 GestureEventDetails tap_details(type, 1, 0); |
107 return tap_details; | 107 return tap_details; |
108 } | 108 } |
109 | 109 |
| 110 gfx::RectF ClampBoundingBox(const gfx::RectF& bounds, |
| 111 float min_length, |
| 112 float max_length) { |
| 113 float width = bounds.width(); |
| 114 float height = bounds.height(); |
| 115 if (min_length) { |
| 116 width = std::max(min_length, width); |
| 117 height = std::max(min_length, height); |
| 118 } |
| 119 if (max_length) { |
| 120 width = std::min(max_length, width); |
| 121 height = std::min(max_length, height); |
| 122 } |
| 123 const gfx::PointF center = bounds.CenterPoint(); |
| 124 return gfx::RectF( |
| 125 center.x() - width / 2.f, center.y() - height / 2.f, width, height); |
| 126 } |
| 127 |
110 } // namespace | 128 } // namespace |
111 | 129 |
112 // GestureProvider:::Config | 130 // GestureProvider:::Config |
113 | 131 |
114 GestureProvider::Config::Config() | 132 GestureProvider::Config::Config() |
115 : display(gfx::Display::kInvalidDisplayID, gfx::Rect(1, 1)), | 133 : display(gfx::Display::kInvalidDisplayID, gfx::Rect(1, 1)), |
116 disable_click_delay(false), | 134 disable_click_delay(false), |
117 gesture_begin_end_types_enabled(false), | 135 gesture_begin_end_types_enabled(false), |
118 min_gesture_bounds_length(0) {} | 136 min_gesture_bounds_length(0), |
| 137 max_gesture_bounds_length(0) {} |
119 | 138 |
120 GestureProvider::Config::~Config() {} | 139 GestureProvider::Config::~Config() {} |
121 | 140 |
122 // GestureProvider::ScaleGestureListener | 141 // GestureProvider::ScaleGestureListener |
123 | 142 |
124 class GestureProvider::ScaleGestureListenerImpl | 143 class GestureProvider::ScaleGestureListenerImpl |
125 : public ScaleGestureDetector::ScaleGestureListener { | 144 : public ScaleGestureDetector::ScaleGestureListener { |
126 public: | 145 public: |
127 ScaleGestureListenerImpl(const ScaleGestureDetector::Config& config, | 146 ScaleGestureListenerImpl(const ScaleGestureDetector::Config& config, |
128 GestureProvider* provider) | 147 GestureProvider* provider) |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 // GestureProvider | 562 // GestureProvider |
544 | 563 |
545 GestureProvider::GestureProvider(const Config& config, | 564 GestureProvider::GestureProvider(const Config& config, |
546 GestureProviderClient* client) | 565 GestureProviderClient* client) |
547 : client_(client), | 566 : client_(client), |
548 touch_scroll_in_progress_(false), | 567 touch_scroll_in_progress_(false), |
549 pinch_in_progress_(false), | 568 pinch_in_progress_(false), |
550 double_tap_support_for_page_(true), | 569 double_tap_support_for_page_(true), |
551 double_tap_support_for_platform_(true), | 570 double_tap_support_for_platform_(true), |
552 gesture_begin_end_types_enabled_(config.gesture_begin_end_types_enabled), | 571 gesture_begin_end_types_enabled_(config.gesture_begin_end_types_enabled), |
553 min_gesture_bounds_length_(config.min_gesture_bounds_length) { | 572 min_gesture_bounds_length_(config.min_gesture_bounds_length), |
| 573 max_gesture_bounds_length_(config.max_gesture_bounds_length) { |
554 DCHECK(client); | 574 DCHECK(client); |
| 575 DCHECK(!min_gesture_bounds_length_ || !max_gesture_bounds_length_ || |
| 576 min_gesture_bounds_length_ <= max_gesture_bounds_length_); |
555 InitGestureDetectors(config); | 577 InitGestureDetectors(config); |
556 } | 578 } |
557 | 579 |
558 GestureProvider::~GestureProvider() {} | 580 GestureProvider::~GestureProvider() {} |
559 | 581 |
560 bool GestureProvider::OnTouchEvent(const MotionEvent& event) { | 582 bool GestureProvider::OnTouchEvent(const MotionEvent& event) { |
561 TRACE_EVENT1("input", "GestureProvider::OnTouchEvent", | 583 TRACE_EVENT1("input", "GestureProvider::OnTouchEvent", |
562 "action", GetMotionEventActionName(event.GetAction())); | 584 "action", GetMotionEventActionName(event.GetAction())); |
563 | 585 |
564 DCHECK_NE(0u, event.GetPointerCount()); | 586 DCHECK_NE(0u, event.GetPointerCount()); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 void GestureProvider::Send(GestureEventData gesture) { | 674 void GestureProvider::Send(GestureEventData gesture) { |
653 DCHECK(!gesture.time.is_null()); | 675 DCHECK(!gesture.time.is_null()); |
654 // The only valid events that should be sent without an active touch sequence | 676 // The only valid events that should be sent without an active touch sequence |
655 // are SHOW_PRESS and TAP, potentially triggered by the double-tap | 677 // are SHOW_PRESS and TAP, potentially triggered by the double-tap |
656 // delay timing out. | 678 // delay timing out. |
657 DCHECK(current_down_event_ || gesture.type() == ET_GESTURE_TAP || | 679 DCHECK(current_down_event_ || gesture.type() == ET_GESTURE_TAP || |
658 gesture.type() == ET_GESTURE_SHOW_PRESS); | 680 gesture.type() == ET_GESTURE_SHOW_PRESS); |
659 | 681 |
660 // TODO(jdduke): Provide a way of skipping this clamping for stylus and/or | 682 // TODO(jdduke): Provide a way of skipping this clamping for stylus and/or |
661 // mouse-based input, perhaps by exposing the source type on MotionEvent. | 683 // mouse-based input, perhaps by exposing the source type on MotionEvent. |
662 const gfx::RectF& gesture_bounds = gesture.details.bounding_box_f(); | 684 gesture.details.set_bounding_box( |
663 gesture.details.set_bounding_box(gfx::RectF( | 685 ClampBoundingBox(gesture.details.bounding_box_f(), |
664 gesture_bounds.x(), | 686 min_gesture_bounds_length_, |
665 gesture_bounds.y(), | 687 max_gesture_bounds_length_)); |
666 std::max(min_gesture_bounds_length_, gesture_bounds.width()), | |
667 std::max(min_gesture_bounds_length_, gesture_bounds.height()))); | |
668 | 688 |
669 switch (gesture.type()) { | 689 switch (gesture.type()) { |
670 case ET_GESTURE_LONG_PRESS: | 690 case ET_GESTURE_LONG_PRESS: |
671 DCHECK(!scale_gesture_listener_->IsScaleGestureDetectionInProgress()); | 691 DCHECK(!scale_gesture_listener_->IsScaleGestureDetectionInProgress()); |
672 current_longpress_time_ = gesture.time; | 692 current_longpress_time_ = gesture.time; |
673 break; | 693 break; |
674 case ET_GESTURE_LONG_TAP: | 694 case ET_GESTURE_LONG_TAP: |
675 current_longpress_time_ = base::TimeTicks(); | 695 current_longpress_time_ = base::TimeTicks(); |
676 break; | 696 break; |
677 case ET_GESTURE_SCROLL_BEGIN: | 697 case ET_GESTURE_SCROLL_BEGIN: |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 if (current_down_event_) | 826 if (current_down_event_) |
807 return; | 827 return; |
808 | 828 |
809 const bool double_tap_enabled = double_tap_support_for_page_ && | 829 const bool double_tap_enabled = double_tap_support_for_page_ && |
810 double_tap_support_for_platform_; | 830 double_tap_support_for_platform_; |
811 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 831 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
812 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 832 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
813 } | 833 } |
814 | 834 |
815 } // namespace ui | 835 } // namespace ui |
OLD | NEW |