change for webpagecapture
[framework/osp/web.git] / src / controls / FWebCtrl_Web.cpp
index 3d4b7fe..f92d336 100755 (executable)
@@ -38,6 +38,7 @@
 #include <FSys_VibratorImpl.h>
 #include <FUiAnim_EflNode.h>
 #include <FUiAnim_VisualElement.h>
+#include <FUiAnim_VisualElementImpl.h>
 #include <FUi_CoordinateSystemUtils.h>
 #include <FUi_AccessibilityContainer.h>
 #include <FUi_AccessibilityElement.h>
@@ -144,14 +145,27 @@ _WebAccessibilityListener::OnAccessibilityFocusIn(const _AccessibilityContainer&
 bool
 _WebAccessibilityListener::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
 {
-       return true;
+       Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pView));
+       SysAssertf(pSmartData, "Failed to get webkit smart data.");
+
+       Elm_Access_Action_Info* pActionInfo = new Elm_Access_Action_Info();
+       SysTryReturn(NID_WEB_CTRL, pActionInfo, false, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       bool result = false;
+
+       pActionInfo->action_type = ELM_ACCESS_ACTION_UNHIGHLIGHT;
+
+       result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
+       delete pActionInfo;
+
+       return result;
 }
 
 
 bool
 _WebAccessibilityListener::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
 {
-       const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pView));
+       Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pView));
        SysAssertf(pSmartData, "Failed to get webkit smart data.");
 
        Elm_Access_Action_Info* pActionInfo = new Elm_Access_Action_Info();
@@ -161,7 +175,7 @@ _WebAccessibilityListener::OnAccessibilityActionPerformed(const _AccessibilityCo
 
        pActionInfo->action_type = ELM_ACCESS_ACTION_ACTIVATE;
 
-       result = pSmartData->api->screen_reader_action_execute(const_cast<Ewk_View_Smart_Data*>(pSmartData), pActionInfo);
+       result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
        delete pActionInfo;
 
        return result;
@@ -213,7 +227,7 @@ _WebAccessibilityFocusHandler::~_WebAccessibilityFocusHandler(void)
 bool
 _WebAccessibilityFocusHandler::OnMoveFocus(Tizen::Ui::_AccessibilityFocusDirection direction)
 {
-       const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pView));
+       Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pView));
        SysAssertf(pSmartData, "Failed to get webkit smart data.");
 
        Elm_Access_Action_Info* pActionInfo = new Elm_Access_Action_Info();
@@ -223,15 +237,19 @@ _WebAccessibilityFocusHandler::OnMoveFocus(Tizen::Ui::_AccessibilityFocusDirecti
 
        if (direction == Tizen::Ui::_ACCESSIBILITY_FOCUS_DIRECTION_PREVIOUS)
        {
-               pActionInfo->action_type = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
+               pActionInfo->action_type = ELM_ACCESS_ACTION_HIGHLIGHT;
 
-               result = pSmartData->api->screen_reader_action_execute(const_cast<Ewk_View_Smart_Data*>(pSmartData), pActionInfo);
+               pActionInfo->action_by = ELM_ACCESS_ACTION_HIGHLIGHT_PREV;
+
+               result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
        }
        else if (direction == Tizen::Ui::_ACCESSIBILITY_FOCUS_DIRECTION_NEXT)
        {
-               pActionInfo->action_type = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
+               pActionInfo->action_type = ELM_ACCESS_ACTION_HIGHLIGHT;
+
+               pActionInfo->action_by = ELM_ACCESS_ACTION_HIGHLIGHT_NEXT;
 
-               result = pSmartData->api->screen_reader_action_execute(const_cast<Ewk_View_Smart_Data*>(pSmartData), pActionInfo);
+               result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
        }
        delete pActionInfo;
 
@@ -242,7 +260,7 @@ _WebAccessibilityFocusHandler::OnMoveFocus(Tizen::Ui::_AccessibilityFocusDirecti
 bool
 _WebAccessibilityFocusHandler::OnMoveFocus(const Tizen::Graphics::Point& point)
 {
-       const Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pView));
+       Ewk_View_Smart_Data* pSmartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(__pView));
        SysAssertf(pSmartData, "Failed to get webkit smart data.");
 
        Elm_Access_Action_Info* pActionInfo = new Elm_Access_Action_Info();
@@ -254,7 +272,7 @@ _WebAccessibilityFocusHandler::OnMoveFocus(const Tizen::Graphics::Point& point)
        pActionInfo->x = point.x;
        pActionInfo->y = point.y;
 
-       result = pSmartData->api->screen_reader_action_execute(const_cast<Ewk_View_Smart_Data*>(pSmartData), pActionInfo);
+       result = pSmartData->api->screen_reader_action_execute(pSmartData, pActionInfo);
        delete pActionInfo;
 
        return result;
