2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FWebCtrl_Web.cpp
20 * @brief The file contains the definition of _Web class.
22 * The file contains the definition of _Web class.
25 #include <Elementary.h>
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>
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"
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;
69 class _WebAccessibilityListener
70 : public Tizen::Ui::_IAccessibilityListener
73 _WebAccessibilityListener(Evas_Object* pView);
75 virtual ~_WebAccessibilityListener(void);
77 virtual bool OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element);
79 virtual bool OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element);
81 virtual bool OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element);
83 virtual bool OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element);
85 virtual bool OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element);
87 virtual bool OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element);
89 virtual bool OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element);
91 virtual bool OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element);
93 virtual bool OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element);
100 _WebAccessibilityListener::_WebAccessibilityListener(Evas_Object* pView)
106 _WebAccessibilityListener::~_WebAccessibilityListener(void)
112 _WebAccessibilityListener::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
119 _WebAccessibilityListener::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
126 _WebAccessibilityListener::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
133 _WebAccessibilityListener::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
140 _WebAccessibilityListener::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
147 _WebAccessibilityListener::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
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.");
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));
157 pActionInfo->action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
159 result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
167 _WebAccessibilityListener::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
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.");
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));
177 pActionInfo->action_type = ELM_ACCESS_ACTION_ACTIVATE;
179 result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
187 _WebAccessibilityListener::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
194 _WebAccessibilityListener::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
200 class _WebAccessibilityFocusHandler
201 : public Tizen::Ui::_IAccessibilityFocusHandler
204 _WebAccessibilityFocusHandler(Evas_Object* pView);
206 virtual ~_WebAccessibilityFocusHandler(void);
208 virtual bool OnMoveFocus(Tizen::Ui::_AccessibilityFocusDirection direction);
210 virtual bool OnMoveFocus(const Tizen::Graphics::Point& point);
213 Evas_Object* __pView;
217 _WebAccessibilityFocusHandler::_WebAccessibilityFocusHandler(Evas_Object* pView)
223 _WebAccessibilityFocusHandler::~_WebAccessibilityFocusHandler(void)
229 _WebAccessibilityFocusHandler::OnMoveFocus(Tizen::Ui::_AccessibilityFocusDirection direction)
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.");
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));
239 if (direction == Tizen::Ui::_ACCESSIBILITY_FOCUS_DIRECTION_PREVIOUS)
241 pActionInfo->action_type = ELM_ACCESS_ACTION_HIGHLIGHT;
243 pActionInfo->action_by = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
245 result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
247 else if (direction == Tizen::Ui::_ACCESSIBILITY_FOCUS_DIRECTION_NEXT)
249 pActionInfo->action_type = ELM_ACCESS_ACTION_HIGHLIGHT;
251 pActionInfo->action_by = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
253 result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
262 _WebAccessibilityFocusHandler::OnMoveFocus(const Tizen::Graphics::Point& point)
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.");
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));
272 pActionInfo->action_type = ELM_ACCESS_ACTION_READ;
273 pActionInfo->x = point.x;
274 pActionInfo->y = point.y;
276 result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
286 namespace Tizen { namespace Web { namespace Controls
291 OnEdgeLeft(void* pUserData, Evas_Object* pView, void* pEventInfo)
293 _Web* pCore = reinterpret_cast< _Web* >(pUserData);
294 SysAssertf(pCore, "Failed to request");
296 pCore->SetEdgeReachedEvent(WEB_EDGE_LEFT);
301 OnEdgeRight(void* pUserData, Evas_Object* pView, void* pEventInfo)
303 _Web* pCore = reinterpret_cast< _Web* >(pUserData);
304 SysAssertf(pCore, "Failed to request");
306 pCore->SetEdgeReachedEvent(WEB_EDGE_RIGHT);
311 OnEdgeTop(void* pUserData, Evas_Object* pView, void* pEventInfo)
313 _Web* pCore = reinterpret_cast< _Web* >(pUserData);
314 SysAssertf(pCore, "Failed to request");
316 pCore->SetEdgeReachedEvent(WEB_EDGE_TOP);
321 OnEdgeBottom(void* pUserData, Evas_Object* pView, void* pEventInfo)
323 _Web* pCore = reinterpret_cast< _Web* >(pUserData);
324 SysAssertf(pCore, "Failed to request");
326 pCore->SetEdgeReachedEvent(WEB_EDGE_BOTTOM);
331 : __pGestureHandler(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)
346 , __pTextElement(null)
347 , __previousTouchedPosition(0.0f, 0.0f)
348 , __isFullScreenEntered(false)
351 SetBackgroundColor(Color(0, 0, 0, 0));
357 RemoveGestureListener();
362 _Web::CreateWebN(void)
364 result r = E_SUCCESS;
366 std::unique_ptr<_Web> pWeb(new (std::nothrow) _Web());
367 SysTryReturn(NID_WEB_CTRL, pWeb.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
369 pWeb->__pWebSetting = std::unique_ptr<WebSetting>(new (std::nothrow) WebSetting());
370 SysTryReturn(NID_WEB_CTRL, pWeb->__pWebSetting.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
372 pWeb->AcquireHandle();
373 pWeb->SetMultiTouchEnabled(true);
374 pWeb->SetTouchPressThreshold(0.08);
376 r = pWeb->AddGestureListeners();
377 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
379 r = pWeb->InitializeGestureStates();
380 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
382 return pWeb.release();
387 _Web::CreateWebkitEvasObject(void)
389 result r = E_SUCCESS;
391 std::unique_ptr<_EflWebkit> pEflWebkit(new (std::nothrow) _EflWebkit());
392 SysTryReturnResult(NID_WEB_CTRL, pEflWebkit.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
394 _VisualElement* pVe = GetVisualElement();
395 r = pEflWebkit->Construct(GetAbsoluteBounds(), *pVe, this);
396 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
398 _VisualElementImpl* pVeImpl = _VisualElementImpl::GetInstance(*pVe);
399 pVeImpl->SetCaptureProvider(this);
401 __pEflWebkit = std::move(pEflWebkit);
403 Evas_Object* pView = GetWebNativeNode();
404 evas_object_smart_callback_add(pView, "edge,left", OnEdgeLeft, this);
405 evas_object_smart_callback_add(pView, "edge,right", OnEdgeRight, this);
406 evas_object_smart_callback_add(pView, "edge,top", OnEdgeTop, this);
407 evas_object_smart_callback_add(pView, "edge,bottom", OnEdgeBottom, this);
414 _Web::InitializeGestureStates(void)
416 __pPinchGestureHandler = std::unique_ptr<_PinchGestureState>(new (std::nothrow) _PinchGestureState(this));
417 SysTryReturnResult(NID_WEB_CTRL, __pPinchGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
419 __pTapGestureHandler = std::unique_ptr<_TapGestureState>(new (std::nothrow) _TapGestureState(this));
420 SysTryReturnResult(NID_WEB_CTRL, __pTapGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
422 __pPanningGestureHandler = std::unique_ptr<_PanningGestureState>(new (std::nothrow) _PanningGestureState(this));
423 SysTryReturnResult(NID_WEB_CTRL, __pPanningGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
425 __pFlickGestureHandler = std::unique_ptr<_FlickGestureState>(new (std::nothrow) _FlickGestureState(this));
426 SysTryReturnResult(NID_WEB_CTRL, __pFlickGestureHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
428 __pGestureHandler = __pTapGestureHandler.get();
435 _Web::AddGestureListeners(void)
437 result r = E_SUCCESS;
439 std::unique_ptr<_TouchFlickGestureDetector> pGestureFlick(new (std::nothrow) _TouchFlickGestureDetector());
440 SysTryReturnResult(NID_WEB_CTRL, pGestureFlick.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
442 r = pGestureFlick->AddGestureListener(*this);
443 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
445 r = AddGestureDetector(*pGestureFlick.get());
446 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
448 __pGestureFlick = std::move(pGestureFlick);
450 std::unique_ptr<_TouchLongPressGestureDetector> pGestureLongPress(new (std::nothrow) _TouchLongPressGestureDetector());
451 SysTryReturnResult(NID_WEB_CTRL, pGestureLongPress.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
453 r = pGestureLongPress->AddGestureListener(*this);
454 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
456 r = AddGestureDetector(*pGestureLongPress.get());
457 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
459 __pGestureLongPress = std::move(pGestureLongPress);
461 std::unique_ptr<_TouchTapGestureDetector> pGestureDoubleTap(new (std::nothrow) _TouchTapGestureDetector());
462 SysTryReturnResult(NID_WEB_CTRL, pGestureDoubleTap.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
464 r = pGestureDoubleTap->AddGestureListener(*this);
465 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
467 r = AddGestureDetector(*pGestureDoubleTap.get());
468 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
470 __pGestureDoubleTap = std::move(pGestureDoubleTap);
472 std::unique_ptr<_TouchPinchGestureDetector> pGesturePinch(new (std::nothrow) _TouchPinchGestureDetector());
473 SysTryReturnResult(NID_WEB_CTRL, pGesturePinch.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
475 r = pGesturePinch->AddGestureListener(*this);
476 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
478 r = AddGestureDetector(*pGesturePinch.get());
479 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
481 __pGesturePinch = std::move(pGesturePinch);
488 _Web::RemoveGestureListener(void)
490 if (__pGestureFlick.get())
492 __pGestureFlick->RemoveGestureListener(*this);
493 RemoveGestureDetector(*__pGestureFlick);
496 if (__pGestureLongPress.get())
498 __pGestureLongPress->RemoveGestureListener(*this);
499 RemoveGestureDetector(*__pGestureLongPress);
502 if (__pGestureDoubleTap.get())
504 __pGestureDoubleTap->RemoveGestureListener(*this);
505 RemoveGestureDetector(*__pGestureDoubleTap);
508 if (__pGesturePinch.get())
510 __pGesturePinch->RemoveGestureListener(*this);
511 RemoveGestureDetector(*__pGesturePinch);
514 Evas_Object* pView = GetWebNativeNode();
517 evas_object_smart_callback_del(pView, "edge,left", OnEdgeLeft);
518 evas_object_smart_callback_del(pView, "edge,right", OnEdgeRight);
519 evas_object_smart_callback_del(pView, "edge,top", OnEdgeTop);
520 evas_object_smart_callback_del(pView, "edge,bottom", OnEdgeBottom);
526 _Web::InitializeWebNativeNode(void)
528 result r = E_SUCCESS;
530 r = CreateWebkitEvasObject();
531 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
533 SetNativeObjectFocusable(false);
535 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
536 SysTryReturn(NID_WEB_CTRL, pContainer, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(E_SYSTEM));
538 __pTextElement = new (std::nothrow) _AccessibilityElement(true);
539 SysTryReturn(NID_WEB_CTRL, __pTextElement, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
541 __pTextElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
542 __pTextElement->SetLabel(L"Web control");
544 pContainer->AddElement(*__pTextElement);
545 pContainer->Activate(true);
547 _WebAccessibilityListener* pListener = new (std::nothrow) _WebAccessibilityListener(GetWebNativeNode());
548 SysTryReturn(NID_WEB_CTRL, pListener, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
550 pContainer->AddListener(*dynamic_cast<_IAccessibilityListener*>(pListener));
552 _WebAccessibilityFocusHandler* pFocusHandler = new (std::nothrow) _WebAccessibilityFocusHandler(GetWebNativeNode());
553 SysTryReturn(NID_WEB_CTRL, pFocusHandler, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
555 pContainer->SetFocusHandler(dynamic_cast<_IAccessibilityFocusHandler*>(pFocusHandler));
562 _Web::GetAbsoluteCoordinate(Point relativePoint)
564 return _CoordinateSystemUtils::Transform(ConvertToScreenPosition(relativePoint));
569 _Web::GetAbsoluteCoordinate(FloatPoint relativePoint)
571 return _CoordinateSystemUtils::Transform(ConvertToScreenPosition(relativePoint));
576 _Web::GetRelativeCoordinate(Point absolutePoint)
578 return ConvertToControlPosition(_CoordinateSystemUtils::InverseTransform(absolutePoint));
583 _Web::GetRelativeCoordinate(FloatPoint absolutePoint)
585 return ConvertToControlPosition(_CoordinateSystemUtils::InverseTransform(absolutePoint));
590 _Web::GetWebNativeNode(void)
592 if (__pEflWebkit.get())
594 return __pEflWebkit->GetWebEvasObject();
602 _Web::GetSetting(void) const
604 return __pWebSetting.get();
608 _Web::GetEflWebkit(void) const
610 return __pEflWebkit.get();
615 _Web::OnAttaching(const _Control* pParent)
617 if (__pEflWebkit.get())
619 evas_object_show(__pEflWebkit->GetWebEvasObject());
620 evas_object_focus_set(__pEflWebkit->GetWebEvasObject(), EINA_TRUE);
628 _Web::OnBoundsChanging(const Rectangle& bounds)
630 Rectangle absoluteBounds = GetAbsoluteBounds();
631 Rectangle webBounds = GetBounds();
632 _ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetTransformer();
633 SysTryReturnResult(NID_WEB_CTRL, pXformer, E_SYSTEM, "[%s] A system error has been occurred. Failed to get coordinate transformer.", GetErrorMessage(E_SYSTEM));
635 if (__pEflWebkit.get() && __isRotated == false)
637 evas_object_move(__pEflWebkit->GetWebEvasObject(), pXformer->TransformHorizontal(absoluteBounds.x - webBounds.x + bounds.x), pXformer->TransformVertical(absoluteBounds.y - webBounds.y + bounds.y));
638 evas_object_resize(__pEflWebkit->GetWebEvasObject(), pXformer->TransformHorizontal(bounds.width), pXformer->TransformVertical(bounds.height));
646 _Web::OnBoundsChanged(void)
653 _Web::OnChangeLayout(_ControlOrientation orientation)
660 _Web::ChangeGesture(_WebGestureType type)
664 case WEB_GESTURE_TYPE_TAP:
665 __pGestureHandler = __pTapGestureHandler.get();
666 __gestureType = WEB_GESTURE_TYPE_TAP;
669 case WEB_GESTURE_TYPE_PANNING:
670 __pGestureHandler = __pPanningGestureHandler.get();
671 __gestureType = WEB_GESTURE_TYPE_PANNING;
674 case WEB_GESTURE_TYPE_FLICK:
675 __pGestureHandler = __pFlickGestureHandler.get();
676 __gestureType = WEB_GESTURE_TYPE_FLICK;
679 case WEB_GESTURE_TYPE_PINCH:
680 __pGestureHandler = __pPinchGestureHandler.get();
681 __gestureType = WEB_GESTURE_TYPE_PINCH;
691 _Web::SetEdgeReachedEvent(_WebEdgeType type)
698 __edgeType &= ~WEB_EDGE_RIGHT;
702 __edgeType &= ~WEB_EDGE_LEFT;
706 __edgeType &= ~WEB_EDGE_BOTTOM;
709 case WEB_EDGE_BOTTOM:
710 __edgeType &= ~WEB_EDGE_TOP;
720 _Web::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
722 if (__pEflWebkit.get())
724 __edgeType = WEB_EDGE_NONE;
725 __previousTouchedPosition = touchInfo.GetCurrentPosition();
727 SendTouchEventForJavaScript(touchInfo);
729 return __pGestureHandler->OnTouchPressed(source, touchInfo);
737 _Web::CanOutOfEdgeLeft(float scrollDistanceX, int pageDistance)
739 if (scrollDistanceX < 0.0f)
741 __edgeType &= ~WEB_EDGE_RIGHT;
745 else if (scrollDistanceX > 0.0f && pageDistance != 0)
747 __edgeType &= ~WEB_EDGE_LEFT;
755 _Web::CanOutOfEdgeRight(float scrollDistanceX, int pageDistance)
757 if (scrollDistanceX > 0.0f)
759 __edgeType &= ~WEB_EDGE_LEFT;
763 else if (scrollDistanceX < 0.0f && pageDistance != 0)
765 __edgeType &= ~WEB_EDGE_RIGHT;
773 _Web::CanOutOfEdgeTop(float scrollDistanceY, int pageDistance)
775 if (scrollDistanceY < 0.0f)
777 __edgeType &= ~WEB_EDGE_BOTTOM;
781 else if (scrollDistanceY > 0.0f && pageDistance != 0)
783 __edgeType &= ~WEB_EDGE_TOP;
791 _Web::CanOutOfEdgeBottom(float scrollDistanceY, int pageDistance)
793 if (scrollDistanceY > 0.0f)
795 __edgeType &= ~WEB_EDGE_TOP;
799 else if (scrollDistanceY < 0.0f && pageDistance != 0)
801 __edgeType &= ~WEB_EDGE_BOTTOM;
809 _Web::CanConsumeTouchMoved(float scrollDistanceX, float scrollDistanceY)
811 if (__edgeType == WEB_EDGE_NONE)
819 int scrollHeight = 0;
820 ewk_view_scroll_size_get(GetWebNativeNode(), &scrollWidth, &scrollHeight);
824 ewk_view_scroll_pos_get(GetWebNativeNode(), &scrollX, &scrollY);
826 if (scrollWidth == 0)
828 if (__edgeType & WEB_EDGE_TOP)
830 if (!CanOutOfEdgeTop(scrollDistanceY, scrollY - 0))
835 else if (__edgeType & WEB_EDGE_BOTTOM)
837 if (!CanOutOfEdgeBottom(scrollDistanceY, scrollY - scrollHeight))
844 if (scrollHeight == 0)
846 if (__edgeType & WEB_EDGE_LEFT)
848 if (!CanOutOfEdgeLeft(scrollDistanceX, scrollX - 0))
853 else if (__edgeType & WEB_EDGE_RIGHT)
855 if (!CanOutOfEdgeRight(scrollDistanceX, scrollX - scrollWidth))
862 if (scrollWidth > 0 && scrollHeight > 0)
864 if ((__edgeType & WEB_EDGE_LEFT) && (__edgeType & WEB_EDGE_TOP))
866 if (!CanOutOfEdgeLeft(scrollDistanceX, scrollX - 0) || !CanOutOfEdgeTop(scrollDistanceY, scrollY - 0))
871 else if ((__edgeType & WEB_EDGE_LEFT) && (__edgeType & WEB_EDGE_BOTTOM))
873 if (!CanOutOfEdgeLeft(scrollDistanceX, scrollX - 0) || !CanOutOfEdgeBottom(scrollDistanceY, scrollY - scrollHeight))
878 else if ((__edgeType & WEB_EDGE_RIGHT) && (__edgeType & WEB_EDGE_TOP))
880 if (!CanOutOfEdgeRight(scrollDistanceX, scrollX - scrollWidth) || !CanOutOfEdgeTop(scrollDistanceY, scrollY - 0))
885 else if ((__edgeType & WEB_EDGE_RIGHT) && (__edgeType & WEB_EDGE_BOTTOM))
887 if (!CanOutOfEdgeRight(scrollDistanceX, scrollX - scrollWidth) || !CanOutOfEdgeBottom(scrollDistanceY, scrollY - scrollHeight))
899 _Web::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
901 if (__pEflWebkit.get())
903 SendTouchEventForJavaScript(touchInfo);
905 float scrollDistanceX = __previousTouchedPosition.x - touchInfo.GetCurrentPosition().x;
906 float scrollDistanceY = __previousTouchedPosition.y - touchInfo.GetCurrentPosition().y;
907 __previousTouchedPosition = touchInfo.GetCurrentPosition();
909 if (CanConsumeTouchMoved(scrollDistanceX, scrollDistanceY))
911 return __pGestureHandler->OnTouchMoved(source, touchInfo);
920 _Web::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
924 if (__pEflWebkit.get())
926 SendTouchEventForJavaScript(touchInfo);
928 return __pGestureHandler->OnTouchReleased(source, touchInfo);
936 _Web::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
938 if (__pEflWebkit.get())
940 SendTouchEventForJavaScript(touchInfo);
942 return __pGestureHandler->OnTouchCanceled(source, touchInfo);
950 _Web::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
952 if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_TAP)
954 return __pTapGestureHandler->OnLongPressGestureDetected(gesture);
962 _Web::OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
969 _Web::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
971 if (__pEflWebkit.get())
973 return __pTapGestureHandler->OnTapGestureDetected(gesture);
981 _Web::OnTapGestureCanceled(_TouchTapGestureDetector& gesture)
988 _Web::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
990 if (__pEflWebkit.get())
992 return __pFlickGestureHandler->OnFlickGestureDetected(gesture);
1000 _Web::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
1007 _Web::OnPinchGestureStarted(Tizen::Ui::_TouchPinchGestureDetector& gesture)
1009 if (__pEflWebkit.get())
1011 return __pPinchGestureHandler->OnPinchGestureStarted(gesture);
1019 _Web::OnPinchGestureChanged(Tizen::Ui::_TouchPinchGestureDetector& gesture)
1021 if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_PINCH)
1023 return __pPinchGestureHandler->OnPinchGestureChanged(gesture);
1031 _Web::OnPinchGestureFinished(Tizen::Ui::_TouchPinchGestureDetector& gesture)
1033 if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_PINCH)
1035 return __pPinchGestureHandler->OnPinchGestureFinished(gesture);
1043 _Web::OnPinchGestureCanceled(Tizen::Ui::_TouchPinchGestureDetector& gesture)
1050 _Web::OnCanvasRequestedN(const FloatRectangle& bounds)
1052 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);
1053 if (bounds.width == 0.0f || bounds.height == 0.0f)
1055 FloatDimension size(GetSizeF());
1056 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.");
1059 result r = E_SUCCESS;
1061 Rectangle absBounds(_CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::Transform(bounds)));
1063 Eina_Rectangle rect;
1064 EINA_RECTANGLE_SET(&rect, absBounds.x, absBounds.y, absBounds.width, absBounds.height);
1066 Evas_Object* pWebFrame = GetWebNativeNode();
1067 Evas_Object* pScreenShot = ewk_view_screenshot_contents_get(pWebFrame, rect, 1.0f, evas_object_evas_get(pWebFrame));
1069 std::unique_ptr<Canvas> pCanvas(new (std::nothrow) Canvas());
1070 SysTryReturn(NID_WEB_CTRL, pCanvas.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1074 BufferInfo bufferInfo;
1076 r = _Utility::GetPixelBufferFromEvasObject(pScreenShot, bufferInfo);
1077 evas_object_del(pScreenShot);
1078 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1080 r = pCanvas->Construct(bufferInfo);
1081 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1085 r = pCanvas->Construct(bounds);
1086 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1089 return pCanvas.release();
1094 _Web::OnCapturedBitmapRequestedN(void)
1096 result r = E_SUCCESS;
1098 BufferInfo bufferInfo;
1099 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));
1102 int bufferSize = bufferInfo.bitsPerPixel * bufferInfo.width * bufferInfo.height;
1104 r = buffer.Construct(reinterpret_cast < byte* >(bufferInfo.pPixels), 0, bufferSize, bufferSize);
1105 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1107 std::unique_ptr<Bitmap> pBitmap(new (std::nothrow) Bitmap());
1108 SysTryReturn(NID_WEB_CTRL, pBitmap.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1110 r = pBitmap->Construct(buffer, Dimension(bufferInfo.width, bufferInfo.height), BITMAP_PIXEL_FORMAT_ARGB8888);
1111 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1113 return pBitmap.release();
1118 _Web::OnCaptureAcquire(BufferInfo& output)
1120 result r = E_SUCCESS;
1122 FloatPoint position(GetPositionF());
1123 FloatDimension size(GetSizeF());
1125 Dimension absSize(_CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::Transform(size)));
1127 Eina_Rectangle rect;
1128 EINA_RECTANGLE_SET(&rect, 0, 0, absSize.width, absSize.height);
1130 Evas_Object* pWebFrame = GetWebNativeNode();
1131 Evas_Object* pScreenShot = ewk_view_screenshot_contents_get(pWebFrame, rect, 1.0f, evas_object_evas_get(pWebFrame));
1132 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));
1134 r = _Utility::GetPixelBufferFromEvasObject(pScreenShot, output);
1135 evas_object_del(pScreenShot);
1136 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] propagating", GetErrorMessage(r));
1143 _Web::SendTouchEventForJavaScript(const _TouchInfo& touchInfo)
1145 result r = E_SUCCESS;
1147 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1148 SysAssertf(pTouchManager, "Failed to get touch manager.");
1150 std::unique_ptr<IListT<_FingerInfo*> > pTouchList(pTouchManager->GetMultiFingerInfoListN());
1151 SysTryReturnVoidResult(NID_WEB_CTRL, pTouchList.get(), GetLastResult(), "[%s] Failed to get touch list.", GetErrorMessage(GetLastResult()));
1153 std::unique_ptr<IBidirectionalEnumeratorT<_FingerInfo*> > pTouchListEnum(pTouchList->GetBidirectionalEnumeratorN());
1154 SysAssertf(pTouchListEnum.get() != null, "Failed to get enumerator of touch list.");
1156 Eina_List* pPointList = null;
1157 _FingerInfo* pFingerInfo = null;
1158 while(pTouchListEnum->MoveNext() == E_SUCCESS)
1160 r = pTouchListEnum->GetCurrent(pFingerInfo);
1161 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1163 _TouchStatus state = pFingerInfo->GetStatus();
1164 if(state == _TOUCH_PRESSED || state == _TOUCH_MOVED || state == _TOUCH_RELEASED || state == _TOUCH_CANCELED)
1166 Point integerPoint(_CoordinateSystemUtils::ConvertToInteger(GetAbsoluteCoordinate(pFingerInfo->GetPoint())));
1168 Ewk_Touch_Point* pPoint = static_cast<Ewk_Touch_Point*>(calloc(1, sizeof(Ewk_Touch_Point)));
1169 pPoint->id = pFingerInfo->GetPointId();
1170 pPoint->x = integerPoint.x;
1171 pPoint->y = integerPoint.y;
1172 pPoint->state = GetEvasTouchState((TouchStatus)pFingerInfo->GetStatus());
1173 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);
1175 pPointList = eina_list_append(pPointList, pPoint);
1179 ewk_view_feed_touch_event(__pEflWebkit->GetWebEvasObject(), GetEwkTouchEvent(touchInfo.GetTouchStatus()), pPointList, null);
1182 EINA_LIST_FREE(pPointList, pData)
1187 Ewk_Touch_Event_Type
1188 _Web::GetEwkTouchEvent(_TouchStatus touchStatus)
1190 Ewk_Touch_Event_Type ewkTouchEvent = EWK_TOUCH_CANCEL;
1192 switch (touchStatus)
1194 case _TOUCH_PRESSED :
1195 ewkTouchEvent = EWK_TOUCH_START;
1198 ewkTouchEvent = EWK_TOUCH_MOVE;
1200 case _TOUCH_RELEASED :
1201 ewkTouchEvent = EWK_TOUCH_END;
1203 case _TOUCH_CANCELED :
1206 ewkTouchEvent = EWK_TOUCH_CANCEL;
1210 return ewkTouchEvent;
1214 Evas_Touch_Point_State
1215 _Web::GetEvasTouchState(TouchStatus touchStatus)
1217 Evas_Touch_Point_State evasTouchState = EVAS_TOUCH_POINT_CANCEL;
1219 switch (touchStatus)
1221 case TOUCH_PRESSED :
1222 evasTouchState = EVAS_TOUCH_POINT_DOWN;
1225 evasTouchState = EVAS_TOUCH_POINT_MOVE;
1227 case TOUCH_RELEASED :
1228 evasTouchState = EVAS_TOUCH_POINT_UP;
1230 case TOUCH_CANCELED :
1233 evasTouchState = EVAS_TOUCH_POINT_CANCEL;
1234 //todo : mapping EVAS_TOUCH_POINT_STILL, /**< Touch point is not moved af
1238 return evasTouchState;
1243 _Web::SetFullScreenEntered(bool isFullScreenEntered)
1245 __isFullScreenEntered = isFullScreenEntered;
1250 _Web::SetFocusEnd(bool focus)
1257 _Web::IsFocusEnd(void)
1264 _Web::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
1266 Ecore_X_Window rootWindow = ecore_x_window_root_first_get();
1267 Ecore_X_Atom keyboardExist = ecore_x_atom_get("X External Keyboard Exist");
1268 unsigned int keyboardNumber = 0;
1269 int ret = ecore_x_window_prop_card32_get(rootWindow, keyboardExist, &keyboardNumber, 1);
1270 if (keyboardNumber == 0)
1275 _KeyCode keyCode = keyInfo.GetKeyCode();
1277 if (IsFocusEnd() == true)
1280 evas_object_focus_set(GetWebNativeNode(), EINA_FALSE);
1288 evas_object_focus_set(GetWebNativeNode(), EINA_FALSE);
1295 evas_object_focus_set(GetWebNativeNode(), EINA_TRUE);
1302 _Web::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1304 if (__isFullScreenEntered)
1306 if (keyInfo.GetKeyCode() == _KEY_ESC || keyInfo.GetKeyCode() == _KEY_BACK)
1308 __isFullScreenEntered = false;
1310 ewk_view_fullscreen_exit(GetWebNativeNode());
1321 _Web::OnDrawFocus(void)
1326 }}} // Tizen::Web::Controls