Implement Flick.
authorEunmi Lee <eunmi15.lee@samsung.com>
Mon, 27 Aug 2012 08:10:19 +0000 (17:10 +0900)
committerEunmi Lee <eunmi15.lee@samsung.com>
Mon, 27 Aug 2012 08:54:33 +0000 (17:54 +0900)
[Title] Implement Flick.
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] N/A

Change-Id: I4c66477b4c15017f418f8f5f5ca80dad7843d8af

Source/WebKit2/PlatformTizen.cmake
Source/WebKit2/UIProcess/API/efl/GestureClient.cpp
Source/WebKit2/UIProcess/API/efl/GestureClient.h
Source/WebKit2/UIProcess/API/efl/tizen/EasingUtilities.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/efl/tizen/EasingUtilities.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/efl/tizen/Flick.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/efl/tizen/Flick.h [new file with mode: 0644]

index 9a38bf9..e261df1 100755 (executable)
@@ -53,6 +53,8 @@ LIST(APPEND WebKit2_SOURCES
     UIProcess/API/efl/editor/TextSelectionHandle.cpp
     UIProcess/API/efl/editor/TextSelectionMagnifier.cpp
 
+    UIProcess/API/efl/tizen/EasingUtilities.cpp
+    UIProcess/API/efl/tizen/Flick.cpp
     UIProcess/API/efl/tizen/Zoom.cpp
     UIProcess/API/efl/tizen/ewk_popup_picker.cpp
 
index 05035d8..373e788 100755 (executable)
@@ -33,8 +33,9 @@ namespace WebKit {
 
 GestureClient::GestureClient(Evas_Object* viewWidget)
     : m_viewWidget(viewWidget)
+    , m_pan(Pan::create(viewWidget))
+    , m_flick(Flick::create(viewWidget))
 {
-    m_pan = Pan::create(viewWidget);
 }
 
 GestureClient::~GestureClient()
@@ -205,12 +206,12 @@ void GestureClient::movePan(const IntPoint& position)
 
 void GestureClient::startFlick(const IntPoint& position, const IntPoint& velocity)
 {
-    notImplemented();
+    m_flick->start(velocity);
 }
 
 void GestureClient::endFlick(const IntPoint& position, const IntPoint& velocity)
 {
-    notImplemented();
+    m_flick->stop();
 }
 
 void GestureClient::startPinch(const IntPoint& position, double scale)
index dd4fc2c..4414d4c 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef GestureClient_h
 #define GestureClient_h
 
+#include "Flick.h"
 #include "Pan.h"
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
@@ -56,8 +57,9 @@ public:
 private:
     GestureClient(Evas_Object*);
 
-    OwnPtr<Pan> m_pan;
     Evas_Object* m_viewWidget;
+    OwnPtr<Pan> m_pan;
+    OwnPtr<Flick> m_flick;
 };
 
 } // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/API/efl/tizen/EasingUtilities.cpp b/Source/WebKit2/UIProcess/API/efl/tizen/EasingUtilities.cpp
