74782d2f2b2450f2fea6c118b8b27c53fecd65d1
[framework/osp/web.git] / src / controls / FWebCtrl_Web.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_Web.cpp
20  * @brief               The file contains the definition of _Web class.
21  *
22  * The file contains the definition of _Web class.
23  */
24 #include <Elementary.h>
25 #include <memory>
26 #include <FBaseByteBuffer.h>
27 #include <FBaseColLinkedListT.h>
28 #include <FBaseSysLog.h>
29 #include <FBaseColIListT.h>
30 #include <FGrpFloatPoint.h>
31 #include <FGrpPoint.h>
32 #include <FGrpBitmap.h>
33 #include <FGrpCanvas.h>
34 #include <FGrpFloatRectangle.h>
35 #include <FSysVibrator.h>
36 #include <FWebCtrlWebSetting.h>
37 #include <FGrp_CoordinateSystem.h>
38 #include <FSys_VibratorImpl.h>
39 #include <FUiAnim_EflNode.h>
40 #include <FUiAnim_VisualElement.h>
41 #include <FUiAnim_VisualElementImpl.h>
42 #include <FUi_CoordinateSystemUtils.h>
43 #include <FUi_AccessibilityContainer.h>
44 #include <FUi_AccessibilityElement.h>
45 #include <FUi_IAccessibilityFocusHandler.h>
46 #include <FUi_IAccessibilityListener.h>
47 #include <FUi_Math.h>
48 #include <FUi_TouchManager.h>
49 #include "FWebCtrl_EflWebkit.h"
50 #include "FWebCtrl_GestureState.h"
51 #include "FWebCtrl_Web.h"
52 #include "FWebCtrl_WebSettingImpl.h"
53 #include "FWebCtrl_Utility.h"
54
55
56 using namespace Tizen::Base;
57 using namespace Tizen::Base::Collection;
58 using namespace Tizen::Graphics;
59 using namespace Tizen::Ui;
60 using namespace Tizen::Ui::Animations;
61
62
63 namespace
64 {
65
66
67 class _WebAccessibilityListener
68         : public Tizen::Ui::_IAccessibilityListener
69 {
70 public:
71         _WebAccessibilityListener(Evas_Object* pView);
72
73         virtual ~_WebAccessibilityListener(void);
74
75         virtual bool OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element);
76
77         virtual bool OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element);
78
79         virtual bool OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element);
80
81         virtual bool OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element);
82
83         virtual bool OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element);
84
85         virtual bool OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element);
86
87         virtual bool OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element);
88
89         virtual bool OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element);
90
91         virtual bool OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element);
92
93 private:
94         Evas_Object* __pView;
95 };
96
97
98 _WebAccessibilityListener::_WebAccessibilityListener(Evas_Object* pView)
99         : __pView(pView)
100 {
101 }
102
103
104 _WebAccessibilityListener::~_WebAccessibilityListener(void)
105 {
106 }
107
108
109 bool
110 _WebAccessibilityListener::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
111 {
112         return true;
113 }
114
115
116 bool
117 _WebAccessibilityListener::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
118 {
119         return true;
120 }
121
122
123 bool
124 _WebAccessibilityListener::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
125 {
126         return true;
127 }
128
129
130 bool
131 _WebAccessibilityListener::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
132 {
133         return true;
134 }
135
136
137 bool
138 _WebAccessibilityListener::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
139 {
140         return true;
141 }
142
143
144 bool
145 _WebAccessibilityListener::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
146 {
147         Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pView));
148         SysAssertf(pSmartData, "Failed to get webkit smart data.");
149
150         Elm_Access_Action_Info* pActionInfo = new Elm_Access_Action_Info();
151         SysTryReturn(NID_WEB_CTRL, pActionInfo, false, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
152
153         bool result = false;
154
155         pActionInfo->action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
156
157         result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
158         delete pActionInfo;
159
160         return result;
161 }
162
163
164 bool
165 _WebAccessibilityListener::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
166 {
167         Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pView));
168         SysAssertf(pSmartData, "Failed to get webkit smart data.");
169
170         Elm_Access_Action_Info* pActionInfo = new Elm_Access_Action_Info();
171         SysTryReturn(NID_WEB_CTRL, pActionInfo, false, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
172
173         bool result = false;
174
175         pActionInfo->action_type = ELM_ACCESS_ACTION_ACTIVATE;
176
177         result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
178         delete pActionInfo;
179
180         return result;
181 }
182
183
184 bool
185 _WebAccessibilityListener::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
186 {
187         return true;
188 }
189
190
191 bool
192 _WebAccessibilityListener::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
193 {
194         return true;
195 }
196
197
198 class _WebAccessibilityFocusHandler
199         : public Tizen::Ui::_IAccessibilityFocusHandler
200 {
201 public:
202         _WebAccessibilityFocusHandler(Evas_Object* pView);
203
204         virtual ~_WebAccessibilityFocusHandler(void);
205
206         virtual bool OnMoveFocus(Tizen::Ui::_AccessibilityFocusDirection direction);
207
208         virtual bool OnMoveFocus(const Tizen::Graphics::Point& point);
209
210 private:
211         Evas_Object* __pView;
212 };
213
214
215 _WebAccessibilityFocusHandler::_WebAccessibilityFocusHandler(Evas_Object* pView)
216         : __pView(pView)
217 {
218 }
219
220
221 _WebAccessibilityFocusHandler::~_WebAccessibilityFocusHandler(void)
222 {
223 }
224
225
226 bool
227 _WebAccessibilityFocusHandler::OnMoveFocus(Tizen::Ui::_AccessibilityFocusDirection direction)
228 {
229         Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pView));
230         SysAssertf(pSmartData, "Failed to get webkit smart data.");
231
232         Elm_Access_Action_Info* pActionInfo = new Elm_Access_Action_Info();
233         SysTryReturn(NID_WEB_CTRL, pActionInfo, false, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
234
235         bool result = false;
236
237         if (direction == Tizen::Ui::_ACCESSIBILITY_FOCUS_DIRECTION_PREVIOUS)
238         {
239                 pActionInfo->action_type = ELM_ACCESS_ACTION_HIGHLIGHT;
240
241                 pActionInfo->action_by = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
242
243                 result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
244         }
245         else if (direction == Tizen::Ui::_ACCESSIBILITY_FOCUS_DIRECTION_NEXT)
246         {
247                 pActionInfo->action_type = ELM_ACCESS_ACTION_HIGHLIGHT;
248
249                 pActionInfo->action_by = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
250
251                 result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
252         }
253         delete pActionInfo;
254
255         return result;
256 }
257
258
259 bool
260 _WebAccessibilityFocusHandler::OnMoveFocus(const Tizen::Graphics::Point& point)
261 {
262         Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pView));
263         SysAssertf(pSmartData, "Failed to get webkit smart data.");
264
265         Elm_Access_Action_Info* pActionInfo = new Elm_Access_Action_Info();
266         SysTryReturn(NID_WEB_CTRL, pActionInfo, false, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
267
268         bool result = false;
269
270         pActionInfo->action_type = ELM_ACCESS_ACTION_READ;
271         pActionInfo->x = point.x;
272         pActionInfo->y = point.y;
273
274         result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
275         delete pActionInfo;
276
277         return result;
278 }
279
280
281 }
282
283
284 namespace Tizen { namespace Web { namespace Controls
285 {
286
287
288 void
289 OnEdgeLeft(void* pUserData, Evas_Object* pView, void* pEventInfo)
290 {
291         _Web* pCore = reinterpret_cast< _Web* >(pUserData);
292         SysAssertf(pCore, "Failed to request");
293
294         pCore->SetEdgeReachedEvent(WEB_EDGE_LEFT);
295 }
296
297
298 void
299 OnEdgeRight(void* pUserData, Evas_Object* pView, void* pEventInfo)
300 {
301         _Web* pCore = reinterpret_cast< _Web* >(pUserData);
302         SysAssertf(pCore, "Failed to request");
303
304         pCore->SetEdgeReachedEvent(WEB_EDGE_RIGHT);
305 }
306
307
308 void
309 OnEdgeTop(void* pUserData, Evas_Object* pView, void* pEventInfo)
310 {
311         _Web* pCore = reinterpret_cast< _Web* >(pUserData);
312         SysAssertf(pCore, "Failed to request");
313
314         pCore->SetEdgeReachedEvent(WEB_EDGE_TOP);
315 }
316
317
318 void
319 OnEdgeBottom(void* pUserData, Evas_Object* pView, void* pEventInfo)
320 {
321         _Web* pCore = reinterpret_cast< _Web* >(pUserData);
322         SysAssertf(pCore, "Failed to request");
323
324         pCore->SetEdgeReachedEvent(WEB_EDGE_BOTTOM);
325 }
326
327
328 _Web::_Web(void)
329         : __pGestureHandler(null)
330         , __pEflWebkit(null)
331         , __pWebSetting(null)
332         , __pGestureFlick(null)
333         , __pGestureLongPress(null)
334         , __pGesturePinch(null)
335         , __pGestureDoubleTap(null)
336         , __pTouchEventInfoList(null)
337         , __pTapGestureHandler(null)
338         , __pPanningGestureHandler(null)
339         , __pFlickGestureHandler(null)
340         , __pPinchGestureHandler(null)
341         , __gestureType(WEB_GESTURE_TYPE_TAP)
342         , __edgeType(WEB_EDGE_NONE)
343         , __pTextElement(null)
344         , __previousTouchedPosition(0.0f, 0.0f)
345 {
346         SetBackgroundColor(Color(0, 0, 0, 0));
347 }
348
349
350 _Web::~_Web(void)
351 {
352         RemoveGestureListener();
353 }
354
355
356 _Web*
357 _Web::CreateWebN(void)
358 {
359         result r = E_SUCCESS;
360
361         std::unique_ptr<_Web> pWeb(new (std::nothrow) _Web());
362         SysTryReturn(NID_WEB_CTRL, pWeb.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
363
364         pWeb->__pWebSetting = std::unique_ptr<WebSetting>(new (std::nothrow) WebSetting());
365         SysTryReturn(NID_WEB_CTRL, pWeb->__pWebSetting.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
366
367         pWeb->AcquireHandle();
368         pWeb->SetMultiTouchEnabled(true);
369         pWeb->SetTouchPressThreshold(0.08);
370
371         r = pWeb->AddGestureListeners();
372         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
373
374         r = pWeb->InitializeGestureStates();
375         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
376
377         return pWeb.release();
378 }
379
380
381 result
382 _Web::CreateWebkitEvasObject(void)
383 {
384         result r = E_SUCCESS;
385
386         std::unique_ptr<_EflWebkit> pEflWebkit(new (std::nothrow) _EflWebkit());
387         SysTryReturnResult(NID_WEB_CTRL, pEflWebkit.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
388
389         _VisualElement* pVe = GetVisualElement();
390         r = pEflWebkit->Construct(GetAbsoluteBounds(), *pVe, this);
391         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
392
393         _VisualElementImpl* pVeImpl = _VisualElementImpl::GetInstance(*pVe);
394         pVeImpl->SetCaptureProvider(this);
395
396         __pEflWebkit = std::move(pEflWebkit);
397
398         Evas_Object* pView = GetWebNativeNode();
399         evas_object_smart_callback_add(pView, "edge,left", OnEdgeLeft, this);
400         evas_object_smart_callback_add(pView, "edge,right", OnEdgeRight, this);
401         evas_object_smart_callback_add(pView, "edge,top", OnEdgeTop, this);
402         evas_object_smart_callback_add(pView, "edge,bottom", OnEdgeBottom, this);
403
404         return E_SUCCESS;
405 }
406
407
408 result
409 _Web::InitializeGestureStates(void)
410 {
411         __pPinchGestureHandler = std::unique_ptr<_PinchGestureState>(new (std::nothrow) _PinchGestureState(this));
412         SysTryReturnResult(NID_WEB_CTRL, __pPinchGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
413
414         __pTapGestureHandler = std::unique_ptr<_TapGestureState>(new (std::nothrow) _TapGestureState(this));
415         SysTryReturnResult(NID_WEB_CTRL, __pTapGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
416
417         __pPanningGestureHandler = std::unique_ptr<_PanningGestureState>(new (std::nothrow) _PanningGestureState(this));
418         SysTryReturnResult(NID_WEB_CTRL, __pPanningGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
419
420         __pFlickGestureHandler = std::unique_ptr<_FlickGestureState>(new (std::nothrow) _FlickGestureState(this));
421         SysTryReturnResult(NID_WEB_CTRL, __pFlickGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
422
423         __pGestureHandler = __pTapGestureHandler.get();
424
425         return E_SUCCESS;
426 }
427
428
429 result
430 _Web::AddGestureListeners(void)
431 {
432         result r = E_SUCCESS;
433
434         std::unique_ptr<_TouchFlickGestureDetector> pGestureFlick(new (std::nothrow) _TouchFlickGestureDetector());
435         SysTryReturnResult(NID_WEB_CTRL, pGestureFlick.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
436
437         r = pGestureFlick->AddGestureListener(*this);
438         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
439
440         r = AddGestureDetector(*pGestureFlick.get());
441         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
442
443         __pGestureFlick = std::move(pGestureFlick);
444
445         std::unique_ptr<_TouchLongPressGestureDetector> pGestureLongPress(new (std::nothrow) _TouchLongPressGestureDetector());
446         SysTryReturnResult(NID_WEB_CTRL, pGestureLongPress.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
447
448         r = pGestureLongPress->AddGestureListener(*this);
449         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
450
451         r = AddGestureDetector(*pGestureLongPress.get());
452         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
453
454         __pGestureLongPress = std::move(pGestureLongPress);
455
456         std::unique_ptr<_TouchTapGestureDetector> pGestureDoubleTap(new (std::nothrow) _TouchTapGestureDetector());
457         SysTryReturnResult(NID_WEB_CTRL, pGestureDoubleTap.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
458
459         r = pGestureDoubleTap->AddGestureListener(*this);
460         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
461
462         r = AddGestureDetector(*pGestureDoubleTap.get());
463         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
464
465         __pGestureDoubleTap = std::move(pGestureDoubleTap);
466
467         std::unique_ptr<_TouchPinchGestureDetector> pGesturePinch(new (std::nothrow) _TouchPinchGestureDetector());
468         SysTryReturnResult(NID_WEB_CTRL, pGesturePinch.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
469
470         r = pGesturePinch->AddGestureListener(*this);
471         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
472
473         r = AddGestureDetector(*pGesturePinch.get());
474         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
475
476         __pGesturePinch = std::move(pGesturePinch);
477
478         return E_SUCCESS;
479 }
480
481
482 void
483 _Web::RemoveGestureListener(void)
484 {
485         if (__pGestureFlick.get())
486         {
487                 __pGestureFlick->RemoveGestureListener(*this);
488                 RemoveGestureDetector(*__pGestureFlick);
489         }
490
491         if (__pGestureLongPress.get())
492         {
493                 __pGestureLongPress->RemoveGestureListener(*this);
494                 RemoveGestureDetector(*__pGestureLongPress);
495         }
496
497         if (__pGestureDoubleTap.get())
498         {
499                 __pGestureDoubleTap->RemoveGestureListener(*this);
500                 RemoveGestureDetector(*__pGestureDoubleTap);
501         }
502
503         if (__pGesturePinch.get())
504         {
505                 __pGesturePinch->RemoveGestureListener(*this);
506                 RemoveGestureDetector(*__pGesturePinch);
507         }
508
509         Evas_Object* pView = GetWebNativeNode();
510         if (pView)
511         {
512                 evas_object_smart_callback_del(pView, "edge,left", OnEdgeLeft);
513                 evas_object_smart_callback_del(pView, "edge,right", OnEdgeRight);
514                 evas_object_smart_callback_del(pView, "edge,top", OnEdgeTop);
515                 evas_object_smart_callback_del(pView, "edge,bottom", OnEdgeBottom);
516         }
517 }
518
519
520 result
521 _Web::InitializeWebNativeNode(void)
522 {
523         result r = E_SUCCESS;
524
525         r = CreateWebkitEvasObject();
526         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
527
528         SetNativeObjectFocusable(false);
529
530         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
531         SysTryReturn(NID_WEB_CTRL, pContainer, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(E_SYSTEM));
532
533         __pTextElement = new (std::nothrow) _AccessibilityElement(true);
534         SysTryReturn(NID_WEB_CTRL, __pTextElement, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
535
536         __pTextElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
537         __pTextElement->SetLabel(L"Web control");
538
539         pContainer->AddElement(*__pTextElement);
540         pContainer->Activate(true);
541
542         _WebAccessibilityListener* pListener = new (std::nothrow) _WebAccessibilityListener(GetWebNativeNode());
543         SysTryReturn(NID_WEB_CTRL, pListener, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
544
545         pContainer->AddListener(*dynamic_cast<_IAccessibilityListener*>(pListener));
546
547         _WebAccessibilityFocusHandler* pFocusHandler = new (std::nothrow) _WebAccessibilityFocusHandler(GetWebNativeNode());
548         SysTryReturn(NID_WEB_CTRL, pFocusHandler, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
549
550         pContainer->SetFocusHandler(dynamic_cast<_IAccessibilityFocusHandler*>(pFocusHandler));
551
552         return E_SUCCESS;
553 }
554
555
556 Point
557 _Web::GetAbsoluteCoordinate(Point relativePoint)
558 {
559         return _CoordinateSystemUtils::Transform(ConvertToScreenPosition(relativePoint));
560 }
561
562
563 FloatPoint
564 _Web::GetAbsoluteCoordinate(FloatPoint relativePoint)
565 {
566         return _CoordinateSystemUtils::Transform(ConvertToScreenPosition(relativePoint));
567 }
568
569
570 Point
571 _Web::GetRelativeCoordinate(Point absolutePoint)
572 {
573         return ConvertToControlPosition(_CoordinateSystemUtils::InverseTransform(absolutePoint));
574 }
575
576
577 FloatPoint
578 _Web::GetRelativeCoordinate(FloatPoint absolutePoint)
579 {
580         return ConvertToControlPosition(_CoordinateSystemUtils::InverseTransform(absolutePoint));
581 }
582
583
584 Evas_Object*
585 _Web::GetWebNativeNode(void)
586 {
587         if (__pEflWebkit.get())
588         {
589                 return __pEflWebkit->GetWebEvasObject();
590         }
591
592         return null;
593 }
594
595
596 WebSetting*
597 _Web::GetSetting(void) const
598 {
599         return __pWebSetting.get();
600 }
601
602
603 result
604 _Web::OnAttaching(const _Control* pParent)
605 {
606         if (__pEflWebkit.get())
607         {
608                 evas_object_show(__pEflWebkit->GetWebEvasObject());
609                 evas_object_focus_set(__pEflWebkit->GetWebEvasObject(), EINA_TRUE);
610         }
611
612         return E_SUCCESS;
613 }
614
615
616 result
617 _Web::OnBoundsChanging(const Rectangle& bounds)
618 {
619         Rectangle absoluteBounds = GetAbsoluteBounds();
620         Rectangle webBounds = GetBounds();
621         _ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetTransformer();
622         SysTryReturnResult(NID_WEB_CTRL, pXformer, E_SYSTEM, "[%s] A system error has been occurred. Failed to get coordinate transformer.", GetErrorMessage(E_SYSTEM));
623
624         if (__pEflWebkit.get())
625         {
626                 evas_object_move(__pEflWebkit->GetWebEvasObject(), pXformer->TransformHorizontal(absoluteBounds.x - webBounds.x + bounds.x), pXformer->TransformVertical(absoluteBounds.y - webBounds.y + bounds.y));
627                 evas_object_resize(__pEflWebkit->GetWebEvasObject(), pXformer->TransformHorizontal(bounds.width), pXformer->TransformVertical(bounds.height));
628         }
629
630         return E_SUCCESS;
631 }
632
633
634 void
635 _Web::ChangeGesture(_WebGestureType type)
636 {
637         switch (type)
638         {
639         case WEB_GESTURE_TYPE_TAP:
640                 __pGestureHandler = __pTapGestureHandler.get();
641                 __gestureType = WEB_GESTURE_TYPE_TAP;
642                 break;
643
644         case WEB_GESTURE_TYPE_PANNING:
645                 __pGestureHandler = __pPanningGestureHandler.get();
646                 __gestureType = WEB_GESTURE_TYPE_PANNING;
647                 break;
648
649         case WEB_GESTURE_TYPE_FLICK:
650                 __pGestureHandler = __pFlickGestureHandler.get();
651                 __gestureType = WEB_GESTURE_TYPE_FLICK;
652                 break;
653
654         case WEB_GESTURE_TYPE_PINCH:
655                 __pGestureHandler = __pPinchGestureHandler.get();
656                 __gestureType = WEB_GESTURE_TYPE_PINCH;
657                 break;
658
659         default:
660                 SysAssert(false);
661         }
662 }
663
664
665 void
666 _Web::SetEdgeReachedEvent(_WebEdgeType type)
667 {
668         __edgeType |= type;
669
670         switch(type)
671         {
672         case WEB_EDGE_LEFT:
673                 __edgeType &= ~WEB_EDGE_RIGHT;
674                 break;
675
676         case WEB_EDGE_RIGHT:
677                 __edgeType &= ~WEB_EDGE_LEFT;
678                 break;
679
680         case WEB_EDGE_TOP:
681                 __edgeType &= ~WEB_EDGE_BOTTOM;
682                 break;
683
684         case WEB_EDGE_BOTTOM:
685                 __edgeType &= ~WEB_EDGE_TOP;
686                 break;
687
688         default:
689                 SysAssert(false);
690         }
691 }
692
693
694 bool
695 _Web::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
696 {
697         if (__pEflWebkit.get())
698         {
699                 __edgeType = WEB_EDGE_NONE;
700                 __previousTouchedPosition = touchInfo.GetCurrentPosition();
701
702                 SendTouchEventForJavaScript(touchInfo);
703
704                 return __pGestureHandler->OnTouchPressed(source, touchInfo);
705         }
706
707         return false;
708 }
709
710
711 bool
712 _Web::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
713 {
714         if (__pEflWebkit.get())
715         {
716                 if (__gestureType == WEB_GESTURE_TYPE_TAP)
717                 {
718                         __pPanningGestureHandler->InitializeTextSelectionStatus();
719                 }
720
721                 SendTouchEventForJavaScript(touchInfo);
722
723                 __pGestureHandler->OnTouchMoved(source, touchInfo);
724
725                 float scrollDistanceX = __previousTouchedPosition.x - touchInfo.GetCurrentPosition().x;
726                 float scrollDistanceY = __previousTouchedPosition.y - touchInfo.GetCurrentPosition().y;
727                 __previousTouchedPosition = touchInfo.GetCurrentPosition();
728
729                 if (__edgeType !=  WEB_EDGE_NONE && __gestureType == WEB_GESTURE_TYPE_PANNING)
730                 {
731                         if (_Abs(scrollDistanceY) < _Abs(scrollDistanceX))
732                         {
733                                 if  (__edgeType & WEB_EDGE_LEFT)
734                                 {
735                                         if (scrollDistanceX < 0)
736                                         {
737                                                 __edgeType &= ~WEB_EDGE_RIGHT;
738
739                                                 return false;
740                                         }
741                                         else
742                                         {
743                                                 __edgeType &= ~WEB_EDGE_LEFT;
744                                         }
745                                 }
746                                 else if  (__edgeType & WEB_EDGE_RIGHT)
747                                 {
748                                         if (scrollDistanceX > 0)
749                                         {
750                                                 __edgeType &= ~WEB_EDGE_LEFT;
751
752                                                 return false;
753                                         }
754                                         else
755                                         {
756                                                 __edgeType &= ~WEB_EDGE_RIGHT;
757                                         }
758                                 }
759                         }
760                         else if (_Abs(scrollDistanceY) > _Abs(scrollDistanceX))
761                         {
762                                 if  (__edgeType & WEB_EDGE_TOP)
763                                 {
764                                         if (scrollDistanceY < 0)
765                                         {
766                                                 __edgeType &= ~WEB_EDGE_BOTTOM;
767
768                                                 return false;
769                                         }
770                                         else
771                                         {
772                                                 __edgeType &= ~WEB_EDGE_TOP;
773                                         }
774                                 }
775                                 else if  (__edgeType & WEB_EDGE_BOTTOM)
776                                 {
777                                         if (scrollDistanceY > 0)
778                                         {
779                                                 __edgeType &= ~WEB_EDGE_TOP;
780
781                                                 return false;
782                                         }
783                                         else
784                                         {
785                                                 __edgeType &= ~WEB_EDGE_BOTTOM;
786                                         }
787                                 }
788                         }
789                 }
790
791                 return true;
792         }
793
794         return false;
795 }
796
797
798 bool
799 _Web::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
800 {
801         SetFocused();
802
803         if (__pEflWebkit.get())
804         {
805                 SendTouchEventForJavaScript(touchInfo);
806
807                 return __pGestureHandler->OnTouchReleased(source, touchInfo);
808         }
809
810         return false;
811 }
812
813
814 bool
815 _Web::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
816 {
817         if (__pEflWebkit.get())
818         {
819                 SendTouchEventForJavaScript(touchInfo);
820
821                 return __pGestureHandler->OnTouchCanceled(source, touchInfo);
822         }
823
824         return false;
825 }
826
827
828 void
829 _Web::OnTouchPressHandled(const _Control& control)
830 {
831 }
832
833
834 void
835 _Web::OnTouchReleaseHandled(const _Control& control)
836 {
837 }
838
839
840 void
841 _Web::OnTouchMoveHandled(const _Control& control)
842 {
843 }
844
845
846 void
847 _Web::OnTouchCancelHandled(const _Control& control)
848 {
849 }
850
851
852 bool
853 _Web::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
854 {
855         if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_TAP)
856         {
857                 return __pTapGestureHandler->OnLongPressGestureDetected(gesture);
858         }
859
860         return true;
861 }
862
863
864 bool
865 _Web::OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
866 {
867         return true;
868 }
869
870
871 bool
872 _Web::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
873 {
874         if (__pEflWebkit.get())
875         {
876                 return __pTapGestureHandler->OnTapGestureDetected(gesture);
877         }
878
879         return true;
880 }
881
882
883 bool
884 _Web::OnTapGestureCanceled(_TouchTapGestureDetector& gesture)
885 {
886         return true;
887 }
888
889
890 bool
891 _Web::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
892 {
893         if (__pEflWebkit.get() && _WebSettingImpl::GetInstance(__pWebSetting.get())->IsScrollEnabled())
894         {
895                 return __pFlickGestureHandler->OnFlickGestureDetected(gesture);
896         }
897
898         return true;
899 }
900
901
902 bool
903 _Web::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
904 {
905         return true;
906 }
907
908
909 bool
910 _Web::OnPinchGestureStarted(Tizen::Ui::_TouchPinchGestureDetector& gesture)
911 {
912         if (__pEflWebkit.get())
913         {
914                 return __pPinchGestureHandler->OnPinchGestureStarted(gesture);
915         }
916
917         return true;
918 }
919
920
921 bool
922 _Web::OnPinchGestureChanged(Tizen::Ui::_TouchPinchGestureDetector& gesture)
923 {
924         if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_PINCH)
925         {
926                 return __pPinchGestureHandler->OnPinchGestureChanged(gesture);
927         }
928
929         return true;
930 }
931
932
933 bool
934 _Web::OnPinchGestureFinished(Tizen::Ui::_TouchPinchGestureDetector& gesture)
935 {
936         if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_PINCH)
937         {
938                 return __pPinchGestureHandler->OnPinchGestureFinished(gesture);
939         }
940
941         return true;
942 }
943
944
945 bool
946 _Web::OnPinchGestureCanceled(Tizen::Ui::_TouchPinchGestureDetector& gesture)
947 {
948         return true;
949 }
950
951
952 Canvas*
953 _Web::OnCanvasRequestedN(const FloatRectangle& bounds)
954 {
955         SysTryReturn(NID_WEB_CTRL, bounds.width >= 0.0f && bounds.height >= 0.0f, null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Canvas size is out of range. size = (%f, %f)", bounds.width, bounds.height);
956         if (bounds.width == 0.0f || bounds.height == 0.0f)
957         {
958                 FloatDimension size(GetSizeF());
959                 SysTryReturn(NID_WEB_CTRL, bounds.x >= 0.0f && bounds.y >= 0.0f && bounds.x <= size.width && bounds.y <= size.height, null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Bounds is out of range.");
960         }
961
962         result r = E_SUCCESS;
963
964         Rectangle absBounds(_CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::Transform(bounds)));
965
966         Eina_Rectangle rect;
967         EINA_RECTANGLE_SET(&rect, absBounds.x, absBounds.y, absBounds.width, absBounds.height);
968
969         Evas_Object* pWebFrame = GetWebNativeNode();
970         Evas_Object* pScreenShot = ewk_view_screenshot_contents_get(pWebFrame, rect, 1.0f, evas_object_evas_get(pWebFrame));
971
972         std::unique_ptr<Canvas> pCanvas(new (std::nothrow) Canvas());
973         SysTryReturn(NID_WEB_CTRL, pCanvas.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
974
975         if (pScreenShot)
976         {
977                 BufferInfo bufferInfo;
978
979                 r = _Utility::GetPixelBufferFromEvasObject(pScreenShot, bufferInfo);
980                 evas_object_del(pScreenShot);
981                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
982
983                 r = pCanvas->Construct(bufferInfo);
984                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
985         }
986         else
987         {
988                 r = pCanvas->Construct(bounds);
989                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
990         }
991
992         return pCanvas.release();
993 }
994
995
996 Bitmap*
997 _Web::OnCapturedBitmapRequestedN(void)
998 {
999         result r = E_SUCCESS;
1000
1001         BufferInfo bufferInfo;
1002         SysTryReturn(NID_WEB_CTRL, OnCaptureAcquire(bufferInfo), null, E_SYSTEM, "[%s] A system error has been occurred. Failed to get snapshot of Web control", GetErrorMessage(E_SYSTEM));
1003
1004         ByteBuffer buffer;
1005         int bufferSize = bufferInfo.bitsPerPixel * bufferInfo.width * bufferInfo.height;
1006
1007         r = buffer.Construct(reinterpret_cast < byte* >(bufferInfo.pPixels), 0, bufferSize, bufferSize);
1008         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1009
1010         std::unique_ptr<Bitmap> pBitmap(new (std::nothrow) Bitmap());
1011         SysTryReturn(NID_WEB_CTRL, pBitmap.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1012
1013         r = pBitmap->Construct(buffer, Dimension(bufferInfo.width, bufferInfo.height), BITMAP_PIXEL_FORMAT_ARGB8888);
1014         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1015
1016         return pBitmap.release();
1017 }
1018
1019
1020 bool
1021 _Web::OnCaptureAcquire(BufferInfo& output)
1022 {
1023         result r = E_SUCCESS;
1024
1025         FloatPoint position(GetPositionF());
1026         FloatDimension size(GetSizeF());
1027
1028         Dimension absSize(_CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::Transform(size)));
1029
1030         Eina_Rectangle rect;
1031         EINA_RECTANGLE_SET(&rect, 0, 0, absSize.width, absSize.height);
1032
1033         Evas_Object* pWebFrame = GetWebNativeNode();
1034         Evas_Object* pScreenShot = ewk_view_screenshot_contents_get(pWebFrame, rect, 1.0f, evas_object_evas_get(pWebFrame));
1035         SysTryReturn(NID_WEB_CTRL, pScreenShot, false, E_SYSTEM, "[%s] A system error has been occurred. Failed to get snapshot of Web control", GetErrorMessage(E_SYSTEM));
1036
1037         r = _Utility::GetPixelBufferFromEvasObject(pScreenShot, output);
1038         evas_object_del(pScreenShot);
1039         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] propagating", GetErrorMessage(r));
1040
1041         return true;
1042 }
1043
1044
1045 void
1046 _Web::SendTouchEventForJavaScript(const _TouchInfo& touchInfo)
1047 {
1048         result r = E_SUCCESS;
1049
1050         _TouchManager* pTouchManager = _TouchManager::GetInstance();
1051         SysAssertf(pTouchManager, "Failed to get touch manager.");
1052
1053         std::unique_ptr<IListT<_FingerInfo*> > pTouchList(pTouchManager->GetMultiFingerInfoListN());
1054         SysTryReturnVoidResult(NID_WEB_CTRL, pTouchList.get(), GetLastResult(), "[%s] Failed to get touch list.", GetErrorMessage(GetLastResult()));
1055
1056         std::unique_ptr<IBidirectionalEnumeratorT<_FingerInfo*> > pTouchListEnum(pTouchList->GetBidirectionalEnumeratorN());
1057         SysAssertf(pTouchListEnum.get() != null, "Failed to get enumerator of touch list.");
1058
1059         Eina_List* pPointList = null;
1060         _FingerInfo* pFingerInfo = null;
1061         while(pTouchListEnum->MoveNext() == E_SUCCESS)
1062         {
1063                 r = pTouchListEnum->GetCurrent(pFingerInfo);
1064                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1065
1066                 _TouchStatus state = pFingerInfo->GetStatus();
1067                 if(state == _TOUCH_PRESSED || state == _TOUCH_MOVED || state == _TOUCH_RELEASED || state == _TOUCH_CANCELED)
1068                 {
1069                         Point integerPoint(_CoordinateSystemUtils::ConvertToInteger(GetAbsoluteCoordinate(pFingerInfo->GetPoint())));
1070
1071                         Ewk_Touch_Point* pPoint = static_cast<Ewk_Touch_Point*>(calloc(1, sizeof(Ewk_Touch_Point)));
1072                         pPoint->id = pFingerInfo->GetPointId();
1073                         pPoint->x = integerPoint.x;
1074                         pPoint->y = integerPoint.y;
1075                         pPoint->state = GetEvasTouchState((TouchStatus)pFingerInfo->GetStatus());
1076                         SysSecureLog(NID_WEB_CTRL, "The current value of id is %lu, x is %d, y is %d, state is %d", pPoint->id, pPoint->x, pPoint->y, pPoint->state);
1077
1078                         pPointList = eina_list_append(pPointList, pPoint);
1079                 }
1080         }
1081
1082         ewk_view_feed_touch_event(__pEflWebkit->GetWebEvasObject(), GetEwkTouchEvent(touchInfo.GetTouchStatus()), pPointList, null);
1083
1084         void* pData = null;
1085         EINA_LIST_FREE(pPointList, pData)
1086         free(pData);
1087 }
1088
1089
1090 Ewk_Touch_Event_Type
1091 _Web::GetEwkTouchEvent(_TouchStatus touchStatus)
1092 {
1093         Ewk_Touch_Event_Type ewkTouchEvent = EWK_TOUCH_CANCEL;
1094
1095         switch (touchStatus)
1096         {
1097         case _TOUCH_PRESSED :
1098                 ewkTouchEvent = EWK_TOUCH_START;
1099                 break;
1100         case _TOUCH_MOVED :
1101                 ewkTouchEvent = EWK_TOUCH_MOVE;
1102                 break;
1103         case _TOUCH_RELEASED :
1104                 ewkTouchEvent = EWK_TOUCH_END;
1105                 break;
1106         case _TOUCH_CANCELED :
1107                 //fall through
1108         default :
1109                 ewkTouchEvent = EWK_TOUCH_CANCEL;
1110                 break;
1111         }
1112
1113         return ewkTouchEvent;
1114 }
1115
1116
1117 Evas_Touch_Point_State
1118 _Web::GetEvasTouchState(TouchStatus touchStatus)
1119 {
1120         Evas_Touch_Point_State evasTouchState = EVAS_TOUCH_POINT_CANCEL;
1121
1122         switch (touchStatus)
1123         {
1124         case TOUCH_PRESSED :
1125                 evasTouchState = EVAS_TOUCH_POINT_DOWN;
1126                 break;
1127         case TOUCH_MOVED :
1128                 evasTouchState = EVAS_TOUCH_POINT_MOVE;
1129                 break;
1130         case TOUCH_RELEASED :
1131                 evasTouchState = EVAS_TOUCH_POINT_UP;
1132                 break;
1133         case TOUCH_CANCELED :
1134                 //fall through
1135         default :
1136                 evasTouchState = EVAS_TOUCH_POINT_CANCEL;
1137                 //todo : mapping    EVAS_TOUCH_POINT_STILL, /**< Touch point is not moved af
1138                 break;
1139         }
1140
1141         return evasTouchState;
1142 }
1143
1144
1145 }}} // Tizen::Web::Controls