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;
65 namespace Tizen { namespace Web { namespace Controls
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);
284 OnEdgeLeft(void* pUserData, Evas_Object* pView, void* pEventInfo)
286 _Web* pCore = reinterpret_cast< _Web* >(pUserData);
287 SysAssertf(pCore, "Failed to request");
289 pCore->SetEdgeReachedEvent(WEB_EDGE_LEFT);
294 OnEdgeRight(void* pUserData, Evas_Object* pView, void* pEventInfo)
296 _Web* pCore = reinterpret_cast< _Web* >(pUserData);
297 SysAssertf(pCore, "Failed to request");
299 pCore->SetEdgeReachedEvent(WEB_EDGE_RIGHT);
304 OnEdgeTop(void* pUserData, Evas_Object* pView, void* pEventInfo)
306 _Web* pCore = reinterpret_cast< _Web* >(pUserData);
307 SysAssertf(pCore, "Failed to request");
309 pCore->SetEdgeReachedEvent(WEB_EDGE_TOP);
314 OnEdgeBottom(void* pUserData, Evas_Object* pView, void* pEventInfo)
316 _Web* pCore = reinterpret_cast< _Web* >(pUserData);
317 SysAssertf(pCore, "Failed to request");
319 pCore->SetEdgeReachedEvent(WEB_EDGE_BOTTOM);
324 : __pGestureHandler(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)
341 , __pTextElement(null)
342 , __previousTouchedPosition(0.0f, 0.0f)
343 , __isFullScreenEntered(false)
345 , __touchPressed(false)
347 SetBackgroundColor(Color(0, 0, 0, 0));
353 RemoveGestureListener();
355 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
358 pContainer->RemoveListener(*dynamic_cast<_IAccessibilityListener*>(__pWebAccessibilityListener.get()));
359 pContainer->SetFocusHandler(null);
365 _Web::CreateWebN(void)
367 result r = E_SUCCESS;
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));
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));
375 pWeb->AcquireHandle();
376 pWeb->SetMultiTouchEnabled(true);
377 pWeb->SetTouchPressThreshold(0.08);
379 r = pWeb->AddGestureListeners();
380 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
382 r = pWeb->InitializeGestureStates();
383 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
385 return pWeb.release();
390 _Web::CreateWebkitEvasObject(void)
392 result r = E_SUCCESS;
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));
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));
401 _VisualElementImpl* pVeImpl = _VisualElementImpl::GetInstance(*pVe);
402 pVeImpl->SetCaptureProvider(this);
404 __pEflWebkit = std::move(pEflWebkit);
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);
417 _Web::InitializeGestureStates(void)
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));
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));
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));
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));
431 __pGestureHandler = __pTapGestureHandler.get();
438 _Web::AddGestureListeners(void)
440 result r = E_SUCCESS;
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));
445 r = pGestureFlick->AddGestureListener(*this);
446 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
448 r = AddGestureDetector(*pGestureFlick.get());
449 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
451 __pGestureFlick = std::move(pGestureFlick);
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));
456 r = pGestureLongPress->AddGestureListener(*this);
457 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
459 r = AddGestureDetector(*pGestureLongPress.get());
460 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
462 __pGestureLongPress = std::move(pGestureLongPress);
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));
467 r = pGestureDoubleTap->AddGestureListener(*this);
468 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
470 r = AddGestureDetector(*pGestureDoubleTap.get());
471 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
473 __pGestureDoubleTap = std::move(pGestureDoubleTap);
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));
478 r = pGesturePinch->AddGestureListener(*this);
479 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
481 r = AddGestureDetector(*pGesturePinch.get());
482 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
484 __pGesturePinch = std::move(pGesturePinch);
491 _Web::RemoveGestureListener(void)
493 if (__pGestureFlick.get())
495 __pGestureFlick->RemoveGestureListener(*this);
496 RemoveGestureDetector(*__pGestureFlick);
499 if (__pGestureLongPress.get())
501 __pGestureLongPress->RemoveGestureListener(*this);
502 RemoveGestureDetector(*__pGestureLongPress);
505 if (__pGestureDoubleTap.get())
507 __pGestureDoubleTap->RemoveGestureListener(*this);
508 RemoveGestureDetector(*__pGestureDoubleTap);
511 if (__pGesturePinch.get())
513 __pGesturePinch->RemoveGestureListener(*this);
514 RemoveGestureDetector(*__pGesturePinch);
517 Evas_Object* pView = GetWebNativeNode();
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);
529 _Web::InitializeWebNativeNode(void)
531 result r = E_SUCCESS;
533 r = CreateWebkitEvasObject();
534 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
536 SetNativeObjectFocusable(false);
538 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
539 SysTryReturn(NID_WEB_CTRL, pContainer, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(E_SYSTEM));
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));
544 __pTextElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
545 __pTextElement->SetLabel(L"Web control");
547 pContainer->AddElement(*__pTextElement);
548 pContainer->Activate(true);
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));
553 __pWebAccessibilityListener = std::move(pListener);
555 pContainer->AddListener(*dynamic_cast<_IAccessibilityListener*>(__pWebAccessibilityListener.get()));
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));
560 __pWebAccessibilityFocusHandler = std::move(pFocusHandler);
562 pContainer->SetFocusHandler(dynamic_cast<_IAccessibilityFocusHandler*>(__pWebAccessibilityFocusHandler.get()));
569 _Web::GetAbsoluteCoordinate(Point relativePoint)
571 return _CoordinateSystemUtils::Transform(ConvertToScreenPosition(relativePoint));
576 _Web::GetAbsoluteCoordinate(FloatPoint relativePoint)
578 return _CoordinateSystemUtils::Transform(ConvertToScreenPosition(relativePoint));
583 _Web::GetRelativeCoordinate(Point absolutePoint)
585 return ConvertToControlPosition(_CoordinateSystemUtils::InverseTransform(absolutePoint));
590 _Web::GetRelativeCoordinate(FloatPoint absolutePoint)
592 return ConvertToControlPosition(_CoordinateSystemUtils::InverseTransform(absolutePoint));
597 _Web::GetWebNativeNode(void)
599 if (__pEflWebkit.get())
601 return __pEflWebkit->GetWebEvasObject();
609 _Web::GetSetting(void) const
611 return __pWebSetting.get();
616 _Web::GetEflWebkit(void) const
618 return __pEflWebkit.get();
623 _Web::GetTouchPosition(void) const
625 return __previousTouchedPosition;
630 _Web::OnAttaching(const _Control* pParent)
632 if (__pEflWebkit.get())
634 evas_object_show(__pEflWebkit->GetWebEvasObject());
635 evas_object_focus_set(__pEflWebkit->GetWebEvasObject(), EINA_TRUE);
643 _Web::OnBoundsChanging(const Rectangle& bounds)
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));
650 if (__pEflWebkit.get() && __isRotated == false)
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));
661 _Web::OnBoundsChanged(void)
668 _Web::OnChangeLayout(_ControlOrientation orientation)
675 _Web::ChangeGesture(_WebGestureType type)
679 case WEB_GESTURE_TYPE_TAP:
680 __pGestureHandler = __pTapGestureHandler.get();
681 __gestureType = WEB_GESTURE_TYPE_TAP;
684 case WEB_GESTURE_TYPE_PANNING:
685 __pGestureHandler = __pPanningGestureHandler.get();
686 __gestureType = WEB_GESTURE_TYPE_PANNING;
689 case WEB_GESTURE_TYPE_FLICK:
690 __pGestureHandler = __pFlickGestureHandler.get();
691 __gestureType = WEB_GESTURE_TYPE_FLICK;
694 case WEB_GESTURE_TYPE_PINCH:
695 __pGestureHandler = __pPinchGestureHandler.get();
696 __gestureType = WEB_GESTURE_TYPE_PINCH;
706 _Web::SetEdgeReachedEvent(_WebEdgeType type)
713 __edgeType &= ~WEB_EDGE_RIGHT;
717 __edgeType &= ~WEB_EDGE_LEFT;
721 __edgeType &= ~WEB_EDGE_BOTTOM;
724 case WEB_EDGE_BOTTOM:
725 __edgeType &= ~WEB_EDGE_TOP;
735 _Web::OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
737 __touchPressed = true;
739 if (__pEflWebkit.get())
741 __edgeType = WEB_EDGE_NONE;
742 __previousTouchedPosition = touchInfo.GetCurrentPosition();
744 SendTouchEventForJavaScript(touchInfo);
746 return __pGestureHandler->OnTouchPressed(source, touchInfo);
754 _Web::CanOutOfEdgeLeft(float scrollDistanceX, int pageDistance)
756 if (scrollDistanceX < 0.0f)
758 __edgeType &= ~WEB_EDGE_RIGHT;
762 else if (scrollDistanceX > 0.0f && pageDistance != 0)
764 __edgeType &= ~WEB_EDGE_LEFT;
772 _Web::CanOutOfEdgeRight(float scrollDistanceX, int pageDistance)
774 if (scrollDistanceX > 0.0f)
776 __edgeType &= ~WEB_EDGE_LEFT;
780 else if (scrollDistanceX < 0.0f && pageDistance != 0)
782 __edgeType &= ~WEB_EDGE_RIGHT;
790 _Web::CanOutOfEdgeTop(float scrollDistanceY, int pageDistance)
792 if (scrollDistanceY < 0.0f)
794 __edgeType &= ~WEB_EDGE_BOTTOM;
798 else if (scrollDistanceY > 0.0f && pageDistance != 0)
800 __edgeType &= ~WEB_EDGE_TOP;
808 _Web::CanOutOfEdgeBottom(float scrollDistanceY, int pageDistance)
810 if (scrollDistanceY > 0.0f)
812 __edgeType &= ~WEB_EDGE_TOP;
816 else if (scrollDistanceY < 0.0f && pageDistance != 0)
818 __edgeType &= ~WEB_EDGE_BOTTOM;
826 _Web::CanConsumeTouchMoved(float scrollDistanceX, float scrollDistanceY)
828 if (__edgeType == WEB_EDGE_NONE)
836 int scrollHeight = 0;
837 ewk_view_scroll_size_get(GetWebNativeNode(), &scrollWidth, &scrollHeight);
841 ewk_view_scroll_pos_get(GetWebNativeNode(), &scrollX, &scrollY);
843 if (scrollWidth == 0)
845 if (__edgeType & WEB_EDGE_TOP)
847 if (!CanOutOfEdgeTop(scrollDistanceY, scrollY - 0))
852 else if (__edgeType & WEB_EDGE_BOTTOM)
854 if (!CanOutOfEdgeBottom(scrollDistanceY, scrollY - scrollHeight))
861 if (scrollHeight == 0)
863 if (__edgeType & WEB_EDGE_LEFT)
865 if (!CanOutOfEdgeLeft(scrollDistanceX, scrollX - 0))
870 else if (__edgeType & WEB_EDGE_RIGHT)
872 if (!CanOutOfEdgeRight(scrollDistanceX, scrollX - scrollWidth))
879 if (scrollWidth > 0 && scrollHeight > 0)
881 if ((__edgeType & WEB_EDGE_LEFT) && (__edgeType & WEB_EDGE_TOP))
883 if (!CanOutOfEdgeLeft(scrollDistanceX, scrollX - 0) || !CanOutOfEdgeTop(scrollDistanceY, scrollY - 0))
888 else if ((__edgeType & WEB_EDGE_LEFT) && (__edgeType & WEB_EDGE_BOTTOM))
890 if (!CanOutOfEdgeLeft(scrollDistanceX, scrollX - 0) || !CanOutOfEdgeBottom(scrollDistanceY, scrollY - scrollHeight))
895 else if ((__edgeType & WEB_EDGE_RIGHT) && (__edgeType & WEB_EDGE_TOP))
897 if (!CanOutOfEdgeRight(scrollDistanceX, scrollX - scrollWidth) || !CanOutOfEdgeTop(scrollDistanceY, scrollY - 0))
902 else if ((__edgeType & WEB_EDGE_RIGHT) && (__edgeType & WEB_EDGE_BOTTOM))
904 if (!CanOutOfEdgeRight(scrollDistanceX, scrollX - scrollWidth) || !CanOutOfEdgeBottom(scrollDistanceY, scrollY - scrollHeight))
916 _Web::OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
918 if (__pEflWebkit.get())
920 SendTouchEventForJavaScript(touchInfo);
922 float scrollDistanceX = __previousTouchedPosition.x - touchInfo.GetCurrentPosition().x;
923 float scrollDistanceY = __previousTouchedPosition.y - touchInfo.GetCurrentPosition().y;
924 __previousTouchedPosition = touchInfo.GetCurrentPosition();
926 if (CanConsumeTouchMoved(scrollDistanceX, scrollDistanceY))
928 return __pGestureHandler->OnTouchMoved(source, touchInfo);
937 _Web::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
939 __touchPressed = false;
943 if (__pEflWebkit.get())
945 SendTouchEventForJavaScript(touchInfo);
947 return __pGestureHandler->OnTouchReleased(source, touchInfo);
955 _Web::OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
957 if (__pEflWebkit.get())
959 SendTouchEventForJavaScript(touchInfo);
961 return __pGestureHandler->OnTouchCanceled(source, touchInfo);
969 _Web::OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
971 if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_TAP)
973 return __pTapGestureHandler->OnLongPressGestureDetected(gesture);
981 _Web::OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
988 _Web::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
990 if (__pEflWebkit.get())
992 return __pTapGestureHandler->OnTapGestureDetected(gesture);
1000 _Web::OnTapGestureCanceled(_TouchTapGestureDetector& gesture)
1007 _Web::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
1009 if (__pEflWebkit.get())
1011 return __pFlickGestureHandler->OnFlickGestureDetected(gesture);
1019 _Web::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
1026 _Web::OnPinchGestureStarted(Tizen::Ui::_TouchPinchGestureDetector& gesture)
1028 if (__pEflWebkit.get())
1030 return __pPinchGestureHandler->OnPinchGestureStarted(gesture);
1038 _Web::OnPinchGestureChanged(Tizen::Ui::_TouchPinchGestureDetector& gesture)
1040 if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_PINCH)
1042 return __pPinchGestureHandler->OnPinchGestureChanged(gesture);
1050 _Web::OnPinchGestureFinished(Tizen::Ui::_TouchPinchGestureDetector& gesture)
1052 if (__pEflWebkit.get() && __gestureType == WEB_GESTURE_TYPE_PINCH)
1054 return __pPinchGestureHandler->OnPinchGestureFinished(gesture);
1062 _Web::OnPinchGestureCanceled(Tizen::Ui::_TouchPinchGestureDetector& gesture)
1069 _Web::OnCanvasRequestedN(const FloatRectangle& bounds)
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)
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.");
1078 result r = E_SUCCESS;
1080 Rectangle absBounds(_CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::Transform(bounds)));
1082 Eina_Rectangle rect;
1083 EINA_RECTANGLE_SET(&rect, absBounds.x, absBounds.y, absBounds.width, absBounds.height);
1085 Evas_Object* pWebFrame = GetWebNativeNode();
1086 Evas_Object* pScreenShot = ewk_view_screenshot_contents_get(pWebFrame, rect, 1.0f, evas_object_evas_get(pWebFrame));
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));
1093 BufferInfo bufferInfo;
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));
1099 r = pCanvas->Construct(bufferInfo);
1100 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1104 r = pCanvas->Construct(bounds);
1105 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
1108 return pCanvas.release();
1113 _Web::OnCapturedBitmapRequestedN(void)
1115 result r = E_SUCCESS;
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));
1121 int bufferSize = bufferInfo.bitsPerPixel * bufferInfo.width * bufferInfo.height;
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));
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));
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));
1132 return pBitmap.release();
1137 _Web::OnCaptureAcquire(BufferInfo& output)
1139 result r = E_SUCCESS;
1141 FloatPoint position(GetPositionF());
1142 FloatDimension size(GetSizeF());
1144 Dimension absSize(_CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::Transform(size)));
1146 Eina_Rectangle rect;
1147 EINA_RECTANGLE_SET(&rect, 0, 0, absSize.width, absSize.height);
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));
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));
1162 _Web::SendTouchEventForJavaScript(const _TouchInfo& touchInfo)
1164 result r = E_SUCCESS;
1166 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1167 SysAssertf(pTouchManager, "Failed to get touch manager.");
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()));
1172 std::unique_ptr<IBidirectionalEnumeratorT<_FingerInfo*> > pTouchListEnum(pTouchList->GetBidirectionalEnumeratorN());
1173 SysAssertf(pTouchListEnum.get() != null, "Failed to get enumerator of touch list.");
1175 Eina_List* pPointList = null;
1176 _FingerInfo* pFingerInfo = null;
1177 while(pTouchListEnum->MoveNext() == E_SUCCESS)
1179 r = pTouchListEnum->GetCurrent(pFingerInfo);
1180 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1182 _TouchStatus state = pFingerInfo->GetStatus();
1183 if(state == _TOUCH_PRESSED || state == _TOUCH_MOVED || state == _TOUCH_RELEASED || state == _TOUCH_CANCELED)
1185 Point integerPoint(_CoordinateSystemUtils::ConvertToInteger(GetAbsoluteCoordinate(pFingerInfo->GetPoint())));
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);
1194 pPointList = eina_list_append(pPointList, pPoint);
1198 ewk_view_feed_touch_event(__pEflWebkit->GetWebEvasObject(), GetEwkTouchEvent(touchInfo.GetTouchStatus()), pPointList, null);
1201 EINA_LIST_FREE(pPointList, pData)
1206 Ewk_Touch_Event_Type
1207 _Web::GetEwkTouchEvent(_TouchStatus touchStatus)
1209 Ewk_Touch_Event_Type ewkTouchEvent = EWK_TOUCH_CANCEL;
1211 switch (touchStatus)
1213 case _TOUCH_PRESSED :
1214 ewkTouchEvent = EWK_TOUCH_START;
1217 ewkTouchEvent = EWK_TOUCH_MOVE;
1219 case _TOUCH_RELEASED :
1220 ewkTouchEvent = EWK_TOUCH_END;
1222 case _TOUCH_CANCELED :
1225 ewkTouchEvent = EWK_TOUCH_CANCEL;
1229 return ewkTouchEvent;
1233 Evas_Touch_Point_State
1234 _Web::GetEvasTouchState(TouchStatus touchStatus)
1236 Evas_Touch_Point_State evasTouchState = EVAS_TOUCH_POINT_CANCEL;
1238 switch (touchStatus)
1240 case TOUCH_PRESSED :
1241 evasTouchState = EVAS_TOUCH_POINT_DOWN;
1244 evasTouchState = EVAS_TOUCH_POINT_MOVE;
1246 case TOUCH_RELEASED :
1247 evasTouchState = EVAS_TOUCH_POINT_UP;
1249 case TOUCH_CANCELED :
1252 evasTouchState = EVAS_TOUCH_POINT_CANCEL;
1253 //todo : mapping EVAS_TOUCH_POINT_STILL, /**< Touch point is not moved af
1257 return evasTouchState;
1262 _Web::SetFullScreenEntered(bool isFullScreenEntered)
1264 __isFullScreenEntered = isFullScreenEntered;
1269 _Web::SetFocusEnd(bool focus)
1276 _Web::IsFocusEnd(void) const
1283 _Web::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
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)
1294 _KeyCode keyCode = keyInfo.GetKeyCode();
1296 if (IsFocusEnd() == true)
1299 evas_object_focus_set(GetWebNativeNode(), EINA_FALSE);
1307 evas_object_focus_set(GetWebNativeNode(), EINA_FALSE);
1314 evas_object_focus_set(GetWebNativeNode(), EINA_TRUE);
1321 _Web::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
1323 if (__isFullScreenEntered)
1325 if (keyInfo.GetKeyCode() == _KEY_ESC || keyInfo.GetKeyCode() == _KEY_BACK)
1327 __isFullScreenEntered = false;
1329 ewk_view_fullscreen_exit(GetWebNativeNode());
1340 _Web::OnDrawFocus(void)
1346 _Web::OnFocusLost(const _Control& source)
1348 _Control::OnFocusLost(*this);
1350 if (__touchPressed == true)
1352 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1353 SysAssertf(pTouchManager, "Failed to get touch manager.");
1355 Point absPoint(_CoordinateSystemUtils::ConvertToInteger(pTouchManager->GetPosition(pTouchManager->GetCurrentPointId())));
1357 Ewk_Touch_Point* pPoint = static_cast< Ewk_Touch_Point* >(calloc(1, sizeof(Ewk_Touch_Point)));
1359 pPoint->x = absPoint.x;
1360 pPoint->y = absPoint.y;
1361 pPoint->state = EVAS_TOUCH_POINT_CANCEL;
1363 Eina_List* pPointList = null;
1364 pPointList = eina_list_append(pPointList, pPoint);
1366 ewk_view_feed_touch_event(GetWebNativeNode(), EWK_TOUCH_CANCEL, pPointList, null);
1369 EINA_LIST_FREE(pPointList, pData)
1372 __touchPressed = false;
1379 }}} // Tizen::Web::Controls