Commit 39435e11 authored by Navid Zolghadr's avatar Navid Zolghadr Committed by Commit Bot

Cleanup early long press activation in GestureDetector

This patch cleans up the early long press activation
that so far can only be caused by a stylus button on
CrOS with clear conditions. It adds the according
checks to the logic to only run it for stylus pointers.
So it should have no functional change.

This helps to add a similar mechanism for touch
pointers on Android in the later patches.

Bug: 1086263
Change-Id: I0a4c5a802505ac22b6186b88d343143472850d7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2216310Reviewed-by: default avatarSean O'Brien <seobrien@chromium.org>
Reviewed-by: default avatarNavid Zolghadr <nzolghadr@chromium.org>
Commit-Queue: Navid Zolghadr <nzolghadr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771870}
parent 3dec9843
......@@ -340,9 +340,19 @@ bool GestureDetector::OnTouchEvent(const MotionEvent& ev,
last_focus_y_ = focus_y;
}
if (stylus_button_accelerated_longpress_enabled_ &&
(ev.GetFlags() & ui::EF_LEFT_MOUSE_BUTTON)) {
OnStylusButtonPress(ev);
// Try to activate long press gesture early.
if (ev.GetPointerCount() == 1 &&
timeout_handler_->HasTimeout(LONG_PRESS)) {
if (ev.GetToolType(0) == MotionEvent::ToolType::STYLUS &&
stylus_button_accelerated_longpress_enabled_ &&
(ev.GetFlags() & ui::EF_LEFT_MOUSE_BUTTON)) {
// This will generate a ET_GESTURE_LONG_PRESS event with
// EF_LEFT_MOUSE_BUTTON, which is consumed by MetalayerMode if that
// feature is enabled, because MetalayerMode is also activated by a
// stylus button press and has precedence over this press acceleration
// feature.
ActivateLongPressGesture(ev);
}
}
if (!two_finger_tap_allowed_for_gesture_)
......@@ -479,9 +489,7 @@ void GestureDetector::OnShowPressTimeout() {
}
void GestureDetector::OnLongPressTimeout() {
timeout_handler_->StopTimeout(TAP);
defer_confirm_single_tap_ = false;
listener_->OnLongPress(*current_down_event_);
ActivateLongPressGesture(*current_down_event_);
}
void GestureDetector::OnTapTimeout() {
......@@ -495,17 +503,9 @@ void GestureDetector::OnTapTimeout() {
}
}
void GestureDetector::OnStylusButtonPress(const MotionEvent& ev) {
if (!timeout_handler_->HasTimeout(LONG_PRESS))
return;
timeout_handler_->StopTimeout(TAP);
timeout_handler_->StopTimeout(SHOW_PRESS);
timeout_handler_->StopTimeout(LONG_PRESS);
void GestureDetector::ActivateLongPressGesture(const MotionEvent& ev) {
timeout_handler_->Stop();
defer_confirm_single_tap_ = false;
// This will generate a ET_GESTURE_LONG_PRESS event with EF_LEFT_MOUSE_BUTTON,
// which is consumed by MetalayerMode if that feature is enabled, because
// MetalayerMode is also activated by a stylus button press and has precedence
// over this press acceleration feature.
listener_->OnLongPress(ev);
}
......
......@@ -116,7 +116,7 @@ class GESTURE_DETECTION_EXPORT GestureDetector {
void OnShowPressTimeout();
void OnLongPressTimeout();
void OnTapTimeout();
void OnStylusButtonPress(const MotionEvent& ev);
void ActivateLongPressGesture(const MotionEvent& ev);
void Cancel();
void CancelTaps();
bool IsRepeatedTap(const MotionEvent& first_down,
......
......@@ -1262,10 +1262,12 @@ TEST_F(GestureProviderTest, StylusButtonCausesLongPress) {
MockMotionEvent event =
ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
event.SetToolType(0, MotionEvent::ToolType::STYLUS);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
event = ObtainMotionEvent(event_time + kOneMicrosecond,
MotionEvent::Action::MOVE);
event.SetToolType(0, MotionEvent::ToolType::STYLUS);
event.set_flags(EF_LEFT_MOUSE_BUTTON);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
......@@ -1277,10 +1279,12 @@ TEST_F(GestureProviderTest, DisabledStylusButtonDoesNotCauseLongPress) {
MockMotionEvent event =
ObtainMotionEvent(event_time, MotionEvent::Action::DOWN);
event.SetToolType(0, MotionEvent::ToolType::STYLUS);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
event = ObtainMotionEvent(event_time + kOneMicrosecond,
MotionEvent::Action::MOVE);
event.SetToolType(0, MotionEvent::ToolType::STYLUS);
event.set_flags(EF_LEFT_MOUSE_BUTTON);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_NE(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment