Add support for pinch gesture processing in the MT compositor.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Feb 2012 21:12:58 +0000 (21:12 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Feb 2012 21:12:58 +0000 (21:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77804

Patch by Sadrul Habib Chowdhury <sadrul@chromium.org> on 2012-02-08
Reviewed by James Robinson.

* public/WebInputEvent.h:
* src/WebCompositorInputHandlerImpl.cpp:
(WebKit::WebCompositorInputHandlerImpl::WebCompositorInputHandlerImpl):
(WebKit::WebCompositorInputHandlerImpl::handleInputEvent):
* src/WebCompositorInputHandlerImpl.h:
(WebCompositorInputHandlerImpl):
* src/WebInputEventConversion.cpp:
(WebKit::PlatformGestureEventBuilder::PlatformGestureEventBuilder):
* src/WebPopupMenuImpl.cpp:
(WebKit::WebPopupMenuImpl::handleInputEvent):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::handleInputEvent):
* tests/WebCompositorInputHandlerImplTest.cpp:

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

Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebInputEvent.h
Source/WebKit/chromium/src/WebCompositorInputHandlerImpl.cpp
Source/WebKit/chromium/src/WebCompositorInputHandlerImpl.h
Source/WebKit/chromium/src/WebInputEventConversion.cpp
Source/WebKit/chromium/src/WebPopupMenuImpl.cpp
Source/WebKit/chromium/src/WebViewImpl.cpp
Source/WebKit/chromium/tests/WebCompositorInputHandlerImplTest.cpp

index 0a7d28d..bf2acbc 100644 (file)
@@ -1,3 +1,24 @@
+2012-02-08  Sadrul Habib Chowdhury  <sadrul@chromium.org>
+
+        Add support for pinch gesture processing in the MT compositor.
+        https://bugs.webkit.org/show_bug.cgi?id=77804
+
+        Reviewed by James Robinson.
+
+        * public/WebInputEvent.h:
+        * src/WebCompositorInputHandlerImpl.cpp:
+        (WebKit::WebCompositorInputHandlerImpl::WebCompositorInputHandlerImpl):
+        (WebKit::WebCompositorInputHandlerImpl::handleInputEvent):
+        * src/WebCompositorInputHandlerImpl.h:
+        (WebCompositorInputHandlerImpl):
+        * src/WebInputEventConversion.cpp:
+        (WebKit::PlatformGestureEventBuilder::PlatformGestureEventBuilder):
+        * src/WebPopupMenuImpl.cpp:
+        (WebKit::WebPopupMenuImpl::handleInputEvent):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::handleInputEvent):
+        * tests/WebCompositorInputHandlerImplTest.cpp:
+
 2012-02-08  Nico Weber  <nicolasweber@gmx.de>
 
         [chromium] Make dependency on Accelerate.framework explicit.
index 57b1f4b..e42e451 100644 (file)
@@ -109,6 +109,9 @@ public:
         GestureTap,
         GestureTapDown,
         GestureDoubleTap,
+        GesturePinchBegin,
+        GesturePinchEnd,
+        GesturePinchUpdate,
 
         // WebTouchEvent
         TouchStart,
@@ -351,6 +354,8 @@ public:
     int y;
     int globalX;
     int globalY;
+
+    // NOTE: |deltaX| and |deltaY| represents the amount to scroll for Scroll gesture events. For Pinch gesture events, |deltaX| represents the scaling/magnification factor.
     float deltaX;
     float deltaY;
 
index 367bc3e..40c151d 100644 (file)
@@ -83,6 +83,7 @@ WebCompositorInputHandlerImpl::WebCompositorInputHandlerImpl(CCInputHandlerClien
     , m_inputHandlerClient(inputHandlerClient)
 #ifndef NDEBUG
     , m_expectScrollUpdateEnd(false)
+    , m_expectPinchUpdateEnd(false)
 #endif
     , m_scrollStarted(false)
 {
@@ -173,6 +174,28 @@ void WebCompositorInputHandlerImpl::handleInputEvent(const WebInputEvent& event)
             m_scrollStarted = false;
             return;
         }
+    } else if (event.type == WebInputEvent::GesturePinchBegin) {
+        ASSERT(!m_expectPinchUpdateEnd);
+#ifndef NDEBUG
+        m_expectPinchUpdateEnd = true;
+#endif
+        m_inputHandlerClient->pinchGestureBegin();
+        m_client->didHandleInputEvent();
+        return;
+    } else if (event.type == WebInputEvent::GesturePinchEnd) {
+        ASSERT(m_expectPinchUpdateEnd);
+#ifndef NDEBUG
+        m_expectPinchUpdateEnd = false;
+#endif
+        m_inputHandlerClient->pinchGestureEnd();
+        m_client->didHandleInputEvent();
+        return;
+    } else if (event.type == WebInputEvent::GesturePinchUpdate) {
+        ASSERT(m_expectPinchUpdateEnd);
+        const WebGestureEvent& gestureEvent = *static_cast<const WebGestureEvent*>(&event);
+        m_inputHandlerClient->pinchGestureUpdate(gestureEvent.deltaX, IntPoint(gestureEvent.x, gestureEvent.y));
+        m_client->didHandleInputEvent();
+        return;
     }
     m_client->didNotHandleInputEvent(true /* sendToWidget */);
 }
index 7a63268..a2f1302 100644 (file)
@@ -72,6 +72,7 @@ private:
 
 #ifndef NDEBUG
     bool m_expectScrollUpdateEnd;
+    bool m_expectPinchUpdateEnd;
 #endif
     bool m_scrollStarted;
 
index ddd4736..64ba311 100644 (file)
@@ -155,6 +155,11 @@ PlatformGestureEventBuilder::PlatformGestureEventBuilder(Widget* widget, const W
     case WebInputEvent::GestureDoubleTap:
         m_type = PlatformEvent::GestureDoubleTap;
         break;
+    case WebInputEvent::GesturePinchBegin:
+    case WebInputEvent::GesturePinchEnd:
+    case WebInputEvent::GesturePinchUpdate:
+        // FIXME: Once PlatformGestureEvent is updated to support pinch, this should set m_type to appropriate PlatformEvent type.
+        ASSERT_NOT_REACHED();
     default:
         ASSERT_NOT_REACHED();
     }
index 03f31d8..3f328f5 100644 (file)
@@ -275,6 +275,12 @@ bool WebPopupMenuImpl::handleInputEvent(const WebInputEvent& inputEvent)
     case WebInputEvent::MouseEnter:
     case WebInputEvent::ContextMenu:
         return false;
+
+    case WebInputEvent::GesturePinchBegin:
+    case WebInputEvent::GesturePinchEnd:
+    case WebInputEvent::GesturePinchUpdate:
+        // FIXME: Once PlatformGestureEvent is updated to support pinch, this should call handleGestureEvent, just like it currently does for gesture scroll.
+        return false;
     }
     return false;
 }
index 8269a1d..a05e989 100644 (file)
@@ -1416,6 +1416,15 @@ bool WebViewImpl::handleInputEvent(const WebInputEvent& inputEvent)
         break;
 #endif
 
+#if ENABLE(GESTURE_EVENTS)
+    case WebInputEvent::GesturePinchBegin:
+    case WebInputEvent::GesturePinchEnd:
+    case WebInputEvent::GesturePinchUpdate:
+        // FIXME: Once PlatformGestureEvent is updated to support pinch, this should call handleGestureEvent, just like it currently does for gesture scroll.
+        handled = false;
+        break;
+#endif
+
     default:
         handled = false;
     }
