Changeset 94797 in webkit


Ignore:
Timestamp:
Sep 8, 2011 2:11:44 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Implement double tap detection in GestureRecognizerChromium
https://bugs.webkit.org/show_bug.cgi?id=67709

Patch by Varun Jain <varunjain@google.com> on 2011-09-08
Reviewed by Dimitri Glazkov.

  • Source/WebCore/page/EventHandler.cpp:
  • Source/WebCore/platform/PlatformGestureEvent.h:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r94783 r94797  
     12011-09-08  Varun Jain  <varunjain@google.com>
     2
     3        Implement double tap detection in GestureRecognizerChromium
     4        https://bugs.webkit.org/show_bug.cgi?id=67709
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        *  Source/WebCore/page/EventHandler.cpp:
     9        *  Source/WebCore/platform/PlatformGestureEvent.h:
     10
    1112011-09-08  Ulan Degenbaev  <ulan@chromium.org>
    212
  • trunk/Source/WebCore/page/EventHandler.cpp

    r94772 r94797  
    22222222        return true;
    22232223    }
     2224    case PlatformGestureEvent::DoubleTapType:
     2225        break;
    22242226    case PlatformGestureEvent::ScrollUpdateType: {
    22252227        const float tickDivisor = (float)WheelEvent::tickMultiplier;
  • trunk/Source/WebCore/platform/PlatformGestureEvent.h

    r94772 r94797  
    4141        TapType,
    4242        TapDownType,
     43        DoubleTapType,
    4344    };
    4445
  • trunk/Source/WebCore/platform/chromium/GestureRecognizerChromium.cpp

    r94772 r94797  
    6363    addEdgeFunction(Scroll, FirstFinger, Released, false, &GestureRecognizerChromium::scrollEnd);
    6464    addEdgeFunction(Scroll, FirstFinger, Cancelled, false, &GestureRecognizerChromium::scrollEnd);
     65
     66    addEdgeFunction(FirstClickReceived, FirstFinger, Pressed, false, &GestureRecognizerChromium::touchDown);
     67    addEdgeFunction(PendingDoubleClick, FirstFinger, Cancelled, false, &GestureRecognizerChromium::noGesture);
     68    addEdgeFunction(PendingDoubleClick, FirstFinger, Released, false, &GestureRecognizerChromium::doubleClick);
     69    addEdgeFunction(PendingDoubleClick, FirstFinger, Moved, false, &GestureRecognizerChromium::maybeDoubleClick);
     70    addEdgeFunction(PendingDoubleClick, FirstFinger, Stationary, false, &GestureRecognizerChromium::maybeDoubleClick);
    6571}
    6672
     
    8793}
    8894
     95bool GestureRecognizerChromium::isInSecondClickTimeWindow()
     96{
     97    double duration(m_lastTouchTime - m_lastClickTime);
     98    return duration >= minimumTouchDownDurationInSecondsForClick && duration < maximumTouchDownDurationInSecondsForClick;
     99}
     100
    89101bool GestureRecognizerChromium::isInsideManhattanSquare(const PlatformTouchPoint& point)
    90102{
     
    101113{
    102114    gestures->append(PlatformGestureEvent(PlatformGestureEvent::TapType, m_firstTouchPosition, m_firstTouchScreenPosition, m_lastTouchTime, 0.f, 0.f, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
     115}
     116
     117void GestureRecognizerChromium::appendDoubleClickGestureEvent(const PlatformTouchPoint& touchPoint, Gestures gestures)
     118{
     119    gestures->append(PlatformGestureEvent(PlatformGestureEvent::DoubleTapType, m_firstTouchPosition, m_firstTouchScreenPosition, m_lastTouchTime, 0.f, 0.f, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
    103120}
    104121
     
    143160void GestureRecognizerChromium::updateValues(const double touchTime, const PlatformTouchPoint& touchPoint)
    144161{
     162    if (state() == FirstClickReceived) {
     163        m_firstTouchTime = touchTime;
     164        m_lastClickTime = m_lastTouchTime;
     165    }
    145166    m_lastTouchTime = touchTime;
    146167    if (state() == NoGesture) {
     
    165186bool GestureRecognizerChromium::touchDown(const PlatformTouchPoint& touchPoint, Gestures gestures)
    166187{
     188    ASSERT(state() == NoGesture || state() == FirstClickReceived);
     189    appendTapDownGestureEvent(touchPoint, gestures);
     190    if (state() == FirstClickReceived && isInSecondClickTimeWindow() && isInsideManhattanSquare(touchPoint)) {
     191        setState(PendingDoubleClick);
     192        return false;
     193    }
    167194    setState(PendingSyntheticClick);
    168     appendTapDownGestureEvent(touchPoint, gestures);
    169195    return false;
    170196}
     
    178204}
    179205
    180 bool GestureRecognizerChromium::noGesture(const PlatformTouchPoint&, Gestures)
    181 {
    182     reset();
    183     return false;
    184 }
    185 
    186 bool GestureRecognizerChromium::click(const PlatformTouchPoint& point, Gestures gestures)
     206bool GestureRecognizerChromium::doubleClick(const PlatformTouchPoint& point, Gestures gestures)
    187207{
    188208    if (isInClickTimeWindow() && isInsideManhattanSquare(point)) {
    189209        setState(NoGesture);
     210        appendDoubleClickGestureEvent(point, gestures);
     211        return true;
     212    }
     213    return noGesture(point, gestures);
     214}
     215
     216bool GestureRecognizerChromium::maybeDoubleClick(const PlatformTouchPoint& point, Gestures gestures)
     217{
     218    ASSERT(state() == GestureRecognizerChromium::PendingDoubleClick);
     219    if (point.state() == PlatformTouchPoint::TouchMoved && !isInsideManhattanSquare(point))
     220        return noGesture(point, gestures);
     221    return false;
     222}
     223
     224bool GestureRecognizerChromium::noGesture(const PlatformTouchPoint&, Gestures)
     225{
     226    reset();
     227    return false;
     228}
     229
     230bool GestureRecognizerChromium::click(const PlatformTouchPoint& point, Gestures gestures)
     231{
     232    if (isInClickTimeWindow() && isInsideManhattanSquare(point)) {
     233        setState(FirstClickReceived);
    190234        appendClickGestureEvent(point, gestures);
    191235        return true;
  • trunk/Source/WebCore/platform/chromium/GestureRecognizerChromium.h

    r94772 r94797  
    4949        NoGesture,
    5050        PendingSyntheticClick,
    51         Scroll
     51        Scroll,
     52        FirstClickReceived,
     53        PendingDoubleClick,
    5254    };
    5355
     
    6971    void appendTapDownGestureEvent(const PlatformTouchPoint&, Gestures);
    7072    void appendClickGestureEvent(const PlatformTouchPoint&, Gestures);
     73    void appendDoubleClickGestureEvent(const PlatformTouchPoint&, Gestures);
    7174    void appendScrollGestureBegin(const PlatformTouchPoint&, Gestures);
    7275    void appendScrollGestureEnd(const PlatformTouchPoint&, Gestures);
    7376    void appendScrollGestureUpdate(const PlatformTouchPoint&, Gestures);
    7477    bool isInClickTimeWindow();
     78    bool isInSecondClickTimeWindow();
    7579    bool isInsideManhattanSquare(const PlatformTouchPoint&);
    7680    void setState(State value) { m_state = value; }
     
    8488    bool scrollEnd(const PlatformTouchPoint&, Gestures);
    8589
     90    bool doubleClick(const PlatformTouchPoint&, Gestures);
     91    bool maybeDoubleClick(const PlatformTouchPoint&, Gestures);
     92
    8693    WTF::HashMap<int, GestureTransitionFunction> m_edgeFunctions;
    8794    IntPoint m_firstTouchPosition;
     
    9097    State m_state;
    9198    double m_lastTouchTime;
     99    double m_lastClickTime;
    92100
    93101    bool m_ctrlKey;
  • trunk/Source/WebCore/platform/chromium/PopupContainer.cpp

    r94772 r94797  
    307307        return true;
    308308    }
     309    case PlatformGestureEvent::DoubleTapType:
     310        break;
    309311    case PlatformGestureEvent::ScrollUpdateType: {
    310312        PlatformWheelEvent syntheticWheelEvent(gestureEvent.position(), gestureEvent.globalPosition(), gestureEvent.deltaX(), gestureEvent.deltaY(), gestureEvent.deltaX() / 120.0f, gestureEvent.deltaY() / 120.0f, ScrollByPixelWheelEvent, /* isAccepted */ false, gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey(), gestureEvent.metaKey());
  • trunk/Source/WebKit/chromium/tests/InnerGestureRecognizerTest.cpp

    r94772 r94797  
    3737using namespace WebCore;
    3838
    39 
    4039class InspectableGestureRecognizerChromium : public WebCore::GestureRecognizerChromium {
    4140public:
     
    158157};
    159158
     159void SimulateAndTestFirstClick(InspectableGestureRecognizerChromium& gm)
     160{
     161    ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
     162
     163    BuildablePlatformTouchPoint press(10, 15, PlatformTouchPoint::TouchPressed);
     164    BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press);
     165    OwnPtr<Vector<WebCore::PlatformGestureEvent> > gestureStart(gm.processTouchEventForGestures(pressEvent, false));
     166    ASSERT_EQ((unsigned int)1, gestureStart->size());
     167    ASSERT_EQ(PlatformGestureEvent::TapDownType, (*gestureStart)[0].type());
     168    ASSERT_EQ(GestureRecognizerChromium::PendingSyntheticClick, gm.state());
     169
     170    BuildablePlatformTouchPoint release(10, 16, PlatformTouchPoint::TouchReleased);
     171    BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release);
     172    gm.setFirstTouchTime(gm.firstTouchTime() - 0.01);
     173    OwnPtr<Vector<WebCore::PlatformGestureEvent> > gestureEnd(gm.processTouchEventForGestures(releaseEvent, false));
     174    ASSERT_EQ((unsigned int)1, gestureEnd->size());
     175    ASSERT_EQ(PlatformGestureEvent::TapType, (*gestureEnd)[0].type());
     176}
     177
    160178typedef OwnPtr<Vector<WebCore::PlatformGestureEvent> > Gestures;
    161179
     
    283301    ASSERT_EQ(3.0, gm.firstTouchTime());
    284302    ASSERT_EQ(0.0, gm.lastTouchTime() - gm.firstTouchTime());
     303}
     304
     305TEST_F(GestureRecognizerTest, doubleTapGestureTest)
     306{
     307    InspectableGestureRecognizerChromium gm;
     308    SimulateAndTestFirstClick(gm);
     309    ASSERT_EQ(GestureRecognizerChromium::FirstClickReceived, gm.state());
     310
     311    BuildablePlatformTouchPoint press(10, 15, PlatformTouchPoint::TouchPressed);
     312    BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press);
     313    gm.setLastTouchTime(gm.lastTouchTime() - 0.01);
     314    Gestures gestureStart(gm.processTouchEventForGestures(pressEvent, false));
     315    ASSERT_EQ((unsigned int)1, gestureStart->size());
     316    ASSERT_EQ(PlatformGestureEvent::TapDownType, (*gestureStart)[0].type());
     317    ASSERT_EQ(GestureRecognizerChromium::PendingDoubleClick, gm.state());
     318
     319    BuildablePlatformTouchPoint move(10, 16, PlatformTouchPoint::TouchMoved);
     320    BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move);
     321    Gestures gestureMove(gm.processTouchEventForGestures(moveEvent, false));
     322    ASSERT_EQ((unsigned int)0, gestureMove->size());
     323    ASSERT_EQ(GestureRecognizerChromium::PendingDoubleClick, gm.state());
     324
     325    BuildablePlatformTouchPoint release(10, 16, PlatformTouchPoint::TouchReleased);
     326    BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release);
     327    gm.setFirstTouchTime(gm.firstTouchTime() - 0.01);
     328    Gestures gestureEnd(gm.processTouchEventForGestures(releaseEvent, false));
     329    ASSERT_EQ((unsigned int)1, gestureEnd->size());
     330    ASSERT_EQ(PlatformGestureEvent::DoubleTapType, (*gestureEnd)[0].type());
     331    ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
     332}
     333
     334TEST_F(GestureRecognizerTest, doubleTapGestureIncompleteTest)
     335{
     336    InspectableGestureRecognizerChromium gm;
     337    SimulateAndTestFirstClick(gm);
     338    ASSERT_EQ(GestureRecognizerChromium::FirstClickReceived, gm.state());
     339
     340    BuildablePlatformTouchPoint press(10, 15, PlatformTouchPoint::TouchPressed);
     341    BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press);
     342    gm.setLastTouchTime(gm.lastTouchTime() - 0.01);
     343    Gestures gestureStart(gm.processTouchEventForGestures(pressEvent, false));
     344    ASSERT_EQ((unsigned int)1, gestureStart->size());
     345    ASSERT_EQ(PlatformGestureEvent::TapDownType, (*gestureStart)[0].type());
     346    ASSERT_EQ(GestureRecognizerChromium::PendingDoubleClick, gm.state());
     347
     348    BuildablePlatformTouchPoint move(10, 50, PlatformTouchPoint::TouchMoved);
     349    BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move);
     350    Gestures gestureMove(gm.processTouchEventForGestures(moveEvent, false));
     351    ASSERT_EQ((unsigned int)0, gestureMove->size());
     352    ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
     353
     354    BuildablePlatformTouchPoint release(10, 50, PlatformTouchPoint::TouchReleased);
     355    BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release);
     356    gm.setFirstTouchTime(gm.firstTouchTime() - 0.01);
     357    Gestures gestureEnd(gm.processTouchEventForGestures(releaseEvent, false));
     358    ASSERT_EQ((unsigned int)0, gestureEnd->size());
     359    ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
    285360}
    286361
     
    339414    ASSERT_EQ((unsigned int)1, gestureEnd->size());
    340415    ASSERT_EQ(PlatformGestureEvent::TapType, (*gestureEnd)[0].type());
    341     ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
     416    ASSERT_EQ(GestureRecognizerChromium::FirstClickReceived, gm.state());
    342417}
    343418
Note: See TracChangeset for help on using the changeset viewer.