Commit e3b63ed1 authored by dgozman@chromium.org's avatar dgozman@chromium.org

Touch emulator: overwrite timestamps from mouse event with current time.

On some platfroms, mouse events come with a bad timestamp, which leads to
awkward time-dependent gestures. For example, fling animation may be almost
instant.
Using base::TimeTicks::Now() is good enough for emulation purposes, because
emulator spawns new events itself.

BUG=367156

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266548 0039d316-1c4b-4281-b951-d872f2087c98
parent 2537fcff
...@@ -316,7 +316,7 @@ void TouchEmulator::PinchEnd(const WebGestureEvent& event) { ...@@ -316,7 +316,7 @@ void TouchEmulator::PinchEnd(const WebGestureEvent& event) {
client_->ForwardGestureEvent(pinch_event_); client_->ForwardGestureEvent(pinch_event_);
} }
void TouchEmulator::FillPinchEvent(const WebInputEvent& event) { void TouchEmulator::FillPinchEvent(const WebGestureEvent& event) {
pinch_event_.timeStampSeconds = event.timeStampSeconds; pinch_event_.timeStampSeconds = event.timeStampSeconds;
pinch_event_.modifiers = event.modifiers; pinch_event_.modifiers = event.modifiers;
pinch_event_.sourceDevice = blink::WebGestureEvent::Touchscreen; pinch_event_.sourceDevice = blink::WebGestureEvent::Touchscreen;
...@@ -361,6 +361,16 @@ bool TouchEmulator::FillTouchEventAndPoint(const WebMouseEvent& mouse_event) { ...@@ -361,6 +361,16 @@ bool TouchEmulator::FillTouchEventAndPoint(const WebMouseEvent& mouse_event) {
WebTouchEventTraits::ResetTypeAndTouchStates( WebTouchEventTraits::ResetTypeAndTouchStates(
eventType, mouse_event.timeStampSeconds, &touch_event_); eventType, mouse_event.timeStampSeconds, &touch_event_);
// On some platforms mouse event's timestamp does not necessarily relate to
// the system time at all, so use base::TimeTicks::HighResNow() if possible,
// or base::TimeTicks::Now() otherwise.
base::TimeTicks now;
if (base::TimeTicks::IsHighResNowFastAndReliable())
now = base::TimeTicks::HighResNow();
else
now = base::TimeTicks::Now();
touch_event_.timeStampSeconds = (now - base::TimeTicks()).InSecondsF();
WebTouchPoint& point = touch_event_.touches[0]; WebTouchPoint& point = touch_event_.touches[0];
point.id = 0; point.id = 0;
point.radiusX = point.radiusY = 1.f; point.radiusX = point.radiusY = 1.f;
......
...@@ -48,7 +48,7 @@ class CONTENT_EXPORT TouchEmulator : public ui::GestureProviderClient { ...@@ -48,7 +48,7 @@ class CONTENT_EXPORT TouchEmulator : public ui::GestureProviderClient {
bool InPinchGestureMode() const; bool InPinchGestureMode() const;
bool FillTouchEventAndPoint(const blink::WebMouseEvent& mouse_event); bool FillTouchEventAndPoint(const blink::WebMouseEvent& mouse_event);
void FillPinchEvent(const blink::WebInputEvent& event); void FillPinchEvent(const blink::WebGestureEvent& event);
// The following methods generate and pass gesture events to the renderer. // The following methods generate and pass gesture events to the renderer.
void PinchBegin(const blink::WebGestureEvent& event); void PinchBegin(const blink::WebGestureEvent& event);
......
...@@ -202,7 +202,7 @@ TEST_F(TouchEmulatorTest, Touch) { ...@@ -202,7 +202,7 @@ TEST_F(TouchEmulatorTest, Touch) {
MouseUp(200, 200); MouseUp(200, 200);
EXPECT_EQ( EXPECT_EQ(
"TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate" "TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate"
" TouchEnd GestureScrollEnd", " TouchEnd GestureFlingStart",
ExpectedEvents()); ExpectedEvents());
} }
...@@ -214,13 +214,13 @@ TEST_F(TouchEmulatorTest, MultipleTouches) { ...@@ -214,13 +214,13 @@ TEST_F(TouchEmulatorTest, MultipleTouches) {
MouseUp(200, 200); MouseUp(200, 200);
EXPECT_EQ( EXPECT_EQ(
"TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate" "TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate"
" TouchEnd GestureScrollEnd", " TouchEnd GestureFlingStart",
ExpectedEvents()); ExpectedEvents());
MouseMove(300, 200); MouseMove(300, 200);
MouseMove(200, 200); MouseMove(200, 200);
EXPECT_EQ("", ExpectedEvents()); EXPECT_EQ("", ExpectedEvents());
MouseDown(300, 200); MouseDown(300, 200);
EXPECT_EQ("TouchStart GestureTapDown", ExpectedEvents()); EXPECT_EQ("TouchStart GestureFlingCancel GestureTapDown", ExpectedEvents());
MouseDrag(300, 300); MouseDrag(300, 300);
EXPECT_EQ( EXPECT_EQ(
"TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate", "TouchMove GestureTapCancel GestureScrollBegin GestureScrollUpdate",
......
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