Source/WebCore: [chromium] Code cleanup FIXME in Chromium recognizer
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Sep 2011 00:32:00 +0000 (00:32 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Sep 2011 00:32:00 +0000 (00:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67448

Patch by Robert Kroeger <rjkroege@chromium.org> on 2011-09-01
Reviewed by Adam Barth.

* page/EventHandler.cpp:
(WebCore::EventHandler::handleGestureEvent):
Fixed a bug noticed by a benjaminp while reviewing a different
ndonned patch where global positions were not being set correctly
on gesture-driven mouse wheel events.
* platform/chromium/GestureRecognizerChromium.cpp:
Changed static per-edge functions into methods and improves
encapsulation. No new functionality is present.
(WebCore::GestureRecognizerChromium::GestureRecognizerChromium):
(WebCore::GestureRecognizerChromium::reset):
(WebCore::GestureRecognizerChromium::~GestureRecognizerChromium):
(WebCore::GestureRecognizerChromium::addEdgeFunction):
(WebCore::GestureRecognizerChromium::isInClickTimeWindow):
(WebCore::GestureRecognizerChromium::isInsideManhattanSquare):
(WebCore::GestureRecognizerChromium::appendClickGestureEvent):
(WebCore::GestureRecognizerChromium::processTouchEventForGestures):
(WebCore::GestureRecognizerChromium::appendScrollGestureBegin):
(WebCore::GestureRecognizerChromium::appendScrollGestureEnd):
(WebCore::GestureRecognizerChromium::appendScrollGestureUpdate):
(WebCore::GestureRecognizerChromium::updateValues):
(WebCore::GestureRecognizerChromium::signature):
(WebCore::GestureRecognizerChromium::touchDown):
(WebCore::GestureRecognizerChromium::scrollEnd):
(WebCore::GestureRecognizerChromium::noGesture):
(WebCore::GestureRecognizerChromium::click):
(WebCore::GestureRecognizerChromium::isClickOrScroll):
(WebCore::GestureRecognizerChromium::inScroll):
* platform/chromium/GestureRecognizerChromium.h:
(WebCore::GestureRecognizerChromium::setState):

Source/WebKit/chromium: [chromium] Code cleanup FIXME in Chromium recognizer
https://bugs.webkit.org/show_bug.cgi?id=67448

Updated GestureRecognizer unit tests for more encapsulated
gesture recognizer implementation.

Patch by Robert Kroeger <rjkroege@chromium.org> on 2011-09-01
Reviewed by Adam Barth.

* tests/InnerGestureRecognizerTest.cpp:
(InspectableGestureRecognizerChromium::InspectableGestureRecognizerChromium):
(InspectableGestureRecognizerChromium::signature):
(InspectableGestureRecognizerChromium::edgeFunction):
(InspectableGestureRecognizerChromium::updateValues):
(InspectableGestureRecognizerChromium::addEdgeFunction):
(InspectableGestureRecognizerChromium::setStateTest):
(InspectableGestureRecognizerChromium::isInsideManhattanSquare):
(InspectableGestureRecognizerChromium::isInClickTimeWindow):
(InspectableGestureRecognizerChromium::stubEdgeFunction):
(GestureRecognizerTest::GestureRecognizerTest):
(TEST_F):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@94373 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/page/EventHandler.cpp
Source/WebCore/platform/chromium/GestureRecognizerChromium.cpp
Source/WebCore/platform/chromium/GestureRecognizerChromium.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/tests/InnerGestureRecognizerTest.cpp

index a156208..365a7c4 100644 (file)
@@ -1,3 +1,40 @@
+2011-09-01  Robert Kroeger  <rjkroege@chromium.org>
+
+       [chromium] Code cleanup FIXME in Chromium recognizer
+        https://bugs.webkit.org/show_bug.cgi?id=67448
+
+        Reviewed by Adam Barth.
+
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::handleGestureEvent):
+        Fixed a bug noticed by a benjaminp while reviewing a different
+        ndonned patch where global positions were not being set correctly
+        on gesture-driven mouse wheel events.
+        * platform/chromium/GestureRecognizerChromium.cpp:
+        Changed static per-edge functions into methods and improves
+        encapsulation. No new functionality is present.
+        (WebCore::GestureRecognizerChromium::GestureRecognizerChromium):
+        (WebCore::GestureRecognizerChromium::reset):
+        (WebCore::GestureRecognizerChromium::~GestureRecognizerChromium):
+        (WebCore::GestureRecognizerChromium::addEdgeFunction):
+        (WebCore::GestureRecognizerChromium::isInClickTimeWindow):
+        (WebCore::GestureRecognizerChromium::isInsideManhattanSquare):
+        (WebCore::GestureRecognizerChromium::appendClickGestureEvent):
+        (WebCore::GestureRecognizerChromium::processTouchEventForGestures):
+        (WebCore::GestureRecognizerChromium::appendScrollGestureBegin):
+        (WebCore::GestureRecognizerChromium::appendScrollGestureEnd):
+        (WebCore::GestureRecognizerChromium::appendScrollGestureUpdate):
+        (WebCore::GestureRecognizerChromium::updateValues):
+        (WebCore::GestureRecognizerChromium::signature):
+        (WebCore::GestureRecognizerChromium::touchDown):
+        (WebCore::GestureRecognizerChromium::scrollEnd):
+        (WebCore::GestureRecognizerChromium::noGesture):
+        (WebCore::GestureRecognizerChromium::click):
+        (WebCore::GestureRecognizerChromium::isClickOrScroll):
+        (WebCore::GestureRecognizerChromium::inScroll):
+        * platform/chromium/GestureRecognizerChromium.h:
+        (WebCore::GestureRecognizerChromium::setState):
+
 2011-09-01  Julien Chaffraix  <jchaffraix@webkit.org>
 
         Move LayoutRepainter to its own class
index a1f1cfc..21ecf32 100644 (file)
@@ -2222,8 +2222,9 @@ bool EventHandler::handleGestureEvent(const PlatformGestureEvent& gestureEvent)
     case PlatformGestureEvent::ScrollUpdateType: {
         const float tickDivisor = (float)WheelEvent::tickMultiplier;
         // FIXME: Replace this interim implementation once the above fixme has been addressed.
-        IntPoint point(gestureEvent.position().x() + gestureEvent.deltaX(), gestureEvent.position().y() + gestureEvent.deltaY());
-        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());
+        IntPoint point(gestureEvent.position().x(), gestureEvent.position().y());
+        IntPoint globalPoint(gestureEvent.globalPosition().x(), gestureEvent.globalPosition().y());
+        PlatformWheelEvent syntheticWheelEvent(point, globalPoint, gestureEvent.deltaX(), gestureEvent.deltaY(), gestureEvent.deltaX() / tickDivisor, gestureEvent.deltaY() / tickDivisor, ScrollByPixelWheelEvent, /* isAccepted */ false, gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey(), gestureEvent.metaKey());
         handleWheelEvent(syntheticWheelEvent);
         return true;
     }
