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)
73 _TapGestureState::~_TapGestureState(void)
79 _TapGestureState::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
81 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
82 SysAssertf(pSmartData, "Failed to get webkit smart data.");
84 Ewk_Event_Gesture gestureEvent;
86 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, Point(0, 0), Point(0, 0), 0.0, 0);
87 pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
96 _TapGestureState::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
98 __doubleTapped = true;
105 _TapGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
107 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
108 SysAssertf(pSmartData, "Failed to get webkit smart data.");
110 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
112 Ewk_Event_Gesture gestureEvent;
114 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 1);
115 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
117 __longPressed = false;
118 __doubleTapped = false;
125 _TapGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
127 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
128 SysAssertf(pSmartData, "Failed to get webkit smart data.");
130 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);
135 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
137 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PANNING);
144 _TapGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
146 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
147 SysAssertf(pSmartData, "Failed to get webkit smart data.");
149 Ewk_Event_Gesture gestureEvent;
150 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
154 Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(__pWebCore->GetWebNativeNode(), absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
155 SysTryReturn(NID_WEB_CTRL, pEwkHitTest, true, E_SYSTEM, "Failed to get hit test.");
157 String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
159 if (tagName.Equals(L"INPUT", false) || tagName.Equals(L"TEXTAREA", false))
161 Eina_Rectangle leftHandle;
162 Eina_Rectangle rightHandle;
164 ewk_view_text_selection_range_get(__pWebCore->GetWebNativeNode(), &leftHandle, &rightHandle);
165 if ((rightHandle.x == 0) && (rightHandle.y == 0))
167 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, absPoint, Point(0, 0), 0.0, 1);
168 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
172 else if (__doubleTapped)
174 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 2);
175 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
179 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 1);
180 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
188 _TapGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
190 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
191 SysAssertf(pSmartData, "Failed to get webkit smart data.");
193 Ewk_Event_Gesture gestureEvent;
195 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, Point(0, 0), Point(0, 0), 0.0, 0);
196 pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
202 _PanningGestureState::_PanningGestureState(_Web* pWeb)
208 _PanningGestureState::~_PanningGestureState(void)
214 _PanningGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
221 _PanningGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
223 if (_WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled())
225 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
226 SysAssertf(pSmartData, "Failed to get webkit smart data.");
228 Ewk_Event_Gesture gestureEvent;
230 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
232 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
233 pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
241 _PanningGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
243 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
244 SysAssertf(pSmartData, "Failed to get webkit smart data.");
246 Ewk_Event_Gesture gestureEvent;
248 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
250 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
251 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
253 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
260 _PanningGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
262 return OnTouchReleased(source, touchInfo);
266 _FlickGestureState::_FlickGestureState(_Web* pWeb)
273 _FlickGestureState::~_FlickGestureState(void)
279 _FlickGestureState::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
281 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_FLICK);
283 int duration = gesture.GetDuration();
284 gesture.GetDistance(__velocity.x, __velocity.y);
286 __velocity.x = (__velocity.x * FLICK_SCROLL_WEIGHT) / duration;
287 __velocity.y = (__velocity.y * FLICK_SCROLL_WEIGHT) / duration;
294 _FlickGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
296 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
297 SysAssertf(pSmartData, "Failed to get webkit smart data.");
299 Ewk_Event_Gesture gestureEvent;
301 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
303 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
304 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
306 SetGestureEvent(gestureEvent, EWK_GESTURE_FLICK, Point(0, 0), Point(0, 0), 0.0, 0);
307 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
309 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
316 _FlickGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
323 _FlickGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
325 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
326 SysAssertf(pSmartData, "Failed to get webkit smart data.");
328 Ewk_Event_Gesture gestureEvent;
330 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
332 SetGestureEvent(gestureEvent, EWK_GESTURE_FLICK, absPoint, __velocity, 0, 0);
333 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
340 _FlickGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
342 return OnTouchPressed(source, touchInfo);
346 _PinchGestureState::_PinchGestureState(_Web* pWeb)
348 , __standardScale(0.0)
353 _PinchGestureState::~_PinchGestureState(void)
359 _PinchGestureState::OnPinchGestureStarted(_TouchPinchGestureDetector& gesture)
361 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PINCH);
363 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
364 SysAssertf(pSmartData, "Failed to get webkit smart data.");
366 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
367 __standardScale = static_cast< double >(gesture.GetScaleF());
369 Ewk_Event_Gesture gestureEvent;
371 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), 1.0, 0);
372 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
379 _PinchGestureState::OnPinchGestureChanged(_TouchPinchGestureDetector& gesture)
381 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
382 SysAssertf(pSmartData, "Failed to get webkit smart data.");
384 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
385 double relScale = static_cast< double >(gesture.GetScaleF()) /__standardScale;
387 Ewk_Event_Gesture gestureEvent;
389 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), relScale, 0);
390 pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
397 _PinchGestureState::OnPinchGestureFinished(_TouchPinchGestureDetector& gesture)
399 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
400 SysAssertf(pSmartData, "Failed to get webkit smart data.");
402 Ewk_Event_Gesture gestureEvent;
404 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
405 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
412 _PinchGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
419 _PinchGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
426 _PinchGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
428 _TouchManager* pTouchManager = _TouchManager::GetInstance();
429 SysAssertf(pTouchManager, "Failed to get touch manager.");
431 if(pTouchManager->GetPointCount() == 0)
433 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
441 _PinchGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
443 const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
444 SysAssertf(pSmartData, "Failed to get webkit smart data.");
446 Ewk_Event_Gesture gestureEvent;
448 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
449 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
451 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);