2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FWebCtrl_GestureState.cpp
20 * @brief The file contains the definition of _Web class.
22 * The file contains the definition of _Web class.
26 #include <FBaseSysLog.h>
27 #include <FGrpPoint.h>
28 #include <FUi_CoordinateSystemUtils.h>
29 #include <FUi_Control.h>
30 #include <FUi_UiTouchEvent.h>
31 #include "FWebCtrl_GestureState.h"
32 #include "FWebCtrl_Web.h"
33 #include "FWebCtrl_WebSettingImpl.h"
36 using namespace Tizen::Base;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Ui;
41 namespace Tizen { namespace Web { namespace Controls
45 static const int FLICK_SCROLL_WEIGHT = 3000;
46 static const double PINCH_ZOOM_FINGER_FACTOR = 1.0;
47 static const double PINCH_ZOOM_DISTANCE_TOLERANCE = 40.0;
51 SetGestureEvent(Ewk_Event_Gesture& gestureEvent, Ewk_Gesture_Type gestureType, const Point& absPoint, const Point& velocity, double scale, int count)
53 gestureEvent.type = gestureType;
54 gestureEvent.position.x = absPoint.x;
55 gestureEvent.position.y = absPoint.y;
56 gestureEvent.velocity.x = velocity.x;
57 gestureEvent.velocity.y = velocity.y;
58 gestureEvent.scale = scale;
59 gestureEvent.count = count;
60 gestureEvent.timestamp = ecore_time_get() * 1000;
64 _TapGestureState::_TapGestureState(_Web* pWeb)
66 , __longPressed(false)
67 , __doubleTapped(false)
72 _TapGestureState::~_TapGestureState(void)
78 _TapGestureState::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
80 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
81 SysAssertf(pSmartData, "Failed to get webkit smart data.");
83 Ewk_Event_Gesture gestureEvent;
85 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, Point(0, 0), Point(0, 0), 0.0, 0);
86 pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
95 _TapGestureState::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
97 __doubleTapped = true;
104 _TapGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
106 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
107 SysAssertf(pSmartData, "Failed to get webkit smart data.");
109 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
111 Ewk_Event_Gesture gestureEvent;
113 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 1);
114 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
116 __longPressed = false;
117 __doubleTapped = false;
124 _TapGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
126 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
127 SysAssertf(pSmartData, "Failed to get webkit smart data.");
129 Ewk_Event_Gesture gestureEvent;
131 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
133 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
134 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
136 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PANNING);
143 _TapGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
150 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
151 SysAssertf(pSmartData, "Failed to get webkit smart data.");
153 Ewk_Event_Gesture gestureEvent;
154 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
158 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 2);
159 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
163 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 1);
165 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
172 _TapGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
174 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
175 SysAssertf(pSmartData, "Failed to get webkit smart data.");
177 Ewk_Event_Gesture gestureEvent;
179 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, Point(0, 0), Point(0, 0), 0.0, 0);
180 pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
186 _PanningGestureState::_PanningGestureState(_Web* pWeb)
192 _PanningGestureState::~_PanningGestureState(void)
198 _PanningGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
205 _PanningGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
207 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
208 SysAssertf(pSmartData, "Failed to get webkit smart data.");
210 Ewk_Event_Gesture gestureEvent;
212 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
214 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
215 pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
222 _PanningGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
224 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
225 SysAssertf(pSmartData, "Failed to get webkit smart data.");
227 Ewk_Event_Gesture gestureEvent;
229 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
231 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
232 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
234 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
241 _PanningGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
243 return OnTouchReleased(source, touchInfo);
247 _FlickGestureState::_FlickGestureState(_Web* pWeb)
254 _FlickGestureState::~_FlickGestureState(void)
260 _FlickGestureState::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
262 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_FLICK);
264 int duration = gesture.GetDuration();
265 gesture.GetDistance(__velocity.x, __velocity.y);
267 __velocity.x = (__velocity.x * FLICK_SCROLL_WEIGHT) / duration;
268 __velocity.y = (__velocity.y * FLICK_SCROLL_WEIGHT) / duration;
275 _FlickGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
277 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
278 SysAssertf(pSmartData, "Failed to get webkit smart data.");
280 Ewk_Event_Gesture gestureEvent;
282 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
284 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
285 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
287 SetGestureEvent(gestureEvent, EWK_GESTURE_FLICK, Point(0, 0), Point(0, 0), 0.0, 0);
288 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
290 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
297 _FlickGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
304 _FlickGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
306 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
307 SysAssertf(pSmartData, "Failed to get webkit smart data.");
309 Ewk_Event_Gesture gestureEvent;
311 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
313 SetGestureEvent(gestureEvent, EWK_GESTURE_FLICK, absPoint, __velocity, 0, 0);
314 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
321 _FlickGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
323 return OnTouchPressed(source, touchInfo);
327 _PinchGestureState::_PinchGestureState(_Web* pWeb)
329 , __standardScale(0.0)
334 _PinchGestureState::~_PinchGestureState(void)
340 _PinchGestureState::OnPinchGestureStarted(_TouchPinchGestureDetector& gesture)
342 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PINCH);
344 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
345 SysAssertf(pSmartData, "Failed to get webkit smart data.");
347 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
348 __standardScale = static_cast< double >(gesture.GetScaleF());
350 Ewk_Event_Gesture gestureEvent;
352 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), 1.0, 0);
353 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
360 _PinchGestureState::OnPinchGestureChanged(_TouchPinchGestureDetector& gesture)
362 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
363 SysAssertf(pSmartData, "Failed to get webkit smart data.");
365 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
366 double relScale = static_cast< double >(gesture.GetScaleF()) /__standardScale;
368 Ewk_Event_Gesture gestureEvent;
370 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), relScale, 0);
371 pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
378 _PinchGestureState::OnPinchGestureFinished(_TouchPinchGestureDetector& gesture)
380 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
381 SysAssertf(pSmartData, "Failed to get webkit smart data.");
383 Ewk_Event_Gesture gestureEvent;
385 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
386 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
388 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
395 _PinchGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
402 _PinchGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
409 _PinchGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
416 _PinchGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
418 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
419 SysAssertf(pSmartData, "Failed to get webkit smart data.");
421 Ewk_Event_Gesture gestureEvent;
423 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
424 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
426 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);