Fix position check for double tap gesture detection. A double tap

should not be detected if the two taps are far from each other.
https://bugs.webkit.org/show_bug.cgi?id=69270

Patch by Varun Jain <varunjain@chromium.org> on 2011-10-04
Reviewed by Darin Fisher.

Test: Source/WebKit/chromium/tests/InnerGestureRecognizerTest.cpp

* platform/chromium/GestureRecognizerChromium.cpp:
(WebCore::GestureRecognizerChromium::isSecondClickInsideManhattanSquare):
(WebCore::GestureRecognizerChromium::updateValues):
(WebCore::GestureRecognizerChromium::click):
* platform/chromium/GestureRecognizerChromium.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96657 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9bc6d725
2011-10-04 Varun Jain <varunjain@chromium.org>
Fix position check for double tap gesture detection. A double tap
should not be detected if the two taps are far from each other.
https://bugs.webkit.org/show_bug.cgi?id=69270
Reviewed by Darin Fisher.
Test: Source/WebKit/chromium/tests/InnerGestureRecognizerTest.cpp
* platform/chromium/GestureRecognizerChromium.cpp:
(WebCore::GestureRecognizerChromium::isSecondClickInsideManhattanSquare):
(WebCore::GestureRecognizerChromium::updateValues):
(WebCore::GestureRecognizerChromium::click):
* platform/chromium/GestureRecognizerChromium.h:
2011-10-04 Nayan Kumar K <nayankk@motorola.com>
[WebKit2][gtk] Generate gtk-doc for WebKit2-GTK.
......
......@@ -45,6 +45,7 @@ GestureRecognizerChromium::GestureRecognizerChromium()
, m_state(GestureRecognizerChromium::NoGesture)
, m_lastTouchTime(0.0)
, m_lastClickTime(0.0)
, m_lastClickPosition()
, m_lastTouchPosition()
, m_lastTouchScreenPosition()
, m_xVelocity(0.0)
......@@ -111,6 +112,12 @@ bool GestureRecognizerChromium::isInsideManhattanSquare(const PlatformTouchPoint
return manhattanDistance < maximumTouchMoveInPixelsForClick;
}
bool GestureRecognizerChromium::isSecondClickInsideManhattanSquare(const PlatformTouchPoint& point)
{
int manhattanDistance = abs(point.pos().x() - m_lastClickPosition.x()) + abs(point.pos().y() - m_lastClickPosition.y());
return manhattanDistance < maximumTouchMoveInPixelsForClick;
}
bool GestureRecognizerChromium::isOverMinFlickSpeed()
{
return (m_xVelocity * m_xVelocity + m_yVelocity * m_yVelocity) > minFlickSpeedSquared;
......@@ -175,10 +182,10 @@ void GestureRecognizerChromium::updateValues(const double touchTime, const Platf
double interval(touchTime - m_lastTouchTime);
m_xVelocity = (touchPoint.pos().x() - m_lastTouchPosition.x()) / interval;
m_yVelocity = (touchPoint.pos().y() - m_lastTouchPosition.y()) / interval;
m_lastTouchPosition = touchPoint.pos();
m_lastTouchScreenPosition = touchPoint.screenPos();
}
m_lastTouchTime = touchTime;
m_lastTouchPosition = touchPoint.pos();
m_lastTouchScreenPosition = touchPoint.screenPos();
if (state() == NoGesture) {
m_firstTouchTime = touchTime;
m_firstTouchPosition = touchPoint.pos();
......@@ -230,9 +237,10 @@ bool GestureRecognizerChromium::click(const PlatformTouchPoint& point, Gestures
if (isInClickTimeWindow() && isInsideManhattanSquare(point)) {
gestureAdded = true;
appendClickGestureEvent(point, gestures);
if (isInSecondClickTimeWindow())
if (isInSecondClickTimeWindow() && isSecondClickInsideManhattanSquare(point))
appendDoubleClickGestureEvent(point, gestures);
m_lastClickTime = m_lastTouchTime;
m_lastClickTime = m_lastTouchTime;
m_lastClickPosition = m_lastTouchPosition;
}
reset();
return gestureAdded;
......
......@@ -75,6 +75,7 @@ private:
bool isInClickTimeWindow();
bool isInSecondClickTimeWindow();
bool isInsideManhattanSquare(const PlatformTouchPoint&);
bool isSecondClickInsideManhattanSquare(const PlatformTouchPoint&);
bool isOverMinFlickSpeed();
void setState(State value) { m_state = value; }
void updateValues(double touchTime, const PlatformTouchPoint&);
......@@ -93,6 +94,7 @@ private:
State m_state;
double m_lastTouchTime;
double m_lastClickTime;
IntPoint m_lastClickPosition;
IntPoint m_lastTouchPosition;
IntPoint m_lastTouchScreenPosition;
float m_xVelocity;
......
......@@ -357,15 +357,14 @@ TEST_F(GestureRecognizerTest, MAYBE_doubleTapGestureIncompleteTest)
ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
BuildablePlatformTouchPoint press(10, 15, PlatformTouchPoint::TouchPressed);
BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press);
gm.setLastTouchTime(gm.lastTouchTime() - 0.01);
BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press, 1000. + 0.7 + 0.01);
Gestures gestureStart(gm.processTouchEventForGestures(pressEvent, false));
ASSERT_EQ(1u, gestureStart->size());
ASSERT_EQ(PlatformGestureEvent::TapDownType, (*gestureStart)[0].type());
ASSERT_EQ(GestureRecognizerChromium::PendingSyntheticClick, gm.state());
BuildablePlatformTouchPoint move(10, 50, PlatformTouchPoint::TouchMoved);
BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move);
BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move, 1000. + 0.7 + 0.02);
Gestures gestureMove(gm.processTouchEventForGestures(moveEvent, false));
ASSERT_EQ(2u, gestureMove->size());
ASSERT_EQ(PlatformGestureEvent::ScrollBeginType, (*gestureMove)[0].type());
......@@ -373,14 +372,42 @@ TEST_F(GestureRecognizerTest, MAYBE_doubleTapGestureIncompleteTest)
ASSERT_EQ(GestureRecognizerChromium::Scroll, gm.state());
BuildablePlatformTouchPoint release(10, 50, PlatformTouchPoint::TouchReleased);
BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release);
gm.setFirstTouchTime(gm.firstTouchTime() - 0.01);
BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release, 1000. + 0.7 + 0.03);
Gestures gestureEnd(gm.processTouchEventForGestures(releaseEvent, false));
ASSERT_EQ(1u, gestureEnd->size());
ASSERT_EQ(PlatformGestureEvent::ScrollEndType, (*gestureEnd)[0].type());
ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
}
#if OS(MAC_OS_X)
#define MAYBE_doubleTapGestureIncompleteDueToSecondClickPositionTest DISABLED_doubleTapGestureIncompleteDueToSecondClickPositionTest
#else
#define MAYBE_doubleTapGestureIncompleteDueToSecondClickPositionTest doubleTapGestureIncompleteDueToSecondClickPositionTest
#endif
TEST_F(GestureRecognizerTest, MAYBE_doubleTapGestureIncompleteDueToSecondClickPositionTest)
{
InspectableGestureRecognizerChromium gm;
SimulateAndTestFirstClick(gm);
ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
IntPoint awayFromFirstClick(24, 26);
BuildablePlatformTouchPoint press(awayFromFirstClick.x(), awayFromFirstClick.y(), PlatformTouchPoint::TouchPressed);
BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press, 1000. + 0.7 + 0.01);
Gestures gestureStart(gm.processTouchEventForGestures(pressEvent, false));
ASSERT_EQ(1u, gestureStart->size());
ASSERT_EQ(PlatformGestureEvent::TapDownType, (*gestureStart)[0].type());
ASSERT_EQ(GestureRecognizerChromium::PendingSyntheticClick, gm.state());
BuildablePlatformTouchPoint release(awayFromFirstClick.x(), awayFromFirstClick.y(), PlatformTouchPoint::TouchReleased);
BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release, 1000. + 0.7 + 0.025);
Gestures gestureEnd(gm.processTouchEventForGestures(releaseEvent, false));
ASSERT_EQ(1u, gestureEnd->size());
ASSERT_EQ(PlatformGestureEvent::TapType, (*gestureEnd)[0].type());
ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
}
TEST_F(GestureRecognizerTest, tapDownWithoutTapGestureTest)
{
InspectableGestureRecognizerChromium gm;
......@@ -420,24 +447,20 @@ TEST_F(GestureRecognizerTest, MAYBE_tapDownWithTapGestureTest)
ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
BuildablePlatformTouchPoint press(10, 15, PlatformTouchPoint::TouchPressed);
BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press);
BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press, 1000.);
Gestures gestureStart(gm.processTouchEventForGestures(pressEvent, false));
ASSERT_EQ(1u, gestureStart->size());
ASSERT_EQ(PlatformGestureEvent::TapDownType, (*gestureStart)[0].type());
ASSERT_EQ(GestureRecognizerChromium::PendingSyntheticClick, gm.state());
BuildablePlatformTouchPoint move(10, 16, PlatformTouchPoint::TouchMoved);
BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move);
BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move, 1000.);
Gestures gestureMove(gm.processTouchEventForGestures(moveEvent, false));
ASSERT_EQ(0u, gestureMove->size());
ASSERT_EQ(GestureRecognizerChromium::PendingSyntheticClick, gm.state());
BuildablePlatformTouchPoint release(10, 16, PlatformTouchPoint::TouchReleased);
BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release);
// set first touch time so that we pass the test for
// minimumTouchDownDurationInSecondsForClick
gm.setFirstTouchTime(gm.firstTouchTime() - 0.01);
BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release, 1000. + 0.011);
Gestures gestureEnd(gm.processTouchEventForGestures(releaseEvent, false));
ASSERT_EQ(1u, gestureEnd->size());
ASSERT_EQ(PlatformGestureEvent::TapType, (*gestureEnd)[0].type());
......@@ -487,14 +510,13 @@ TEST_F(GestureRecognizerTest, gestureScrollEvents)
ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
BuildablePlatformTouchPoint press(10, 15, PlatformTouchPoint::TouchPressed);
BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press);
BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press, 1000.);
gm.processTouchEventForGestures(pressEvent, false);
ASSERT_EQ(GestureRecognizerChromium::PendingSyntheticClick, gm.state());
BuildablePlatformTouchPoint move(10, 50, PlatformTouchPoint::TouchMoved);
BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move);
gm.setLastTouchTime(gm.lastTouchTime() - 0.2);
BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move, 1000. + 0.2);
Gestures gestureStart(gm.processTouchEventForGestures(moveEvent, false));
bool scrollStarted = false, scrollUpdated = false;
for (unsigned int i = 0; i < gestureStart->size(); i++) {
......@@ -515,8 +537,7 @@ TEST_F(GestureRecognizerTest, gestureScrollEvents)
ASSERT_EQ(GestureRecognizerChromium::Scroll, gm.state());
BuildablePlatformTouchPoint release(10, 50, PlatformTouchPoint::TouchReleased);
BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release);
gm.setLastTouchTime(gm.lastTouchTime() - 0.2);
BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release, 1000. + 0.2 + 0.2);
bool scrollEnd = false;
Gestures gestureEnd(gm.processTouchEventForGestures(releaseEvent, false));
for (unsigned int i = 0; i < gestureEnd->size(); i++) {
......@@ -540,14 +561,14 @@ TEST_F(GestureRecognizerTest, flickGestureTest)
ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
BuildablePlatformTouchPoint press(10, 15, PlatformTouchPoint::TouchPressed);
BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press);
BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press, 1000.);
Gestures gestureStart(gm.processTouchEventForGestures(pressEvent, false));
ASSERT_EQ((unsigned int)1, gestureStart->size());
ASSERT_EQ(PlatformGestureEvent::TapDownType, (*gestureStart)[0].type());
ASSERT_EQ(GestureRecognizerChromium::PendingSyntheticClick, gm.state());
BuildablePlatformTouchPoint move(10, 50, PlatformTouchPoint::TouchMoved);
BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move);
BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move, 1000. + 0.02);
Gestures gestureMove(gm.processTouchEventForGestures(moveEvent, false));
bool scrollStarted = false, scrollUpdated = false;
for (unsigned int i = 0; i < gestureMove->size(); i++) {
......@@ -568,12 +589,12 @@ TEST_F(GestureRecognizerTest, flickGestureTest)
ASSERT_EQ(GestureRecognizerChromium::Scroll, gm.state());
BuildablePlatformTouchPoint release(10, 50, PlatformTouchPoint::TouchReleased);
BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release);
BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release, 1000. + 0.06);
Gestures gestureEnd(gm.processTouchEventForGestures(releaseEvent, false));
ASSERT_EQ((unsigned int) 1, gestureEnd->size());
ASSERT_EQ(PlatformGestureEvent::ScrollEndType, (*gestureEnd)[0].type());
ASSERT_GT((*gestureEnd)[0].deltaX(), 0);
ASSERT_GT((*gestureEnd)[0].deltaY(), 0);
ASSERT_EQ((*gestureEnd)[0].deltaX(), 0);
ASSERT_EQ((*gestureEnd)[0].deltaY(), 1750.);
ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
}
......
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