index 17db5b5..75602b3 100644 (file)
 #include "config.h"
 #include "GestureRecognizerChromium.h"
 
-#include "PlatformMouseEvent.h"
-#include "PlatformWheelEvent.h"
-
 namespace WebCore {
 
-// FIXME: Convert to methods.
-static bool click(InnerGestureRecognizer*, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures);
-static bool isClickOrScroll(InnerGestureRecognizer*, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures);
-static bool inScroll(InnerGestureRecognizer*, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures);
-static bool scrollEnd(InnerGestureRecognizer*, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures);
-static bool noGesture(InnerGestureRecognizer*, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures);
-static bool touchDown(InnerGestureRecognizer*, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures);
-
 // FIXME: Make these configurable programmatically.
 static const double maximumTouchDownDurationInSecondsForClick = 0.8;
 static const double minimumTouchDownDurationInSecondsForClick = 0.01;
 static const int maximumTouchMoveInPixelsForClick = 20;
 
-InnerGestureRecognizer::InnerGestureRecognizer()
+GestureRecognizerChromium::GestureRecognizerChromium()
     : m_firstTouchTime(0.0)
-    , m_state(InnerGestureRecognizer::NoGesture)
+    , m_state(GestureRecognizerChromium::NoGesture)
     , m_lastTouchTime(0.0)
     , m_ctrlKey(false)
     , m_altKey(false)
@@ -65,50 +54,50 @@ InnerGestureRecognizer::InnerGestureRecognizer()
     const PlatformTouchPoint::State Stationary = PlatformTouchPoint::TouchStationary;
     const PlatformTouchPoint::State Cancelled = PlatformTouchPoint::TouchCancelled;
 
-    addEdgeFunction(NoGesture, FirstFinger, Pressed, false, touchDown);
-    addEdgeFunction(PendingSyntheticClick, FirstFinger, Cancelled, false, noGesture);
-    addEdgeFunction(PendingSyntheticClick, FirstFinger, Released, false, click);
-    addEdgeFunction(PendingSyntheticClick, FirstFinger, Moved, false, isClickOrScroll);
-    addEdgeFunction(PendingSyntheticClick, FirstFinger, Stationary, false, isClickOrScroll);
-    addEdgeFunction(Scroll, FirstFinger, Moved, false, inScroll);
-    addEdgeFunction(Scroll, FirstFinger, Released, false, scrollEnd);
-    addEdgeFunction(Scroll, FirstFinger, Cancelled, false, scrollEnd);
+    addEdgeFunction(NoGesture, FirstFinger, Pressed, false, &GestureRecognizerChromium::touchDown);
+    addEdgeFunction(PendingSyntheticClick, FirstFinger, Cancelled, false, &GestureRecognizerChromium::noGesture);
+    addEdgeFunction(PendingSyntheticClick, FirstFinger, Released, false, &GestureRecognizerChromium::click);
+    addEdgeFunction(PendingSyntheticClick, FirstFinger, Moved, false, &GestureRecognizerChromium::isClickOrScroll);
+    addEdgeFunction(PendingSyntheticClick, FirstFinger, Stationary, false, &GestureRecognizerChromium::isClickOrScroll);
+    addEdgeFunction(Scroll, FirstFinger, Moved, false, &GestureRecognizerChromium::inScroll);
+    addEdgeFunction(Scroll, FirstFinger, Released, false, &GestureRecognizerChromium::scrollEnd);
+    addEdgeFunction(Scroll, FirstFinger, Cancelled, false, &GestureRecognizerChromium::scrollEnd);
 }
 