index cc8359f..9df969e 100644 (file)
@@ -46,12 +46,25 @@ class MockInputHandlerClient : public WebCore::CCInputHandlerClient {
 public:
     MockInputHandlerClient()
         : m_scrollStatus(ScrollStarted)
+        , m_pinchStarted(false)
+        , m_pinchEnded(false)
+        , m_pinchMagnification(0)
     {
     }
     virtual ~MockInputHandlerClient() { }
 
     void setScrollStatus(ScrollStatus status) { m_scrollStatus = status; }
 
+    bool pinchStarted() const { return m_pinchStarted; }
+    bool pinchEnded() const { return m_pinchEnded; }
+    float pinchMaginifcation() const { return m_pinchMagnification; }
+
+    void resetPinch()
+    {
+        m_pinchStarted = m_pinchStarted = false;
+        m_pinchMagnification = 0;
+    }
+
 private:
     virtual void setNeedsRedraw() OVERRIDE { }
     virtual ScrollStatus scrollBegin(const WebCore::IntPoint&) OVERRIDE
@@ -62,9 +75,18 @@ private:
     virtual void scrollEnd() OVERRIDE { }
 
     virtual bool haveWheelEventHandlers() OVERRIDE { return false; }
-    virtual void pinchGestureBegin() OVERRIDE { }
-    virtual void pinchGestureUpdate(float magnifyDelta, const WebCore::IntPoint& anchor) OVERRIDE { }
-    virtual void pinchGestureEnd() OVERRIDE { }
+    virtual void pinchGestureBegin() OVERRIDE
+    {
+        m_pinchStarted = true;
+    }
+    virtual void pinchGestureUpdate(float magnifyDelta, const WebCore::IntPoint& anchor) OVERRIDE
+    {
+        m_pinchMagnification = magnifyDelta;
+    }
+    virtual void pinchGestureEnd() OVERRIDE
+    {
+        m_pinchEnded = true;
+    }
     virtual void startPageScaleAnimation(const WebCore::IntSize& targetPosition,
                                          bool anchorPoint,
                                          float pageScale,
@@ -72,6 +94,9 @@ private:
                                          double durationMs) OVERRIDE { }
 
     ScrollStatus m_scrollStatus;
+    bool m_pinchStarted;
+    bool m_pinchEnded;
+    float m_pinchMagnification;
 };
 
 class MockWebCompositorInputHandlerClient : public WebKit::WebCompositorInputHandlerClient {
@@ -200,4 +225,60 @@ TEST(WebCompositorInputHandlerImpl, gestureScroll)
     WebKit::WebCompositor::shutdown();
 }
 
+TEST(WebCompositorInputHandlerImpl, gesturePinch)
+{
+    WebKit::WebCompositor::initialize(0);
+#ifndef NDEBUG
+    // WebCompositorInputHandler APIs can only be called from the compositor thread.
+    WebCore::DebugScopedSetImplThread alwaysImplThread;
+#endif
+
+    MockInputHandlerClient mockInputHandler;
+    OwnPtr<WebCompositorInputHandlerImpl> inputHandler = WebCompositorInputHandlerImpl::create(&mockInputHandler);
+    MockWebCompositorInputHandlerClient mockClient;
+    inputHandler->setClient(&mockClient);
+
+    WebKit::WebGestureEvent gesture;
+
+    gesture.type = WebKit::WebInputEvent::GesturePinchBegin;
+    inputHandler->handleInputEvent(gesture);
+    EXPECT_TRUE(mockClient.handled());
+    EXPECT_FALSE(mockClient.sendToWidget());
+    EXPECT_TRUE(mockInputHandler.pinchStarted());
+    mockClient.reset();
+    mockInputHandler.resetPinch();
+
+    gesture.type = WebKit::WebInputEvent::GesturePinchUpdate;
+    gesture.deltaX = 1.5;
+    inputHandler->handleInputEvent(gesture);
+    EXPECT_TRUE(mockClient.handled());
+    EXPECT_FALSE(mockClient.sendToWidget());
+    EXPECT_FALSE(mockInputHandler.pinchEnded());
+    EXPECT_EQ(1.5, mockInputHandler.pinchMaginifcation());
+    mockClient.reset();
+    mockInputHandler.resetPinch();
+
+    gesture.type = WebKit::WebInputEvent::GesturePinchUpdate;
+    gesture.deltaX = 0.5;
+    inputHandler->handleInputEvent(gesture);
+    EXPECT_TRUE(mockClient.handled());
+    EXPECT_FALSE(mockClient.sendToWidget());
+    EXPECT_FALSE(mockInputHandler.pinchEnded());
+    EXPECT_EQ(0.5, mockInputHandler.pinchMaginifcation());
+    mockClient.reset();
+    mockInputHandler.resetPinch();
+
+    gesture.type = WebKit::WebInputEvent::GesturePinchEnd;
+    inputHandler->handleInputEvent(gesture);
+    EXPECT_TRUE(mockClient.handled());
+    EXPECT_FALSE(mockClient.sendToWidget());
+    EXPECT_TRUE(mockInputHandler.pinchEnded());
+    mockClient.reset();
+    mockInputHandler.resetPinch();
+
+    inputHandler->setClient(0);
+
+    WebKit::WebCompositor::shutdown();
+}
+
 }