new file mode 100644 (file)
index 0000000..876da22
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2001 Robert Penner All rights reserved.
+ * Copyright (C) 2012 Samsung Electronics
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of contributors may be
+ *    used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Robert Penner's easing equations. http://www.robertpenner.com/easing/
+ * static function easeInOut (t:Number, b:Number, c:Number, d:Number):Number {
+ *     if ((t/=d/2) < 1) return c/2*t*t*t + b;
+ *     return c/2*((t-=2)*t*t + 2) + b;
+ * }
+ */
+float easeInOutCubic(int duration, int index)
+{
+    // If index is bigger than duration, it is error.
+    if (index > duration)
+        return 0;
+
+    // Time is reversed value of index.
+    float time = duration - index;
+    const float constant = 1;
+    float value;
+
+    if ((time /= (duration / 2)) < 1) {
+        value = (constant / 2) * time * time * time;
+    } else {
+        time -= 2;
+        value = (constant / 2) * (time * time * time + 2);
+    }
+
+    return value;
+}
diff --git a/Source/WebKit2/UIProcess/API/efl/tizen/EasingUtilities.h b/Source/WebKit2/UIProcess/API/efl/tizen/EasingUtilities.h
new file mode 100644 (file)
index 0000000..b14aebc
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2001 Robert Penner All rights reserved.
+ * Copyright (C) 2012 Samsung Electronics
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of contributors may be
+ *    used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EasingUtilities_h
+#define EasingUtilities_h
+
+float easeInOutCubic(int duration, int index);
+
+#endif // EasingUtilities_h
diff --git a/Source/WebKit2/UIProcess/API/efl/tizen/Flick.cpp b/Source/WebKit2/UIProcess/API/efl/tizen/Flick.cpp
new file mode 100644 (file)
index 0000000..064d9a8
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "Flick.h"
+
+#include "EasingUtilities.h"
+#include "PageClientImpl.h"
+#include "WKAPICast.h"
+#include "WKPageTizen.h"
+#include "ewk_view_private.h"
+
+using namespace WebCore;
+using namespace WebKit;
+
+#define FLICK_DISTANCE_FACTOR 3 // It's measurement value. The more it's large, the more the total distance is extended.
+
+Flick::Flick(Evas_Object* viewWidget)
+    : m_viewWidget(viewWidget)
+    , m_velocity()
+    , m_flickIndex(0)
+    , m_flickAnimator(0)
+{
+}
+
+Flick::~Flick()
+{
+    stop();
+}
+
+void Flick::start(IntPoint velocity)
+{
+    stop();
+
+    if (!velocity.x() && !velocity.y())
+        return;
+
+    m_velocity = velocity;
+    m_flickIndex = 0;
+    m_flickAnimator = ecore_animator_add(flickAnimatorCallback, this);
+}
+
+void Flick::stop()
+{
+    if (m_flickAnimator) {
+        ecore_animator_del(m_flickAnimator);
+        m_flickAnimator = 0;
+    }
+}
+
+Eina_Bool Flick::flickAnimatorCallback(void* data)
+{
+    return static_cast<Flick*>(data)->process();
+}
+
+bool Flick::process()
+{
+    double frametime = ecore_animator_frametime_get();
+    double valueOfEaseInOutCubic = easeInOutCubic(FLICK_DISTANCE_FACTOR / frametime, m_flickIndex);
+    Evas_Coord deltaX = -1 * m_velocity.x() * frametime * valueOfEaseInOutCubic;
+    Evas_Coord deltaY = -1 * m_velocity.y() * frametime * valueOfEaseInOutCubic;
+
+    m_flickIndex++;
+    PageClientImpl* pageClientImpl = ewkViewGetPageClient(m_viewWidget);
+
+    if (!deltaX && !deltaY) {
+        m_flickAnimator = 0;
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+        pageClientImpl->updateTextSelectionHandlesAndContextMenu(true);
+#endif
+        return false;
+
+    } else {
+        ewkViewSendScrollEvent(m_viewWidget, deltaX, deltaY);
+        IntPoint scrollPosition = pageClientImpl->scrollPosition();
+        WKPageScrollBy(toAPI(pageClientImpl->page()), toAPI(IntSize(deltaX, deltaY)));
+        ewkViewSendEdgeEvent(m_viewWidget, scrollPosition, deltaX, deltaY);
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+        pageClientImpl->updateTextSelectionHandlesAndContextMenu(false);
+#endif
+        return true;
+    }
+}
diff --git a/Source/WebKit2/UIProcess/API/efl/tizen/Flick.h b/Source/WebKit2/UIProcess/API/efl/tizen/Flick.h
new file mode 100644 (file)
index 0000000..d3f8a62
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef Flick_h
+#define Flick_h
+
+#include <Ecore.h>
+#include <Eina.h>
+#include <Evas.h>
+#include <WebCore/IntPoint.h>
+#include <wtf/PassOwnPtr.h>
+
+class Flick {
+public:
+    static PassOwnPtr<Flick> create(Evas_Object* viewWidget)
+    {
+        return adoptPtr(new Flick(viewWidget));
+    }
+    ~Flick();
+
+    void start(WebCore::IntPoint velocity);
+    void stop();
+
+private:
+    static Eina_Bool flickAnimatorCallback(void*);
+
+private:
+    Flick(Evas_Object*);
+    bool process();
+
+    Evas_Object* m_viewWidget;
+    WebCore::IntPoint m_velocity;
+    int m_flickIndex;
+    Ecore_Animator* m_flickAnimator;
+};
+
+#endif // Flick_h