From: huayong.xu Date: Mon, 28 Nov 2022 10:30:16 +0000 (+0800) Subject: [Tizen] Add API for 'url,changed' event. X-Git-Tag: accepted/tizen/6.0/unified/20221130.122629^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F32%2F284832%2F1;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git [Tizen] Add API for 'url,changed' event. Change-Id: Idbfedd9a473af39b1e8a015a689a9b9b08d31a50 --- 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 ac2d7d1..3f626dc 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 @@ -44,7 +44,7 @@ class WebEngine; namespace { -static WebEngine* gInstance = NULL; +static WebEngine* gInstance = nullptr; static int gInstanceCount = 0; bool OnGoBack(); @@ -566,6 +566,11 @@ public: mScrollEdgeReachedCallback = callback; } + void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback) + { + mUrlChangedCallback = callback; + } + void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback) { mNavigationPolicyDecisionCallback = callback; @@ -589,6 +594,7 @@ public: Dali::WebEnginePlugin::WebEnginePageLoadCallback mPageLoadFinishedCallback; Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback mPageLoadErrorCallback; Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback mScrollEdgeReachedCallback; + Dali::WebEnginePlugin::WebEngineUrlChangedCallback mUrlChangedCallback; Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback mNavigationPolicyDecisionCallback; std::vector mResultCallbacks; @@ -667,6 +673,10 @@ bool OnLoadUrl() { gInstance->mPageLoadErrorCallback(gInstance->mUrl, WebView::LoadErrorCode::UNKNOWN); } + if (gInstance->mUrlChangedCallback) + { + gInstance->mUrlChangedCallback("http://new-test"); + } if (gInstance->mNavigationPolicyDecisionCallback) { std::unique_ptr policyDecision(new MockWebEnginePolicyDecision()); @@ -954,7 +964,12 @@ void WebEngine::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePa void WebEngine::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback) { - Internal::Adaptor::GetImplementation( *this ).RegisterScrollEdgeReachedCallback(callback); + Internal::Adaptor::GetImplementation(*this).RegisterScrollEdgeReachedCallback(callback); +} + +void WebEngine::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback) +{ + Internal::Adaptor::GetImplementation(*this).RegisterUrlChangedCallback(callback); } void WebEngine::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp index c898b06..6477ccd 100755 --- a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp @@ -48,6 +48,7 @@ const char* const TEST_URL2( "http://www.somewhere.valid2.com" ); static int gPageLoadStartedCallbackCalled = 0; static int gPageLoadFinishedCallbackCalled = 0; static int gScrollEdgeReachedCallbackCalled = 0; +static int gUrlChangedCallbackCalled = 0; static int gNavigationPolicyDecidedCallbackCalled = 0; static int gEvaluateJavaScriptCallbackCalled = 0; static bool gTouched = false; @@ -82,6 +83,11 @@ static void OnScrollEdgeReached( Dali::WebEnginePlugin::ScrollEdge edge ) gScrollEdgeReachedCallbackCalled++; } +static void OnUrlChanged( WebView view, const std::string& url ) +{ + gUrlChangedCallbackCalled++; +} + static void OnNavigationPolicyDecided(std::unique_ptr decision) { gNavigationPolicyDecidedCallbackCalled++; @@ -183,10 +189,12 @@ int UtcDaliWebViewPageNavigation(void) view.RegisterPageLoadStartedCallback( &OnPageLoadStarted ); view.RegisterPageLoadFinishedCallback( &OnPageLoadFinished ); view.RegisterPageLoadErrorCallback( &OnPageLoadError ); + view.RegisterUrlChangedCallback( &OnUrlChanged ); DALI_TEST_EQUALS( gPageLoadStartedCallbackCalled, 0, TEST_LOCATION ); DALI_TEST_EQUALS( gPageLoadFinishedCallbackCalled, 0, TEST_LOCATION ); DALI_TEST_EQUALS( gPageLoadErrorCallbackCalled, 0, TEST_LOCATION ); + DALI_TEST_EQUALS( gUrlChangedCallbackCalled, 0, TEST_LOCATION ); view.LoadUrl( TEST_URL1 ); view.GetNaturalSize(); @@ -195,6 +203,7 @@ int UtcDaliWebViewPageNavigation(void) DALI_TEST_EQUALS( gPageLoadStartedCallbackCalled, 1, TEST_LOCATION ); DALI_TEST_EQUALS( gPageLoadFinishedCallbackCalled, 1, TEST_LOCATION ); DALI_TEST_EQUALS( gPageLoadErrorCallbackCalled, 1, TEST_LOCATION ); + DALI_TEST_EQUALS( gUrlChangedCallbackCalled, 1, TEST_LOCATION ); view.LoadUrl( TEST_URL2 ); view.Suspend(); @@ -207,6 +216,7 @@ int UtcDaliWebViewPageNavigation(void) DALI_TEST_EQUALS( view.CanGoForward(), false, TEST_LOCATION ); DALI_TEST_EQUALS( gPageLoadStartedCallbackCalled, 2, TEST_LOCATION ); DALI_TEST_EQUALS( gPageLoadFinishedCallbackCalled, 2, TEST_LOCATION ); + DALI_TEST_EQUALS( gUrlChangedCallbackCalled, 2, TEST_LOCATION ); view.GoBack(); Test::EmitGlobalTimerSignal(); 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 94b21fd..fa86237 100755 --- a/dali-toolkit/devel-api/controls/web-view/web-view.cpp +++ b/dali-toolkit/devel-api/controls/web-view/web-view.cpp @@ -199,6 +199,11 @@ void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngine Dali::Toolkit::GetImpl(*this).RegisterScrollEdgeReachedCallback(callback); } +void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback) +{ + Dali::Toolkit::GetImpl(*this).RegisterUrlChangedCallback(callback); +} + void WebView::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback) { Dali::Toolkit::GetImpl(*this).RegisterNavigationPolicyDecidedCallback(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 7c54efc..8c7b1c8 100755 --- a/dali-toolkit/devel-api/controls/web-view/web-view.h +++ b/dali-toolkit/devel-api/controls/web-view/web-view.h @@ -385,6 +385,13 @@ public: void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback); /** + * @brief Callback to be called when url is changed. + * + * @param[in] callback + */ + void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback); + + /** * @brief Callback to be called when navigation policy would be decided. * * @param[in] callback 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 562c8d3..f090d6f 100755 --- a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp +++ b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp @@ -493,6 +493,14 @@ void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngine } } +void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback) +{ + if(mWebEngine) + { + mWebEngine.RegisterUrlChangedCallback(callback); + } +} + void WebView::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback) { 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 0205dd7..2eeb092 100755 --- a/dali-toolkit/internal/controls/web-view/web-view-impl.h +++ b/dali-toolkit/internal/controls/web-view/web-view-impl.h @@ -204,6 +204,11 @@ public: void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback); /** + * @copydoc Dali::Toolkit::WebView::RegisterUrlChangedCallback() + */ + void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback); + + /** * @copydoc Dali::Toolkit::WebView::RegisterNavigationPolicyDecidedCallback() */ void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);