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 <FBaseRtTimer.h>
27 #include <FBaseSysLog.h>
28 #include <FGrpPoint.h>
29 #include <FUi_CoordinateSystemUtils.h>
30 #include <FUi_Control.h>
31 #include <FUi_TouchManager.h>
32 #include <FUi_UiTouchEvent.h>
33 #include "FWebCtrl_GestureState.h"
34 #include "FWebCtrl_Web.h"
35 #include "FWebCtrl_WebImpl.h"
36 #include "FWebCtrl_WebSettingImpl.h"
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Runtime;
41 using namespace Tizen::Graphics;
42 using namespace Tizen::Ui;
43 using namespace Tizen::Web::Controls;
46 namespace Tizen { namespace Web { namespace Controls
50 static const int FLICK_SCROLL_WEIGHT = 3000;
51 static const double PINCH_ZOOM_FINGER_FACTOR = 1.0;
52 static const double PINCH_ZOOM_DISTANCE_TOLERANCE = 40.0;
56 SetGestureEvent(Ewk_Event_Gesture& gestureEvent, Ewk_Gesture_Type gestureType, const Point& absPoint, const Point& velocity, double scale, int count)
58 gestureEvent.type = gestureType;
59 gestureEvent.position.x = absPoint.x;
60 gestureEvent.position.y = absPoint.y;
61 gestureEvent.velocity.x = velocity.x;
62 gestureEvent.velocity.y = velocity.y;
63 gestureEvent.scale = scale;
64 gestureEvent.count = count;
65 gestureEvent.timestamp = ecore_time_get() * 1000;
69 _TapGestureState::_TapGestureState(_Web* pWeb)
71 , __longPressed(false)
72 , __doubleTapped(false)
75 , __pressedPosition(0.0f, 0.0f)
77 __timer.Construct(*this);
81 _TapGestureState::~_TapGestureState(void)
87 _TapGestureState::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
89 if (__pressed == false)
101 _TapGestureState::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
103 __doubleTapped = true;
110 _TapGestureState::PressTouch(void)
112 Ewk_Event_Gesture gestureEvent;
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);
124 _TapGestureState::ReleaseTouch(void)
128 if (!__pWebCore->Contains(__pressedPosition))
130 _TouchInfo dummyTouchInfo;
131 OnTouchCanceled(*__pWebCore, dummyTouchInfo);
135 Evas_Object* pView = __pWebCore->GetWebNativeNode();
136 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(__pressedPosition)));
140 Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(pView, absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
141 SysTryReturnVoidResult(NID_WEB_CTRL, pEwkHitTest, E_SYSTEM, "Failed to get hit test.");
143 String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
145 Eina_Hash* pAttrHash = ewk_hit_test_attribute_hash_get(pEwkHitTest);
146 char* pValue = reinterpret_cast< char* >(eina_hash_find(pAttrHash, "contenteditable"));
147 if (tagName.Equals(L"INPUT", false) || tagName.Equals(L"TEXTAREA", false) || pValue)
149 Eina_Rectangle leftHandle;
150 Eina_Rectangle rightHandle;
152 ewk_view_text_selection_range_get(pView, &leftHandle, &rightHandle);
153 if (((rightHandle.x + rightHandle.w) == 0) && ((rightHandle.y + rightHandle.h) == 0))
155 Ewk_Event_Gesture gestureEvent;
157 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, absPoint, Point(0, 0), 0.0, 1);
159 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(pView));
160 SysAssertf(pSmartData, "Failed to get webkit smart data.");
161 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
167 Ewk_Event_Gesture gestureEvent;
174 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, touchCount);
176 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(pView));
177 SysAssertf(pSmartData, "Failed to get webkit smart data.");
178 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
184 _TapGestureState::LongPressTouch(void)
186 //To disable focus ring
187 Ewk_Event_Gesture gestureEvent;
189 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, Point(0, 0), Point(0, 0), 0.0, 0);
191 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
192 SysAssertf(pSmartData, "Failed to get webkit smart data.");
193 pSmartData->api->gesture_move(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
198 _TapGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
200 __pressedPosition = touchInfo.GetCurrentPosition();
202 if (__pressed == false)
206 __longPressed = false;
207 __doubleTapped = false;
224 _TapGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
226 Ewk_Event_Gesture gestureEvent;
227 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
229 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
231 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
232 SysAssertf(pSmartData, "Failed to get webkit smart data.");
233 pSmartData->api->gesture_start(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
235 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PANNING);
237 if (!_WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled())
247 _TapGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
251 if (__pressed == true)
263 _TapGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
265 Ewk_Event_Gesture gestureEvent;
267 SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, Point(0, 0), Point(0, 0), 0.0, 0);
269 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
270 SysAssertf(pSmartData, "Failed to get webkit smart data.");
271 pSmartData->api->gesture_move(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
278 _TapGestureState::OnTimerExpired(Timer& timer)
280 if (__longPressed == false)
284 if (__released == true)
292 _PanningGestureState::_PanningGestureState(_Web* pWeb)
298 _PanningGestureState::~_PanningGestureState(void)
304 _PanningGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
311 _PanningGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
313 if (!_WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled())
318 Ewk_Event_Gesture gestureEvent;
319 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
321 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
323 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
324 SysAssertf(pSmartData, "Failed to get webkit smart data.");
325 pSmartData->api->gesture_move(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
332 _PanningGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
334 Ewk_Event_Gesture gestureEvent;
335 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
337 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
339 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
340 SysAssertf(pSmartData, "Failed to get webkit smart data.");
341 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
343 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
350 _PanningGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
352 return OnTouchReleased(source, touchInfo);
356 _FlickGestureState::_FlickGestureState(_Web* pWeb)
363 _FlickGestureState::~_FlickGestureState(void)
369 _FlickGestureState::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
371 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_FLICK);
373 if (_WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled())
375 int duration = gesture.GetDuration();
376 gesture.GetDistance(__velocity.x, __velocity.y);
378 __velocity.x = (__velocity.x * FLICK_SCROLL_WEIGHT) / duration;
379 __velocity.y = (__velocity.y * FLICK_SCROLL_WEIGHT) / duration;
387 _FlickGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
394 _FlickGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
401 _FlickGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
403 Ewk_Event_Gesture gestureEvent;
404 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
406 SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
408 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
409 SysAssertf(pSmartData, "Failed to get webkit smart data.");
410 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
412 if (_WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled())
414 SetGestureEvent(gestureEvent, EWK_GESTURE_FLICK, absPoint, __velocity, 0.0, 0);
416 pSmartData->api->gesture_start(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
419 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
426 _FlickGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
428 return OnTouchPressed(source, touchInfo);
432 _PinchGestureState::_PinchGestureState(_Web* pWeb)
434 , __standardScale(0.0)
439 _PinchGestureState::~_PinchGestureState(void)
445 _PinchGestureState::OnPinchGestureStarted(_TouchPinchGestureDetector& gesture)
447 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PINCH);
449 Ewk_Event_Gesture gestureEvent;
450 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
451 __standardScale = static_cast< double >(gesture.GetScaleF());
453 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), 1.0, 0);
455 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
456 SysAssertf(pSmartData, "Failed to get webkit smart data.");
457 pSmartData->api->gesture_start(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
464 _PinchGestureState::OnPinchGestureChanged(_TouchPinchGestureDetector& gesture)
466 Ewk_Event_Gesture gestureEvent;
467 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
468 double relScale = static_cast< double >(gesture.GetScaleF()) /__standardScale;
470 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), relScale, 0);
472 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
473 SysAssertf(pSmartData, "Failed to get webkit smart data.");
474 pSmartData->api->gesture_move(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
481 _PinchGestureState::OnPinchGestureFinished(_TouchPinchGestureDetector& gesture)
483 Ewk_Event_Gesture gestureEvent;
485 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
487 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
488 SysAssertf(pSmartData, "Failed to get webkit smart data.");
489 pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
496 _PinchGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
503 _PinchGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
510 _PinchGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
512 _TouchManager* pTouchManager = _TouchManager::GetInstance();
513 SysAssertf(pTouchManager, "Failed to get touch manager.");
514 if(pTouchManager->GetPointCount() == 0)
516 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
524 _PinchGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
526 Ewk_Event_Gesture gestureEvent;
528 SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
530 const Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
531 SysAssertf(pSmartData, "Failed to get webkit smart data.");
532 pSmartData->api->gesture_end(const_cast< Ewk_View_Smart_Data* >(pSmartData), &gestureEvent);
534 __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);