From 49f4aba622282abe49713de9f1bb0ee8085855a5 Mon Sep 17 00:00:00 2001 From: "huayong.xu" Date: Mon, 1 Mar 2021 18:20:45 +0800 Subject: [PATCH] Add APIs for hit test in web view. This patch is to add some APIs for hit test into web view. Meanwhile WebFormRepostDecision is removed. Change-Id: I54fbb798f36ea6eaab197d993b2691ddfdc20a32 --- .../dali-toolkit-test-utils/toolkit-web-engine.cpp | 201 ++++++++++++++++----- .../src/dali-toolkit/utc-Dali-WebView.cpp | 62 ++++++- .../controls/web-view/web-form-repost-decision.cpp | 47 ----- .../controls/web-view/web-form-repost-decision.h | 78 -------- .../devel-api/controls/web-view/web-view.cpp | 20 +- .../devel-api/controls/web-view/web-view.h | 91 ++++++---- dali-toolkit/devel-api/file.list | 2 - .../internal/controls/web-view/web-view-impl.cpp | 48 +++-- .../internal/controls/web-view/web-view-impl.h | 48 +++-- 9 files changed, 347 insertions(+), 250 deletions(-) delete mode 100644 dali-toolkit/devel-api/controls/web-view/web-form-repost-decision.cpp delete mode 100755 dali-toolkit/devel-api/controls/web-view/web-form-repost-decision.h diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp index 0b8a473..0b0c203 100755 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -70,6 +72,7 @@ bool OnEvaluteJavaScript(); bool OnJavaScriptAlert(); bool OnJavaScriptConfirm(); bool OnJavaScriptPrompt(); +bool OnHitTestCreated(); bool OnScrollEdge(); bool OnScreenshotCaptured(); bool OnVideoPlaying(); @@ -227,30 +230,6 @@ private: Dali::WebEngineContext::CacheModel mockModel; }; -class MockWebEngineSecurityOrigin : public Dali::WebEngineSecurityOrigin -{ -public: - MockWebEngineSecurityOrigin() - : mockUrl("https://test.html") - , mockPotocol("https") - { - } - - std::string GetHost() const - { - return mockUrl; - } - - std::string GetProtocol() const - { - return mockPotocol; - } - -private: - std::string mockUrl; - std::string mockPotocol; -}; - class MockWebEngineCookieManager : public Dali::WebEngineCookieManager { public: @@ -701,6 +680,100 @@ public: } }; +class MockWebEngineHitTest : public Dali::WebEngineHitTest +{ +public: + MockWebEngineHitTest() + { + } + + ResultContext GetResultContext() const override + { + return ResultContext::DOCUMENT; + } + + std::string GetLinkUri() const override + { + return "http://test.html"; + } + + std::string GetLinkTitle() const override + { + return "test"; + } + + std::string GetLinkLabel() const override + { + return "label"; + } + + std::string GetImageUri() const override + { + return "http://test.jpg"; + } + + std::string GetMediaUri() const override + { + return "http://test.mp4"; + } + + std::string GetTagName() const override + { + return "img"; + } + + std::string GetNodeValue() const override + { + return "test"; + } + + Dali::Property::Map& GetAttributes() const override + { + return mockAttributesMap; + } + + std::string GetImageFileNameExtension() const override + { + return "jpg"; + } + + Dali::PixelData GetImageBuffer() override + { + uint8_t* faviconData = new uint8_t[ 16 ]; + memset(faviconData, 0xff, 16); + return Dali::PixelData::New( faviconData, 16, 2, 2, + Dali::Pixel::Format::RGBA8888, + Dali::PixelData::ReleaseFunction::DELETE_ARRAY ); + } + +private: + mutable Dali::Property::Map mockAttributesMap; +}; + +class MockWebEngineSecurityOrigin : public Dali::WebEngineSecurityOrigin +{ +public: + MockWebEngineSecurityOrigin() + : mockUrl("https://test.html") + , mockPotocol("https") + { + } + + std::string GetHost() const + { + return mockUrl; + } + + std::string GetProtocol() const + { + return mockPotocol; + } + +private: + std::string mockUrl; + std::string mockPotocol; +}; + class MockWebEngineSettings : public WebEngineSettings { public: @@ -1103,6 +1176,22 @@ public: } } + std::unique_ptr CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode) + { + std::unique_ptr hitTest(new MockWebEngineHitTest()); + return hitTest; + } + + bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback) + { + if (callback) + { + ConnectToGlobalSignal( &OnHitTestCreated ); + mHitTestCreatedCallback = callback; + } + return true; + } + void ClearHistory() { ConnectToGlobalSignal( &OnClearHistory ); @@ -1118,7 +1207,7 @@ public: mUserAgent = userAgent; } - void ScrollBy( int dx, int dy ) + void ScrollBy( int32_t dx, int32_t dy ) { mScrollPosition += Dali::Vector2( dx, dy ); if ( mScrollPosition.y + mScrollSize.height > mContentSize.height ) @@ -1127,7 +1216,7 @@ public: } } - bool ScrollEdgeBy( int dx, int dy ) + bool ScrollEdgeBy( int32_t dx, int32_t dy ) { mScrollPosition += Dali::Vector2( dx, dy ); if ( mScrollPosition.y + mScrollSize.height > mContentSize.height ) @@ -1137,7 +1226,7 @@ public: return true; } - void SetScrollPosition( int x, int y ) + void SetScrollPosition( int32_t x, int32_t y ) { mScrollPosition.x = x; mScrollPosition.y = y; @@ -1193,7 +1282,7 @@ public: return mScaleFactor; } - Dali::PixelData GetScreenshot(Dali::Rect viewArea, float scaleFactor) + Dali::PixelData GetScreenshot(Dali::Rect viewArea, float scaleFactor) { uint32_t bufferSize = viewArea.width * viewArea.height * 4 ; uint8_t* pixel = new uint8_t[ bufferSize ]; @@ -1203,7 +1292,7 @@ public: Dali::PixelData::ReleaseFunction::DELETE_ARRAY ); } - bool GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback) + bool GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback) { if ( callback ) { @@ -1347,13 +1436,14 @@ public: WebEngineCookieManager* mockWebEngineCookieManager; WebEngineSettings* mockWebEngineSettings; - std::vector mResultCallbacks; - Dali::WebEnginePlugin::JavaScriptAlertCallback mJavaScriptAlertCallback; - Dali::WebEnginePlugin::JavaScriptConfirmCallback mJavaScriptConfirmCallback; - Dali::WebEnginePlugin::JavaScriptPromptCallback mJavaScriptPromptCallback; - Dali::WebEnginePlugin::ScreenshotCapturedCallback mScreenshotCapturedCallback; - Dali::WebEnginePlugin::VideoPlayingCallback mVideoPlayingCallback; - Dali::WebEnginePlugin::GeolocationPermissionCallback mGeolocationPermissionCallback; + std::vector mResultCallbacks; + Dali::WebEnginePlugin::JavaScriptAlertCallback mJavaScriptAlertCallback; + Dali::WebEnginePlugin::JavaScriptConfirmCallback mJavaScriptConfirmCallback; + Dali::WebEnginePlugin::JavaScriptPromptCallback mJavaScriptPromptCallback; + Dali::WebEnginePlugin::ScreenshotCapturedCallback mScreenshotCapturedCallback; + Dali::WebEnginePlugin::VideoPlayingCallback mVideoPlayingCallback; + Dali::WebEnginePlugin::GeolocationPermissionCallback mGeolocationPermissionCallback; + Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback mHitTestCreatedCallback; }; @@ -1519,6 +1609,17 @@ bool OnGeolocationPermission() return false; } +bool OnHitTestCreated() +{ + DisconnectFromGlobalSignal(&OnHitTestCreated); + if (gInstance) + { + std::unique_ptr test(new MockWebEngineHitTest()); + gInstance->mHitTestCreatedCallback(std::move(test)); + } + return false; +} + bool OnClearHistory() { DisconnectFromGlobalSignal( &OnClearHistory ); @@ -1649,11 +1750,11 @@ WebEngine WebEngine::DownCast( BaseHandle handle ) return WebEngine( dynamic_cast< Internal::Adaptor::WebEngine* >( handle.GetObjectPtr() ) ); } -void WebEngine::Create( int width, int height, const std::string& locale, const std::string& timezoneId ) +void WebEngine::Create( uint32_t width, uint32_t height, const std::string& locale, const std::string& timezoneId ) { } -void WebEngine::Create( int width, int height, int argc, char** argv ) +void WebEngine::Create( uint32_t width, uint32_t height, uint32_t argc, char** argv ) { } @@ -1827,6 +1928,16 @@ void WebEngine::JavaScriptPromptReply( const std::string& result ) { } +std::unique_ptr WebEngine::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode) +{ + return Internal::Adaptor::GetImplementation(*this).CreateHitTest(x, y, mode); +} + +bool WebEngine::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback) +{ + return Internal::Adaptor::GetImplementation(*this).CreateHitTestAsynchronously(x, y, mode, callback); +} + void WebEngine::ClearAllTilesResources() { } @@ -1859,12 +1970,12 @@ void WebEngine::AddDynamicCertificatePath(const std::string& host, const std::st { } -Dali::PixelData WebEngine::GetScreenshot(Dali::Rect viewArea, float scaleFactor) +Dali::PixelData WebEngine::GetScreenshot(Dali::Rect viewArea, float scaleFactor) { return Internal::Adaptor::GetImplementation( *this ).GetScreenshot(viewArea, scaleFactor); } -bool WebEngine::GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback) +bool WebEngine::GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback) { return Internal::Adaptor::GetImplementation( *this ).GetScreenshotAsynchronously(viewArea, scaleFactor, callback); } @@ -1889,17 +2000,17 @@ void WebEngine::SetUserAgent( const std::string& userAgent ) Internal::Adaptor::GetImplementation( *this ).SetUserAgent( userAgent ); } -void WebEngine::ScrollBy( int dx, int dy ) +void WebEngine::ScrollBy( int32_t dx, int32_t dy ) { Internal::Adaptor::GetImplementation( *this ).ScrollBy( dx, dy ); } -bool WebEngine::ScrollEdgeBy( int dx, int dy ) +bool WebEngine::ScrollEdgeBy( int32_t dx, int32_t dy ) { return Internal::Adaptor::GetImplementation( *this ).ScrollEdgeBy( dx, dy ); } -void WebEngine::SetScrollPosition( int x, int y ) +void WebEngine::SetScrollPosition( int32_t x, int32_t y ) { Internal::Adaptor::GetImplementation( *this ).SetScrollPosition( x, y ); } @@ -1919,7 +2030,7 @@ Dali::Vector2 WebEngine::GetContentSize() const return Internal::Adaptor::GetImplementation( *this ).GetContentSize(); } -void WebEngine::SetSize( int width, int height ) +void WebEngine::SetSize( uint32_t width, uint32_t height ) { } @@ -1993,7 +2104,7 @@ float WebEngine::GetLoadProgressPercentage() const return Internal::Adaptor::GetImplementation( *this ).GetLoadProgressPercentage(); } -void WebEngine::UpdateDisplayArea( Dali::Rect< int > displayArea ) +void WebEngine::UpdateDisplayArea( Dali::Rect< int32_t > displayArea ) { } diff --git a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp index 6cacfbf..cf649ce 100755 --- a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp @@ -26,7 +26,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -43,7 +45,6 @@ #include #include #include -#include #include #include @@ -74,7 +75,7 @@ static bool gTouched = false; static bool gHovered = false; static bool gWheelEventHandled = false; static int gFormRepostDecisionCallbackCalled = 0; -static std::shared_ptr gFormRepostDecisionInstance = nullptr; +static std::shared_ptr gFormRepostDecisionInstance = nullptr; static int gFrameRenderedCallbackCalled = 0; static int gRequestInterceptorCallbackCalled = 0; static std::shared_ptr gRequestInterceptorInstance = nullptr; @@ -96,9 +97,10 @@ static int gMimeOverriddenCallbackCalled = 0; static std::vector> gSecurityOriginList; static std::vector> gPasswordDataList; static int gContextMenuCustomizedCallbackCalled = 0; -static std::shared_ptr gContextMenuInstance = 0; +static std::shared_ptr gContextMenuInstance = nullptr; static int gContextMenuItemSelectedCallbackCalled = 0; -static std::shared_ptr gContextMenuItemInstance = 0; +static std::shared_ptr gContextMenuItemInstance = nullptr; +static int gHitTestCreatedCallbackCalled = 0; struct CallbackFunctor { @@ -145,6 +147,12 @@ static void OnUrlChanged( WebView view, const std::string& url ) gUrlChangedCallbackCalled++; } +static bool OnHitTestCreated(std::unique_ptr test) +{ + gHitTestCreatedCallbackCalled++; + return true; +} + static void OnPageLoadError(WebView view, std::shared_ptr error) { gPageLoadErrorCallbackCalled++; @@ -208,7 +216,7 @@ static bool OnWheelEvent( Actor actor, const Dali::WheelEvent& wheel ) return true; } -static void OnFormRepostDecision(WebView, std::shared_ptr decision) +static void OnFormRepostDecision(WebView, std::shared_ptr decision) { gFormRepostDecisionCallbackCalled++; gFormRepostDecisionInstance = std::move(decision); @@ -1335,6 +1343,50 @@ int UtcDaliWebViewPolicyDecisionRequest(void) END_TEST; } +int UtcDaliWebViewHitTest(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + // load url. + view.LoadUrl( TEST_URL1 ); + + // sync hit test. + std::unique_ptr hitTest = view.CreateHitTest(100, 100, Dali::WebEngineHitTest::HitTestMode::DEFAULT); + DALI_TEST_CHECK(hitTest != 0); + DALI_TEST_EQUALS(hitTest->GetResultContext(), Dali::WebEngineHitTest::ResultContext::DOCUMENT, TEST_LOCATION); + std::string testLinkUri("http://test.html"); + DALI_TEST_EQUALS(hitTest->GetLinkUri(), testLinkUri, TEST_LOCATION); + std::string testLinkTitle("test"); + DALI_TEST_EQUALS(hitTest->GetLinkTitle(), testLinkTitle, TEST_LOCATION); + std::string testLinkLabel("label"); + DALI_TEST_EQUALS(hitTest->GetLinkLabel(), testLinkLabel, TEST_LOCATION); + std::string testImageUri("http://test.jpg"); + DALI_TEST_EQUALS(hitTest->GetImageUri(), testImageUri, TEST_LOCATION); + std::string testMediaUri("http://test.mp4"); + DALI_TEST_EQUALS(hitTest->GetMediaUri(), testMediaUri, TEST_LOCATION); + std::string testTagName("img"); + DALI_TEST_EQUALS(hitTest->GetTagName(), testTagName, TEST_LOCATION); + std::string testNodeValue("test"); + DALI_TEST_EQUALS(hitTest->GetNodeValue(), testNodeValue, TEST_LOCATION); + Dali::Property::Map* testMap = &hitTest->GetAttributes(); + DALI_TEST_CHECK(testMap); + std::string testImageFileNameExtension("jpg"); + DALI_TEST_EQUALS(hitTest->GetImageFileNameExtension(), testImageFileNameExtension, TEST_LOCATION); + Dali::PixelData testImageBuffer = hitTest->GetImageBuffer(); + DALI_TEST_CHECK((int)testImageBuffer.GetWidth() == 2 && (int)testImageBuffer.GetHeight() == 2); + + // async... + bool result = view.CreateHitTestAsynchronously(100, 100, Dali::WebEngineHitTest::HitTestMode::DEFAULT, &OnHitTestCreated); + DALI_TEST_CHECK(result); + Test::EmitGlobalTimerSignal(); + DALI_TEST_EQUALS( gHitTestCreatedCallbackCalled, 1, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliWebViewEvaluteJavaScript(void) { ToolkitTestApplication application; diff --git a/dali-toolkit/devel-api/controls/web-view/web-form-repost-decision.cpp b/dali-toolkit/devel-api/controls/web-view/web-form-repost-decision.cpp deleted file mode 100644 index 219d2ca..0000000 --- a/dali-toolkit/devel-api/controls/web-view/web-form-repost-decision.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// CLASS HEADER -#include - -// EXTERNAL INCLUDES -#include - -namespace Dali -{ -namespace Toolkit -{ -WebFormRepostDecision::WebFormRepostDecision(std::shared_ptr decision) -: mFormRepostDecision(std::move(decision)) -{ -} - -WebFormRepostDecision::~WebFormRepostDecision() -{ -} - -void WebFormRepostDecision::Reply(bool allowed) -{ - if(mFormRepostDecision) - { - mFormRepostDecision->Reply(allowed); - } -} - -} // namespace Toolkit - -} // namespace Dali diff --git a/dali-toolkit/devel-api/controls/web-view/web-form-repost-decision.h b/dali-toolkit/devel-api/controls/web-view/web-form-repost-decision.h deleted file mode 100755 index 755fe57..0000000 --- a/dali-toolkit/devel-api/controls/web-view/web-form-repost-decision.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef DALI_TOOLKIT_WEB_FORM_REPOST_DECISION_H -#define DALI_TOOLKIT_WEB_FORM_REPOST_DECISION_H - -/* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// EXTERNAL INCLUDES -#include -#include - -// INTERNAL INCLUDES -#include - -namespace Dali -{ -class WebEngineFormRepostDecision; - -namespace Toolkit -{ -/** - * @addtogroup dali_toolkit_controls_web_view - * @{ - */ - -/** - * @brief WebFormRepostDecision is a class for form repost decision of WebView. - * - * - * For working WebFormRepostDecision, a Dali::WebEngineFormRepostDecision should be provided. - * - */ -class DALI_TOOLKIT_API WebFormRepostDecision -{ -public: - /** - * @brief Creates a WebFormRepostDecision. - */ - WebFormRepostDecision(std::shared_ptr decision); - - /** - * @brief Destructor. - */ - virtual ~WebFormRepostDecision() final; - - /** - * @brief Reply the result about form repost decision. - * - * @param[in] allowed Whether allow form repost decision request or not - */ - void Reply(bool allowed); - -private: - std::shared_ptr mFormRepostDecision; -}; - -/** - * @} - */ - -} // namespace Toolkit - -} // namespace Dali - -#endif // DALI_TOOLKIT_WEB_FORM_REPOST_DECISION_H diff --git a/dali-toolkit/devel-api/controls/web-view/web-view.cpp b/dali-toolkit/devel-api/controls/web-view/web-view.cpp index f73e9dc..d3c201a 100755 --- a/dali-toolkit/devel-api/controls/web-view/web-view.cpp +++ b/dali-toolkit/devel-api/controls/web-view/web-view.cpp @@ -59,7 +59,7 @@ WebView WebView::New(const std::string& locale, const std::string& timezoneId) return Internal::WebView::New(locale, timezoneId); } -WebView WebView::New(int argc, char** argv) +WebView WebView::New(uint32_t argc, char** argv) { return Internal::WebView::New(argc, argv); } @@ -169,12 +169,12 @@ bool WebView::StopInspectorServer() return Dali::Toolkit::GetImpl(*this).StopInspectorServer(); } -void WebView::ScrollBy(int deltaX, int deltaY) +void WebView::ScrollBy(int32_t deltaX, int32_t deltaY) { Dali::Toolkit::GetImpl(*this).ScrollBy(deltaX, deltaY); } -bool WebView::ScrollEdgeBy(int deltaX, int deltaY) +bool WebView::ScrollEdgeBy(int32_t deltaX, int32_t deltaY) { return Dali::Toolkit::GetImpl(*this).ScrollEdgeBy(deltaX, deltaY); } @@ -244,6 +244,16 @@ void WebView::JavaScriptPromptReply(const std::string& result) Dali::Toolkit::GetImpl(*this).JavaScriptPromptReply(result); } +std::unique_ptr WebView::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode) +{ + return Dali::Toolkit::GetImpl(*this).CreateHitTest(x, y, mode); +} + +bool WebView::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback) +{ + return Dali::Toolkit::GetImpl(*this).CreateHitTestAsynchronously(x, y, mode, callback); +} + void WebView::ClearHistory() { Dali::Toolkit::GetImpl(*this).ClearHistory(); @@ -279,12 +289,12 @@ void WebView::AddDynamicCertificatePath(const std::string& host, const std::stri Dali::Toolkit::GetImpl(*this).AddDynamicCertificatePath(host, certPath); } -Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect viewArea, float scaleFactor) +Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect viewArea, float scaleFactor) { return Dali::Toolkit::GetImpl(*this).GetScreenshot(viewArea, scaleFactor); } -bool WebView::GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback) +bool WebView::GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback) { return Dali::Toolkit::GetImpl(*this).GetScreenshotAsynchronously(viewArea, scaleFactor, callback); } diff --git a/dali-toolkit/devel-api/controls/web-view/web-view.h b/dali-toolkit/devel-api/controls/web-view/web-view.h index 6d8d3b9..4f9159d 100755 --- a/dali-toolkit/devel-api/controls/web-view/web-view.h +++ b/dali-toolkit/devel-api/controls/web-view/web-view.h @@ -216,7 +216,7 @@ public: /** * @brief WebView signal type related with form repost decision. */ - using WebViewFormRepostDecisionSignalType = Signal)>; + using WebViewFormRepostDecisionSignalType = Signal)>; /** * @brief WebView signal type related with frame rendered. @@ -260,7 +260,7 @@ public: public: /** - * @brief Creates an initialized WebView. + * @brief Create an initialized WebView. * @return A handle to a newly allocated Dali WebView * * @note WebView will not display anything @@ -268,7 +268,7 @@ public: static WebView New(); /** - * @brief Creates an initialized WebView. + * @brief Create an initialized WebView. * * @param [in] locale The locale of Web * @param [in] timezoneId The timezoneId of Web @@ -276,15 +276,15 @@ public: static WebView New(const std::string& locale, const std::string& timezoneId); /** - * @brief Creates an initialized WebView. + * @brief Create an initialized WebView. * * @param [in] argc The count of arguments of Applications * @param [in] argv The string array of arguments of Applications */ - static WebView New(int argc, char** argv); + static WebView New(uint32_t argc, char** argv); /** - * @brief Creates an uninitialized WebView. + * @brief Create an uninitialized WebView. */ WebView(); @@ -311,7 +311,7 @@ public: WebView& operator=(const WebView& WebView); /** - * @brief Downcasts a handle to WebView handle. + * @brief Downcast a handle to WebView handle. * * If handle points to a WebView, the downcast produces valid handle. * If not, the returned handle is left uninitialized. @@ -349,14 +349,14 @@ public: Dali::Toolkit::ImageView& GetFavicon(); /** - * @brief Loads a web page based on a given URL. + * @brief Load a web page based on a given URL. * * @param [in] url The URL of the resource to load */ void LoadUrl(const std::string& url); /** - * @brief Loads a given string as web contents. + * @brief Load a given string as web contents. * * @param [in] htmlString The string to use as the contents of the web page */ @@ -374,7 +374,7 @@ public: bool LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl); /** - * @brief Requests loading the given contents by MIME type into the view object + * @brief Request loading the given contents by MIME type into the view object * * @param[in] contents The content to load * @param[in] contentSize The size of contents (in bytes) @@ -387,27 +387,27 @@ public: bool LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri); /** - * @brief Reloads the Web. + * @brief Reload the Web. */ void Reload(); /** - * @brief Reloads the current page's document without cache + * @brief Reload the current page's document without cache */ bool ReloadWithoutCache(); /** - * @brief Stops loading web contents on the current page. + * @brief Stop loading web contents on the current page. */ void StopLoading(); /** - * @brief Suspends the operation associated with the view. + * @brief Suspend the operation associated with the view. */ void Suspend(); /** - * @brief Resumes the operation associated with the view object after calling Suspend(). + * @brief Resume the operation associated with the view object after calling Suspend(). */ void Resume(); @@ -457,48 +457,48 @@ public: bool StopInspectorServer(); /** - * @brief Scrolls web page of view by deltaX and deltaY. + * @brief Scroll web page of view by deltaX and deltaY. * @param[in] deltaX The delta x of scroll * @param[in] deltaY The delta y of scroll */ - void ScrollBy(int deltaX, int deltaY); + void ScrollBy(int32_t deltaX, int32_t deltaY); /** - * @brief Scrolls edge of view by deltaX and deltaY. + * @brief Scroll edge of view by deltaX and deltaY. * * @param[in] deltaX horizontal offset to scroll * @param[in] deltaY vertical offset to scroll * * @return true if succeeded, false otherwise */ - bool ScrollEdgeBy(int deltaX, int deltaY); + bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY); /** - * @brief Returns whether forward is possible. + * @brief Return whether forward is possible. * * @return True if forward is possible, false otherwise */ bool CanGoForward(); /** - * @brief Goes forward in the navigation history. + * @brief Go forward in the navigation history. */ void GoForward(); /** - * @brief Returns whether backward is possible. + * @brief Return whether backward is possible. * * @return True if backward is possible, false otherwise */ bool CanGoBack(); /** - * @brief Goes back in the navigation history. + * @brief Go back in the navigation history. */ void GoBack(); /** - * @brief Evaluates JavaScript code represented as a string. + * @brief Evaluate JavaScript code represented as a string. * * @param[in] script The JavaScript code * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result @@ -506,7 +506,7 @@ public: void EvaluateJavaScript(const std::string& script, std::function resultHandler); /** - * @brief Evaluates JavaScript code represented as a string. + * @brief Evaluate JavaScript code represented as a string. * * @param[in] script The JavaScript code */ @@ -577,24 +577,47 @@ public: void JavaScriptPromptReply(const std::string& result); /** - * @brief Clears the history of Web. + * @brief Create a new hit test. + * + * @param[in] x the horizontal position to query + * @param[in] y the vertical position to query + * @param[in] mode the mode of hit test + * + * @return a new hit test object. + */ + std::unique_ptr CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode); + + /** + * @brief Create a hit test asynchronously. + * + * @param[in] x the horizontal position to query + * @param[in] y the vertical position to query + * @param[in] mode the mode of hit test + * @param[in] callback The callback function + * + * @return true if succeeded, false otherwise. + */ + bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback); + + /** + * @brief Clear the history of Web. */ void ClearHistory(); /** - * @brief Clears all tiles resources of Web. + * @brief Clear all tiles resources of Web. */ void ClearAllTilesResources(); /** - * @brief Scales the current page, centered at the given point. + * @brief Scale the current page, centered at the given point. * @param[in] scaleFactor a new factor to be scaled. * @param[in] point a center coordinate. */ void SetScaleFactor(float scaleFactor, Dali::Vector2 point); /** - * @brief Gets the current scale factor of the page. + * @brief Get the current scale factor of the page. * @return The current scale factor. */ float GetScaleFactor() const; @@ -606,7 +629,7 @@ public: void ActivateAccessibility(bool activated); /** - * @brief Searches and highlights the given string in the document. + * @brief Search and highlights the given string in the document. * @param[in] text The text to find * @param[in] options The options to find * @param[in] maxMatchCount The maximum match count to find @@ -630,7 +653,7 @@ public: * * @return image view of screen shot */ - Dali::Toolkit::ImageView GetScreenshot(Dali::Rect viewArea, float scaleFactor); + Dali::Toolkit::ImageView GetScreenshot(Dali::Rect viewArea, float scaleFactor); /** * @brief Request to get snapshot of the specified viewArea of page asynchronously. @@ -641,7 +664,7 @@ public: * * @return true if requested successfully, false otherwise */ - bool GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, WebViewScreenshotCapturedCallback callback); + bool GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, WebViewScreenshotCapturedCallback callback); /** * @brief Asynchronous request to check if there is a video playing in the given view. @@ -774,14 +797,14 @@ public: public: // Not intended for application developers /// @cond internal /** - * @brief Creates a handle using the Toolkit::Internal implementation. + * @brief Create a handle using the Toolkit::Internal implementation. * * @param[in] implementation The WebView implementation */ DALI_INTERNAL WebView(Internal::WebView& implementation); /** - * @brief Allows the creation of this WebView from an Internal::CustomActor pointer. + * @brief Allow the creation of this WebView from an Internal::CustomActor pointer. * * @param[in] internal A pointer to the internal CustomActor */ diff --git a/dali-toolkit/devel-api/file.list b/dali-toolkit/devel-api/file.list index 716c86c..f583d3c 100755 --- a/dali-toolkit/devel-api/file.list +++ b/dali-toolkit/devel-api/file.list @@ -42,7 +42,6 @@ SET( devel_api_src_files ${devel_api_src_dir}/controls/web-view/web-back-forward-list.cpp ${devel_api_src_dir}/controls/web-view/web-context.cpp ${devel_api_src_dir}/controls/web-view/web-cookie-manager.cpp - ${devel_api_src_dir}/controls/web-view/web-form-repost-decision.cpp ${devel_api_src_dir}/controls/web-view/web-settings.cpp ${devel_api_src_dir}/controls/web-view/web-view.cpp ${devel_api_src_dir}/focus-manager/keyinput-focus-manager.cpp @@ -258,7 +257,6 @@ SET( devel_api_web_view_header_files ${devel_api_src_dir}/controls/web-view/web-back-forward-list.h ${devel_api_src_dir}/controls/web-view/web-context.h ${devel_api_src_dir}/controls/web-view/web-cookie-manager.h - ${devel_api_src_dir}/controls/web-view/web-form-repost-decision.h ${devel_api_src_dir}/controls/web-view/web-settings.h ${devel_api_src_dir}/controls/web-view/web-view.h ) diff --git a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp index 0dd6834..6a3af8d 100644 --- a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp +++ b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,6 @@ #include #include #include -#include #include #include #include @@ -141,7 +141,7 @@ WebView::WebView(const std::string& locale, const std::string& timezoneId) } } -WebView::WebView(int argc, char** argv) +WebView::WebView(uint32_t argc, char** argv) : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)), mUrl(), mVisual(), @@ -196,7 +196,7 @@ Toolkit::WebView WebView::New(const std::string& locale, const std::string& time return handle; } -Toolkit::WebView WebView::New(int argc, char** argv) +Toolkit::WebView WebView::New(uint32_t argc, char** argv) { WebView* impl = new WebView(argc, argv); Toolkit::WebView handle = Toolkit::WebView(*impl); @@ -449,7 +449,7 @@ bool WebView::StopInspectorServer() return mWebEngine ? mWebEngine.StopInspectorServer() : false; } -void WebView::ScrollBy(int deltaX, int deltaY) +void WebView::ScrollBy(int32_t deltaX, int32_t deltaY) { if(mWebEngine) { @@ -457,7 +457,7 @@ void WebView::ScrollBy(int deltaX, int deltaY) } } -bool WebView::ScrollEdgeBy(int deltaX, int deltaY) +bool WebView::ScrollEdgeBy(int32_t deltaX, int32_t deltaY) { return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false; } @@ -552,6 +552,27 @@ void WebView::JavaScriptPromptReply(const std::string& result) } } +std::unique_ptr WebView::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode) +{ + std::unique_ptr webHitTest; + if(!mWebEngine) + { + return webHitTest; + } + + return mWebEngine.CreateHitTest(x, y, mode); +} + +bool WebView::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback) +{ + bool result = false; + if(mWebEngine) + { + result = mWebEngine.CreateHitTestAsynchronously(x, y, mode, callback); + } + return result; +} + void WebView::ClearHistory() { if(mWebEngine) @@ -602,7 +623,7 @@ void WebView::AddDynamicCertificatePath(const std::string& host, const std::stri } } -Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect viewArea, float scaleFactor) +Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect viewArea, float scaleFactor) { Dali::Toolkit::ImageView imageView; if(mWebEngine) @@ -613,7 +634,7 @@ Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect viewArea, float return imageView; } -bool WebView::GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback) +bool WebView::GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback) { mScreenshotCapturedCallback = callback; return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false; @@ -644,7 +665,7 @@ void WebView::UpdateDisplayArea(Dali::PropertyNotification& /*source*/) Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT); Vector2 screenPosition = self.GetProperty(Actor::Property::SCREEN_POSITION); - Dali::Rect displayArea; + Dali::Rect displayArea; displayArea.x = screenPosition.x - anchorPointOffSet.x; displayArea.y = screenPosition.y - anchorPointOffSet.y; displayArea.width = actorSize.x; @@ -831,9 +852,8 @@ void WebView::OnFormRepostDecision(std::shared_ptr repostDecision(new Dali::Toolkit::WebFormRepostDecision(decision)); - mFormRepostDecisionSignal.Emit(handle, std::move(repostDecision)); + Dali::Toolkit::WebView handle(GetOwner()); + mFormRepostDecisionSignal.Emit(handle, std::move(decision)); } } @@ -1277,7 +1297,7 @@ bool WebView::OnKeyEvent(const Dali::KeyEvent& event) bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover) { bool result = false; - if(mWebEngine) + if(mWebEngine && mMouseEventsEnabled) { result = mWebEngine.SendHoverEvent(hover); } @@ -1287,7 +1307,7 @@ bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover) bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel) { bool result = false; - if(mWebEngine) + if(mWebEngine && mMouseEventsEnabled) { result = mWebEngine.SendWheelEvent(wheel); } @@ -1314,7 +1334,7 @@ void WebView::OnKeyInputFocusLost() EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last. } -void WebView::SetScrollPosition(int x, int y) +void WebView::SetScrollPosition(int32_t x, int32_t y) { if(mWebEngine) { diff --git a/dali-toolkit/internal/controls/web-view/web-view-impl.h b/dali-toolkit/internal/controls/web-view/web-view-impl.h index 99a964c..4031ee6 100755 --- a/dali-toolkit/internal/controls/web-view/web-view-impl.h +++ b/dali-toolkit/internal/controls/web-view/web-view-impl.h @@ -52,7 +52,7 @@ protected: WebView(const std::string& locale, const std::string& timezoneId); - WebView(int argc, char** argv); + WebView(uint32_t argc, char** argv); virtual ~WebView(); @@ -68,34 +68,32 @@ public: static Toolkit::WebView New(const std::string& locale, const std::string& timezoneId); /** - * @copydoc Dali::Toolkit::WebView::New( int, char** ) + * @copydoc Dali::Toolkit::WebView::New( uint32_t, char** ) */ - static Toolkit::WebView New(int argc, char** argv); + static Toolkit::WebView New(uint32_t argc, char** argv); /** - * @brief Get settings of WebEngine. + * @copydoc Dali::Toolkit::WebView::GetSettings() */ Dali::Toolkit::WebSettings* GetSettings() const; /** - * @brief Get context of WebEngine. + * @copydoc Dali::Toolkit::WebView::GetContext() */ Dali::Toolkit::WebContext* GetContext() const; /** - * @brief Get cookie manager of WebEngine. + * @copydoc Dali::Toolkit::WebView::GetCookieManager() */ Dali::Toolkit::WebCookieManager* GetCookieManager() const; /** - * @brief Get WebBackForwardList of WebEngine. + * @copydoc Dali::Toolkit::WebView::GetBackForwardList() */ Dali::Toolkit::WebBackForwardList* GetBackForwardList() const; /** - * @brief Get Favicon of web page. - * - * @return Handle to a fav icon + * @copydoc Dali::Toolkit::WebView::GetFavicon() */ Dali::Toolkit::ImageView& GetFavicon(); @@ -177,12 +175,12 @@ public: /** * @copydoc Dali::Toolkit::WebView::ScrollBy() */ - void ScrollBy(int deltaX, int deltaY); + void ScrollBy(int32_t deltaX, int32_t deltaY); /** * @copydoc Dali::WebEngine::ScrollEdgeBy() */ - bool ScrollEdgeBy(int deltaX, int deltaY); + bool ScrollEdgeBy(int32_t deltaX, int32_t deltaY); /** * @copydoc Dali::Toolkit::WebView::CanGoForward() @@ -245,6 +243,16 @@ public: void JavaScriptPromptReply(const std::string& result); /** + * @copydoc Dali::Toolkit::WebView::CreateHitTest() + */ + std::unique_ptr CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode); + + /** + * @copydoc Dali::Toolkit::WebView::CreateHitTestAsynchronously() + */ + bool CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback); + + /** * @copydoc Dali::Toolkit::WebView::ClearHistory() */ void ClearHistory(); @@ -282,12 +290,12 @@ public: /** * @copydoc Dali::Toolkit::WebView::GetScreenshot() */ - Dali::Toolkit::ImageView GetScreenshot(Dali::Rect viewArea, float scaleFactor); + Dali::Toolkit::ImageView GetScreenshot(Dali::Rect viewArea, float scaleFactor); /** * @copydoc Dali::Toolkit::WebView::GetScreenshotAsynchronously() */ - bool GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback); + bool GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback); /** * @copydoc Dali::Toolkit::WebView::CheckVideoPlayingAsynchronously() @@ -451,10 +459,10 @@ private: * @param[in] x The coordinate x of scroll * @param[in] y The coordinate y of scroll */ - void SetScrollPosition(int x, int y); + void SetScrollPosition(int32_t x, int32_t y); /** - * @brief Gets the current scroll position of the given view. + * @brief Get the current scroll position of the given view. * @param[out] x The coordinate x of scroll * @param[out] y The coordinate y of scroll */ @@ -640,7 +648,7 @@ private: void OnUrlChanged(const std::string& url); /** - * Signal occurs when the Web View has been touched. + * @brief Signal occurs when the Web View has been touched. * @param[in] actor The Actor Touched * @param[in] touch The Touch Data. * @return Whether to consume event or not. @@ -648,7 +656,7 @@ private: bool OnTouchEvent(Actor actor, const Dali::TouchEvent& touch); /** - * Signal occurs when the Web View has been hovered. + * @brief Signal occurs when the Web View has been hovered. * @param[in] actor The Actor Hovered * @param[in] hover The Hover Data. * @return Whether to consume event or not. @@ -656,7 +664,7 @@ private: bool OnHoverEvent(Actor actor, const Dali::HoverEvent& hover); /** - * Signal occurs when the Web View receives wheel event. + * @brief Signal occurs when the Web View receives wheel event. * @param[in] actor The Actor that receives Wheel event. * @param[in] wheel The Wheel Data. * @return Whether to consume event or not. @@ -769,7 +777,7 @@ private: Dali::PropertyNotification mPositionUpdateNotification; Dali::PropertyNotification mSizeUpdateNotification; Dali::PropertyNotification mScaleUpdateNotification; - Dali::Rect mWebViewArea; + Dali::Rect mWebViewArea; bool mVideoHoleEnabled; bool mMouseEventsEnabled; bool mKeyEventsEnabled; -- 2.7.4