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_WebSettingImpl.h"
37 using namespace Tizen::Base;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Ui;
42 namespace Tizen { namespace Web { namespace Controls
46 static const int FLICK_SCROLL_WEIGHT = 3000;
47 static const double PINCH_ZOOM_FINGER_FACTOR = 1.0;
48 static const double PINCH_ZOOM_DISTANCE_TOLERANCE = 40.0;
52 SetGestureEvent(Ewk_Event_Gesture& gestureEvent, Ewk_Gesture_Type gestureType, const Point& absPoint, const Point& velocity, double scale, int count)
54 gestureEvent.type = gestureType;
55 gestureEvent.position.x = absPoint.x;
56 gestureEvent.position.y = absPoint.y;
57 gestureEvent.velocity.x = velocity.x;
58 gestureEvent.velocity.y = velocity.y;
59 gestureEvent.scale = scale;
60 gestureEvent.count = count;
61 gestureEvent.timestamp = ecore_time_get() * 1000;
65 _TapGestureState::_TapGestureState(_Web* pWeb)
67 , __longPressed(false)
68 , __doubleTapped(false)
69 , __pressedPosition(0.0f, 0.0f)
74 _TapGestureState::~_TapGestureState(void)
80 _TapGestureState::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
82 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
83 SysAssertf(pSmartData, "Failed to get webkit smart data.");
85 Ewk_Event_Gesture gestureEvent;
87 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, Point(0, 0), Point(0, 0), 0.0, 0);
88 pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
97 _TapGestureState::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
99 __doubleTapped = true;
106 _TapGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
108 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
109 SysAssertf(pSmartData, "Failed to get webkit smart data.");
111 __pressedPosition = touchInfo.GetCurrentPosition();
112 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(__pressedPosition)));
114 Ewk_Event_Gesture gestureEvent;
116 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 1);
117 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
119 __longPressed = false;
120 __doubleTapped = false;
127 _TapGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
129 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
130 SysAssertf(pSmartData, "Failed to get webkit smart data.");
132 Ewk_Event_Gesture gestureEvent;
134 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
136 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
137 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
139 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PANNING);
146 _TapGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
148 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
149 SysAssertf(pSmartData, "Failed to get webkit smart data.");
151 Ewk_Event_Gesture gestureEvent;
153 if (__pWebCore->Contains(__pressedPosition))
155 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(__pressedPosition)));
159 Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(__pWebCore->GetWebNativeNode(), absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
160 SysTryReturn(NID_WEB_CTRL, pEwkHitTest, true, E_SYSTEM, "Failed to get hit test.");
162 String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
164 Eina_Hash* pAttrHash = ewk_hit_test_attribute_hash_get(pEwkHitTest);
165 char* pValue = reinterpret_cast< char* >(eina_hash_find(pAttrHash, "contenteditable"));
166 if (tagName.Equals(L"INPUT", false) || tagName.Equals(L"TEXTAREA", false) || pValue)
168 Eina_Rectangle leftHandle;
169 Eina_Rectangle rightHandle;
171 ewk_view_text_selection_range_get(__pWebCore->GetWebNativeNode(), &leftHandle, &rightHandle);
172 if (((rightHandle.x + rightHandle.w) == 0) && ((rightHandle.y + rightHandle.h) == 0))
174 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, absPoint, Point(0, 0), 0.0, 1);
175 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
179 else if (__doubleTapped)
181 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 2);
182 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
186 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 1);
187 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
192 OnTouchCanceled(source, touchInfo);
200 _TapGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
202 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
203 SysAssertf(pSmartData, "Failed to get webkit smart data.");
205 Ewk_Event_Gesture gestureEvent;
207 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, Point(0, 0), Point(0, 0), 0.0, 0);
208 pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
214 _PanningGestureState::_PanningGestureState(_Web* pWeb)
220 _PanningGestureState::~_PanningGestureState(void)
226 _PanningGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
233 _PanningGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
235 if (_WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled())
237 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
238 SysAssertf(pSmartData, "Failed to get webkit smart data.");
240 Ewk_Event_Gesture gestureEvent;
242 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
244 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
245 pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
253 _PanningGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
255 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
256 SysAssertf(pSmartData, "Failed to get webkit smart data.");
258 Ewk_Event_Gesture gestureEvent;
260 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
262 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
263 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
265 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
272 _PanningGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
274 return OnTouchReleased(source, touchInfo);
278 _FlickGestureState::_FlickGestureState(_Web* pWeb)
285 _FlickGestureState::~_FlickGestureState(void)
291 _FlickGestureState::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
293 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_FLICK);
295 int duration = gesture.GetDuration();
296 gesture.GetDistance(__velocity.x, __velocity.y);
298 __velocity.x = (__velocity.x * FLICK_SCROLL_WEIGHT) / duration;
299 __velocity.y = (__velocity.y * FLICK_SCROLL_WEIGHT) / duration;
306 _FlickGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
313 _FlickGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
320 _FlickGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
322 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
323 SysAssertf(pSmartData, "Failed to get webkit smart data.");
325 Ewk_Event_Gesture gestureEvent;
327 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
329 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
330 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
332 SetGestureEvent(gestureEvent, EWK_GESTURE_FLICK, absPoint, __velocity, 0, 0);
333 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
335 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
342 _FlickGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
344 return OnTouchPressed(source, touchInfo);
348 _PinchGestureState::_PinchGestureState(_Web* pWeb)
350 , __standardScale(0.0)
355 _PinchGestureState::~_PinchGestureState(void)
361 _PinchGestureState::OnPinchGestureStarted(_TouchPinchGestureDetector& gesture)
363 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PINCH);
365 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
366 SysAssertf(pSmartData, "Failed to get webkit smart data.");
368 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
369 __standardScale = static_cast< double >(gesture.GetScaleF());
371 Ewk_Event_Gesture gestureEvent;
373 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), 1.0, 0);
374 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
381 _PinchGestureState::OnPinchGestureChanged(_TouchPinchGestureDetector& gesture)
383 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
384 SysAssertf(pSmartData, "Failed to get webkit smart data.");
386 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
387 double relScale = static_cast< double >(gesture.GetScaleF()) /__standardScale;
389 Ewk_Event_Gesture gestureEvent;
391 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), relScale, 0);
392 pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
399 _PinchGestureState::OnPinchGestureFinished(_TouchPinchGestureDetector& gesture)
401 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
402 SysAssertf(pSmartData, "Failed to get webkit smart data.");
404 Ewk_Event_Gesture gestureEvent;
406 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
407 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
414 _PinchGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
421 _PinchGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
428 _PinchGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
430 _TouchManager* pTouchManager = _TouchManager::GetInstance();
431 SysAssertf(pTouchManager, "Failed to get touch manager.");
433 if(pTouchManager->GetPointCount() == 0)
435 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
443 _PinchGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
445 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
446 SysAssertf(pSmartData, "Failed to get webkit smart data.");
448 Ewk_Event_Gesture gestureEvent;
450 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
451 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
453 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);