fix bug for geolocation and contents download
[framework/osp/web.git] / src / controls / FWebCtrl_GestureState.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                FWebCtrl_GestureState.cpp
20  * @brief               The file contains the definition of _Web class.
21  *
22  * The file contains the definition of _Web class.
23  */
24 #include <Ecore.h>
25 #include <EWebKit2.h>
26 #include <FBaseSysLog.h>
27 #include <FGrpPoint.h>
28 #include <FUi_CoordinateSystemUtils.h>
29 #include <FUi_Control.h>
30 #include <FUi_UiTouchEvent.h>
31 #include "FWebCtrl_GestureState.h"
32 #include "FWebCtrl_Web.h"
33 #include "FWebCtrl_WebSettingImpl.h"
34
35
36 using namespace Tizen::Base;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Ui;
39
40
41 namespace Tizen { namespace Web { namespace Controls
42 {
43
44
45 static const int  FLICK_SCROLL_WEIGHT = 3000;
46 static const double PINCH_ZOOM_FINGER_FACTOR = 1.0;
47 static const double PINCH_ZOOM_DISTANCE_TOLERANCE = 40.0;
48
49
50 void
51 SetGestureEvent(Ewk_Event_Gesture& gestureEvent, Ewk_Gesture_Type gestureType, const Point& absPoint, const Point& velocity, double scale, int count)
52 {
53         gestureEvent.type = gestureType;
54         gestureEvent.position.x = absPoint.x;
55         gestureEvent.position.y = absPoint.y;
56         gestureEvent.velocity.x = velocity.x;
57         gestureEvent.velocity.y = velocity.y;
58         gestureEvent.scale = scale;
59         gestureEvent.count = count;
60         gestureEvent.timestamp = ecore_time_get() * 1000;
61 }
62
63
64 _TapGestureState::_TapGestureState(_Web* pWeb)
65         : __pWebCore(pWeb)
66         , __longPressed(false)
67         , __doubleTapped(false)
68 {
69 }
70
71
72 _TapGestureState::~_TapGestureState(void)
73 {
74 }
75
76
77 bool
78 _TapGestureState::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
79 {
80         const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
81         SysAssertf(pSmartData, "Failed to get webkit smart data.");
82
83         Ewk_Event_Gesture gestureEvent;
84
85         SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, Point(0, 0), Point(0, 0), 0.0, 0);
86         pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
87
88         __longPressed = true;
89
90         return true;
91 }
92
93
94 bool
95 _TapGestureState::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
96 {
97         __doubleTapped = true;
98
99         return true;
100 }
101
102
103 bool
104 _TapGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
105 {
106         const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
107         SysAssertf(pSmartData, "Failed to get webkit smart data.");
108
109         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
110
111         Ewk_Event_Gesture gestureEvent;
112
113         SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 1);
114         pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
115
116         __longPressed = false;
117         __doubleTapped = false;
118
119         return true;
120 }
121
122
123 bool
124 _TapGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
125 {
126         const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
127         SysAssertf(pSmartData, "Failed to get webkit smart data.");
128
129         Ewk_Event_Gesture gestureEvent;
130
131         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
132
133         SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
134         pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
135
136         __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PANNING);
137
138         return true;
139 }
140
141
142 bool
143 _TapGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
144 {
145         if (__longPressed)
146         {
147                 return true;
148         }
149
150         const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
151         SysAssertf(pSmartData, "Failed to get webkit smart data.");
152
153         Ewk_Event_Gesture gestureEvent;
154         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
155
156         if (__doubleTapped)
157         {
158                 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 2);
159                 pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
160         }
161         else
162         {
163                 SetGestureEvent(gestureEvent, EWK_GESTURE_TAP, absPoint, Point(0, 0), 0.0, 1);
164         }
165         pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
166
167         return true;
168 }
169
170
171 bool
172 _TapGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
173 {
174         const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
175         SysAssertf(pSmartData, "Failed to get webkit smart data.");
176
177         Ewk_Event_Gesture gestureEvent;
178
179         SetGestureEvent(gestureEvent, EWK_GESTURE_LONG_PRESS, Point(0, 0), Point(0, 0), 0.0, 0);
180         pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
181
182         return true;
183 }
184
185
186 _PanningGestureState::_PanningGestureState(_Web* pWeb)
187         : __pWebCore(pWeb)
188 {
189 }
190
191
192 _PanningGestureState::~_PanningGestureState(void)
193 {
194 }
195
196
197 bool
198 _PanningGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
199 {
200         return true;
201 }
202
203
204 bool
205 _PanningGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
206 {
207         const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
208         SysAssertf(pSmartData, "Failed to get webkit smart data.");
209
210         Ewk_Event_Gesture gestureEvent;
211
212         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
213
214         SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
215         pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
216
217         return true;
218 }
219
220
221 bool
222 _PanningGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
223 {
224         const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pWebCore->GetWebNativeNode()));
225         SysAssertf(pSmartData, "Failed to get webkit smart data.");
226
227         Ewk_Event_Gesture gestureEvent;
228
229         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
230
231         SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
232         pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
233
234         __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
235
236         return true;
237 }
238
239
240 bool
241 _PanningGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
242 {
243         return OnTouchReleased(source, touchInfo);
244 }
245
246
247 _FlickGestureState::_FlickGestureState(_Web* pWeb)
248         : __pWebCore(pWeb)
249         , __velocity(0, 0)
250 {
251 }
252
253
254 _FlickGestureState::~_FlickGestureState(void)
255 {
256 }
257
258
259 bool
260 _FlickGestureState::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
261 {
262         __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_FLICK);
263
264         int duration = gesture.GetDuration();
265         gesture.GetDistance(__velocity.x, __velocity.y);
266
267         __velocity.x = (__velocity.x * FLICK_SCROLL_WEIGHT) / duration;
268         __velocity.y = (__velocity.y * FLICK_SCROLL_WEIGHT) / duration;
269
270         return true;
271 }
272
273
274 bool
275 _FlickGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
276 {
277         const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
278         SysAssertf(pSmartData, "Failed to get webkit smart data.");
279
280         Ewk_Event_Gesture gestureEvent;
281
282         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
283
284         SetGestureEvent(gestureEvent, EWK_GESTURE_PAN, absPoint, Point(0, 0), 0.0, 0);
285         pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
286
287         SetGestureEvent(gestureEvent, EWK_GESTURE_FLICK, Point(0, 0), Point(0, 0), 0.0, 0);
288         pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
289
290         __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
291
292         return true;
293 }
294
295
296 bool
297 _FlickGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
298 {
299         return true;
300 }
301
302
303 bool
304 _FlickGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
305 {
306         const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
307         SysAssertf(pSmartData, "Failed to get webkit smart data.");
308
309         Ewk_Event_Gesture gestureEvent;
310
311         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(touchInfo.GetCurrentPosition())));
312
313         SetGestureEvent(gestureEvent, EWK_GESTURE_FLICK, absPoint, __velocity, 0, 0);
314         pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
315
316         return true;
317 }
318
319
320 bool
321 _FlickGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
322 {
323         return OnTouchPressed(source, touchInfo);
324 }
325
326
327 _PinchGestureState::_PinchGestureState(_Web* pWeb)
328         : __pWebCore(pWeb)
329         , __standardScale(0.0)
330 {
331 }
332
333
334 _PinchGestureState::~_PinchGestureState(void)
335 {
336 }
337
338
339 bool
340 _PinchGestureState::OnPinchGestureStarted(_TouchPinchGestureDetector& gesture)
341 {
342         __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_PINCH);
343
344         const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
345         SysAssertf(pSmartData, "Failed to get webkit smart data.");
346
347         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
348         __standardScale = static_cast< double >(gesture.GetScaleF());
349
350         Ewk_Event_Gesture gestureEvent;
351
352         SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), 1.0, 0);
353         pSmartData->api->gesture_start(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
354
355         return true;
356 }
357
358
359 bool
360 _PinchGestureState::OnPinchGestureChanged(_TouchPinchGestureDetector& gesture)
361 {
362         const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
363         SysAssertf(pSmartData, "Failed to get webkit smart data.");
364
365         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(gesture.GetCenterPointF())));
366         double relScale = static_cast< double >(gesture.GetScaleF()) /__standardScale;
367
368         Ewk_Event_Gesture gestureEvent;
369
370         SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, absPoint, Point(0, 0), relScale, 0);
371         pSmartData->api->gesture_move(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
372
373         return true;
374 }
375
376
377 bool
378 _PinchGestureState::OnPinchGestureFinished(_TouchPinchGestureDetector& gesture)
379 {
380         const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
381         SysAssertf(pSmartData, "Failed to get webkit smart data.");
382
383         Ewk_Event_Gesture gestureEvent;
384
385         SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
386         pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
387
388         __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
389
390         return true;
391 }
392
393
394 bool
395 _PinchGestureState::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
396 {
397         return true;
398 }
399
400
401 bool
402 _PinchGestureState::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
403 {
404         return true;
405 }
406
407
408 bool
409 _PinchGestureState::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
410 {
411         return true;
412 }
413
414
415 bool
416 _PinchGestureState::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
417 {
418         const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get( __pWebCore->GetWebNativeNode()));
419         SysAssertf(pSmartData, "Failed to get webkit smart data.");
420
421         Ewk_Event_Gesture gestureEvent;
422
423         SetGestureEvent(gestureEvent, EWK_GESTURE_PINCH, Point(0, 0), Point(0, 0), 0.0, 0);
424         pSmartData->api->gesture_end(const_cast<Ewk_View_Smart_Data*>(pSmartData), &gestureEvent);
425
426         __pWebCore->ChangeGesture(WEB_GESTURE_TYPE_TAP);
427
428         return true;
429 }
430
431
432 }}}