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