From 153f1a4fb6d4bae78b3c89fe570e5e662a9a54c1 Mon Sep 17 00:00:00 2001 From: zhouleonlei Date: Mon, 15 Mar 2021 17:19:32 +0800 Subject: [PATCH] Add the APIs of webview settings Change-Id: Id76de24b2c5a26f7f57f0e8d111c578b3b32fe2d --- .../dali-toolkit-test-utils/toolkit-web-engine.cpp | 34 ++++++++++ .../src/dali-toolkit/utc-Dali-WebView.cpp | 75 ++++++++++++++++++++++ .../devel-api/controls/web-view/web-settings.cpp | 36 +++++++++++ .../devel-api/controls/web-view/web-settings.h | 63 ++++++++++++++++++ 4 files changed, 208 insertions(+) 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 0b0c203..430615d 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 @@ -989,6 +989,40 @@ public: { } + bool SetViewportMetaTag(bool enable) override + { + return true; + } + + bool SetForceZoom(bool enable) override + { + return true; + } + + bool IsZoomForced() const override + { + return true; + } + + bool SetTextZoomEnabled(bool enable) override + { + return true; + } + + bool IsTextZoomEnabled() const override + { + return true; + } + + void SetExtraFeature(const std::string& feature, bool enable) override + { + } + + bool IsExtraFeatureEnabled(const std::string& feature) const override + { + return true; + } + private: int mockDefaultFontSize; bool mockJavaScriptEnabled; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp index cf649ce..39ebd29 100755 --- a/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp @@ -2207,3 +2207,78 @@ int UtcDaliWebSettingsGetSetDefaultTextEncodingName(void) END_TEST; } +int UtcDaliWebSettingsSetViewportMetaTag(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + Dali::Toolkit::WebSettings* settings = view.GetSettings(); + DALI_TEST_CHECK( settings != 0 ) + + // Check the value is true or not + bool value = settings->SetViewportMetaTag(true); + DALI_TEST_CHECK( value ); + + END_TEST; +} + +int UtcDaliWebSettingsSetForceZoom(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + Dali::Toolkit::WebSettings* settings = view.GetSettings(); + DALI_TEST_CHECK( settings != 0 ) + + // Check the value is true or not + bool value = settings->SetForceZoom(true); + DALI_TEST_CHECK( value ); + + value = settings->IsZoomForced(); + DALI_TEST_CHECK( value ); + + END_TEST; +} + +int UtcDaliWebSettingsSetTextZoomEnabled(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + Dali::Toolkit::WebSettings* settings = view.GetSettings(); + DALI_TEST_CHECK( settings != 0 ) + + // Check the value is true or not + bool value = settings->SetTextZoomEnabled(true); + DALI_TEST_CHECK( value ); + + value = settings->IsTextZoomEnabled(); + DALI_TEST_CHECK( value ); + + END_TEST; +} + +int UtcDaliWebSettingsSetExtraFeature(void) +{ + ToolkitTestApplication application; + + WebView view = WebView::New(); + DALI_TEST_CHECK( view ); + + Dali::Toolkit::WebSettings* settings = view.GetSettings(); + DALI_TEST_CHECK( settings != 0 ) + + // Check the value is true or not + settings->SetExtraFeature("test", true); + bool value = settings->IsExtraFeatureEnabled("test"); + DALI_TEST_CHECK( value ); + + END_TEST; +} + diff --git a/dali-toolkit/devel-api/controls/web-view/web-settings.cpp b/dali-toolkit/devel-api/controls/web-view/web-settings.cpp index d39a93e..b17f48d 100755 --- a/dali-toolkit/devel-api/controls/web-view/web-settings.cpp +++ b/dali-toolkit/devel-api/controls/web-view/web-settings.cpp @@ -234,6 +234,42 @@ void WebSettings::SetDefaultTextEncodingName(const std::string& defaultTextEncod mWebEngineSettings.SetDefaultTextEncodingName(defaultTextEncodingName); } +bool WebSettings::SetViewportMetaTag(bool enable) +{ + return mWebEngineSettings.SetViewportMetaTag(enable); +} + +bool WebSettings::SetForceZoom(bool enable) +{ + return mWebEngineSettings.SetForceZoom(enable); +} + +bool WebSettings::IsZoomForced() const +{ + return mWebEngineSettings.IsZoomForced(); +} + +bool WebSettings::SetTextZoomEnabled(bool enable) +{ + return mWebEngineSettings.SetTextZoomEnabled(enable); +} + +bool WebSettings::IsTextZoomEnabled() const +{ + return mWebEngineSettings.IsTextZoomEnabled(); +} + +void WebSettings::SetExtraFeature(const std::string& feature, bool enable) +{ + mWebEngineSettings.SetExtraFeature(feature, enable); +} + +bool WebSettings::IsExtraFeatureEnabled(const std::string& feature) const +{ + return mWebEngineSettings.IsExtraFeatureEnabled(feature); +} + + } // namespace Toolkit } // namespace Dali diff --git a/dali-toolkit/devel-api/controls/web-view/web-settings.h b/dali-toolkit/devel-api/controls/web-view/web-settings.h index ba8b1fa..de42833 100755 --- a/dali-toolkit/devel-api/controls/web-view/web-settings.h +++ b/dali-toolkit/devel-api/controls/web-view/web-settings.h @@ -344,6 +344,69 @@ public: */ void SetDefaultTextEncodingName(const std::string& defaultTextEncodingName); + /** + * @brief Enables/disables the viewport meta tag. + * + * By default, the viewport meta tag is enabled on mobile and wearable, + * but it is disabled on TV. + * + * @param[in] enable @c true to enable the viewport meta tag + * @c false to disable + * + * @return @c true on success or @c false on failure + */ + bool SetViewportMetaTag(bool enable); + + /** + * @brief Requests setting of force zoom. + * + * @param[in] enable to force zoom + * + * @return @c true on success or @c false on failure + */ + bool SetForceZoom(bool enable); + + /** + * @brief Returns the force zoom status. + * + * @return @c true if enable force zoom or @c false. + */ + bool IsZoomForced() const; + + /** + * @brief Requests setting use of text zoom. + * + * @param[in] enable to text zoom. + * + * @return @c true on success or @c false on failure + */ + bool SetTextZoomEnabled(bool enable); + + /** + * @brief Returns whether text zoom is enabled or not. + * + * @return @c true if enable text zoom or @c false. + */ + bool IsTextZoomEnabled() const; + + /** + * @brief Requests enables/disables to the specific extra feature + * + * @param[in] feature feature name + * @param[in] enable @c true to enable the specific extra feature + * @c false to disable + */ + void SetExtraFeature(const std::string& feature, bool enable); + + /** + * @brief Returns enable/disable to the specific extra feature + * + * @param[in] feature feature name + * + * @return @c true on enable or @c false on disable + */ + bool IsExtraFeatureEnabled(const std::string& feature) const; + private: Dali::WebEngineSettings& mWebEngineSettings; }; -- 2.7.4