Init Tizen 2.2.1
[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 Tizen { namespace Web { namespace Controls
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 void
284 OnEdgeLeft(void* pUserData, Evas_Object* pView, void* pEventInfo)
285 {
286         _Web* pCore = reinterpret_cast< _Web* >(pUserData);
287         SysAssertf(pCore, "Failed to request");
288
289         pCore->SetEdgeReachedEvent(WEB_EDGE_LEFT);
290 }
291
292
293 void
294 OnEdgeRight(void* pUserData, Evas_Object* pView, void* pEventInfo)
295 {
296         _Web* pCore = reinterpret_cast< _Web* >(pUserData);
297         SysAssertf(pCore, "Failed to request");
298
299         pCore->SetEdgeReachedEvent(WEB_EDGE_RIGHT);
300 }
301
302
303 void
304 OnEdgeTop(void* pUserData, Evas_Object* pView, void* pEventInfo)
305 {
306         _Web* pCore = reinterpret_cast< _Web* >(pUserData);
307         SysAssertf(pCore, "Failed to request");
308
309         pCore->SetEdgeReachedEvent(WEB_EDGE_TOP);
310 }
311
312
313 void
314 OnEdgeBottom(void* pUserData, Evas_Object* pView, void* pEventInfo)
315 {
316         _Web* pCore = reinterpret_cast< _Web* >(pUserData);
317         SysAssertf(pCore, "Failed to request");
318
319         pCore->SetEdgeReachedEvent(WEB_EDGE_BOTTOM);
320 }
321
322
323 _Web::_Web(void)
324         : __pGestureHandler(null)
325         , __pEflWebkit(null)
326         , __pWebSetting(null)
327         , __pGestureFlick(null)
328         , __pGestureLongPress(null)
329         , __pGesturePinch(null)
330         , __pGestureDoubleTap(null)
331         , __pTouchEventInfoList(null)
332         , __pTapGestureHandler(null)
333         , __pPanningGestureHandler(null)
334         , __pFlickGestureHandler(null)
335         , __pPinchGestureHandler(null)
336         , __pWebAccessibilityListener(null)
337         , __pWebAccessibilityFocusHandler(null)
338         , __gestureType(WEB_GESTURE_TYPE_TAP)
339         , __edgeType(WEB_EDGE_NONE)
340         , __focus(false)
341         , __pTextElement(null)
342         , __previousTouchedPosition(0.0f, 0.0f)
343         , __isFullScreenEntered(false)
344         , __isRotated(false)
345         , __touchPressed(false)
346 {
347         SetBackgroundColor(Color(0, 0, 0, 0));
348 }
349
350
351 _Web::~_Web(void)
352 {
353         RemoveGestureListener();
354
355         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
356         if (pContainer)
357         {
358                 pContainer->RemoveListener(*dynamic_cast<_IAccessibilityListener*>(__pWebAccessibilityListener.get()));
359                 pContainer->SetFocusHandler(null);
360         }
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         return pWeb.release();
386 }
387
388
389 result
390 _Web::CreateWebkitEvasObject(void)
391 {
392         result r = E_SUCCESS;
393
394         std::unique_ptr<_EflWebkit> pEflWebkit(new (std::nothrow) _EflWebkit());
395         SysTryReturnResult(NID_WEB_CTRL, pEflWebkit.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
396
397         _VisualElement* pVe = GetVisualElement();
398         r = pEflWebkit->Construct(GetAbsoluteBounds(), *pVe, this);
399         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
400
401         _VisualElementImpl* pVeImpl = _VisualElementImpl::GetInstance(*pVe);
402         pVeImpl->SetCaptureProvider(this);
403
404         __pEflWebkit = std::move(pEflWebkit);
405
406         Evas_Object* pView = GetWebNativeNode();
407         evas_object_smart_callback_add(pView, "edge,left", OnEdgeLeft, this);
408         evas_object_smart_callback_add(pView, "edge,right", OnEdgeRight, this);
409         evas_object_smart_callback_add(pView, "edge,top", OnEdgeTop, this);
410         evas_object_smart_callback_add(pView, "edge,bottom", OnEdgeBottom, this);
411
412         return E_SUCCESS;
413 }
414
415
416 result
417 _Web::InitializeGestureStates(void)
418 {
419         __pPinchGestureHandler = std::unique_ptr<_PinchGestureState>(new (std::nothrow) _PinchGestureState(this));
420         SysTryReturnResult(NID_WEB_CTRL, __pPinchGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
421
422         __pTapGestureHandler = std::unique_ptr<_TapGestureState>(new (std::nothrow) _TapGestureState(this));
423         SysTryReturnResult(NID_WEB_CTRL, __pTapGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
424
425         __pPanningGestureHandler = std::unique_ptr<_PanningGestureState>(new (std::nothrow) _PanningGestureState(this));
426         SysTryReturnResult(NID_WEB_CTRL, __pPanningGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
427
428         __pFlickGestureHandler = std::unique_ptr<_FlickGestureState>(new (std::nothrow) _FlickGestureState(this));
429         SysTryReturnResult(NID_WEB_CTRL, __pFlickGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
430
431         __pGestureHandler = __pTapGestureHandler.get();
432
433         return E_SUCCESS;
434 }
435
436
437 result
438 _Web::AddGestureListeners(void)
439 {
440         result r = E_SUCCESS;
441
442         std::unique_ptr<_TouchFlickGestureDetector> pGestureFlick(new (std::nothrow) _TouchFlickGestureDetector());
443         SysTryReturnResult(NID_WEB_CTRL, pGestureFlick.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
444
445         r = pGestureFlick->AddGestureListener(*this);
446         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
447
448         r = AddGestureDetector(*pGestureFlick.get());
449         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
450
451         __pGestureFlick = std::move(pGestureFlick);
452
453         std::unique_ptr<_TouchLongPressGestureDetector> pGestureLongPress(new (std::nothrow) _TouchLongPressGestureDetector());
454         SysTryReturnResult(NID_WEB_CTRL, pGestureLongPress.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
455
456         r = pGestureLongPress->AddGestureListener(*this);
457         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
458
459         r = AddGestureDetector(*pGestureLongPress.get());
460         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
461
462         __pGestureLongPress = std::move(pGestureLongPress);
463
464         std::unique_ptr<_TouchTapGestureDetector> pGestureDoubleTap(new (std::nothrow) _TouchTapGestureDetector());
465         SysTryReturnResult(NID_WEB_CTRL, pGestureDoubleTap.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
466
467         r = pGestureDoubleTap->AddGestureListener(*this);
468         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
469
470         r = AddGestureDetector(*pGestureDoubleTap.get());
471         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
472
473         __pGestureDoubleTap = std::move(pGestureDoubleTap);
474
475         std::unique_ptr<_TouchPinchGestureDetector> pGesturePinch(new (std::nothrow) _TouchPinchGestureDetector());
476         SysTryReturnResult(NID_WEB_CTRL, pGesturePinch.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
477
478         r = pGesturePinch->AddGestureListener(*this);
479         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
480
481         r = AddGestureDetector(*pGesturePinch.get());
482         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
483
484         __pGesturePinch = std::move(pGesturePinch);
485
486         return E_SUCCESS;
487 }
488
489
490 void
491 _Web::RemoveGestureListener(void)
492 {
493         if (__pGestureFlick.get())
494         {
495                 __pGestureFlick->RemoveGestureListener(*this);
496                 RemoveGestureDetector(*__pGestureFlick);
497         }
498
499         if (__pGestureLongPress.get())
500         {
501                 __pGestureLongPress->RemoveGestureListener(*this);
502                 RemoveGestureDetector(*__pGestureLongPress);
503         }
504
505         if (__pGestureDoubleTap.get())
506         {
507                 __pGestureDoubleTap->RemoveGestureListener(*this);
508                 RemoveGestureDetector(*__pGestureDoubleTap);
509         }
510
511         if (__pGesturePinch.get())
512         {
513                 __pGesturePinch->RemoveGestureListener(*this);
514                 RemoveGestureDetector(*__pGesturePinch);
515         }
516
517         Evas_Object* pView = GetWebNativeNode();
518         if (pView)
519         {
520                 evas_object_smart_callback_del(pView, "edge,left", OnEdgeLeft);
521                 evas_object_smart_callback_del(pView, "edge,right", OnEdgeRight);
522                 evas_object_smart_callback_del(pView, "edge,top", OnEdgeTop);
523                 evas_object_smart_callback_del(pView, "edge,bottom", OnEdgeBottom);
524         }
525 }
526
527
528 result
529 _Web::InitializeWebNativeNode(void)
530 {
531         result r = E_SUCCESS;
532
533         r = CreateWebkitEvasObject();
534         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
535
536         SetNativeObjectFocusable(false);
537
538         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
539         SysTryReturn(NID_WEB_CTRL, pContainer, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(E_SYSTEM));
540
541         __pTextElement = new (std::nothrow) _AccessibilityElement(true);
542         SysTryReturn(NID_WEB_CTRL, __pTextElement, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
543
544         __pTextElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
545         __pTextElement->SetLabel(L"Web control");
546
547         pContainer->AddElement(*__pTextElement);
548         pContainer->Activate(true);
549
550         std::unique_ptr<_WebAccessibilityListener> pListener(new (std::nothrow) _WebAccessibilityListener(GetWebNativeNode()));
551         SysTryReturn(NID_WEB_CTRL, pListener, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
552
553         __pWebAccessibilityListener = std::move(pListener);
554
555         pContainer->AddListener(*dynamic_cast<_IAccessibilityListener*>(__pWebAccessibilityListener.get()));
556
557         std::unique_ptr<_WebAccessibilityFocusHandler> pFocusHandler(new (std::nothrow) _WebAccessibilityFocusHandler(GetWebNativeNode()));
558         SysTryReturn(NID_WEB_CTRL, pFocusHandler, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
559
560         __pWebAccessibilityFocusHandler = std::move(pFocusHandler);
561
562         pContainer->SetFocusHandler(dynamic_cast<_IAccessibilityFocusHandler*>(__pWebAccessibilityFocusHandler.get()));
563
564         return E_SUCCESS;
565 }
566
567
568 Point
569 _Web::GetAbsoluteCoordinate(Point relativePoint)
570 {
571         return _CoordinateSystemUtils::Transform(ConvertToScreenPosition(relativePoint));
572 }
573
574
575 FloatPoint
576 _Web::GetAbsoluteCoordinate(FloatPoint relativePoint)
577 {
578         return _CoordinateSystemUtils::Transform(ConvertToScreenPosition(relativePoint));
579 }
580
581
582 Point
583 _Web::GetRelativeCoordinate(Point absolutePoint)
584 {
585         return ConvertToControlPosition(_CoordinateSystemUtils::InverseTransform(absolutePoint));
586 }
587
588
589 FloatPoint
590 _Web::GetRelativeCoordinate(FloatPoint absolutePoint)
591 {
592         return ConvertToControlPosition(_CoordinateSystemUtils::InverseTransform(absolutePoint));
593 }
594
595
596 Evas_Object*
597 _Web::GetWebNativeNode(void)
598 {
599         if (__pEflWebkit.get())
600         {
601                 return __pEflWebkit->GetWebEvasObject();
602         }
603
604         return null;
605 }
606
607
608 WebSetting*
609 _Web::GetSetting(void) const
610 {
611         return __pWebSetting.get();
612 }
613
614
615 _EflWebkit*
616 _Web::GetEflWebkit(void) const
617 {
618         return __pEflWebkit.get();
619 }
620
621
622 FloatPoint
623 _Web::GetTouchPosition(void) const
624 {
625         return __previousTouchedPosition;
626 }
627
628
629 result
630 _Web::OnAttaching(const _Control* pParent)
631 {
632         if (__pEflWebkit.get())
633         {
634                 evas_object_show(__pEflWebkit->GetWebEvasObject());
635                 evas_object_focus_set(__pEflWebkit->GetWebEvasObject(), EINA_TRUE);
636         }
637
638         return E_SUCCESS;
639 }
640
641
642 result
643 _Web::OnBoundsChanging(const Rectangle& bounds)
644 {
645         Rectangle absoluteBounds = GetAbsoluteBounds();
646         Rectangle webBounds = GetBounds();
647         _ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetTransformer();
648         SysTryReturnResult(NID_WEB_CTRL, pXformer, E_SYSTEM, "[%s] A system error has been occurred. Failed to get coordinate transformer.", GetErrorMessage(E_SYSTEM));
649
650         if (__pEflWebkit.get() && __isRotated == false)
651         {
652                 evas_object_move(__pEflWebkit->GetWebEvasObject(), pXformer->TransformHorizontal(absoluteBounds.x - webBounds.x + bounds.x), pXformer->TransformVertical(absoluteBounds.y - webBounds.y + bounds.y));
653                 evas_object_resize(__pEflWebkit->GetWebEvasObject(), pXformer->TransformHorizontal(bounds.width), pXformer->TransformVertical(bounds.height));
654         }
655
656         return E_SUCCESS;
657 }
658
659
660 void
661 _Web::OnBoundsChanged(void)
662 {
663         __isRotated = false;
664 }
665
666
667 void
668 _Web::OnChangeLayout(_ControlOrientation orientation)
669 {
670         __isRotated = true;
671 }
672
673
674 void
675 _Web::ChangeGesture(_WebGestureType type)
676 {
677         switch (type)
678         {
679         case WEB_GESTURE_TYPE_TAP:
680                 __pGestureHandler = __pTapGestureHandler.get();
681                 __gestureType = WEB_GESTURE_TYPE_TAP;
682                 break;
683
684         case WEB_GESTURE_TYPE_PANNING:
685                 __pGestureHandler = __pPanningGestureHandler.get();
686                 __gestureType = WEB_GESTURE_TYPE_PANNING;
687                 break;
688
689         case WEB_GESTURE_TYPE_FLICK:
690                 __pGestureHandler = __pFlickGestureHandler.get();
691                 __gestureType = WEB_GESTURE_TYPE_FLICK;
692                 break;
693
694         case WEB_GESTURE_TYPE_PINCH:
695                 __pGestureHandler = __pPinchGestureHandler.get();
696                 __gestureType = WEB_GESTURE_TYPE_PINCH;
697                 break;
698
699         default:
700                 SysAssert(false);
701         }
702 }
703
704
705 void
706 _Web::SetEdgeReachedEvent(_WebEdgeType type)
707 {
708         __edgeType |= type;
709
710         switch(type)
711         {
712         case WEB_EDGE_LEFT:
713                 __edgeType &= ~WEB_EDGE_RIGHT;
714                 break;
715
716         case WEB_EDGE_RIGHT:
717                 __edgeType &= ~WEB_EDGE_LEFT;
718                 break;
719
720         case WEB_EDGE_TOP:
721                 __edgeType &= ~WEB_EDGE_BOTTOM;
722                 break;
723
724         case WEB_EDGE_BOTTOM:
725                 __edgeType &= ~WEB_EDGE_TOP;
726                 break;
727
728         default:
729                 SysAssert(false);
730         }
731 }
732
733
734 bool
735 _Web::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
736 {
737         __touchPressed = true;
738
739         if (__pEflWebkit.get())
740         {
741                 __edgeType = WEB_EDGE_NONE;
742                 __previousTouchedPosition = touchInfo.GetCurrentPosition();
743
744                 SendTouchEventForJavaScript(touchInfo);
745
746                 return __pGestureHandler->OnTouchPressed(source, touchInfo);
747         }
748
749         return false;
750 }
751
752
753 bool
754 _Web::CanOutOfEdgeLeft(float scrollDistanceX, int pageDistance)
755 {
756         if (scrollDistanceX < 0.0f)
757         {
758                 __edgeType &= ~WEB_EDGE_RIGHT;
759
760                 return false;
761         }
762         else if (scrollDistanceX > 0.0f && pageDistance != 0)
763         {
764                 __edgeType &= ~WEB_EDGE_LEFT;
765         }
766
767         return true;
768 }
769
770
771 bool
772 _Web::CanOutOfEdgeRight(float scrollDistanceX, int pageDistance)
773 {
774         if (scrollDistanceX > 0.0f)
775         {
776                 __edgeType &= ~WEB_EDGE_LEFT;
777
778                 return false;
779         }
780         else if (scrollDistanceX < 0.0f &&  pageDistance != 0)
781         {
782                 __edgeType &= ~WEB_EDGE_RIGHT;
783         }
784
785         return true;
786 }
787
788
789 bool
790 _Web::CanOutOfEdgeTop(float scrollDistanceY, int pageDistance)
791 {
792         if (scrollDistanceY < 0.0f)
793         {
794                 __edgeType &= ~WEB_EDGE_BOTTOM;
795
796                 return false;
797         }
798         else if (scrollDistanceY > 0.0f && pageDistance != 0)
799         {
800                 __edgeType &= ~WEB_EDGE_TOP;
801         }
802
803         return true;
804 }
805
806
807 bool
808 _Web::CanOutOfEdgeBottom(float scrollDistanceY, int pageDistance)
809 {
810         if (scrollDistanceY > 0.0f)
811         {
812                 __edgeType &= ~WEB_EDGE_TOP;
813
814                 return false;
815         }
816         else if (scrollDistanceY < 0.0f && pageDistance != 0)
817         {
818                 __edgeType &= ~WEB_EDGE_BOTTOM;
819         }
820
821         return true;
822 }
823
824
825 bool
826 _Web::CanConsumeTouchMoved(float scrollDistanceX, float scrollDistanceY)
827 {
828         if (__edgeType ==  WEB_EDGE_NONE)
829         {
830                 return true;
831         }
832
833         bool ret = true;
834
835         int scrollWidth = 0;
836         int scrollHeight = 0;
837         ewk_view_scroll_size_get(GetWebNativeNode(), &scrollWidth, &scrollHeight);
838
839         int scrollX = 0;
840         int scrollY = 0;
841         ewk_view_scroll_pos_get(GetWebNativeNode(), &scrollX, &scrollY);
842
843         if (scrollWidth == 0)
844         {
845                 if (__edgeType & WEB_EDGE_TOP)
846                 {
847                         if (!CanOutOfEdgeTop(scrollDistanceY, scrollY - 0))
848                         {
849                                 return false;
850                         }
851                 }
852                 else if (__edgeType & WEB_EDGE_BOTTOM)
853                 {
854                         if (!CanOutOfEdgeBottom(scrollDistanceY, scrollY - scrollHeight))
855                         {
856                                 return false;
857                         }
858                 }
859         }
860
861         if (scrollHeight == 0)
862         {
863                 if (__edgeType & WEB_EDGE_LEFT)
864                 {
865                         if (!CanOutOfEdgeLeft(scrollDistanceX, scrollX - 0))
866                         {
867                                 return false;
868                         }
869                 }
870                 else if  (__edgeType & WEB_EDGE_RIGHT)
871                 {
872                         if (!CanOutOfEdgeRight(scrollDistanceX, scrollX - scrollWidth))
873                         {
874                                 return false;
875                         }
876                 }
877         }
878
879         if (scrollWidth > 0 && scrollHeight > 0)
880         {
881                 if  ((__edgeType & WEB_EDGE_LEFT) && (__edgeType & WEB_EDGE_TOP))
882                 {
883                         if (!CanOutOfEdgeLeft(scrollDistanceX, scrollX - 0) || !CanOutOfEdgeTop(scrollDistanceY, scrollY - 0))
884                         {
885                                 return false;
886                         }
887                 }
888                 else if  ((__edgeType & WEB_EDGE_LEFT) && (__edgeType & WEB_EDGE_BOTTOM))
889                 {
890                         if (!CanOutOfEdgeLeft(scrollDistanceX, scrollX - 0) || !CanOutOfEdgeBottom(scrollDistanceY, scrollY - scrollHeight))
891                         {
892                                 return false;
893                         }
894                 }
895                 else if  ((__edgeType & WEB_EDGE_RIGHT) && (__edgeType & WEB_EDGE_TOP))
896                 {
897                         if (!CanOutOfEdgeRight(scrollDistanceX, scrollX - scrollWidth) || !CanOutOfEdgeTop(scrollDistanceY, scrollY - 0))
898                         {
899                                 return false;
900                         }
901                 }
902                 else if  ((__edgeType & WEB_EDGE_RIGHT) && (__edgeType & WEB_EDGE_BOTTOM))
903                 {
904                         if (!CanOutOfEdgeRight(scrollDistanceX, scrollX - scrollWidth) || !CanOutOfEdgeBottom(scrollDistanceY, scrollY - scrollHeight))
905                         {
906                                 return false;
907                         }
908                 }
909         }
910
911         return true;
912 }
913
914
915 bool
916 _Web::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
917 {
918         if (__pEflWebkit.get())
919         {
920                 SendTouchEventForJavaScript(touchInfo);
921
922                 float scrollDistanceX = __previousTouchedPosition.x - touchInfo.GetCurrentPosition().x;
923                 float scrollDistanceY = __previousTouchedPosition.y - touchInfo.GetCurrentPosition().y;
924                 __previousTouchedPosition = touchInfo.GetCurrentPosition();
925
926                 if (CanConsumeTouchMoved(scrollDistanceX, scrollDistanceY))
927                 {
928                         return __pGestureHandler->OnTouchMoved(source, touchInfo);
929                 }
930         }
931
932         return false;
933 }
934
935
936 bool
937 _Web::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
938 {
939         __touchPressed = false;
940
941         SetFocused();
942
943         if (__pEflWebkit.get())
944         {
945                 SendTouchEventForJavaScript(touchInfo);
946
947                 return __pGestureHandler->OnTouchReleased(source, touchInfo);
948         }
949
950         return false;
951 }
952
953
954 bool
955 _Web::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
956 {
957         if (__pEflWebkit.get())
958         {
959                 SendTouchEventForJavaScript(touchInfo);
960
961                 return __pGestureHandler->OnTouchCanceled(source, touchInfo);
962         }
963
964         return false;
965 }
966
967
968 bool
969 _Web::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
970 {
971         if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_TAP)
972         {
973                 return __pTapGestureHandler->OnLongPressGestureDetected(gesture);
974         }
975
976         return false;
977 }
978
979
980 bool
981 _Web::OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
982 {
983         return false;
984 }
985
986
987 bool
988 _Web::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
989 {
990         if (__pEflWebkit.get())
991         {
992                 return __pTapGestureHandler->OnTapGestureDetected(gesture);
993         }
994
995         return false;
996 }
997
998
999 bool
1000 _Web::OnTapGestureCanceled(_TouchTapGestureDetector& gesture)
1001 {
1002         return false;
1003 }
1004
1005
1006 bool
1007 _Web::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
1008 {
1009         if (__pEflWebkit.get())
1010         {
1011                 return __pFlickGestureHandler->OnFlickGestureDetected(gesture);
1012         }
1013
1014         return false;
1015 }
1016
1017
1018 bool
1019 _Web::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
1020 {
1021         return false;
1022 }
1023
1024
1025 bool
1026 _Web::OnPinchGestureStarted(Tizen::Ui::_TouchPinchGestureDetector& gesture)
1027 {
1028         if (__pEflWebkit.get())
1029         {
1030                 return __pPinchGestureHandler->OnPinchGestureStarted(gesture);
1031         }
1032
1033         return false;
1034 }
1035
1036
1037 bool
1038 _Web::OnPinchGestureChanged(Tizen::Ui::_TouchPinchGestureDetector& gesture)
1039 {
1040         if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_PINCH)
1041         {
1042                 return __pPinchGestureHandler->OnPinchGestureChanged(gesture);
1043         }
1044
1045         return false;
1046 }
1047
1048
1049 bool
1050 _Web::OnPinchGestureFinished(Tizen::Ui::_TouchPinchGestureDetector& gesture)
1051 {
1052         if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_PINCH)
1053         {
1054                 return __pPinchGestureHandler->OnPinchGestureFinished(gesture);
1055         }
1056
1057         return false;
1058 }
1059
1060
1061 bool
1062 _Web::OnPinchGestureCanceled(Tizen::Ui::_TouchPinchGestureDetector& gesture)
1063 {
1064         return false;
1065 }
1066
1067
1068 Canvas*
1069 _Web::OnCanvasRequestedN(const FloatRectangle& bounds)
1070 {
1071         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);
1072         if (bounds.width == 0.0f || bounds.height == 0.0f)
1073         {
1074                 FloatDimension size(GetSizeF());
1075                 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.");
1076         }
1077
1078         result r = E_SUCCESS;
1079
1080         Rectangle absBounds(_CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::Transform(bounds)));
1081
1082         Eina_Rectangle rect;
1083         EINA_RECTANGLE_SET(&rect, absBounds.x, absBounds.y, absBounds.width, absBounds.height);
1084
1085         Evas_Object* pWebFrame = GetWebNativeNode();
1086         Evas_Object* pScreenShot = ewk_view_screenshot_contents_get(pWebFrame, rect, 1.0f, evas_object_evas_get(pWebFrame));
1087
1088         std::unique_ptr<Canvas> pCanvas(new (std::nothrow) Canvas());
1089         SysTryReturn(NID_WEB_CTRL, pCanvas.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1090
1091         if (pScreenShot)
1092         {
1093                 BufferInfo bufferInfo;
1094
1095                 r = _Utility::GetPixelBufferFromEvasObject(pScreenShot, bufferInfo);
1096                 evas_object_del(pScreenShot);
1097                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1098
1099                 r = pCanvas->Construct(bufferInfo);
1100                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1101         }
1102         else
1103         {
1104                 r = pCanvas->Construct(bounds);
1105                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1106         }
1107
1108         return pCanvas.release();
1109 }
1110
1111
1112 Bitmap*
1113 _Web::OnCapturedBitmapRequestedN(void)
1114 {
1115         result r = E_SUCCESS;
1116
1117         BufferInfo bufferInfo;
1118         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));
1119
1120         ByteBuffer buffer;
1121         int bufferSize = bufferInfo.bitsPerPixel * bufferInfo.width * bufferInfo.height;
1122
1123         r = buffer.Construct(reinterpret_cast < byte* >(bufferInfo.pPixels), 0, bufferSize, bufferSize);
1124         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1125
1126         std::unique_ptr<Bitmap> pBitmap(new (std::nothrow) Bitmap());
1127         SysTryReturn(NID_WEB_CTRL, pBitmap.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1128
1129         r = pBitmap->Construct(buffer, Dimension(bufferInfo.width, bufferInfo.height), BITMAP_PIXEL_FORMAT_ARGB8888);
1130         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1131
1132         return pBitmap.release();
1133 }
1134
1135
1136 bool
1137 _Web::OnCaptureAcquire(BufferInfo& output)
1138 {
1139         result r = E_SUCCESS;
1140
1141         FloatPoint position(GetPositionF());
1142         FloatDimension size(GetSizeF());
1143
1144         Dimension absSize(_CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::Transform(size)));
1145
1146         Eina_Rectangle rect;
1147         EINA_RECTANGLE_SET(&rect, 0, 0, absSize.width, absSize.height);
1148
1149         Evas_Object* pWebFrame = GetWebNativeNode();
1150         Evas_Object* pScreenShot = ewk_view_screenshot_contents_get(pWebFrame, rect, 1.0f, evas_object_evas_get(pWebFrame));
1151         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));
1152
1153         r = _Utility::GetPixelBufferFromEvasObject(pScreenShot, output);
1154         evas_object_del(pScreenShot);
1155         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] propagating", GetErrorMessage(r));
1156
1157         return true;
1158 }
1159
1160
1161 void
1162 _Web::SendTouchEventForJavaScript(const _TouchInfo& touchInfo)
1163 {
1164         result r = E_SUCCESS;
1165
1166         _TouchManager* pTouchManager = _TouchManager::GetInstance();
1167         SysAssertf(pTouchManager, "Failed to get touch manager.");
1168
1169         std::unique_ptr<IListT<_FingerInfo*> > pTouchList(pTouchManager->GetMultiFingerInfoListN());
1170         SysTryReturnVoidResult(NID_WEB_CTRL, pTouchList.get(), GetLastResult(), "[%s] Failed to get touch list.", GetErrorMessage(GetLastResult()));
1171
1172         std::unique_ptr<IBidirectionalEnumeratorT<_FingerInfo*> > pTouchListEnum(pTouchList->GetBidirectionalEnumeratorN());
1173         SysAssertf(pTouchListEnum.get() != null, "Failed to get enumerator of touch list.");
1174
1175         Eina_List* pPointList = null;
1176         _FingerInfo* pFingerInfo = null;
1177         while(pTouchListEnum->MoveNext() == E_SUCCESS)
1178         {
1179                 r = pTouchListEnum->GetCurrent(pFingerInfo);
1180                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1181
1182                 _TouchStatus state = pFingerInfo->GetStatus();
1183                 if(state == _TOUCH_PRESSED || state == _TOUCH_MOVED || state == _TOUCH_RELEASED || state == _TOUCH_CANCELED)
1184                 {
1185                         Point integerPoint(_CoordinateSystemUtils::ConvertToInteger(GetAbsoluteCoordinate(pFingerInfo->GetPoint())));
1186
1187                         Ewk_Touch_Point* pPoint = static_cast<Ewk_Touch_Point*>(calloc(1, sizeof(Ewk_Touch_Point)));
1188                         pPoint->id = pFingerInfo->GetPointId();
1189                         pPoint->x = integerPoint.x;
1190                         pPoint->y = integerPoint.y;
1191                         pPoint->state = GetEvasTouchState((TouchStatus)pFingerInfo->GetStatus());
1192                         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);
1193
1194                         pPointList = eina_list_append(pPointList, pPoint);
1195                 }
1196         }
1197
1198         ewk_view_feed_touch_event(__pEflWebkit->GetWebEvasObject(), GetEwkTouchEvent(touchInfo.GetTouchStatus()), pPointList, null);
1199
1200         void* pData = null;
1201         EINA_LIST_FREE(pPointList, pData)
1202         free(pData);
1203 }
1204
1205
1206 Ewk_Touch_Event_Type
1207 _Web::GetEwkTouchEvent(_TouchStatus touchStatus)
1208 {
1209         Ewk_Touch_Event_Type ewkTouchEvent = EWK_TOUCH_CANCEL;
1210
1211         switch (touchStatus)
1212         {
1213         case _TOUCH_PRESSED :
1214                 ewkTouchEvent = EWK_TOUCH_START;
1215                 break;
1216         case _TOUCH_MOVED :
1217                 ewkTouchEvent = EWK_TOUCH_MOVE;
1218                 break;
1219         case _TOUCH_RELEASED :
1220                 ewkTouchEvent = EWK_TOUCH_END;
1221                 break;
1222         case _TOUCH_CANCELED :
1223                 //fall through
1224         default :
1225                 ewkTouchEvent = EWK_TOUCH_CANCEL;
1226                 break;
1227         }
1228
1229         return ewkTouchEvent;
1230 }
1231
1232
1233 Evas_Touch_Point_State
1234 _Web::GetEvasTouchState(TouchStatus touchStatus)
1235 {
1236         Evas_Touch_Point_State evasTouchState = EVAS_TOUCH_POINT_CANCEL;
1237
1238         switch (touchStatus)
1239         {
1240         case TOUCH_PRESSED :
1241                 evasTouchState = EVAS_TOUCH_POINT_DOWN;
1242                 break;
1243         case TOUCH_MOVED :
1244                 evasTouchState = EVAS_TOUCH_POINT_MOVE;
1245                 break;
1246         case TOUCH_RELEASED :
1247                 evasTouchState = EVAS_TOUCH_POINT_UP;
1248                 break;
1249         case TOUCH_CANCELED :
1250                 //fall through
1251         default :
1252                 evasTouchState = EVAS_TOUCH_POINT_CANCEL;
1253                 //todo : mapping    EVAS_TOUCH_POINT_STILL, /**< Touch point is not moved af
1254                 break;
1255         }
1256
1257         return evasTouchState;
1258 }
1259
1260
1261 void
1262 _Web::SetFullScreenEntered(bool isFullScreenEntered)
1263 {
1264         __isFullScreenEntered = isFullScreenEntered;
1265 }
1266
1267
1268 void
1269 _Web::SetFocusEnd(bool focus)
1270 {
1271         __focus = focus;
1272 }
1273
1274
1275 bool
1276 _Web::IsFocusEnd(void) const
1277 {
1278         return __focus;
1279 }
1280
1281
1282 bool
1283 _Web::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1284 {
1285         Ecore_X_Window rootWindow = ecore_x_window_root_first_get();
1286         Ecore_X_Atom keyboardExist = ecore_x_atom_get("X External Keyboard Exist");
1287         unsigned int keyboardNumber = 0;
1288         int ret = ecore_x_window_prop_card32_get(rootWindow, keyboardExist, &keyboardNumber, 1);
1289         if (keyboardNumber == 0)
1290         {
1291                 return false;
1292         }
1293
1294         _KeyCode keyCode = keyInfo.GetKeyCode();
1295
1296         if (IsFocusEnd() == true)
1297         {
1298                 SetFocusEnd(false);
1299                 evas_object_focus_set(GetWebNativeNode(), EINA_FALSE);
1300                 return false;
1301         }
1302
1303         switch(keyCode)
1304         {
1305         case _KEY_UP:
1306         case _KEY_DOWN:
1307                 evas_object_focus_set(GetWebNativeNode(), EINA_FALSE);
1308                 return false;
1309                 break;
1310         default:
1311                 break;
1312         }
1313
1314         evas_object_focus_set(GetWebNativeNode(), EINA_TRUE);
1315
1316         return true;
1317 }
1318
1319
1320 bool
1321 _Web::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1322 {
1323         if (__isFullScreenEntered)
1324         {
1325                 if (keyInfo.GetKeyCode() == _KEY_ESC || keyInfo.GetKeyCode() == _KEY_BACK)
1326                 {
1327                         __isFullScreenEntered = false;
1328
1329                         ewk_view_fullscreen_exit(GetWebNativeNode());
1330
1331                         return true;
1332                 }
1333         }
1334
1335         return false;
1336 }
1337
1338
1339 void
1340 _Web::OnDrawFocus(void)
1341 {
1342 }
1343
1344
1345 bool
1346 _Web::OnFocusLost(const _Control& source)
1347 {
1348         _Control::OnFocusLost(*this);
1349
1350         if (__touchPressed == true)
1351         {
1352                 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1353                 SysAssertf(pTouchManager, "Failed to get touch manager.");
1354
1355                 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(pTouchManager->GetPosition(pTouchManager->GetCurrentPointId())));
1356
1357                 Ewk_Touch_Point* pPoint = static_cast< Ewk_Touch_Point* >(calloc(1, sizeof(Ewk_Touch_Point)));
1358                 pPoint->id = 0;
1359                 pPoint->x = absPoint.x;
1360                 pPoint->y = absPoint.y;
1361                 pPoint->state = EVAS_TOUCH_POINT_CANCEL;
1362
1363                 Eina_List* pPointList = null;
1364                 pPointList = eina_list_append(pPointList, pPoint);
1365
1366                 ewk_view_feed_touch_event(GetWebNativeNode(), EWK_TOUCH_CANCEL, pPointList, null);
1367
1368                 void* pData = null;
1369                 EINA_LIST_FREE(pPointList, pData)
1370                 free(pData);
1371
1372                 __touchPressed = false;
1373         }
1374
1375         return false;
1376 }
1377
1378
1379 }}} // Tizen::Web::Controls