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);
100 _TapGestureState::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
102 __doubleTapped = true;
109 _TapGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
111 Ewk_Event_Gesture gestureEvent;
112 __pressedPosition = touchInfo.GetCurrentPosition();
113 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(__pressedPosition)));
115 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 1);
117 const Ewk_View_Smart_Data* pSmartData = static_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
118 SysAssertf(pSmartData, "Failed to get webkit smart data.");
119 pSmartData->api->gesture_start(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
121 __longPressed = false;
122 __doubleTapped = false;
129 _TapGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
131 Ewk_Event_Gesture gestureEvent;
132 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
134 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
136 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
137 SysAssertf(pSmartData, "Failed to get webkit smart data.");
138 pSmartData->api->gesture_start(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
140 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PANNING);
142 if (!_WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled())
152 _TapGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
154 if (!__pWebCore->Contains(__pressedPosition))
156 return OnTouchCanceled(source, touchInfo);
159 Evas_Object* pView = __pWebCore->GetWebNativeNode();
160 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(__pressedPosition)));
164 Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(pView, absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
165 SysTryReturn(NID_WEB_CTRL, pEwkHitTest, true, E_SYSTEM, "Failed to get hit test.");
167 String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
169 Eina_Hash* pAttrHash = ewk_hit_test_attribute_hash_get(pEwkHitTest);
170 char* pValue = reinterpret_cast< char* >(eina_hash_find(pAttrHash, "contenteditable"));
171 if (tagName.Equals(L"INPUT", false) || tagName.Equals(L"TEXTAREA", false) || pValue)
173 Eina_Rectangle leftHandle;
174 Eina_Rectangle rightHandle;
176 ewk_view_text_selection_range_get(pView, &leftHandle, &rightHandle);
177 if (((rightHandle.x + rightHandle.w) == 0) && ((rightHandle.y + rightHandle.h) == 0))
179 Ewk_Event_Gesture gestureEvent;
181 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, absPoint, Point(0, 0), 0.0, 1);
183 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(pView));
184 SysAssertf(pSmartData, "Failed to get webkit smart data.");
185 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
191 Ewk_Event_Gesture gestureEvent;
198 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, touchCount);
200 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(pView));
201 SysAssertf(pSmartData, "Failed to get webkit smart data.");
202 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
210 _TapGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
212 Ewk_Event_Gesture gestureEvent;
214 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, Point(0, 0), Point(0, 0), 0.0, 0);
216 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
217 SysAssertf(pSmartData, "Failed to get webkit smart data.");
218 pSmartData->api->gesture_move(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
224 _PanningGestureState::_PanningGestureState(_Web* pWeb)
230 _PanningGestureState::~_PanningGestureState(void)
236 _PanningGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
243 _PanningGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
245 if (!_WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled())
250 Ewk_Event_Gesture gestureEvent;
251 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
253 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
255 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
256 SysAssertf(pSmartData, "Failed to get webkit smart data.");
257 pSmartData->api->gesture_move(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
264 _PanningGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
266 Ewk_Event_Gesture gestureEvent;
267 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
269 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
271 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
272 SysAssertf(pSmartData, "Failed to get webkit smart data.");
273 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
275 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
282 _PanningGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
284 return OnTouchReleased(source, touchInfo);
288 _FlickGestureState::_FlickGestureState(_Web* pWeb)
295 _FlickGestureState::~_FlickGestureState(void)
301 _FlickGestureState::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
303 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_FLICK);
305 if (_WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled())
307 int duration = gesture.GetDuration();
308 gesture.GetDistance(__velocity.x, __velocity.y);
310 __velocity.x = (__velocity.x * FLICK_SCROLL_WEIGHT) / duration;
311 __velocity.y = (__velocity.y * FLICK_SCROLL_WEIGHT) / duration;
319 _FlickGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
326 _FlickGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
333 _FlickGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
335 Ewk_Event_Gesture gestureEvent;
336 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
338 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
340 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
341 SysAssertf(pSmartData, "Failed to get webkit smart data.");
342 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
344 if (_WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled())
346 SetGestureEvent(gestureEvent, EWK_GESTURE_FLICK, absPoint, __velocity, 0.0, 0);
348 pSmartData->api->gesture_start(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
351 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
358 _FlickGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
360 return OnTouchPressed(source, touchInfo);
364 _PinchGestureState::_PinchGestureState(_Web* pWeb)
366 , __standardScale(0.0)
371 _PinchGestureState::~_PinchGestureState(void)
377 _PinchGestureState::OnPinchGestureStarted(_TouchPinchGestureDetector& gesture)
379 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PINCH);
381 Ewk_Event_Gesture gestureEvent;
382 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
383 __standardScale = static_cast< double >(gesture.GetScaleF());
385 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), 1.0, 0);
387 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
388 SysAssertf(pSmartData, "Failed to get webkit smart data.");
389 pSmartData->api->gesture_start(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
396 _PinchGestureState::OnPinchGestureChanged(_TouchPinchGestureDetector& gesture)
398 Ewk_Event_Gesture gestureEvent;
399 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
400 double relScale = static_cast< double >(gesture.GetScaleF()) /__standardScale;
402 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), relScale, 0);
404 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
405 SysAssertf(pSmartData, "Failed to get webkit smart data.");
406 pSmartData->api->gesture_move(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
413 _PinchGestureState::OnPinchGestureFinished(_TouchPinchGestureDetector& gesture)
415 Ewk_Event_Gesture gestureEvent;
417 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
419 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
420 SysAssertf(pSmartData, "Failed to get webkit smart data.");
421 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
428 _PinchGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
435 _PinchGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
442 _PinchGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
444 _TouchManager* pTouchManager = _TouchManager::GetInstance();
445 SysAssertf(pTouchManager, "Failed to get touch manager.");
446 if(pTouchManager->GetPointCount() == 0)
448 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
456 _PinchGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
458 Ewk_Event_Gesture gestureEvent;
460 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
462 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
463 SysAssertf(pSmartData, "Failed to get webkit smart data.");
464 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
466 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);