Commit 7d4d18b6 authored by tdresser@chromium.org's avatar tdresser@chromium.org

Don't send touch move events within the slop region in Aura.

This brings Aura into line with Android behaviour.

BUG=334040
TEST=TouchEventQueueTest.*Suppression*

Review URL: https://codereview.chromium.org/163983004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251400 0039d316-1c4b-4281-b951-d872f2087c98
parent bd36e178
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "ui/gfx/android/view_configuration.h" #include "ui/gfx/android/view_configuration.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#else
#include "ui/events/gestures/gesture_configuration.h"
#endif #endif
using base::Time; using base::Time;
...@@ -48,7 +50,8 @@ namespace { ...@@ -48,7 +50,8 @@ namespace {
// TODO(jdduke): Instead of relying on command line flags or conditional // TODO(jdduke): Instead of relying on command line flags or conditional
// conditional compilation here, we should instead use an InputRouter::Settings // conditional compilation here, we should instead use an InputRouter::Settings
// construct, supplied and customized by the RenderWidgetHostView. // construct, supplied and customized by the RenderWidgetHostView. See
// crbug.com/343917.
bool GetTouchAckTimeoutDelayMs(size_t* touch_ack_timeout_delay_ms) { bool GetTouchAckTimeoutDelayMs(size_t* touch_ack_timeout_delay_ms) {
CommandLine* parsed_command_line = CommandLine::ForCurrentProcess(); CommandLine* parsed_command_line = CommandLine::ForCurrentProcess();
if (!parsed_command_line->HasSwitch(switches::kTouchAckTimeoutDelayMs)) if (!parsed_command_line->HasSwitch(switches::kTouchAckTimeoutDelayMs))
...@@ -65,17 +68,20 @@ bool GetTouchAckTimeoutDelayMs(size_t* touch_ack_timeout_delay_ms) { ...@@ -65,17 +68,20 @@ bool GetTouchAckTimeoutDelayMs(size_t* touch_ack_timeout_delay_ms) {
} }
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
bool GetTouchMoveSlopSuppressionLengthDips(double* touch_slop_length_dips) { double GetTouchMoveSlopSuppressionLengthDips() {
const double touch_slop_length_pixels = const double touch_slop_length_pixels =
static_cast<double>(gfx::ViewConfiguration::GetTouchSlopInPixels()); static_cast<double>(gfx::ViewConfiguration::GetTouchSlopInPixels());
const double device_scale_factor = const double device_scale_factor =
gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor(); gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor();
*touch_slop_length_dips = touch_slop_length_pixels / device_scale_factor; return touch_slop_length_pixels / device_scale_factor;
return true; }
#elif defined(USE_AURA)
double GetTouchMoveSlopSuppressionLengthDips() {
return ui::GestureConfiguration::max_touch_move_in_pixels_for_click();
} }
#else #else
bool GetTouchMoveSlopSuppressionLengthDips(double* touch_slop_length_dips) { double GetTouchMoveSlopSuppressionLengthDips() {
return false; return 0;
} }
#endif #endif
...@@ -130,18 +136,12 @@ InputRouterImpl::InputRouterImpl(IPC::Sender* sender, ...@@ -130,18 +136,12 @@ InputRouterImpl::InputRouterImpl(IPC::Sender* sender,
DCHECK(sender); DCHECK(sender);
DCHECK(client); DCHECK(client);
DCHECK(ack_handler); DCHECK(ack_handler);
touch_event_queue_.reset(new TouchEventQueue(this)); touch_event_queue_.reset(
new TouchEventQueue(this, GetTouchMoveSlopSuppressionLengthDips()));
touch_ack_timeout_enabled_ = touch_ack_timeout_enabled_ =
GetTouchAckTimeoutDelayMs(&touch_ack_timeout_delay_ms_); GetTouchAckTimeoutDelayMs(&touch_ack_timeout_delay_ms_);
touch_event_queue_->SetAckTimeoutEnabled(touch_ack_timeout_enabled_, touch_event_queue_->SetAckTimeoutEnabled(touch_ack_timeout_enabled_,
touch_ack_timeout_delay_ms_); touch_ack_timeout_delay_ms_);
double touch_move_slop_suppression_length_dips = 0;
if (GetTouchMoveSlopSuppressionLengthDips(
&touch_move_slop_suppression_length_dips)) {
touch_event_queue_->SetTouchMoveSlopSuppressionEnabled(
true, touch_move_slop_suppression_length_dips);
}
} }
InputRouterImpl::~InputRouterImpl() {} InputRouterImpl::~InputRouterImpl() {}
......
...@@ -620,12 +620,12 @@ TEST_F(InputRouterImplTest, AckedTouchEventState) { ...@@ -620,12 +620,12 @@ TEST_F(InputRouterImplTest, AckedTouchEventState) {
// Move the finger. // Move the finger.
timestamp += base::TimeDelta::FromSeconds(10); timestamp += base::TimeDelta::FromSeconds(10);
MoveTouchPoint(0, 5, 5); MoveTouchPoint(0, 500, 500);
SetTouchTimestamp(timestamp); SetTouchTimestamp(timestamp);
SendTouchEvent(); SendTouchEvent();
EXPECT_FALSE(TouchEventQueueEmpty()); EXPECT_FALSE(TouchEventQueueEmpty());
expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED, expected_events.push_back(new ui::TouchEvent(ui::ET_TOUCH_MOVED,
gfx::Point(5, 5), 0, timestamp)); gfx::Point(500, 500), 0, timestamp));
// Now press a second finger. // Now press a second finger.
timestamp += base::TimeDelta::FromSeconds(10); timestamp += base::TimeDelta::FromSeconds(10);
......
...@@ -176,8 +176,9 @@ class TouchEventQueue::TouchTimeoutHandler { ...@@ -176,8 +176,9 @@ class TouchEventQueue::TouchTimeoutHandler {
// a given slop region, unless the touchstart is preventDefault'ed. // a given slop region, unless the touchstart is preventDefault'ed.
class TouchEventQueue::TouchMoveSlopSuppressor { class TouchEventQueue::TouchMoveSlopSuppressor {
public: public:
TouchMoveSlopSuppressor() TouchMoveSlopSuppressor(double slop_suppression_length_dips)
: slop_suppression_length_dips_squared_(0), : slop_suppression_length_dips_squared_(slop_suppression_length_dips *
slop_suppression_length_dips),
suppressing_touch_moves_(false) {} suppressing_touch_moves_(false) {}
bool FilterEvent(const WebTouchEvent& event) { bool FilterEvent(const WebTouchEvent& event) {
...@@ -210,12 +211,6 @@ class TouchEventQueue::TouchMoveSlopSuppressor { ...@@ -210,12 +211,6 @@ class TouchEventQueue::TouchMoveSlopSuppressor {
suppressing_touch_moves_ = false; suppressing_touch_moves_ = false;
} }
// Note: If a touch sequence is in-progress, suppression may not take effect
// until the subsequent sequence.
void set_slop_length_dips(double length_dips) {
slop_suppression_length_dips_squared_ = length_dips * length_dips;
}
private: private:
double slop_suppression_length_dips_squared_; double slop_suppression_length_dips_squared_;
gfx::PointF touch_sequence_start_position_; gfx::PointF touch_sequence_start_position_;
...@@ -292,12 +287,15 @@ class CoalescedWebTouchEvent { ...@@ -292,12 +287,15 @@ class CoalescedWebTouchEvent {
DISALLOW_COPY_AND_ASSIGN(CoalescedWebTouchEvent); DISALLOW_COPY_AND_ASSIGN(CoalescedWebTouchEvent);
}; };
TouchEventQueue::TouchEventQueue(TouchEventQueueClient* client) TouchEventQueue::TouchEventQueue(TouchEventQueueClient* client,
double touchmove_suppression_length_dips)
: client_(client), : client_(client),
dispatching_touch_ack_(NULL), dispatching_touch_ack_(NULL),
dispatching_touch_(false), dispatching_touch_(false),
touch_filtering_state_(TOUCH_FILTERING_STATE_DEFAULT), touch_filtering_state_(TOUCH_FILTERING_STATE_DEFAULT),
ack_timeout_enabled_(false) { ack_timeout_enabled_(false),
touchmove_slop_suppressor_(
new TouchMoveSlopSuppressor(touchmove_suppression_length_dips)) {
DCHECK(client); DCHECK(client);
} }
...@@ -348,8 +346,7 @@ void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result, ...@@ -348,8 +346,7 @@ void TouchEventQueue::ProcessTouchAck(InputEventAckState ack_result,
if (timeout_handler_ && timeout_handler_->ConfirmTouchEvent(ack_result)) if (timeout_handler_ && timeout_handler_->ConfirmTouchEvent(ack_result))
return; return;
if (touchmove_slop_suppressor_) touchmove_slop_suppressor_->ConfirmTouchEvent(ack_result);
touchmove_slop_suppressor_->ConfirmTouchEvent(ack_result);
if (touch_queue_.empty()) if (touch_queue_.empty())
return; return;
...@@ -491,20 +488,6 @@ void TouchEventQueue::SetAckTimeoutEnabled(bool enabled, ...@@ -491,20 +488,6 @@ void TouchEventQueue::SetAckTimeoutEnabled(bool enabled,
timeout_handler_.reset(new TouchTimeoutHandler(this, ack_timeout_delay_ms)); timeout_handler_.reset(new TouchTimeoutHandler(this, ack_timeout_delay_ms));
} }
void TouchEventQueue::SetTouchMoveSlopSuppressionEnabled(
bool enabled,
double slop_length_dips) {
if (!enabled) {
touchmove_slop_suppressor_.reset();
return;
}
if (!touchmove_slop_suppressor_)
touchmove_slop_suppressor_.reset(new TouchMoveSlopSuppressor());
touchmove_slop_suppressor_->set_slop_length_dips(slop_length_dips);
}
bool TouchEventQueue::IsTimeoutRunningForTesting() const { bool TouchEventQueue::IsTimeoutRunningForTesting() const {
return timeout_handler_ && timeout_handler_->IsTimeoutTimerRunning(); return timeout_handler_ && timeout_handler_->IsTimeoutTimerRunning();
} }
...@@ -553,10 +536,8 @@ TouchEventQueue::FilterBeforeForwarding(const WebTouchEvent& event) { ...@@ -553,10 +536,8 @@ TouchEventQueue::FilterBeforeForwarding(const WebTouchEvent& event) {
if (timeout_handler_ && timeout_handler_->FilterEvent(event)) if (timeout_handler_ && timeout_handler_->FilterEvent(event))
return ACK_WITH_NO_CONSUMER_EXISTS; return ACK_WITH_NO_CONSUMER_EXISTS;
if (touchmove_slop_suppressor_ && if (touchmove_slop_suppressor_->FilterEvent(event))
touchmove_slop_suppressor_->FilterEvent(event)) {
return ACK_WITH_NOT_CONSUMED; return ACK_WITH_NOT_CONSUMED;
}
if (touch_filtering_state_ == DROP_ALL_TOUCHES) if (touch_filtering_state_ == DROP_ALL_TOUCHES)
return ACK_WITH_NO_CONSUMER_EXISTS; return ACK_WITH_NO_CONSUMER_EXISTS;
......
...@@ -37,8 +37,11 @@ class CONTENT_EXPORT TouchEventQueueClient { ...@@ -37,8 +37,11 @@ class CONTENT_EXPORT TouchEventQueueClient {
class CONTENT_EXPORT TouchEventQueue { class CONTENT_EXPORT TouchEventQueue {
public: public:
// The |client| must outlive the TouchEventQueue. // The |client| must outlive the TouchEventQueue. If
explicit TouchEventQueue(TouchEventQueueClient* client); // |touchmove_suppression_length_dips| <= 0, touch move suppression is
// disabled.
TouchEventQueue(TouchEventQueueClient* client,
double touchmove_suppression_length_dips);
~TouchEventQueue(); ~TouchEventQueue();
// Adds an event to the queue. The event may be coalesced with previously // Adds an event to the queue. The event may be coalesced with previously
...@@ -70,11 +73,6 @@ class CONTENT_EXPORT TouchEventQueue { ...@@ -70,11 +73,6 @@ class CONTENT_EXPORT TouchEventQueue {
// touch sequence. // touch sequence.
void SetAckTimeoutEnabled(bool enabled, size_t ack_timeout_delay_ms); void SetAckTimeoutEnabled(bool enabled, size_t ack_timeout_delay_ms);
// Sets whether touchmove's within a slop region will be suppressed if the
// preceding touchstart was not preventDefault'ed.
void SetTouchMoveSlopSuppressionEnabled(bool enabled,
double slop_length_dips);
bool empty() const WARN_UNUSED_RESULT { bool empty() const WARN_UNUSED_RESULT {
return touch_queue_.empty(); return touch_queue_.empty();
} }
...@@ -161,8 +159,8 @@ class CONTENT_EXPORT TouchEventQueue { ...@@ -161,8 +159,8 @@ class CONTENT_EXPORT TouchEventQueue {
bool ack_timeout_enabled_; bool ack_timeout_enabled_;
scoped_ptr<TouchTimeoutHandler> timeout_handler_; scoped_ptr<TouchTimeoutHandler> timeout_handler_;
// Optional suppression of TouchMove's within a slop region when a sequence // Suppression of TouchMove's within a slop region when a sequence has not yet
// has not yet been preventDefaulted, disabled by default. // been preventDefaulted.
scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_; scoped_ptr<TouchMoveSlopSuppressor> touchmove_slop_suppressor_;
DISALLOW_COPY_AND_ASSIGN(TouchEventQueue); DISALLOW_COPY_AND_ASSIGN(TouchEventQueue);
......
...@@ -34,7 +34,7 @@ class TouchEventQueueTest : public testing::Test, ...@@ -34,7 +34,7 @@ class TouchEventQueueTest : public testing::Test,
// testing::Test // testing::Test
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
queue_.reset(new TouchEventQueue(this)); queue_.reset(new TouchEventQueue(this, 0));
queue_->OnHasTouchEventHandlers(true); queue_->OnHasTouchEventHandlers(true);
} }
...@@ -77,8 +77,9 @@ class TouchEventQueueTest : public testing::Test, ...@@ -77,8 +77,9 @@ class TouchEventQueueTest : public testing::Test,
queue_->SetAckTimeoutEnabled(true, timeout_delay_ms); queue_->SetAckTimeoutEnabled(true, timeout_delay_ms);
} }
void SetUpForTouchMoveSlopTesting(double slop_length) { void SetUpForTouchMoveSlopTesting(double slop_length_dips) {
queue_->SetTouchMoveSlopSuppressionEnabled(true, slop_length); queue_.reset(new TouchEventQueue(this, slop_length_dips));
queue_->OnHasTouchEventHandlers(true);
} }
void SendTouchEvent(const WebTouchEvent& event) { void SendTouchEvent(const WebTouchEvent& event) {
......
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