Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Unified Diff: ui/events/gesture_detection/gesture_detector.cc

Issue 1358263002: [Android] Support double-tap selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix aura Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/events/gesture_detection/gesture_detector.cc
diff --git a/ui/events/gesture_detection/gesture_detector.cc b/ui/events/gesture_detection/gesture_detector.cc
index 4180eb3338085423cc09ae1549493f58e06c26a6..bc9c7dfc6fbfd3bbe73df851bf50b2c968a625d6 100644
--- a/ui/events/gesture_detection/gesture_detector.cc
+++ b/ui/events/gesture_detection/gesture_detector.cc
@@ -55,8 +55,8 @@ GestureDetector::Config::Config()
two_finger_tap_enabled(false),
two_finger_tap_max_separation(300),
two_finger_tap_timeout(base::TimeDelta::FromMilliseconds(700)),
- velocity_tracker_strategy(VelocityTracker::Strategy::STRATEGY_DEFAULT) {
-}
+ single_tap_repeat_length(1),
+ velocity_tracker_strategy(VelocityTracker::Strategy::STRATEGY_DEFAULT) {}
GestureDetector::Config::~Config() {}
@@ -129,6 +129,8 @@ GestureDetector::GestureDetector(
always_in_bigger_tap_region_(false),
two_finger_tap_allowed_for_gesture_(false),
is_double_tapping_(false),
+ single_tap_count_(1),
+ single_tap_repeat_length_(1),
last_focus_x_(0),
last_focus_y_(0),
down_focus_x_(0),
@@ -234,14 +236,16 @@ bool GestureDetector::OnTouchEvent(const MotionEvent& ev) {
two_finger_tap_allowed_for_gesture_ = false;
} break;
- case MotionEvent::ACTION_DOWN:
+ case MotionEvent::ACTION_DOWN: {
+ bool maybe_double_tapping =
+ current_down_event_ && previous_up_event_ &&
+ IsConsideredDoubleTap(*current_down_event_, *previous_up_event_, ev);
if (double_tap_listener_) {
+ single_tap_count_ = 1;
bool had_tap_message = timeout_handler_->HasTimeout(TAP);
if (had_tap_message)
timeout_handler_->StopTimeout(TAP);
- if (current_down_event_ && previous_up_event_ && had_tap_message &&
- IsConsideredDoubleTap(
- *current_down_event_, *previous_up_event_, ev)) {
+ if (maybe_double_tapping && had_tap_message) {
// This is a second tap.
is_double_tapping_ = true;
// Give a callback with the first tap of the double-tap.
@@ -253,6 +257,8 @@ bool GestureDetector::OnTouchEvent(const MotionEvent& ev) {
DCHECK(double_tap_timeout_ > base::TimeDelta());
timeout_handler_->StartTimeout(TAP);
}
+ } else if (maybe_double_tapping) {
+ single_tap_count_ = 1 + (single_tap_count_ % single_tap_repeat_length_);
}
down_focus_x_ = last_focus_x_ = focus_x;
@@ -273,7 +279,7 @@ bool GestureDetector::OnTouchEvent(const MotionEvent& ev) {
if (longpress_enabled_)
timeout_handler_->StartTimeout(LONG_PRESS);
handled |= listener_->OnDown(ev);
- break;
+ } break;
case MotionEvent::ACTION_MOVE:
{
@@ -343,12 +349,12 @@ bool GestureDetector::OnTouchEvent(const MotionEvent& ev) {
DCHECK(double_tap_listener_);
handled |= double_tap_listener_->OnDoubleTapEvent(ev);
} else if (always_in_tap_region_) {
- handled = listener_->OnSingleTapUp(ev);
+ handled = listener_->OnSingleTapUp(ev, single_tap_count_);
if (defer_confirm_single_tap_ && double_tap_listener_ != NULL) {
double_tap_listener_->OnSingleTapConfirmed(ev);
}
} else {
-
+ single_tap_count_ = 1;
// A fling must travel the minimum tap distance.
const int pointer_id = ev.GetPointerId(0);
velocity_tracker_.ComputeCurrentVelocity(1000, max_fling_velocity_);
@@ -428,6 +434,9 @@ void GestureDetector::Init(const Config& config) {
two_finger_tap_distance_square_ = config.two_finger_tap_max_separation *
config.two_finger_tap_max_separation;
two_finger_tap_timeout_ = config.two_finger_tap_timeout;
+
+ DCHECK_GE(config.single_tap_repeat_length, 1);
+ single_tap_repeat_length_ = config.single_tap_repeat_length;
}
void GestureDetector::OnShowPressTimeout() {
@@ -463,6 +472,7 @@ void GestureDetector::CancelTaps() {
always_in_tap_region_ = false;
always_in_bigger_tap_region_ = false;
defer_confirm_single_tap_ = false;
+ single_tap_count_ = 1;
}
bool GestureDetector::IsConsideredDoubleTap(

Powered by Google App Engine
This is Rietveld 408576698