-void InnerGestureRecognizer::reset()
+void GestureRecognizerChromium::reset()
 {
     m_firstTouchTime = 0.0;
-    m_state = InnerGestureRecognizer::NoGesture;
+    m_state = GestureRecognizerChromium::NoGesture;
     m_lastTouchTime = 0.0;
 }
 
-InnerGestureRecognizer::~InnerGestureRecognizer()
+GestureRecognizerChromium::~GestureRecognizerChromium()
 {
 }
 
-void InnerGestureRecognizer::addEdgeFunction(State state, unsigned fingerId, PlatformTouchPoint::State touchType, bool touchHandledByJavaScript, GestureTransitionFunction transitionFunction)
+void GestureRecognizerChromium::addEdgeFunction(State state, unsigned fingerId, PlatformTouchPoint::State touchType, bool touchHandledByJavaScript, GestureTransitionFunction transitionFunction)
 {
     m_edgeFunctions.add(signature(state, fingerId, touchType, touchHandledByJavaScript), transitionFunction);
 }
 
-bool InnerGestureRecognizer::isInClickTimeWindow()
+bool GestureRecognizerChromium::isInClickTimeWindow()
 {
     double duration(m_lastTouchTime - m_firstTouchTime);
     return duration >= minimumTouchDownDurationInSecondsForClick && duration < maximumTouchDownDurationInSecondsForClick;
 }
 
-bool InnerGestureRecognizer::isInsideManhattanSquare(const PlatformTouchPoint& point)
+bool GestureRecognizerChromium::isInsideManhattanSquare(const PlatformTouchPoint& point)
 {
     int manhattanDistance = abs(point.pos().x() - m_firstTouchPosition.x()) + abs(point.pos().y() - m_firstTouchPosition.y());
     return manhattanDistance < maximumTouchMoveInPixelsForClick;
 }
 
