44a558611c852aa7a42b3ae92d58eb13c4a3da25
[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         , __focus(false)
344         , __pTextElement(null)
345         , __previousTouchedPosition(0.0f, 0.0f)
346 {
347         SetBackgroundColor(Color(0, 0, 0, 0));
348 }
349
350
351 _Web::~_Web(void)
352 {
353         RemoveGestureListener();
354 }
355
356
357 _Web*
358 _Web::CreateWebN(void)
359 {
360         result r = E_SUCCESS;
361
362         std::unique_ptr<_Web> pWeb(new (std::nothrow) _Web());
363         SysTryReturn(NID_WEB_CTRL, pWeb.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
364
365         pWeb->__pWebSetting = std::unique_ptr<WebSetting>(new (std::nothrow) WebSetting());
366         SysTryReturn(NID_WEB_CTRL, pWeb->__pWebSetting.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
367
368         pWeb->AcquireHandle();
369         pWeb->SetMultiTouchEnabled(true);
370         pWeb->SetTouchPressThreshold(0.08);
371
372         r = pWeb->AddGestureListeners();
373         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
374
375         r = pWeb->InitializeGestureStates();
376         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
377
378         return pWeb.release();
379 }
380
381
382 result
383 _Web::CreateWebkitEvasObject(void)
384 {
385         result r = E_SUCCESS;
386
387         std::unique_ptr<_EflWebkit> pEflWebkit(new (std::nothrow) _EflWebkit());
388         SysTryReturnResult(NID_WEB_CTRL, pEflWebkit.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
389
390         _VisualElement* pVe = GetVisualElement();
391         r = pEflWebkit->Construct(GetAbsoluteBounds(), *pVe, this);
392         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
393
394         _VisualElementImpl* pVeImpl = _VisualElementImpl::GetInstance(*pVe);
395         pVeImpl->SetCaptureProvider(this);
396
397         __pEflWebkit = std::move(pEflWebkit);
398
399         Evas_Object* pView = GetWebNativeNode();
400         evas_object_smart_callback_add(pView, "edge,left", OnEdgeLeft, this);
401         evas_object_smart_callback_add(pView, "edge,right", OnEdgeRight, this);
402         evas_object_smart_callback_add(pView, "edge,top", OnEdgeTop, this);
403         evas_object_smart_callback_add(pView, "edge,bottom", OnEdgeBottom, this);
404
405         return E_SUCCESS;
406 }
407
408
409 result
410 _Web::InitializeGestureStates(void)
411 {
412         __pPinchGestureHandler = std::unique_ptr<_PinchGestureState>(new (std::nothrow) _PinchGestureState(this));
413         SysTryReturnResult(NID_WEB_CTRL, __pPinchGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
414
415         __pTapGestureHandler = std::unique_ptr<_TapGestureState>(new (std::nothrow) _TapGestureState(this));
416         SysTryReturnResult(NID_WEB_CTRL, __pTapGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
417
418         __pPanningGestureHandler = std::unique_ptr<_PanningGestureState>(new (std::nothrow) _PanningGestureState(this));
419         SysTryReturnResult(NID_WEB_CTRL, __pPanningGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
420
421         __pFlickGestureHandler = std::unique_ptr<_FlickGestureState>(new (std::nothrow) _FlickGestureState(this));
422         SysTryReturnResult(NID_WEB_CTRL, __pFlickGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
423
424         __pGestureHandler = __pTapGestureHandler.get();
425
426         return E_SUCCESS;
427 }
428
429
430 result
431 _Web::AddGestureListeners(void)
432 {
433         result r = E_SUCCESS;
434
435         std::unique_ptr<_TouchFlickGestureDetector> pGestureFlick(new (std::nothrow) _TouchFlickGestureDetector());
436         SysTryReturnResult(NID_WEB_CTRL, pGestureFlick.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
437
438         r = pGestureFlick->AddGestureListener(*this);
439         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
440
441         r = AddGestureDetector(*pGestureFlick.get());
442         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
443
444         __pGestureFlick = std::move(pGestureFlick);
445
446         std::unique_ptr<_TouchLongPressGestureDetector> pGestureLongPress(new (std::nothrow) _TouchLongPressGestureDetector());
447         SysTryReturnResult(NID_WEB_CTRL, pGestureLongPress.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
448
449         r = pGestureLongPress->AddGestureListener(*this);
450         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
451
452         r = AddGestureDetector(*pGestureLongPress.get());
453         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
454
455         __pGestureLongPress = std::move(pGestureLongPress);
456
457         std::unique_ptr<_TouchTapGestureDetector> pGestureDoubleTap(new (std::nothrow) _TouchTapGestureDetector());
458         SysTryReturnResult(NID_WEB_CTRL, pGestureDoubleTap.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
459
460         r = pGestureDoubleTap->AddGestureListener(*this);
461         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
462
463         r = AddGestureDetector(*pGestureDoubleTap.get());
464         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
465
466         __pGestureDoubleTap = std::move(pGestureDoubleTap);
467
468         std::unique_ptr<_TouchPinchGestureDetector> pGesturePinch(new (std::nothrow) _TouchPinchGestureDetector());
469         SysTryReturnResult(NID_WEB_CTRL, pGesturePinch.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
470
471         r = pGesturePinch->AddGestureListener(*this);
472         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
473
474         r = AddGestureDetector(*pGesturePinch.get());
475         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
476
477         __pGesturePinch = std::move(pGesturePinch);
478
479         return E_SUCCESS;
480 }
481
482
483 void
484 _Web::RemoveGestureListener(void)
485 {
486         if (__pGestureFlick.get())
487         {
488                 __pGestureFlick->RemoveGestureListener(*this);
489                 RemoveGestureDetector(*__pGestureFlick);
490         }
491
492         if (__pGestureLongPress.get())
493         {
494                 __pGestureLongPress->RemoveGestureListener(*this);
495                 RemoveGestureDetector(*__pGestureLongPress);
496         }
497
498         if (__pGestureDoubleTap.get())
499         {
500                 __pGestureDoubleTap->RemoveGestureListener(*this);
501                 RemoveGestureDetector(*__pGestureDoubleTap);
502         }
503
504         if (__pGesturePinch.get())
505         {
506                 __pGesturePinch->RemoveGestureListener(*this);
507                 RemoveGestureDetector(*__pGesturePinch);
508         }
509
510         Evas_Object* pView = GetWebNativeNode();
511         if (pView)
512         {
513                 evas_object_smart_callback_del(pView, "edge,left", OnEdgeLeft);
514                 evas_object_smart_callback_del(pView, "edge,right", OnEdgeRight);
515                 evas_object_smart_callback_del(pView, "edge,top", OnEdgeTop);
516                 evas_object_smart_callback_del(pView, "edge,bottom", OnEdgeBottom);
517         }
518 }
519
520
521 result
522 _Web::InitializeWebNativeNode(void)
523 {
524         result r = E_SUCCESS;
525
526         r = CreateWebkitEvasObject();
527         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
528
529         SetNativeObjectFocusable(false);
530
531         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
532         SysTryReturn(NID_WEB_CTRL, pContainer, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(E_SYSTEM));
533
534         __pTextElement = new (std::nothrow) _AccessibilityElement(true);
535         SysTryReturn(NID_WEB_CTRL, __pTextElement, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
536
537         __pTextElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
538         __pTextElement->SetLabel(L"Web control");
539
540         pContainer->AddElement(*__pTextElement);
541         pContainer->Activate(true);
542
543         _WebAccessibilityListener* pListener = new (std::nothrow) _WebAccessibilityListener(GetWebNativeNode());
544         SysTryReturn(NID_WEB_CTRL, pListener, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
545
546         pContainer->AddListener(*dynamic_cast<_IAccessibilityListener*>(pListener));
547
548         _WebAccessibilityFocusHandler* pFocusHandler = new (std::nothrow) _WebAccessibilityFocusHandler(GetWebNativeNode());
549         SysTryReturn(NID_WEB_CTRL, pFocusHandler, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
550
551         pContainer->SetFocusHandler(dynamic_cast<_IAccessibilityFocusHandler*>(pFocusHandler));
552
553         return E_SUCCESS;
554 }
555
556
557 Point
558 _Web::GetAbsoluteCoordinate(Point relativePoint)
559 {
560         return _CoordinateSystemUtils::Transform(ConvertToScreenPosition(relativePoint));
561 }
562
563
564 FloatPoint
565 _Web::GetAbsoluteCoordinate(FloatPoint relativePoint)
566 {
567         return _CoordinateSystemUtils::Transform(ConvertToScreenPosition(relativePoint));
568 }
569
570
571 Point
572 _Web::GetRelativeCoordinate(Point absolutePoint)
573 {
574         return ConvertToControlPosition(_CoordinateSystemUtils::InverseTransform(absolutePoint));
575 }
576
577
578 FloatPoint
579 _Web::GetRelativeCoordinate(FloatPoint absolutePoint)
580 {
581         return ConvertToControlPosition(_CoordinateSystemUtils::InverseTransform(absolutePoint));
582 }
583
584
585 Evas_Object*
586 _Web::GetWebNativeNode(void)
587 {
588         if (__pEflWebkit.get())
589         {
590                 return __pEflWebkit->GetWebEvasObject();
591         }
592
593         return null;
594 }
595
596
597 WebSetting*
598 _Web::GetSetting(void) const
599 {
600         return __pWebSetting.get();
601 }
602
603
604 result
605 _Web::OnAttaching(const _Control* pParent)
606 {
607         if (__pEflWebkit.get())
608         {
609                 evas_object_show(__pEflWebkit->GetWebEvasObject());
610                 evas_object_focus_set(__pEflWebkit->GetWebEvasObject(), EINA_TRUE);
611         }
612
613         return E_SUCCESS;
614 }
615
616
617 result
618 _Web::OnBoundsChanging(const Rectangle& bounds)
619 {
620         Rectangle absoluteBounds = GetAbsoluteBounds();
621         Rectangle webBounds = GetBounds();
622         _ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetTransformer();
623         SysTryReturnResult(NID_WEB_CTRL, pXformer, E_SYSTEM, "[%s] A system error has been occurred. Failed to get coordinate transformer.", GetErrorMessage(E_SYSTEM));
624
625         if (__pEflWebkit.get())
626         {
627                 evas_object_move(__pEflWebkit->GetWebEvasObject(), pXformer->TransformHorizontal(absoluteBounds.x - webBounds.x + bounds.x), pXformer->TransformVertical(absoluteBounds.y - webBounds.y + bounds.y));
628                 evas_object_resize(__pEflWebkit->GetWebEvasObject(), pXformer->TransformHorizontal(bounds.width), pXformer->TransformVertical(bounds.height));
629         }
630
631         return E_SUCCESS;
632 }
633
634
635 void
636 _Web::ChangeGesture(_WebGestureType type)
637 {
638         switch (type)
639         {
640         case WEB_GESTURE_TYPE_TAP:
641                 __pGestureHandler = __pTapGestureHandler.get();
642                 __gestureType = WEB_GESTURE_TYPE_TAP;
643                 break;
644
645         case WEB_GESTURE_TYPE_PANNING:
646                 __pGestureHandler = __pPanningGestureHandler.get();
647                 __gestureType = WEB_GESTURE_TYPE_PANNING;
648                 break;
649
650         case WEB_GESTURE_TYPE_FLICK:
651                 __pGestureHandler = __pFlickGestureHandler.get();
652                 __gestureType = WEB_GESTURE_TYPE_FLICK;
653                 break;
654
655         case WEB_GESTURE_TYPE_PINCH:
656                 __pGestureHandler = __pPinchGestureHandler.get();
657                 __gestureType = WEB_GESTURE_TYPE_PINCH;
658                 break;
659
660         default:
661                 SysAssert(false);
662         }
663 }
664
665
666 void
667 _Web::SetEdgeReachedEvent(_WebEdgeType type)
668 {
669         __edgeType |= type;
670
671         switch(type)
672         {
673         case WEB_EDGE_LEFT:
674                 __edgeType &= ~WEB_EDGE_RIGHT;
675                 break;
676
677         case WEB_EDGE_RIGHT:
678                 __edgeType &= ~WEB_EDGE_LEFT;
679                 break;
680
681         case WEB_EDGE_TOP:
682                 __edgeType &= ~WEB_EDGE_BOTTOM;
683                 break;
684
685         case WEB_EDGE_BOTTOM:
686                 __edgeType &= ~WEB_EDGE_TOP;
687                 break;
688
689         default:
690                 SysAssert(false);
691         }
692 }
693
694
695 void
696 _Web::SetFocusEnd(bool focus)
697 {
698         __focus = focus;
699 }
700
701
702 bool
703 _Web::IsFocusEnd(void)
704 {
705         return __focus;
706 }
707
708
709 bool
710 _Web::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
711 {
712         _KeyCode keyCode = keyInfo.GetKeyCode();
713
714         if (IsFocusEnd() == true)
715         {
716                 SetFocusEnd(false);
717                 evas_object_focus_set(GetWebNativeNode(), EINA_FALSE);
718                 return false;
719         }
720
721         switch(keyCode)
722         {
723         case _KEY_UP:
724         case _KEY_DOWN:
725                 evas_object_focus_set(GetWebNativeNode(), EINA_FALSE);
726                 return false;
727                 break;
728         default:
729                 break;
730         }
731
732         evas_object_focus_set(GetWebNativeNode(), EINA_TRUE);
733
734         return true;
735 }
736
737
738 bool
739 _Web::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
740 {
741         return false;
742 }
743
744
745 void
746 _Web::OnDrawFocus(void)
747 {
748 }
749
750
751 bool
752 _Web::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
753 {
754         if (__pEflWebkit.get())
755         {
756                 __edgeType = WEB_EDGE_NONE;
757                 __previousTouchedPosition = touchInfo.GetCurrentPosition();
758
759                 SendTouchEventForJavaScript(touchInfo);
760
761                 return __pGestureHandler->OnTouchPressed(source, touchInfo);
762         }
763
764         return false;
765 }
766
767
768 bool
769 _Web::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
770 {
771         if (__pEflWebkit.get())
772         {
773                 if (__gestureType == WEB_GESTURE_TYPE_TAP)
774                 {
775                         __pPanningGestureHandler->InitializeTextSelectionStatus();
776                 }
777
778                 SendTouchEventForJavaScript(touchInfo);
779
780                 __pGestureHandler->OnTouchMoved(source, touchInfo);
781
782                 float scrollDistanceX = __previousTouchedPosition.x - touchInfo.GetCurrentPosition().x;
783                 float scrollDistanceY = __previousTouchedPosition.y - touchInfo.GetCurrentPosition().y;
784                 __previousTouchedPosition = touchInfo.GetCurrentPosition();
785
786                 if (__edgeType !=  WEB_EDGE_NONE && __gestureType == WEB_GESTURE_TYPE_PANNING)
787                 {
788                         if (_Abs(scrollDistanceY) < _Abs(scrollDistanceX))
789                         {
790                                 if  (__edgeType & WEB_EDGE_LEFT)
791                                 {
792                                         if (scrollDistanceX < 0)
793                                         {
794                                                 __edgeType &= ~WEB_EDGE_RIGHT;
795
796                                                 return false;
797                                         }
798                                         else
799                                         {
800                                                 __edgeType &= ~WEB_EDGE_LEFT;
801                                         }
802                                 }
803                                 else if  (__edgeType & WEB_EDGE_RIGHT)
804                                 {
805                                         if (scrollDistanceX > 0)
806                                         {
807                                                 __edgeType &= ~WEB_EDGE_LEFT;
808
809                                                 return false;
810                                         }
811                                         else
812                                         {
813                                                 __edgeType &= ~WEB_EDGE_RIGHT;
814                                         }
815                                 }
816                         }
817                         else if (_Abs(scrollDistanceY) > _Abs(scrollDistanceX))
818                         {
819                                 if  (__edgeType & WEB_EDGE_TOP)
820                                 {
821                                         if (scrollDistanceY < 0)
822                                         {
823                                                 __edgeType &= ~WEB_EDGE_BOTTOM;
824
825                                                 return false;
826                                         }
827                                         else
828                                         {
829                                                 __edgeType &= ~WEB_EDGE_TOP;
830                                         }
831                                 }
832                                 else if  (__edgeType & WEB_EDGE_BOTTOM)
833                                 {
834                                         if (scrollDistanceY > 0)
835                                         {
836                                                 __edgeType &= ~WEB_EDGE_TOP;
837
838                                                 return false;
839                                         }
840                                         else
841                                         {
842                                                 __edgeType &= ~WEB_EDGE_BOTTOM;
843                                         }
844                                 }
845                         }
846                 }
847
848                 return true;
849         }
850
851         return false;
852 }
853
854
855 bool
856 _Web::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
857 {
858         SetFocused();
859
860         if (__pEflWebkit.get())
861         {
862                 SendTouchEventForJavaScript(touchInfo);
863
864                 return __pGestureHandler->OnTouchReleased(source, touchInfo);
865         }
866
867         return false;
868 }
869
870
871 bool
872 _Web::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
873 {
874         if (__pEflWebkit.get())
875         {
876                 SendTouchEventForJavaScript(touchInfo);
877
878                 return __pGestureHandler->OnTouchCanceled(source, touchInfo);
879         }
880
881         return false;
882 }
883
884
885 void
886 _Web::OnTouchPressHandled(const _Control& control)
887 {
888 }
889
890
891 void
892 _Web::OnTouchReleaseHandled(const _Control& control)
893 {
894 }
895
896
897 void
898 _Web::OnTouchMoveHandled(const _Control& control)
899 {
900 }
901
902
903 void
904 _Web::OnTouchCancelHandled(const _Control& control)
905 {
906 }
907
908
909 bool
910 _Web::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
911 {
912         if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_TAP)
913         {
914                 return __pTapGestureHandler->OnLongPressGestureDetected(gesture);
915         }
916
917         return true;
918 }
919
920
921 bool
922 _Web::OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
923 {
924         return true;
925 }
926
927
928 bool
929 _Web::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
930 {
931         if (__pEflWebkit.get())
932         {
933                 return __pTapGestureHandler->OnTapGestureDetected(gesture);
934         }
935
936         return true;
937 }
938
939
940 bool
941 _Web::OnTapGestureCanceled(_TouchTapGestureDetector& gesture)
942 {
943         return true;
944 }
945
946
947 bool
948 _Web::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
949 {
950         if (__pEflWebkit.get() && _WebSettingImpl::GetInstance(__pWebSetting.get())->IsScrollEnabled())
951         {
952                 return __pFlickGestureHandler->OnFlickGestureDetected(gesture);
953         }
954
955         return true;
956 }
957
958
959 bool
960 _Web::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
961 {
962         return true;
963 }
964
965
966 bool
967 _Web::OnPinchGestureStarted(Tizen::Ui::_TouchPinchGestureDetector& gesture)
968 {
969         if (__pEflWebkit.get())
970         {
971                 return __pPinchGestureHandler->OnPinchGestureStarted(gesture);
972         }
973
974         return true;
975 }
976
977
978 bool
979 _Web::OnPinchGestureChanged(Tizen::Ui::_TouchPinchGestureDetector& gesture)
980 {
981         if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_PINCH)
982         {
983                 return __pPinchGestureHandler->OnPinchGestureChanged(gesture);
984         }
985
986         return true;
987 }
988
989
990 bool
991 _Web::OnPinchGestureFinished(Tizen::Ui::_TouchPinchGestureDetector& gesture)
992 {
993         if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_PINCH)
994         {
995                 return __pPinchGestureHandler->OnPinchGestureFinished(gesture);
996         }
997
998         return true;
999 }
1000
1001
1002 bool
1003 _Web::OnPinchGestureCanceled(Tizen::Ui::_TouchPinchGestureDetector& gesture)
1004 {
1005         return true;
1006 }
1007
1008
1009 Canvas*
1010 _Web::OnCanvasRequestedN(const FloatRectangle& bounds)
1011 {
1012         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);
1013         if (bounds.width == 0.0f || bounds.height == 0.0f)
1014         {
1015                 FloatDimension size(GetSizeF());
1016                 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.");
1017         }
1018
1019         result r = E_SUCCESS;
1020
1021         Rectangle absBounds(_CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::Transform(bounds)));
1022
1023         Eina_Rectangle rect;
1024         EINA_RECTANGLE_SET(&rect, absBounds.x, absBounds.y, absBounds.width, absBounds.height);
1025
1026         Evas_Object* pWebFrame = GetWebNativeNode();
1027         Evas_Object* pScreenShot = ewk_view_screenshot_contents_get(pWebFrame, rect, 1.0f, evas_object_evas_get(pWebFrame));
1028
1029         std::unique_ptr<Canvas> pCanvas(new (std::nothrow) Canvas());
1030         SysTryReturn(NID_WEB_CTRL, pCanvas.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1031
1032         if (pScreenShot)
1033         {
1034                 BufferInfo bufferInfo;
1035
1036                 r = _Utility::GetPixelBufferFromEvasObject(pScreenShot, bufferInfo);
1037                 evas_object_del(pScreenShot);
1038                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1039
1040                 r = pCanvas->Construct(bufferInfo);
1041                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1042         }
1043         else
1044         {
1045                 r = pCanvas->Construct(bounds);
1046                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1047         }
1048
1049         return pCanvas.release();
1050 }
1051
1052
1053 Bitmap*
1054 _Web::OnCapturedBitmapRequestedN(void)
1055 {
1056         result r = E_SUCCESS;
1057
1058         BufferInfo bufferInfo;
1059         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));
1060
1061         ByteBuffer buffer;
1062         int bufferSize = bufferInfo.bitsPerPixel * bufferInfo.width * bufferInfo.height;
1063
1064         r = buffer.Construct(reinterpret_cast < byte* >(bufferInfo.pPixels), 0, bufferSize, bufferSize);
1065         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1066
1067         std::unique_ptr<Bitmap> pBitmap(new (std::nothrow) Bitmap());
1068         SysTryReturn(NID_WEB_CTRL, pBitmap.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1069
1070         r = pBitmap->Construct(buffer, Dimension(bufferInfo.width, bufferInfo.height), BITMAP_PIXEL_FORMAT_ARGB8888);
1071         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1072
1073         return pBitmap.release();
1074 }
1075
1076
1077 bool
1078 _Web::OnCaptureAcquire(BufferInfo& output)
1079 {
1080         result r = E_SUCCESS;
1081
1082         FloatPoint position(GetPositionF());
1083         FloatDimension size(GetSizeF());
1084
1085         Dimension absSize(_CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::Transform(size)));
1086
1087         Eina_Rectangle rect;
1088         EINA_RECTANGLE_SET(&rect, 0, 0, absSize.width, absSize.height);
1089
1090         Evas_Object* pWebFrame = GetWebNativeNode();
1091         Evas_Object* pScreenShot = ewk_view_screenshot_contents_get(pWebFrame, rect, 1.0f, evas_object_evas_get(pWebFrame));
1092         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));
1093
1094         r = _Utility::GetPixelBufferFromEvasObject(pScreenShot, output);
1095         evas_object_del(pScreenShot);
1096         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] propagating", GetErrorMessage(r));
1097
1098         return true;
1099 }
1100
1101
1102 void
1103 _Web::SendTouchEventForJavaScript(const _TouchInfo& touchInfo)
1104 {
1105         result r = E_SUCCESS;
1106
1107         _TouchManager* pTouchManager = _TouchManager::GetInstance();
1108         SysAssertf(pTouchManager, "Failed to get touch manager.");
1109
1110         std::unique_ptr<IListT<_FingerInfo*> > pTouchList(pTouchManager->GetMultiFingerInfoListN());
1111         SysTryReturnVoidResult(NID_WEB_CTRL, pTouchList.get(), GetLastResult(), "[%s] Failed to get touch list.", GetErrorMessage(GetLastResult()));
1112
1113         std::unique_ptr<IBidirectionalEnumeratorT<_FingerInfo*> > pTouchListEnum(pTouchList->GetBidirectionalEnumeratorN());
1114         SysAssertf(pTouchListEnum.get() != null, "Failed to get enumerator of touch list.");
1115
1116         Eina_List* pPointList = null;
1117         _FingerInfo* pFingerInfo = null;
1118         while(pTouchListEnum->MoveNext() == E_SUCCESS)
1119         {
1120                 r = pTouchListEnum->GetCurrent(pFingerInfo);
1121                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1122
1123                 _TouchStatus state = pFingerInfo->GetStatus();
1124                 if(state == _TOUCH_PRESSED || state == _TOUCH_MOVED || state == _TOUCH_RELEASED || state == _TOUCH_CANCELED)
1125                 {
1126                         Point integerPoint(_CoordinateSystemUtils::ConvertToInteger(GetAbsoluteCoordinate(pFingerInfo->GetPoint())));
1127
1128                         Ewk_Touch_Point* pPoint = static_cast<Ewk_Touch_Point*>(calloc(1, sizeof(Ewk_Touch_Point)));
1129                         pPoint->id = pFingerInfo->GetPointId();
1130                         pPoint->x = integerPoint.x;
1131                         pPoint->y = integerPoint.y;
1132                         pPoint->state = GetEvasTouchState((TouchStatus)pFingerInfo->GetStatus());
1133                         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);
1134
1135                         pPointList = eina_list_append(pPointList, pPoint);
1136                 }
1137         }
1138
1139         ewk_view_feed_touch_event(__pEflWebkit->GetWebEvasObject(), GetEwkTouchEvent(touchInfo.GetTouchStatus()), pPointList, null);
1140
1141         void* pData = null;
1142         EINA_LIST_FREE(pPointList, pData)
1143         free(pData);
1144 }
1145
1146
1147 Ewk_Touch_Event_Type
1148 _Web::GetEwkTouchEvent(_TouchStatus touchStatus)
1149 {
1150         Ewk_Touch_Event_Type ewkTouchEvent = EWK_TOUCH_CANCEL;
1151
1152         switch (touchStatus)
1153         {
1154         case _TOUCH_PRESSED :
1155                 ewkTouchEvent = EWK_TOUCH_START;
1156                 break;
1157         case _TOUCH_MOVED :
1158                 ewkTouchEvent = EWK_TOUCH_MOVE;
1159                 break;
1160         case _TOUCH_RELEASED :
1161                 ewkTouchEvent = EWK_TOUCH_END;
1162                 break;
1163         case _TOUCH_CANCELED :
1164                 //fall through
1165         default :
1166                 ewkTouchEvent = EWK_TOUCH_CANCEL;
1167                 break;
1168         }
1169
1170         return ewkTouchEvent;
1171 }
1172
1173
1174 Evas_Touch_Point_State
1175 _Web::GetEvasTouchState(TouchStatus touchStatus)
1176 {
1177         Evas_Touch_Point_State evasTouchState = EVAS_TOUCH_POINT_CANCEL;
1178
1179         switch (touchStatus)
1180         {
1181         case TOUCH_PRESSED :
1182                 evasTouchState = EVAS_TOUCH_POINT_DOWN;
1183                 break;
1184         case TOUCH_MOVED :
1185                 evasTouchState = EVAS_TOUCH_POINT_MOVE;
1186                 break;
1187         case TOUCH_RELEASED :
1188                 evasTouchState = EVAS_TOUCH_POINT_UP;
1189                 break;
1190         case TOUCH_CANCELED :
1191                 //fall through
1192         default :
1193                 evasTouchState = EVAS_TOUCH_POINT_CANCEL;
1194                 //todo : mapping    EVAS_TOUCH_POINT_STILL, /**< Touch point is not moved af
1195                 break;
1196         }
1197
1198         return evasTouchState;
1199 }
1200
1201
1202 }}} // Tizen::Web::Controls