Changeset 93358 in webkit


Ignore:
Timestamp:
Aug 18, 2011 3:19:23 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

GestureRecognizer: Update how gesture-scroll works.

Source/WebCore:

Instead of just sending a series of 'GestureUpdate' events, send a
single 'GestureBegin' event, followed by a series of 'GestureUpdate' events,
and end with a 'GestureEnd' event.
https://bugs.webkit.org/show_bug.cgi?id=66267

Patch by Sadrul Habib Chowdhury <sadrul@chromium.org> on 2011-08-18
Reviewed by Adam Barth.

  • page/EventHandler.cpp:

(WebCore::EventHandler::handleGestureEvent):

  • platform/chromium/GestureRecognizerChromium.cpp:

(WebCore::InnerGestureRecognizer::InnerGestureRecognizer):
(WebCore::InnerGestureRecognizer::appendScrollGestureBegin):
(WebCore::InnerGestureRecognizer::appendScrollGestureEnd):
(WebCore::InnerGestureRecognizer::appendScrollGestureUpdate):
(WebCore::scrollEnd):
(WebCore::isClickOrScroll):
(WebCore::inScroll):

  • platform/chromium/GestureRecognizerChromium.h:

(WebCore::InnerGestureRecognizer::firstTouchPosition):

Source/WebKit/chromium:

Add a unit-test to make sure the correct gesture events are being
generated.
https://bugs.webkit.org/show_bug.cgi?id=66267

Patch by Sadrul Habib Chowdhury <sadrul@chromium.org> on 2011-08-18
Reviewed by Adam Barth.

  • tests/InnerGestureRecognizerTest.cpp:

