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_TouchManager.h>
31 #include <FUi_UiTouchEvent.h>
32 #include "FWebCtrl_GestureState.h"
33 #include "FWebCtrl_Web.h"
34 #include "FWebCtrl_WebImpl.h"
35 #include "FWebCtrl_WebSettingImpl.h"
38 using namespace Tizen::Base;
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Ui;
41 using namespace Tizen::Web::Controls;
44 namespace Tizen { namespace Web { namespace Controls
48 static const int FLICK_SCROLL_WEIGHT = 3000;
49 static const double PINCH_ZOOM_FINGER_FACTOR = 1.0;
50 static const double PINCH_ZOOM_DISTANCE_TOLERANCE = 40.0;
54 SetGestureEvent(Ewk_Event_Gesture& gestureEvent, Ewk_Gesture_Type gestureType, const Point& absPoint, const Point& velocity, double scale, int count)
56 gestureEvent.type = gestureType;
57 gestureEvent.position.x = absPoint.x;
58 gestureEvent.position.y = absPoint.y;
59 gestureEvent.velocity.x = velocity.x;
60 gestureEvent.velocity.y = velocity.y;
61 gestureEvent.scale = scale;
62 gestureEvent.count = count;
63 gestureEvent.timestamp = ecore_time_get() * 1000;
67 _TapGestureState::_TapGestureState(_Web* pWeb)
69 , __longPressed(false)
70 , __doubleTapped(false)
71 , __pressedPosition(0.0f, 0.0f)
76 _TapGestureState::~_TapGestureState(void)
82 _TapGestureState::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
84 //To disable focus ring
85 Ewk_Event_Gesture gestureEvent;
87 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, Point(0, 0), Point(0, 0), 0.0, 0);
89 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
90 SysAssertf(pSmartData, "Failed to get webkit smart data.");
91 pSmartData->api->gesture_move(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
94 _TouchManager* pTouchManager = _TouchManager::GetInstance();
95 SysAssertf(pTouchManager, "Failed to get touch manager.");
97 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(pTouchManager->GetPosition(pTouchManager->GetCurrentPointId())));
99 Ewk_Touch_Point* pPoint = static_cast< Ewk_Touch_Point* >(calloc(1, sizeof(Ewk_Touch_Point)));
101 pPoint->x = absPoint.x;
102 pPoint->y = absPoint.y;
103 pPoint->state = EVAS_TOUCH_POINT_UP;
105 Eina_List* pPointList = null;
106 pPointList = eina_list_append(pPointList, pPoint);
108 ewk_view_feed_touch_event(__pWebCore->GetWebNativeNode(), EWK_TOUCH_END, pPointList, null);
111 EINA_LIST_FREE(pPointList, pData)
114 __longPressed = true;
121 _TapGestureState::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
123 __doubleTapped = true;
130 _TapGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
132 Ewk_Event_Gesture gestureEvent;
133 __pressedPosition = touchInfo.GetCurrentPosition();
134 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(__pressedPosition)));
136 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 1);
138 const Ewk_View_Smart_Data* pSmartData = static_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
139 SysAssertf(pSmartData, "Failed to get webkit smart data.");
140 pSmartData->api->gesture_start(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
142 __longPressed = false;
143 __doubleTapped = false;
150 _TapGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
152 Ewk_Event_Gesture gestureEvent;
153 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
155 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
157 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
158 SysAssertf(pSmartData, "Failed to get webkit smart data.");
159 pSmartData->api->gesture_start(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
161 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PANNING);
168 _TapGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
170 if (__pWebCore->Contains(__pressedPosition))
172 Evas_Object* pView = __pWebCore->GetWebNativeNode();
173 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(__pressedPosition)));
177 Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(pView, absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
178 SysTryReturn(NID_WEB_CTRL, pEwkHitTest, true, E_SYSTEM, "Failed to get hit test.");
180 String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
182 Eina_Hash* pAttrHash = ewk_hit_test_attribute_hash_get(pEwkHitTest);
183 char* pValue = reinterpret_cast< char* >(eina_hash_find(pAttrHash, "contenteditable"));
184 if (tagName.Equals(L"INPUT", false) || tagName.Equals(L"TEXTAREA", false) || pValue)
186 Eina_Rectangle leftHandle;
187 Eina_Rectangle rightHandle;
189 ewk_view_text_selection_range_get(pView, &leftHandle, &rightHandle);
190 if (((rightHandle.x + rightHandle.w) == 0) && ((rightHandle.y + rightHandle.h) == 0))
192 Ewk_Event_Gesture gestureEvent;
194 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, absPoint, Point(0, 0), 0.0, 1);
196 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
197 SysAssertf(pSmartData, "Failed to get webkit smart data.");
198 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
204 Ewk_Event_Gesture gestureEvent;
211 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, touchCount);
213 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
214 SysAssertf(pSmartData, "Failed to get webkit smart data.");
215 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
218 String selectedText(ewk_view_text_selection_text_get(pView));
219 if (selectedText.GetLength() > 0)
221 evas_object_smart_callback_call(pView, "text,selected", NULL);
226 OnTouchCanceled(source, touchInfo);
234 _TapGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
236 Ewk_Event_Gesture gestureEvent;
238 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, Point(0, 0), Point(0, 0), 0.0, 0);
240 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
241 SysAssertf(pSmartData, "Failed to get webkit smart data.");
242 pSmartData->api->gesture_move(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
248 _PanningGestureState::_PanningGestureState(_Web* pWeb)
250 , __textSelected(false)
251 , __textChanged(false)
252 , __selectedText(L"")
257 _PanningGestureState::~_PanningGestureState(void)
263 _PanningGestureState::InitializeTextSelectionStatus(void)
265 __selectedText = String(ewk_view_text_selection_text_get(__pWebCore->GetWebNativeNode()));
266 if (__selectedText.GetLength() > 0)
268 __textSelected = true;
272 __textSelected = false;
274 __textChanged = false;
279 _PanningGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
286 _PanningGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
288 Evas_Object* pView = __pWebCore->GetWebNativeNode();
289 if (_WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled())
291 Ewk_Event_Gesture gestureEvent;
292 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
294 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
296 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(pView));
297 SysAssertf(pSmartData, "Failed to get webkit smart data.");
298 pSmartData->api->gesture_move(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
301 if (__textSelected && !__textChanged)
303 if (!__selectedText.Equals(String(ewk_view_text_selection_text_get(pView))))
305 __textChanged = true;
314 _PanningGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
316 Ewk_Event_Gesture gestureEvent;
317 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
319 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
321 Evas_Object* pView = __pWebCore->GetWebNativeNode();
322 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(pView));
323 SysAssertf(pSmartData, "Failed to get webkit smart data.");
324 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
328 evas_object_smart_callback_call(pView, "text,selected", NULL);
331 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
338 _PanningGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
340 return OnTouchReleased(source, touchInfo);
344 _FlickGestureState::_FlickGestureState(_Web* pWeb)
351 _FlickGestureState::~_FlickGestureState(void)
357 _FlickGestureState::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
359 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_FLICK);
361 int duration = gesture.GetDuration();
362 gesture.GetDistance(__velocity.x, __velocity.y);
364 __velocity.x = (__velocity.x * FLICK_SCROLL_WEIGHT) / duration;
365 __velocity.y = (__velocity.y * FLICK_SCROLL_WEIGHT) / duration;
372 _FlickGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
379 _FlickGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
386 _FlickGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
388 Ewk_Event_Gesture gestureEvent;
389 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
391 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
393 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
394 SysAssertf(pSmartData, "Failed to get webkit smart data.");
395 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
397 SetGestureEvent(gestureEvent, EWK_GESTURE_FLICK, absPoint, __velocity, 0.0, 0);
399 pSmartData->api->gesture_start(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
401 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
408 _FlickGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
410 return OnTouchPressed(source, touchInfo);
414 _PinchGestureState::_PinchGestureState(_Web* pWeb)
416 , __standardScale(0.0)
421 _PinchGestureState::~_PinchGestureState(void)
427 _PinchGestureState::OnPinchGestureStarted(_TouchPinchGestureDetector& gesture)
429 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PINCH);
431 Ewk_Event_Gesture gestureEvent;
432 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
433 __standardScale = static_cast< double >(gesture.GetScaleF());
435 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), 1.0, 0);
437 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
438 SysAssertf(pSmartData, "Failed to get webkit smart data.");
439 pSmartData->api->gesture_start(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
446 _PinchGestureState::OnPinchGestureChanged(_TouchPinchGestureDetector& gesture)
448 Ewk_Event_Gesture gestureEvent;
449 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
450 double relScale = static_cast< double >(gesture.GetScaleF()) /__standardScale;
452 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), relScale, 0);
454 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
455 SysAssertf(pSmartData, "Failed to get webkit smart data.");
456 pSmartData->api->gesture_move(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
463 _PinchGestureState::OnPinchGestureFinished(_TouchPinchGestureDetector& gesture)
465 Ewk_Event_Gesture gestureEvent;
467 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
469 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
470 SysAssertf(pSmartData, "Failed to get webkit smart data.");
471 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
478 _PinchGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
485 _PinchGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
492 _PinchGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
494 _TouchManager* pTouchManager = _TouchManager::GetInstance();
495 SysAssertf(pTouchManager, "Failed to get touch manager.");
496 if(pTouchManager->GetPointCount() == 0)
498 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
506 _PinchGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
508 Ewk_Event_Gesture gestureEvent;
510 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
512 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
513 SysAssertf(pSmartData, "Failed to get webkit smart data.");
514 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
516 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);