From 91d04eb7ee3862fa2d16cab7b1ff26934f119a2b Mon Sep 17 00:00:00 2001 From: Hyunseok Yang Date: Tue, 9 Jul 2013 21:34:54 +0900 Subject: [PATCH] change for webpagecapture Change-Id: Iff596833aa1680e12096e6f8d5537efc10a01a18 Signed-off-by: Hyunseok Yang --- src/controls/FWebCtrl_Web.cpp | 71 ++++++++++++++++++++++++++------------- src/controls/FWebCtrl_Web.h | 12 ++++--- src/controls/FWebCtrl_WebImpl.cpp | 62 ++++++++++++++++++++++++++++++++++ src/controls/FWebCtrl_WebImpl.h | 8 ++--- 4 files changed, 121 insertions(+), 32 deletions(-) mode change 100644 => 100755 src/controls/FWebCtrl_Web.cpp diff --git a/src/controls/FWebCtrl_Web.cpp b/src/controls/FWebCtrl_Web.cpp old mode 100644 new mode 100755 index 9b55a6b..f92d336 --- a/src/controls/FWebCtrl_Web.cpp +++ b/src/controls/FWebCtrl_Web.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -389,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(); @@ -954,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 pCanvas(new (std::nothrow) Canvas()); @@ -973,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)); @@ -995,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)); @@ -1026,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) { diff --git a/src/controls/FWebCtrl_Web.h b/src/controls/FWebCtrl_Web.h index 4306cc5..0c10d30 100755 --- a/src/controls/FWebCtrl_Web.h +++ b/src/controls/FWebCtrl_Web.h @@ -32,6 +32,7 @@ #include #include #include +#include namespace Tizen { namespace Ui { @@ -81,10 +82,11 @@ enum _WebEdgeType class _Web : public Tizen::Ui::_Control - , Tizen::Ui::_ITouchFlickGestureEventListener - , Tizen::Ui::_ITouchLongPressGestureEventListener - , Tizen::Ui::_ITouchPinchGestureEventListener - , Tizen::Ui::_ITouchTapGestureEventListener + , public Tizen::Ui::_ITouchFlickGestureEventListener + , public Tizen::Ui::_ITouchLongPressGestureEventListener + , public Tizen::Ui::_ITouchPinchGestureEventListener + , public Tizen::Ui::_ITouchTapGestureEventListener + , public Tizen::Ui::Animations::_IVisualElementCaptureProvider , virtual public Tizen::Base::Runtime::IEventListener , virtual public Tizen::Ui::_IUiEventListener , virtual public Tizen::Ui::_IUiEventPreviewer @@ -142,6 +144,8 @@ public: virtual Tizen::Graphics::Canvas* OnCanvasRequestedN(const Tizen::Graphics::FloatRectangle& size); virtual Tizen::Graphics::Bitmap* OnCapturedBitmapRequestedN(void); + virtual bool OnCaptureAcquire(Tizen::Graphics::BufferInfo& output); + virtual void OnCaptureReleased(void) {}; private: _Web(const _Web& value); diff --git a/src/controls/FWebCtrl_WebImpl.cpp b/src/controls/FWebCtrl_WebImpl.cpp index 566a4d3..e541ffd 100755 --- a/src/controls/FWebCtrl_WebImpl.cpp +++ b/src/controls/FWebCtrl_WebImpl.cpp @@ -833,6 +833,26 @@ OnContentHandlerUnregistrationRequested(void* pUserData, Evas_Object* pView, voi void +OnFullScreenEntered(void* pUserData, Evas_Object* pView, void* pEventInfo) +{ + _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData); + SysAssertf(pImpl, "Failed to request"); + + SysLog(NID_WEB_CTRL, "Enter."); +} + + +void +OnFullScreenExited(void* pUserData, Evas_Object* pView, void* pEventInfo) +{ + _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData); + SysAssertf(pImpl, "Failed to request"); + + SysLog(NID_WEB_CTRL, "Exit."); +} + + +void OnVibrationRequested(uint64_t duration, void* pUserData) { result r = E_SUCCESS; @@ -1604,6 +1624,8 @@ OnWebPageBlockSelectedByOrientation(void* pUserData, Evas_Object* pView, void* p ewk_view_orientation_send(pView, orientation); OnWebPageBlockSelected(pUserData, pView, pEventInfo); + + SysLog(NID_WEB_CTRL, "Enter."); } @@ -3664,6 +3686,9 @@ _WebImpl::SetEventListenerCallback(void) const evas_object_smart_callback_add(pWebNativeNode, "text,selected", OnWebPageBlockSelected, this); evas_object_smart_callback_add(pWebNativeNode, "frame,rendered", OnWebPageBlockSelectedByOrientation, this); + evas_object_smart_callback_add(pWebNativeNode, "fullscreen,enterfullscreen", OnFullScreenEntered, this); + evas_object_smart_callback_add(pWebNativeNode, "fullscreen,exitfullscreen", OnFullScreenExited, this); + ewk_view_open_panel_callback_set(pWebNativeNode, OnSelectUploadFile, const_cast< _WebImpl* >(this)); Ewk_Context* pContext = ewk_view_context_get(pWebNativeNode); SysAssertf(pContext, "Failed to get webkit instance."); @@ -3746,6 +3771,9 @@ _WebImpl::RemoveEventListenerCallback(void) const evas_object_smart_callback_del(pWebNativeNode, "text,selected", OnWebPageBlockSelected); evas_object_smart_callback_del(pWebNativeNode, "frame,rendered", OnWebPageBlockSelectedByOrientation); + evas_object_smart_callback_del(pWebNativeNode, "fullscreen,enterfullscreen", OnFullScreenEntered); + evas_object_smart_callback_del(pWebNativeNode, "fullscreen,exitfullscreen", OnFullScreenExited); + ewk_view_open_panel_callback_set(null, null, null); Ewk_Context* pContext = ewk_view_context_get(pWebNativeNode); SysAssertf(pContext, "Failed to get webkit instance."); @@ -3958,6 +3986,36 @@ _WebImpl::GetPageSize(void) const } +result +_WebImpl::AddCustomHeader(const String& name, const String& value) +{ + SysTryReturnResult(NID_WEB_CTRL, name.GetLength() > 0, E_INVALID_ARG, "Invalid argument(s) is used. name key is missing."); + + std::unique_ptr pName(_StringConverter::CopyToCharArrayN(name)); + SysTryReturn(NID_WEB_CTRL, pName.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + + std::unique_ptr pValue(_StringConverter::CopyToCharArrayN(value)); + + ewk_view_custom_header_add(__pWebCore->GetWebNativeNode(), pName.get(), pValue.get()); + + return E_SUCCESS; +} + + +result +_WebImpl::RemoveCustomHeader(const String& name) +{ + SysTryReturnResult(NID_WEB_CTRL, name.GetLength() > 0, E_INVALID_ARG, "Invalid argument(s) is used. name key is missing."); + + std::unique_ptr pName(_StringConverter::CopyToCharArrayN(name)); + SysTryReturn(NID_WEB_CTRL, pName.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + + ewk_view_custom_header_remove(__pWebCore->GetWebNativeNode(), pName.get()); + + return E_SUCCESS; +} + + void _WebImpl::SetLoadingErrorOccurred(bool arg) { @@ -4708,6 +4766,8 @@ _WebImpl::ShowUserConfirmPopup(_UserConfirmMode userConfirmMode, void* pPolicy, SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pIndexedDbQuotaConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r)); break; } + default: + break; } CATCH: return r; @@ -4777,6 +4837,8 @@ _WebImpl::ShowUserConfirmPopupAsync(_UserConfirmMode userConfirmMode, void* pPol __pScriptAlertConfirmPopup.release(); break; } + default: + break; } return E_SUCCESS; diff --git a/src/controls/FWebCtrl_WebImpl.h b/src/controls/FWebCtrl_WebImpl.h index 4ee1700..1303c18 100755 --- a/src/controls/FWebCtrl_WebImpl.h +++ b/src/controls/FWebCtrl_WebImpl.h @@ -180,10 +180,6 @@ public: void Reload(void) const; - result AddCustomHeader(const Tizen::Net::Http::HttpHeader& header); - - void RemoveAllCustomHeaders(void); - bool SearchText(const Tizen::Base::String& word, bool searchForward); result SetSetting(const Tizen::Web::Controls::WebSetting& setting); @@ -299,6 +295,10 @@ public: Tizen::Graphics::Dimension GetPageSize(void) const; + result AddCustomHeader(const Tizen::Base::String& name, const Tizen::Base::String& value); + + result RemoveCustomHeader(const Tizen::Base::String& name); + virtual bool IsLayoutable(void) const; void SetEventListenerCallback(void) const; -- 2.7.4