-void InnerGestureRecognizer::appendClickGestureEvent(const PlatformTouchPoint& touchPoint, InnerGestureRecognizer::Gestures gestures)
+void GestureRecognizerChromium::appendClickGestureEvent(const PlatformTouchPoint& touchPoint, Gestures gestures)
 {
-    gestures->append(PlatformGestureEvent(PlatformGestureEvent::TapType, touchPoint.pos(), touchPoint.screenPos(), m_lastTouchTime, 0.0f, 0.0f, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
+    gestures->append(PlatformGestureEvent(PlatformGestureEvent::TapType, m_firstTouchPosition, m_firstTouchScreenPosition, m_lastTouchTime, 0.f, 0.f, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
 }
 
-PlatformGestureRecognizer::PassGestures InnerGestureRecognizer::processTouchEventForGestures(const PlatformTouchEvent& event, bool defaultPrevented)
+PlatformGestureRecognizer::PassGestures GestureRecognizerChromium::processTouchEventForGestures(const PlatformTouchEvent& event, bool defaultPrevented)
 {
     m_ctrlKey = event.ctrlKey();
     m_altKey = event.altKey();
@@ -122,38 +111,37 @@ PlatformGestureRecognizer::PassGestures InnerGestureRecognizer::processTouchEven
         updateValues(event.timestamp(), p);
 
         if (GestureTransitionFunction ef = m_edgeFunctions.get(signature(m_state, p.id(), p.state(), defaultPrevented)))
-            (*ef)(this, p, gestures.get());
+            ((*this).*ef)(p, gestures.get());
     }
     return gestures.release();
 }
 
-void InnerGestureRecognizer::appendScrollGestureBegin(const IntPoint& touchPoint, Gestures gestures)
+void GestureRecognizerChromium::appendScrollGestureBegin(const PlatformTouchPoint& touchPoint, Gestures gestures)
 {
-    gestures->append(PlatformGestureEvent(PlatformGestureEvent::ScrollBeginType, touchPoint, touchPoint, m_lastTouchTime, 0.0f, 0.0f, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
-    m_firstTouchPosition = touchPoint;
-    m_lastTouchPosition = m_firstTouchPosition;
+    gestures->append(PlatformGestureEvent(PlatformGestureEvent::ScrollBeginType, touchPoint.pos(), touchPoint.screenPos(), m_lastTouchTime, 0.f, 0.f, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
 }
 
-void InnerGestureRecognizer::appendScrollGestureEnd(const IntPoint& touchPoint, Gestures gestures)
+void GestureRecognizerChromium::appendScrollGestureEnd(const PlatformTouchPoint& touchPoint, Gestures gestures)
 {
-    gestures->append(PlatformGestureEvent(PlatformGestureEvent::ScrollEndType, m_firstTouchPosition, m_firstTouchPosition, m_lastTouchTime, 0.0f, 0.0f, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
+    gestures->append(PlatformGestureEvent(PlatformGestureEvent::ScrollEndType, touchPoint.pos(), touchPoint.screenPos(), m_lastTouchTime, 0.f, 0.f, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
 }
 
-void InnerGestureRecognizer::appendScrollGestureUpdate(const IntPoint& touchPoint, Gestures gestures)
+void GestureRecognizerChromium::appendScrollGestureUpdate(const PlatformTouchPoint& touchPoint, Gestures gestures)
 {
-    float deltaX(touchPoint.x() - m_lastTouchPosition.x());
-    float deltaY(touchPoint.y() - m_lastTouchPosition.y());
+    float deltaX(touchPoint.pos().x() - m_firstTouchPosition.x());
+    float deltaY(touchPoint.pos().y() - m_firstTouchPosition.y());
 
-    gestures->append(PlatformGestureEvent(PlatformGestureEvent::ScrollUpdateType, m_firstTouchPosition, m_firstTouchPosition, m_lastTouchTime, deltaX, deltaY, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
-    m_lastTouchPosition = touchPoint;
+    gestures->append(PlatformGestureEvent(PlatformGestureEvent::ScrollUpdateType, touchPoint.pos(), touchPoint.screenPos(), m_lastTouchTime, deltaX, deltaY, m_shiftKey, m_ctrlKey, m_altKey, m_metaKey));
+    m_firstTouchPosition = touchPoint.pos();
 }
 
-void InnerGestureRecognizer::updateValues(const double touchTime, const PlatformTouchPoint& touchPoint)
+void GestureRecognizerChromium::updateValues(const double touchTime, const PlatformTouchPoint& touchPoint)
 {
     m_lastTouchTime = touchTime;
     if (state() == NoGesture) {
         m_firstTouchTime = touchTime;
         m_firstTouchPosition = touchPoint.pos();
+        m_firstTouchScreenPosition = touchPoint.screenPos();
     }
 }
 
@@ -163,60 +151,62 @@ void InnerGestureRecognizer::updateValues(const double touchTime, const Platform
 // 1 bit for |handled|
 // 12 bits for |id|
 // 15 bits for the |gestureState|.
-unsigned int InnerGestureRecognizer::signature(State gestureState, unsigned id, PlatformTouchPoint::State touchType, bool handled)
+unsigned int GestureRecognizerChromium::signature(State gestureState, unsigned id, PlatformTouchPoint::State touchType, bool handled)
 {
     ASSERT((id & 0xfff) == id);
     return 1 + ((touchType & 0x7) << 1 | (handled ? 1 << 4 : 0) | ((id & 0xfff) << 5 ) | (gestureState << 17));
 }
 
-static bool touchDown(InnerGestureRecognizer* gestureRecognizer, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures gestures)
+bool GestureRecognizerChromium::touchDown(const PlatformTouchPoint& touchPoint, Gestures gestures)
 {
-    gestureRecognizer->setState(InnerGestureRecognizer::PendingSyntheticClick);
+    setState(PendingSyntheticClick);
+    // FIXME: Divide TapType into down and up events.
     return false;
 }
 
-static bool scrollEnd(InnerGestureRecognizer* gestureRecognizer, const PlatformTouchPoint& point, InnerGestureRecognizer::Gestures gestures)
+bool GestureRecognizerChromium::scrollEnd(const PlatformTouchPoint& point, Gestures gestures)
 {
-    gestureRecognizer->appendScrollGestureEnd(point.pos(), gestures);
-    gestureRecognizer->setState(InnerGestureRecognizer::NoGesture);
+    appendScrollGestureEnd(point, gestures);
+    setState(NoGesture);
+    reset();
     return false;
 }
 
-static bool noGesture(InnerGestureRecognizer* gestureRecognizer, const PlatformTouchPoint&, InnerGestureRecognizer::Gestures gestures)
+bool GestureRecognizerChromium::noGesture(const PlatformTouchPoint&, Gestures)
 {
-    gestureRecognizer->reset();
+    reset();
     return false;
 }
 
-static bool click(InnerGestureRecognizer* gestureRecognizer, const PlatformTouchPoint& point, InnerGestureRecognizer::Gestures gestures)
+bool GestureRecognizerChromium::click(const PlatformTouchPoint& point, Gestures gestures)
 {
-    if (gestureRecognizer->isInClickTimeWindow() && gestureRecognizer->isInsideManhattanSquare(point)) {
-        gestureRecognizer->setState(InnerGestureRecognizer::NoGesture);
-        gestureRecognizer->appendClickGestureEvent(point, gestures);
+    if (isInClickTimeWindow() && isInsideManhattanSquare(point)) {
+        setState(NoGesture);
+        appendClickGestureEvent(point, gestures);
         return true;
     }
-    return noGesture(gestureRecognizer, point, gestures);
+    return noGesture(point, gestures);
 }
 
-static bool isClickOrScroll(InnerGestureRecognizer* gestureRecognizer, const PlatformTouchPoint& point, InnerGestureRecognizer::Gestures gestures)
+bool GestureRecognizerChromium::isClickOrScroll(const PlatformTouchPoint& point, Gestures gestures)
 {
-    if (gestureRecognizer->isInClickTimeWindow() && gestureRecognizer->isInsideManhattanSquare(point)) {
-        gestureRecognizer->setState(InnerGestureRecognizer::PendingSyntheticClick);
+    if (isInClickTimeWindow() && isInsideManhattanSquare(point)) {
+        setState(GestureRecognizerChromium::PendingSyntheticClick);
         return false;
     }
 
-    if (point.state() == PlatformTouchPoint::TouchMoved && !gestureRecognizer->isInsideManhattanSquare(point)) {
-        gestureRecognizer->appendScrollGestureBegin(gestureRecognizer->firstTouchPosition(), gestures);
-        gestureRecognizer->appendScrollGestureUpdate(point.pos(), gestures);
-        gestureRecognizer->setState(InnerGestureRecognizer::Scroll);
+    if (point.state() == PlatformTouchPoint::TouchMoved && !isInsideManhattanSquare(point)) {
+        appendScrollGestureBegin(point, gestures);
+        appendScrollGestureUpdate(point, gestures);
+        setState(Scroll);
         return true;
     }
     return false;
 }
 
-static bool inScroll(InnerGestureRecognizer* gestureRecognizer, const PlatformTouchPoint& point, InnerGestureRecognizer::Gestures gestures)
+bool GestureRecognizerChromium::inScroll(const PlatformTouchPoint& point, Gestures gestures)
 {
-    gestureRecognizer->appendScrollGestureUpdate(point.pos(), gestures);
+    appendScrollGestureUpdate(point, gestures);
     return true;
 }
 
@@ -234,23 +224,4 @@ PlatformGestureRecognizer::~PlatformGestureRecognizer()
 {
 }
 
-GestureRecognizerChromium::GestureRecognizerChromium()
-    : m_innerGestureRecognizer()
-{
-}
-
-GestureRecognizerChromium::~GestureRecognizerChromium()
-{
-}
-
-PlatformGestureRecognizer::PassGestures GestureRecognizerChromium::processTouchEventForGestures(const PlatformTouchEvent& touchEvent, bool defaultPrevented)
-{
-    return m_innerGestureRecognizer.processTouchEventForGestures(touchEvent, defaultPrevented);
-}
-
-void GestureRecognizerChromium::reset()
-{
-    m_innerGestureRecognizer.reset();
-}
-
 } // namespace WebCore
index fd46fe7..6d56cd5 100644 (file)
 #include "PlatformGestureRecognizer.h"
 
 #include "PlatformTouchEvent.h"
-#include "TouchEvent.h"
+#include "PlatformTouchPoint.h"
 #include <wtf/HashMap.h>
 
+class InspectableGestureRecognizerChromium;
+
 namespace WebCore {
 
 class PlatformGestureEvent;
 
-class InnerGestureRecognizer {
+class GestureRecognizerChromium : public PlatformGestureRecognizer  {
 public:
     enum State {
         NoGesture,
@@ -50,32 +52,39 @@ public:
     };
 
     typedef Vector<PlatformGestureEvent>* Gestures;
-    typedef bool (*GestureTransitionFunction)(InnerGestureRecognizer*, const PlatformTouchPoint&, Gestures);
+    typedef bool (GestureRecognizerChromium::*GestureTransitionFunction)(const PlatformTouchPoint&, Gestures);
 
-    ~InnerGestureRecognizer();
+    GestureRecognizerChromium();
+    ~GestureRecognizerChromium();
 
-    void appendClickGestureEvent(const PlatformTouchPoint&, Gestures);
     virtual void reset();
-    bool isInClickTimeWindow();
-    bool isInsideManhattanSquare(const PlatformTouchPoint&);
     virtual PlatformGestureRecognizer::PassGestures  processTouchEventForGestures(const PlatformTouchEvent&, bool defaultPrevented);
-    void appendScrollGestureBegin(const IntPoint&, Gestures);
-    void appendScrollGestureEnd(const IntPoint&, Gestures);
-    void appendScrollGestureUpdate(const IntPoint&, Gestures);
-    void setState(State value) { m_state = value; }
     State state() { return m_state; }
 
-    IntPoint firstTouchPosition() { return m_firstTouchPosition; }
-protected:
-    InnerGestureRecognizer();
+private:
+    friend class ::InspectableGestureRecognizerChromium;
+
+    static unsigned int signature(State, unsigned, PlatformTouchPoint::State, bool);
     void addEdgeFunction(State, unsigned finger, PlatformTouchPoint::State, bool touchHandledByJavaScript, GestureTransitionFunction);
+    void appendClickGestureEvent(const PlatformTouchPoint&, Gestures);
+    void appendScrollGestureBegin(const PlatformTouchPoint&, Gestures);
+    void appendScrollGestureEnd(const PlatformTouchPoint&, Gestures);
+    void appendScrollGestureUpdate(const PlatformTouchPoint&, Gestures);
+    bool isInClickTimeWindow();
+    bool isInsideManhattanSquare(const PlatformTouchPoint&);
+    void setState(State value) { m_state = value; }
     void updateValues(double touchTime, const PlatformTouchPoint&);
-    static unsigned int signature(State, unsigned, PlatformTouchPoint::State, bool);
 
-    friend class GestureRecognizerChromium;
+    bool click(const PlatformTouchPoint&, Gestures);
+    bool isClickOrScroll(const PlatformTouchPoint&, Gestures);
+    bool inScroll(const PlatformTouchPoint&, Gestures);
+    bool noGesture(const PlatformTouchPoint&, Gestures);
+    bool touchDown(const PlatformTouchPoint&, Gestures);
+    bool scrollEnd(const PlatformTouchPoint&, Gestures);
 
     WTF::HashMap<int, GestureTransitionFunction> m_edgeFunctions;
     IntPoint m_firstTouchPosition;
+    IntPoint m_firstTouchScreenPosition;
     double m_firstTouchTime;
     State m_state;
     IntPoint m_lastTouchPosition;
@@ -87,19 +96,6 @@ protected:
     bool m_metaKey;
 };
 
-class GestureRecognizerChromium : public PlatformGestureRecognizer  {
-public:
-
-    GestureRecognizerChromium();
-    virtual ~GestureRecognizerChromium();
-
-    virtual void reset();
-    virtual PlatformGestureRecognizer::PassGestures  processTouchEventForGestures(const PlatformTouchEvent&, bool defaultPrevented);
-private:
-    InnerGestureRecognizer m_innerGestureRecognizer;
-};
-
 } // namespace WebCore
 
 #endif // GestureRecognizerChromium_h
index 7f62e1c..112f0df 100644 (file)
@@ -1,3 +1,27 @@
+2011-09-01  Robert Kroeger  <rjkroege@chromium.org>
+
+        [chromium] Code cleanup FIXME in Chromium recognizer
+        https://bugs.webkit.org/show_bug.cgi?id=67448
+
+        Updated GestureRecognizer unit tests for more encapsulated
+        gesture recognizer implementation.
+
+        Reviewed by Adam Barth.
+
+        * tests/InnerGestureRecognizerTest.cpp:
+        (InspectableGestureRecognizerChromium::InspectableGestureRecognizerChromium):
+        (InspectableGestureRecognizerChromium::signature):
+        (InspectableGestureRecognizerChromium::edgeFunction):
+        (InspectableGestureRecognizerChromium::updateValues):
+        (InspectableGestureRecognizerChromium::addEdgeFunction):
+        (InspectableGestureRecognizerChromium::setStateTest):
+        (InspectableGestureRecognizerChromium::isInsideManhattanSquare):
+        (InspectableGestureRecognizerChromium::isInClickTimeWindow):
+        (InspectableGestureRecognizerChromium::stubEdgeFunction):
+        (GestureRecognizerTest::GestureRecognizerTest):
+        (TEST_F):
+
 2011-09-01  Brian Salomon  <bsalomon@google.com>
 
         [Chromium, Skia] Add virtual to WebGraphicsContext3D to create a new GrGLInterface per context. Insert per-skia-GL-function callback to set correct GL context.
index 7df31e2..2f95c84 100644 (file)
 
 using namespace WebCore;
 
-namespace {
 
-class InspectableInnerGestureRecognizer : public InnerGestureRecognizer {
+class InspectableGestureRecognizerChromium : public WebCore::GestureRecognizerChromium {
 public:
-    InspectableInnerGestureRecognizer()
-        : WebCore::InnerGestureRecognizer()
+    InspectableGestureRecognizerChromium()
+        : WebCore::GestureRecognizerChromium()
     {
     }
 
     int signature(State gestureState, unsigned id, PlatformTouchPoint::State touchType, bool handled)
     {
-        return InnerGestureRecognizer::signature(gestureState, id, touchType, handled);
+        return GestureRecognizerChromium::signature(gestureState, id, touchType, handled);
     };
 
     IntPoint firstTouchPosition() { return m_firstTouchPosition; };
@@ -58,20 +57,43 @@ public:
     void setLastTouchTime(double t) { m_lastTouchTime = t; };
     double lastTouchTime() { return m_lastTouchTime; };
 
-    InnerGestureRecognizer::GestureTransitionFunction edgeFunction(int hash)
+    GestureRecognizerChromium::GestureTransitionFunction edgeFunction(int hash)
     {
         return m_edgeFunctions.get(hash);
     };
 
     virtual void updateValues(double d, const PlatformTouchPoint &p)
     {
-        InnerGestureRecognizer::updateValues(d, p);
+        GestureRecognizerChromium::updateValues(d, p);
     };
 
     void addEdgeFunction(State state, unsigned finger, PlatformTouchPoint::State touchState, bool touchHandledByJavaScript, GestureTransitionFunction function)
     {
-        InnerGestureRecognizer::addEdgeFunction(state, finger, touchState, touchHandledByJavaScript, function);
+        GestureRecognizerChromium::addEdgeFunction(state, finger, touchState, touchHandledByJavaScript, function);
     };
+
+    bool stubEdgeFunction(const PlatformTouchPoint&, GestureRecognizerChromium::Gestures*);
+
+    void setStateTest(State value)
+    {
+        GestureRecognizerChromium::setState(value);
+    };
+
+    bool isInsideManhattanSquare(const PlatformTouchPoint& touchPoint)
+    {
+        return GestureRecognizerChromium::isInsideManhattanSquare(touchPoint);
+    };
+
+    bool isInClickTimeWindow()
+    {
+        return GestureRecognizerChromium::isInClickTimeWindow();
+    };
+
+};
+
+bool InspectableGestureRecognizerChromium::stubEdgeFunction(const PlatformTouchPoint&, GestureRecognizerChromium::Gestures*)
+{
+    return false;
 };
 
 class BuildablePlatformTouchPoint : public WebCore::PlatformTouchPoint {
@@ -126,46 +148,46 @@ public:
     }
 };
 
-class TestGestureRecognizer : public testing::Test {
+class GestureRecognizerTest : public testing::Test {
 public:
-    TestGestureRecognizer() { }
+    GestureRecognizerTest() { }
 
 protected:
     virtual void SetUp() { }
     virtual void TearDown() { }
 };
 
-TEST_F(TestGestureRecognizer, hash)
+TEST_F(GestureRecognizerTest, hash)
 {
-    InspectableInnerGestureRecognizer testGm;
+    InspectableGestureRecognizerChromium testGm;
     const unsigned FirstFinger = 0;
     const unsigned SecondFinger = 1;
 
-    ASSERT_EQ(1 + 0, testGm.signature(InnerGestureRecognizer::NoGesture, FirstFinger, PlatformTouchPoint::TouchReleased, false));
+    ASSERT_EQ(1 + 0, testGm.signature(GestureRecognizerChromium::NoGesture, FirstFinger, PlatformTouchPoint::TouchReleased, false));
 
-    ASSERT_EQ(1 + ((8 | 1) << 1), testGm.signature(InnerGestureRecognizer::NoGesture, FirstFinger, PlatformTouchPoint::TouchPressed, true));
+    ASSERT_EQ(1 + ((8 | 1) << 1), testGm.signature(GestureRecognizerChromium::NoGesture, FirstFinger, PlatformTouchPoint::TouchPressed, true));
 
-    ASSERT_EQ(1 + ((0x10000 | 2) << 1), testGm.signature(InnerGestureRecognizer::PendingSyntheticClick, FirstFinger, PlatformTouchPoint::TouchMoved, false));
+    ASSERT_EQ(1 + ((0x10000 | 2) << 1), testGm.signature(GestureRecognizerChromium::PendingSyntheticClick, FirstFinger, PlatformTouchPoint::TouchMoved, false));
 
-    ASSERT_EQ(1 + (0x20000 << 1), testGm.signature(InnerGestureRecognizer::Scroll, FirstFinger, PlatformTouchPoint::TouchReleased, false));
+    ASSERT_EQ(1 + (0x20000 << 1), testGm.signature(GestureRecognizerChromium::Scroll, FirstFinger, PlatformTouchPoint::TouchReleased, false));
 
-    ASSERT_EQ(1 + ((0x20000 | 1) << 1), testGm.signature(InnerGestureRecognizer::Scroll, FirstFinger, PlatformTouchPoint::TouchPressed, false));
+    ASSERT_EQ(1 + ((0x20000 | 1) << 1), testGm.signature(GestureRecognizerChromium::Scroll, FirstFinger, PlatformTouchPoint::TouchPressed, false));
 
-    ASSERT_EQ(1 + ((0x20000 | 0x10 | 8 | 1) << 1), testGm.signature(InnerGestureRecognizer::Scroll, SecondFinger, PlatformTouchPoint::TouchPressed, true));
+    ASSERT_EQ(1 + ((0x20000 | 0x10 | 8 | 1) << 1), testGm.signature(GestureRecognizerChromium::Scroll, SecondFinger, PlatformTouchPoint::TouchPressed, true));
 }
 
-TEST_F(TestGestureRecognizer, state)
+TEST_F(GestureRecognizerTest, state)
 {
-    InspectableInnerGestureRecognizer testGm;
+    InspectableGestureRecognizerChromium testGm;
 
     ASSERT_EQ(0, testGm.state());
-    testGm.setState(InnerGestureRecognizer::PendingSyntheticClick);
-    ASSERT_EQ(InnerGestureRecognizer::PendingSyntheticClick, testGm.state());
+    testGm.setStateTest(GestureRecognizerChromium::PendingSyntheticClick);
+    ASSERT_EQ(GestureRecognizerChromium::PendingSyntheticClick, testGm.state());
 }
 
-TEST_F(TestGestureRecognizer, isInsideManhattanSquare)
+TEST_F(GestureRecognizerTest, isInsideManhattanSquare)
 {
-    InspectableInnerGestureRecognizer gm;
+    InspectableGestureRecognizerChromium gm;
     BuildablePlatformTouchPoint p;
 
     ASSERT_EQ(0.0, gm.firstTouchPosition().x());
@@ -196,9 +218,9 @@ TEST_F(TestGestureRecognizer, isInsideManhattanSquare)
     ASSERT_FALSE(gm.isInsideManhattanSquare(p));
 }
 
-TEST_F(TestGestureRecognizer, isInClickTimeWindow)
+TEST_F(GestureRecognizerTest, isInClickTimeWindow)
 {
-    InspectableInnerGestureRecognizer gm;
+    InspectableGestureRecognizerChromium gm;
 
     gm.setFirstTouchTime(0.0);
     gm.setLastTouchTime(0.0);
@@ -217,21 +239,21 @@ TEST_F(TestGestureRecognizer, isInClickTimeWindow)
     ASSERT_FALSE(gm.isInClickTimeWindow());
 }
 
-TEST_F(TestGestureRecognizer, addEdgeFunction)
+TEST_F(GestureRecognizerTest, addEdgeFunction)
 {
-    InspectableInnerGestureRecognizer gm;
-    gm.addEdgeFunction(InnerGestureRecognizer::Scroll, 0, PlatformTouchPoint::TouchReleased, true, (InnerGestureRecognizer::GestureTransitionFunction)4096);
+    InspectableGestureRecognizerChromium gm;
+    gm.addEdgeFunction(GestureRecognizerChromium::Scroll, 0, PlatformTouchPoint::TouchReleased, true, (GestureRecognizerChromium::GestureTransitionFunction)&InspectableGestureRecognizerChromium::stubEdgeFunction);
 
-    ASSERT_EQ((InnerGestureRecognizer::GestureTransitionFunction)4096, gm.edgeFunction(gm.signature(InnerGestureRecognizer::Scroll, 0, PlatformTouchPoint::TouchReleased, true)));
+    ASSERT_EQ((GestureRecognizerChromium::GestureTransitionFunction)&InspectableGestureRecognizerChromium::stubEdgeFunction, gm.edgeFunction(gm.signature(GestureRecognizerChromium::Scroll, 0, PlatformTouchPoint::TouchReleased, true)));
 }
 
-TEST_F(TestGestureRecognizer, updateValues)
+TEST_F(GestureRecognizerTest, updateValues)
 {
-    InspectableInnerGestureRecognizer gm;
+    InspectableGestureRecognizerChromium gm;
 
     ASSERT_EQ(0.0, gm.firstTouchTime());
     ASSERT_EQ(0.0, gm.lastTouchTime());
-    ASSERT_EQ(InnerGestureRecognizer::NoGesture, gm.state());
+    ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
 
     BuildablePlatformTouchPoint p1(10, 11);
     gm.updateValues(1.1, p1);
@@ -242,7 +264,7 @@ TEST_F(TestGestureRecognizer, updateValues)
     ASSERT_EQ(0.0, gm.lastTouchTime() - gm.firstTouchTime());
 
     BuildablePlatformTouchPoint p2(13, 14);
-    gm.setState(InnerGestureRecognizer::PendingSyntheticClick);
+    gm.setStateTest(GestureRecognizerChromium::PendingSyntheticClick);
     gm.updateValues(2.0, p2);
 
     ASSERT_EQ(10, gm.firstTouchPosition().x());
@@ -251,7 +273,7 @@ TEST_F(TestGestureRecognizer, updateValues)
     ASSERT_EQ(2.0 - 1.1, gm.lastTouchTime() - gm.firstTouchTime());
 
     BuildablePlatformTouchPoint p3(23, 34);
-    gm.setState(InnerGestureRecognizer::NoGesture);
+    gm.setStateTest(GestureRecognizerChromium::NoGesture);
     gm.updateValues(3.0, p3);
 
     ASSERT_EQ(23, gm.firstTouchPosition().x());
@@ -260,17 +282,17 @@ TEST_F(TestGestureRecognizer, updateValues)
     ASSERT_EQ(0.0, gm.lastTouchTime() - gm.firstTouchTime());
 }
 
-TEST_F(TestGestureRecognizer, gestureScrollEvents)
+TEST_F(GestureRecognizerTest, gestureScrollEvents)
 {
-    InspectableInnerGestureRecognizer gm;
+    InspectableGestureRecognizerChromium gm;
 
-    ASSERT_EQ(InnerGestureRecognizer::NoGesture, gm.state());
+    ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
 
     BuildablePlatformTouchPoint press(10, 15, PlatformTouchPoint::TouchPressed);
     BuildablePlatformTouchEvent pressEvent(WebCore::TouchStart, press);
     gm.processTouchEventForGestures(pressEvent, false);
 
-    ASSERT_EQ(InnerGestureRecognizer::PendingSyntheticClick, gm.state());
+    ASSERT_EQ(GestureRecognizerChromium::PendingSyntheticClick, gm.state());
 
     BuildablePlatformTouchPoint move(10, 50, PlatformTouchPoint::TouchMoved);
     BuildablePlatformTouchEvent moveEvent(WebCore::TouchMove, move);
@@ -291,7 +313,7 @@ TEST_F(TestGestureRecognizer, gestureScrollEvents)
 
     ASSERT_TRUE(scrollStarted);
     ASSERT_TRUE(scrollUpdated);
-    ASSERT_EQ(InnerGestureRecognizer::Scroll, gm.state());
+    ASSERT_EQ(GestureRecognizerChromium::Scroll, gm.state());
 
     BuildablePlatformTouchPoint release(10, 50, PlatformTouchPoint::TouchReleased);
     BuildablePlatformTouchEvent releaseEvent(WebCore::TouchEnd, release);
@@ -307,7 +329,5 @@ TEST_F(TestGestureRecognizer, gestureScrollEvents)
         }
     }
     ASSERT_TRUE(scrollEnd);
-    ASSERT_EQ(InnerGestureRecognizer::NoGesture, gm.state());
+    ASSERT_EQ(GestureRecognizerChromium::NoGesture, gm.state());
 }
-
-} // namespace