2 * Copyright (C) 2012 Samsung Electronics
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 #include "EasingUtilities.h"
24 #include "PageClientImpl.h"
25 #include "WKAPICast.h"
26 #include "WKPageTizen.h"
27 #include "ewk_view_private.h"
29 using namespace WebCore;
30 using namespace WebKit;
32 Flick::Flick(Evas_Object* viewWidget)
33 : m_viewWidget(viewWidget)
45 void Flick::start(IntPoint velocity)
49 if (!velocity.x() && !velocity.y())
52 m_velocity = velocity;
54 m_flickDuration = 1 / ecore_animator_frametime_get();
55 m_flickAnimator = ecore_animator_add(flickAnimatorCallback, this);
56 m_remainder = IntPoint();
61 if (m_flickAnimator) {
62 ecore_animator_del(m_flickAnimator);
67 Eina_Bool Flick::flickAnimatorCallback(void* data)
69 return static_cast<Flick*>(data)->process();
74 double valueOfEaseInOutCubic = easeInOutQuad(m_flickDuration, m_flickIndex);
75 double decimalDeltaX = -1 * m_velocity.x() / m_flickDuration * valueOfEaseInOutCubic + m_remainder.x();
76 double decimalDeltaY = -1 * m_velocity.y() / m_flickDuration * valueOfEaseInOutCubic + m_remainder.y();
77 int deltaX = static_cast<int>(decimalDeltaX);
78 int deltaY = static_cast<int>(decimalDeltaY);
80 m_remainder.setX(decimalDeltaX - deltaX);
81 if (m_remainder.x() >= 0.5) {
83 m_remainder.setX(m_remainder.x() - 0.5);
84 } else if (m_remainder.x() <= -0.5) {
86 m_remainder.setX(m_remainder.x() + 0.5);
89 m_remainder.setY(decimalDeltaY - deltaY);
90 if (m_remainder.y() >= 0.5) {
92 m_remainder.setY(m_remainder.y() - 0.5);
93 } else if (m_remainder.y() <= -0.5) {
95 m_remainder.setY(m_remainder.y() + 0.5);
100 if (m_flickIndex > m_flickDuration) {
102 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
103 PageClientImpl* pageClientImpl = ewkViewGetPageClient(m_viewWidget);
104 EINA_SAFETY_ON_NULL_RETURN_VAL(pageClientImpl, false);
105 pageClientImpl->updateTextSelectionHandlesAndContextMenu(true);
110 if (!deltaX && !deltaY)
113 PageClientImpl* pageClientImpl = ewkViewGetPageClient(m_viewWidget);
114 EINA_SAFETY_ON_NULL_RETURN_VAL(pageClientImpl, true);
115 ewkViewSendScrollEvent(m_viewWidget, deltaX, deltaY);
116 IntPoint scrollPosition = pageClientImpl->scrollPosition();
117 WKPageScrollBy(toAPI(pageClientImpl->page()), toAPI(IntSize(deltaX, deltaY)));
118 ewkViewSendEdgeEvent(m_viewWidget, scrollPosition, deltaX, deltaY);
119 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
120 pageClientImpl->updateTextSelectionHandlesAndContextMenu(false);
123 // Stop flick if we reach the end of contents.
128 ewk_view_scroll_pos_get(m_viewWidget, &scrollX, &scrollY);
129 ewk_view_scroll_size_get(m_viewWidget, &scrollWidth, &scrollHeight);
130 if ((!deltaX || (deltaX < 0 && scrollX == 0) || (deltaX > 0 && scrollX >= scrollWidth))
131 && (!deltaY || (deltaY < 0 && scrollY == 0) || (deltaY > 0 && scrollY >= scrollHeight))) {
132 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
133 // Enable flick in the overflow scroll area even if we reach the end of contents
134 if (pageClientImpl->drawingArea()
135 && pageClientImpl->drawingArea()->layerTreeCoordinatorProxy()
136 && pageClientImpl->drawingArea()->layerTreeCoordinatorProxy()->hasOverflowLayer())