@@ -372,9 +390,13 @@ _Web::CreateWebkitEvasObject(void)
        std::unique_ptr<_EflWebkit> pEflWebkit(new (std::nothrow) _EflWebkit());
        SysTryReturnResult(NID_WEB_CTRL, pEflWebkit.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       r = pEflWebkit->Construct(GetAbsoluteBounds(), *GetVisualElement(), this);
+       _VisualElement* pVe = GetVisualElement();
+       r = pEflWebkit->Construct(GetAbsoluteBounds(), *pVe, this);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
+       _VisualElementImpl* pVeImpl = _VisualElementImpl::GetInstance(*pVe);
+       pVeImpl->SetCaptureProvider(this);
+
        __pEflWebkit = std::move(pEflWebkit);
 
        Evas_Object* pView = GetWebNativeNode();
@@ -781,6 +803,14 @@ _Web::OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
        {
                SendTouchEventForJavaScript(touchInfo);
 
+               Evas_Object* pView = GetWebNativeNode();
+               _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(evas_object_data_get(pView, WEB_CTRL));
+
+               if (pImpl && pImpl->GetTextFromBlock().GetLength() > 0)
+               {
+                       evas_object_smart_callback_call(pView, "text,selected", NULL);
+               }
+
                return __pGestureHandler->OnTouchReleased(source, touchInfo);
        }
 
@@ -929,18 +959,21 @@ _Web::OnPinchGestureCanceled(Tizen::Ui::_TouchPinchGestureDetector& gesture)
 Canvas*
 _Web::OnCanvasRequestedN(const FloatRectangle& bounds)
 {
-       result r = E_SUCCESS;
+       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);
+       if (bounds.width == 0.0f || bounds.height == 0.0f)
+       {
+               FloatDimension size(GetSizeF());
+               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.");
+       }
 
-       Evas_Object* pWebFrame = GetWebNativeNode();
-       Eina_Rectangle rect;
-       BufferInfo bufferInfo;
+       result r = E_SUCCESS;
 
-       Point absPoint(_CoordinateSystemUtils::ConvertToInteger(GetAbsoluteCoordinate(FloatPoint(bounds.x, bounds.y))));
-       Dimension absSize(_CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::HorizontalTransform(bounds.width)),
-               _CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::VerticalTransform(bounds.height)));
+       Rectangle absBounds(_CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::Transform(bounds)));
 
-       EINA_RECTANGLE_SET(&rect, absPoint.x, absPoint.y, absSize.width, absSize.height);
+       Eina_Rectangle rect;
+       EINA_RECTANGLE_SET(&rect, absBounds.x, absBounds.y, absBounds.width, absBounds.height);
 
+       Evas_Object* pWebFrame = GetWebNativeNode();
        Evas_Object* pScreenShot = ewk_view_screenshot_contents_get(pWebFrame, rect, 1.0f, evas_object_evas_get(pWebFrame));
 
        std::unique_ptr<Canvas> pCanvas(new (std::nothrow) Canvas());
@@ -948,6 +981,8 @@ _Web::OnCanvasRequestedN(const FloatRectangle& bounds)
 
        if (pScreenShot)
        {
+               BufferInfo bufferInfo;
+
                r = _Utility::GetPixelBufferFromEvasObject(pScreenShot, bufferInfo);
                evas_object_del(pScreenShot);
                SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
@@ -970,24 +1005,12 @@ _Web::OnCapturedBitmapRequestedN(void)
 {
        result r = E_SUCCESS;
 
-       Evas_Object* pWebFrame = GetWebNativeNode();
-       Eina_Rectangle rect;
-       ByteBuffer buffer;
        BufferInfo bufferInfo;
+       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));
 
-       Dimension size(GetSize());
-       Point absSize(GetAbsoluteCoordinate(Point(size.width, size.height)));
-
-       EINA_RECTANGLE_SET(&rect, 0, 0, absSize.x, absSize.y);
-
-       Evas_Object* pScreenShot = ewk_view_screenshot_contents_get(pWebFrame, rect, 1.0f, evas_object_evas_get(pWebFrame));
-       SysTryReturn(NID_WEB_CTRL, pScreenShot, null, E_SYSTEM, "[%s] A system error has been occurred. Failed to get snapshot of Web control", GetErrorMessage(E_SYSTEM));
-
-       r = _Utility::GetPixelBufferFromEvasObject(pScreenShot, bufferInfo);
-       evas_object_del(pScreenShot);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
-
+       ByteBuffer buffer;
        int bufferSize = bufferInfo.bitsPerPixel * bufferInfo.width * bufferInfo.height;
+
        r = buffer.Construct(reinterpret_cast < byte* >(bufferInfo.pPixels), 0, bufferSize, bufferSize);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] propagating", GetErrorMessage(r));
 
@@ -1001,6 +1024,31 @@ _Web::OnCapturedBitmapRequestedN(void)
 }
 
 
+bool
+_Web::OnCaptureAcquire(BufferInfo& output)
+{
+       result r = E_SUCCESS;
+
+       FloatPoint position(GetPositionF());
+       FloatDimension size(GetSizeF());
+
+       Dimension absSize(_CoordinateSystemUtils::ConvertToInteger(_CoordinateSystemUtils::Transform(size)));
+
+       Eina_Rectangle rect;
+       EINA_RECTANGLE_SET(&rect, 0, 0, absSize.width, absSize.height);
+
+       Evas_Object* pWebFrame = GetWebNativeNode();
+       Evas_Object* pScreenShot = ewk_view_screenshot_contents_get(pWebFrame, rect, 1.0f, evas_object_evas_get(pWebFrame));
+       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));
+
+       r = _Utility::GetPixelBufferFromEvasObject(pScreenShot, output);
+       evas_object_del(pScreenShot);
+       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] propagating", GetErrorMessage(r));
+
+       return true;
+}
+
+
 void
 _Web::DumpPointList(void* pData)
 {