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