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