(WebCore::BuildablePlatformTouchPoint::BuildablePlatformTouchPoint):
(WebCore::BuildablePlatformTouchEvent::BuildablePlatformTouchEvent):
(WebCore::TEST_F):

Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r93356 r93358  
     12011-08-18  Sadrul Habib Chowdhury  <sadrul@chromium.org>
     2
     3        GestureRecognizer: Update how gesture-scroll works.
     4
     5        Instead of just sending a series of 'GestureUpdate' events, send a
     6        single 'GestureBegin' event, followed by a series of 'GestureUpdate' events,
     7        and end with a 'GestureEnd' event.
     8        https://bugs.webkit.org/show_bug.cgi?id=66267
     9
     10        Reviewed by Adam Barth.
     11
     12        * page/EventHandler.cpp:
     13        (WebCore::EventHandler::handleGestureEvent):
     14        * platform/chromium/GestureRecognizerChromium.cpp:
     15        (WebCore::InnerGestureRecognizer::InnerGestureRecognizer):
     16        (WebCore::InnerGestureRecognizer::appendScrollGestureBegin):
     17        (WebCore::InnerGestureRecognizer::appendScrollGestureEnd):
     18        (WebCore::InnerGestureRecognizer::appendScrollGestureUpdate):
     19        (WebCore::scrollEnd):
     20        (WebCore::isClickOrScroll):
     21        (WebCore::inScroll):
     22        * platform/chromium/GestureRecognizerChromium.h:
     23        (WebCore::InnerGestureRecognizer::firstTouchPosition):
     24
    1252011-08-18  Sailesh Agrawal  <sail@chromium.org>
    226
  • trunk/Source/WebCore/page/EventHandler.cpp

    r93134 r93358  
    22232223        const float tickDivisor = (float)WheelEvent::tickMultiplier;
    22242224        // FIXME: Replace this interim implementation once the above fixme has been addressed.
    2225         PlatformWheelEvent syntheticWheelEvent(gestureEvent.position(), gestureEvent.globalPosition(), gestureEvent.deltaX(), gestureEvent.deltaY(), gestureEvent.deltaX() / tickDivisor, gestureEvent.deltaY() / tickDivisor, ScrollByPixelWheelEvent, /* isAccepted */ false, gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey(), gestureEvent.metaKey());
     2225        IntPoint point(gestureEvent.position().x() + gestureEvent.deltaX(), gestureEvent.position().y() + gestureEvent.deltaY());
     2226        PlatformWheelEvent syntheticWheelEvent(point, point, gestureEvent.deltaX(), gestureEvent.deltaY(), gestureEvent.deltaX() / tickDivisor, gestureEvent.deltaY() / tickDivisor, ScrollByPixelWheelEvent, /* isAccepted */ false, gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey(), gestureEvent.metaKey());
    22262227        handleWheelEvent(syntheticWheelEvent);
    22272228        return true;
  • trunk/Source/WebCore/platform/chromium/GestureRecognizerChromium.cpp

    r92234 r93358  
    4141static bool isClickOrScroll(InnerGestureRecognizer*, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures);
    4242static bool inScroll(InnerGestureRecognizer*, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures);
     43static bool scrollEnd(InnerGestureRecognizer*, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures);
    4344static bool noGesture(InnerGestureRecognizer*, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures);
    4445static bool touchDown(InnerGestureRecognizer*, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures);
     
    7172    addEdgeFunction(PendingSyntheticClick, FirstFinger, Stationary, false, isClickOrScroll);
    7273    addEdgeFunction(Scroll, FirstFinger, Moved, false, inScroll);
    73     addEdgeFunction(Scroll, FirstFinger, Released, false, noGesture);
    74     addEdgeFunction(Scroll, FirstFinger, Cancelled, false, noGesture);
     74    addEdgeFunction(Scroll, FirstFinger, Released, false, scrollEnd);
     75    addEdgeFunction(Scroll, FirstFinger, Cancelled, false, scrollEnd);
    7576}
    7677
     
    127128}
    128129
    129 void InnerGestureRecognizer::appendScrollGesture(const PlatformTouchPoint& touchPoint, Gestures gestures)
    130 {
    131     float deltaX(touchPoint.pos().x() - m_firstTouchPosition.x());
    132     float deltaY(touchPoint.pos().y() - m_firstTouchPosition.y());
    133 
    134     gestures->append(PlatformGestureEvent(PlatformGestureEvent::ScrollUpdateType, touchPoint.pos(), touchPoint.screenPos(), m_lastTouchTime, deltaX, deltaY, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
    135     m_firstTouchPosition = touchPoint.pos();
     130void InnerGestureRecognizer::appendScrollGestureBegin(const IntPoint& touchPoint, Gestures gestures)
     131{
     132    gestures->append(PlatformGestureEvent(PlatformGestureEvent::ScrollBeginType, touchPoint, touchPoint, m_lastTouchTime, 0.0f, 0.0f, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
     133    m_firstTouchPosition = touchPoint;
     134    m_lastTouchPosition = m_firstTouchPosition;
     135}
     136
     137void InnerGestureRecognizer::appendScrollGestureEnd(const IntPoint& touchPoint, Gestures gestures)
     138{
     139    gestures->append(PlatformGestureEvent(PlatformGestureEvent::ScrollEndType, m_firstTouchPosition, m_firstTouchPosition, m_lastTouchTime, 0.0f, 0.0f, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
     140}
     141
     142void InnerGestureRecognizer::appendScrollGestureUpdate(const IntPoint& touchPoint, Gestures gestures)
     143{
     144    float deltaX(touchPoint.x() - m_lastTouchPosition.x());
     145    float deltaY(touchPoint.y() - m_lastTouchPosition.y());
     146
     147    gestures->append(PlatformGestureEvent(PlatformGestureEvent::ScrollUpdateType, m_firstTouchPosition, m_firstTouchPosition, m_lastTouchTime, deltaX, deltaY, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
     148    m_lastTouchPosition = touchPoint;
    136149}
    137150
     
    163176}
    164177
     178static bool scrollEnd(InnerGestureRecognizer* gestureRecognizer, const PlatformTouchPoint& point, InnerGestureRecognizer::Gestures gestures)
     179{
     180    gestureRecognizer->appendScrollGestureEnd(point.pos(), gestures);
     181    gestureRecognizer->setState(InnerGestureRecognizer::NoGesture);
     182    return false;
     183}
     184
    165185static bool noGesture(InnerGestureRecognizer* gestureRecognizer, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures gestures)
    166186{
     
    187207
    188208    if (point.state() == PlatformTouchPoint::TouchMoved && !gestureRecognizer->isInsideManhattanSquare(point)) {
    189         gestureRecognizer->appendScrollGesture(point, gestures);
     209        gestureRecognizer->appendScrollGestureBegin(gestureRecognizer->firstTouchPosition(), gestures);
     210        gestureRecognizer->appendScrollGestureUpdate(point.pos(), gestures);
    190211        gestureRecognizer->setState(InnerGestureRecognizer::Scroll);
    191212        return true;
     
    196217static bool inScroll(InnerGestureRecognizer* gestureRecognizer, const PlatformTouchPoint& point, InnerGestureRecognizer::Gestures gestures)
    197218{
    198     gestureRecognizer->appendScrollGesture(point, gestures);
     219    gestureRecognizer->appendScrollGestureUpdate(point.pos(), gestures);
    199220    return true;
    200221}
  • trunk/Source/WebCore/platform/chromium/GestureRecognizerChromium.h

    r92234 r93358  
    6060    bool isInsideManhattanSquare(const PlatformTouchPoint&);
    6161    virtual PlatformGestureRecognizer::PassGestures  processTouchEventForGestures(const PlatformTouchEvent&, bool defaultPrevented);
    62     void appendScrollGesture(const PlatformTouchPoint&, Gestures);
     62    void appendScrollGestureBegin(const IntPoint&, Gestures);
     63    void appendScrollGestureEnd(const IntPoint&, Gestures);
     64    void appendScrollGestureUpdate(const IntPoint&, Gestures);
    6365    void setState(State value) { m_state = value; }
    6466    State state() { return m_state; }
     67
     68    IntPoint firstTouchPosition() { return m_firstTouchPosition; }
    6569protected:
    6670    InnerGestureRecognizer();
     
    7579    double m_firstTouchTime;
    7680    State m_state;
     81    IntPoint m_lastTouchPosition;
    7782    double m_lastTouchTime;
    7883
  • trunk/Source/WebKit/chromium/ChangeLog

    r93350 r93358  
     12011-08-18  Sadrul Habib Chowdhury  <sadrul@chromium.org>
     2
     3        GestureRecognizer: Update how gesture-scroll works.
     4
     5        Add a unit-test to make sure the correct gesture events are being
     6        generated.
     7        https://bugs.webkit.org/show_bug.cgi?id=66267
     8
     9        Reviewed by Adam Barth.
     10
     11        * tests/InnerGestureRecognizerTest.cpp:
     12        (WebCore::BuildablePlatformTouchPoint::BuildablePlatformTouchPoint):
     13        (WebCore::BuildablePlatformTouchEvent::BuildablePlatformTouchEvent):
     14        (WebCore::TEST_F):
     15
    1162011-08-18  Sheriff Bot  <webkit.review.bot@gmail.com>
    217
  • trunk/Source/WebKit/chromium/tests/InnerGestureRecognizerTest.cpp

    r88307 r93358  
    7979    BuildablePlatformTouchPoint();
    8080    BuildablePlatformTouchPoint(int x, int y);
     81    BuildablePlatformTouchPoint(int x, int y, PlatformTouchPoint::State);
    8182
    8283    void setX(int x)
     
    109110};
    110111
     112BuildablePlatformTouchPoint::BuildablePlatformTouchPoint(int x, int y, PlatformTouchPoint::State state)
     113{
     114    m_id = 0;
     115    m_state = state;
     116    m_pos = IntPoint(x, y);
     117    m_screenPos = IntPoint(x, y);
     118}
     119
     120class BuildablePlatformTouchEvent : public WebCore::PlatformTouchEvent {
     121public:
     122    BuildablePlatformTouchEvent(WebCore::TouchEventType type, PlatformTouchPoint& point)
     123    {
     124        m_type = type;
     125        m_touchPoints.append(point);
     126    }
     127};
    111128
    112129class TestGestureRecognizer : public testing::Test {
     
    244261}
    245262
     263TEST_F(TestGestureRecognizer, gestureScrollEvents)
     264{
     265    InspectableInnerGestureRecognizer gm;
     266
     267    ASSERT_EQ(InnerGestureRecognizer::NoGesture, gm.state());
     268
     269    BuildablePlatformTouchPoint press(10, 15, PlatformTouchPoint::TouchPressed);
     270    BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press);
     271    gm.processTouchEventForGestures(pressEvent, false);
     272
     273    ASSERT_EQ(InnerGestureRecognizer::PendingSyntheticClick, gm.state());
     274
     275    BuildablePlatformTouchPoint move(10, 50, PlatformTouchPoint::TouchMoved);
     276    BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move);
     277    OwnPtr<Vector<WebCore::PlatformGestureEvent> > gestureStart(gm.processTouchEventForGestures(moveEvent, false));
     278    bool scrollStarted = false, scrollUpdated = false;
     279    for (unsigned int i = 0; i < gestureStart->size(); i++) {
     280        switch ((*gestureStart)[i].type()) {
     281        case PlatformGestureEvent::ScrollBeginType:
     282            scrollStarted = true;
     283            break;
     284        case PlatformGestureEvent::ScrollUpdateType:
     285            scrollUpdated = true;
     286            break;
     287        default:
     288            ASSERT_TRUE(false);
     289        }
     290    }
     291
     292    ASSERT_TRUE(scrollStarted);
     293    ASSERT_TRUE(scrollUpdated);
     294    ASSERT_EQ(InnerGestureRecognizer::Scroll, gm.state());
     295
     296    BuildablePlatformTouchPoint release(10, 50, PlatformTouchPoint::TouchReleased);
     297    BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release);
     298    bool scrollEnd = false;
     299    OwnPtr<Vector<WebCore::PlatformGestureEvent> > gestureEnd(gm.processTouchEventForGestures(releaseEvent, false));
     300    for (unsigned int i = 0; i < gestureEnd->size(); i++) {
     301        switch ((*gestureEnd)[i].type()) {
     302        case PlatformGestureEvent::ScrollEndType:
     303            scrollEnd = true;
     304            break;
     305        default:
     306            ASSERT_TRUE(false);
     307        }
     308    }
     309    ASSERT_TRUE(scrollEnd);
     310    ASSERT_EQ(InnerGestureRecognizer::NoGesture, gm.state());
     311}
     312
    246313} // namespace
Note: See TracChangeset for help on using the changeset viewer.