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 library 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 library; 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 "EwkViewImpl.h"
24 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
25 #include "LayerTreeCoordinatorProxy.h"
27 #include "PageClientImpl.h"
28 #include "WKAPICast.h"
29 #include "WKPageTizen.h"
30 #include "ewk_view_private.h"
32 using namespace WebCore;
33 using namespace WebKit;
35 Pan::Pan(Evas_Object* ewkView)
40 #if ENABLE(TIZEN_GESTURE_FEATURE)
41 , m_smoothAlgorithm(SmoothAlgorithm::create())
44 m_viewImpl = EwkViewImpl::fromEvasObject(m_ewkView);
45 #if ENABLE(TIZEN_GESTURE_FEATURE)
46 evas_object_event_callback_add(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, onMouseDown, this);
47 evas_object_event_callback_add(m_ewkView, EVAS_CALLBACK_MOUSE_MOVE, onMouseMove, this);
54 ecore_animator_del(m_panAnimator);
55 #if ENABLE(TIZEN_GESTURE_FEATURE)
56 evas_object_event_callback_del(m_ewkView, EVAS_CALLBACK_MOUSE_DOWN, onMouseDown);
57 evas_object_event_callback_del(m_ewkView, EVAS_CALLBACK_MOUSE_MOVE, onMouseMove);
61 void Pan::start(const IntPoint& point)
66 PageClientImpl* pageClientImpl = ewkViewGetPageClient(m_ewkView);
67 EINA_SAFETY_ON_NULL_RETURN(pageClientImpl);
69 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
70 pageClientImpl->findScrollableNode(point);
73 ewkViewClearEdges(pageClientImpl->viewWidget());
74 // Below statement means the update() was not called before start().
75 if (m_lastPoint == IntPoint::zero())
77 m_currentPoint = point;
79 #if ENABLE(TIZEN_GESTURE_FEATURE)
80 m_smoothAlgorithm->initialize();
82 // Process pan directly when Pan is started for situation that Pan is delayed by TouchEvent.
84 m_panAnimator = ecore_animator_add(panAnimatorCallback, this);
87 void Pan::update(const IntPoint& point)
90 m_lastPoint = m_currentPoint;
91 m_currentPoint = point;
97 ecore_animator_del(m_panAnimator);
100 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
101 PageClientImpl* pageClientImpl = ewkViewGetPageClient(m_ewkView);
102 EINA_SAFETY_ON_NULL_RETURN(pageClientImpl);
103 pageClientImpl->updateTextSelectionHandlesAndContextMenu(true);
106 m_lastPoint = m_currentPoint = IntPoint::zero();
109 Eina_Bool Pan::panAnimatorCallback(void* data)
111 static_cast<Pan*>(data)->process();
112 return ECORE_CALLBACK_RENEW;
117 #if ENABLE(TIZEN_GESTURE_FEATURE)
118 m_smoothAlgorithm->correctPoint(m_currentPoint);
120 int deltaX = m_lastPoint.x() - m_currentPoint.x();
121 int deltaY = m_lastPoint.y() - m_currentPoint.y();
123 PageClientImpl* pageClientImpl = ewkViewGetPageClient(m_ewkView);
124 EINA_SAFETY_ON_NULL_RETURN(pageClientImpl);
126 if (!deltaX && !deltaY)
129 ewkViewSendScrollEvent(m_ewkView, deltaX, deltaY);
130 if (ewk_view_horizontal_panning_hold_get(m_ewkView))
132 if (ewk_view_vertical_panning_hold_get(m_ewkView))
135 // Get scrollPosition before scrolling.
136 IntPoint scrollPosition = pageClientImpl->scrollPosition();
137 if (WKPageScrollBy(toAPI(pageClientImpl->page()), toAPI(IntSize(deltaX, deltaY))))
138 ewkViewSendEdgeEvent(pageClientImpl->viewWidget(), scrollPosition, deltaX, deltaY);
139 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
140 pageClientImpl->updateTextSelectionHandlesAndContextMenu(false, true);
142 m_lastPoint = m_currentPoint;
145 #if ENABLE(TIZEN_GESTURE_FEATURE)
146 void Pan::onMouseDown(void* data, Evas*, Evas_Object*, void* eventInfo)
148 static_cast<Pan*>(data)->mouseDown(static_cast<Evas_Event_Mouse_Down*>(eventInfo));
151 void Pan::mouseDown(Evas_Event_Mouse_Down* event)
153 m_smoothAlgorithm->setEventPropagationTime(ecore_loop_time_get() - event->timestamp / 1000.0);
156 void Pan::onMouseMove(void* data, Evas*, Evas_Object*, void* eventInfo)
158 static_cast<Pan*>(data)->mouseMove(static_cast<Evas_Event_Mouse_Move*>(eventInfo));
161 void Pan::mouseMove(Evas_Event_Mouse_Move* event)
164 m_smoothAlgorithm->storeDataToHistory(event->cur.canvas.x, event->cur.canvas.y, event->timestamp / 1000.0);