diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp index fd8f413fe7914f81a11d1c5fd7b15dbf63f46131..c67fea0a02e6ff8268b3a67cedfc34192e73d740 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.cpp @@ -831,6 +831,7 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_FUNCTION("setAutoPreconnect", NapiWebviewController::SetAutoPreconnect), DECLARE_NAPI_STATIC_FUNCTION("isAutoPreconnectEnabled", NapiWebviewController::IsAutoPreconnectEnabled), DECLARE_NAPI_STATIC_FUNCTION("setSocketIdleTimeout", NapiWebviewController::SetSocketIdleTimeout), + DECLARE_NAPI_STATIC_FUNCTION("setScrollbarMode", NapiWebviewController::SetScrollbarMode), }; napi_value constructor = nullptr; napi_define_class(env, WEBVIEW_CONTROLLER_CLASS_NAME.c_str(), WEBVIEW_CONTROLLER_CLASS_NAME.length(), @@ -1109,6 +1110,21 @@ napi_value NapiWebviewController::Init(napi_env env, napi_value exports) sizeof(siteIsolationModeProperties[0]), siteIsolationModeProperties, &siteIsolationModeEnum); napi_set_named_property(env, exports, WEB_SITE_ISOLATION_MODE_ENUM_NAME.c_str(), siteIsolationModeEnum); + napi_value scrollbarModeEnum = nullptr; + napi_property_descriptor scrollbarModeProperties[] = { + DECLARE_NAPI_STATIC_PROPERTY( + "OVERLAY_LAYOUT_SCROLLBAR", + NapiParseUtils::ToInt32Value(env, static_cast(ScrollbarMode::OVERLAY_LAYOUT_SCROLLBAR))), + DECLARE_NAPI_STATIC_PROPERTY( + "FORCE_DISPLAY_SCROLLBAR", + NapiParseUtils::ToInt32Value(env, static_cast(ScrollbarMode::FORCE_DISPLAY_SCROLLBAR))), + }; + napi_define_class(env, WEB_SCROLLBAR_MODE_ENUM_NAME.c_str(), WEB_SCROLLBAR_MODE_ENUM_NAME.length(), + NapiParseUtils::CreateEnumConstructor, nullptr, + sizeof(scrollbarModeProperties) / sizeof(scrollbarModeProperties[0]), scrollbarModeProperties, + &scrollbarModeEnum); + napi_set_named_property(env, exports, WEB_SCROLLBAR_MODE_ENUM_NAME.c_str(), scrollbarModeEnum); + WebviewJavaScriptExecuteCallback::InitJSExcute(env, exports); WebviewCreatePDFExecuteCallback::InitJSExcute(env, exports); return exports; @@ -7960,5 +7976,41 @@ napi_value NapiWebviewController::SetSocketIdleTimeout(napi_env env, napi_callba NWebHelper::Instance().SetSocketIdleTimeout(socketIdleTimeout); return result; } + +napi_value NapiWebviewController::SetScrollbarMode(napi_env env, napi_callback_info info) +{ + if (IS_CALLING_FROM_M114()) { + WVLOG_W("SetScrollbarMode unsupported engine version: M114"); + return nullptr; + } + napi_value thisVar = nullptr; + napi_value result = nullptr; + size_t argc = INTEGER_ONE; + napi_value argv[INTEGER_ONE] = { 0 }; + napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); + + if (argc != INTEGER_ONE) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_NUMBERS_ERROR_ONE, "one")); + return result; + } + + int32_t scrollbarMode = false; + if (!NapiParseUtils::ParseInt32(env, argv[INTEGER_ZERO], scrollbarMode)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::TYPE_ERROR, "mode", "ScrollbarMode")); + return result; + } + + if (scrollbarMode < static_cast(ScrollbarMode::OVERLAY_LAYOUT_SCROLLBAR) || + scrollbarMode > static_cast(ScrollbarMode::FORCE_DISPLAY_SCROLLBAR)) { + BusinessError::ThrowErrorByErrcode(env, PARAM_CHECK_ERROR, + NWebError::FormatString(ParamCheckErrorMsgTemplate::PARAM_TYPE_INVALID, "mode")); + return result; + } + + NWebHelper::Instance().SetScrollbarMode(static_cast(scrollbarMode)); + return result; +} } // namespace NWeb } // namespace OHOS diff --git a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h index d34fd72274b129cce0905c77b3923fa039439b51..54766162689ea34f1b18c131fb6759c5879076cf 100644 --- a/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h +++ b/interfaces/kits/napi/webviewcontroller/napi_webview_controller.h @@ -47,6 +47,7 @@ const std::string WEB_CONTROLLER_ATTACHSTATE_ENUM_NAME = "ControllerAttachState" const std::string WEB_BLANKLESS_ERROR_CODE_ENUM_NAME = "WebBlanklessErrorCode"; const std::string WEB_DESTROY_MODE_ENUM_NAME = "WebDestroyMode"; const std::string WEB_SITE_ISOLATION_MODE_ENUM_NAME = "SiteIsolationMode"; +const std::string WEB_SCROLLBAR_MODE_ENUM_NAME = "ScrollbarMode"; constexpr double TEN_MILLIMETER_TO_INCH = 0.39; struct Scheme { @@ -425,6 +426,7 @@ private: static napi_value SetAutoPreconnect(napi_env env, napi_callback_info info); static napi_value IsAutoPreconnectEnabled(napi_env env, napi_callback_info info); static napi_value SetSocketIdleTimeout(napi_env env, napi_callback_info info); + static napi_value SetScrollbarMode(napi_env env, napi_callback_info info); }; class ArkWebTransfer { diff --git a/ohos_interface/include/ohos_nweb/nweb.h b/ohos_interface/include/ohos_nweb/nweb.h index 5b303a9e48064ba6d2b26af18ff8606df32d8a7a..46ead61033bfc192d27d6fcf69edb7e5073d1be3 100644 --- a/ohos_interface/include/ohos_nweb/nweb.h +++ b/ohos_interface/include/ohos_nweb/nweb.h @@ -292,6 +292,11 @@ enum class WebDestroyMode { FAST_MODE }; +enum class ScrollbarMode { + OVERLAY_LAYOUT_SCROLLBAR, + FORCE_DISPLAY_SCROLLBAR +}; + class OHOS_NWEB_EXPORT NWebMouseEvent { public: virtual ~NWebMouseEvent() = default; diff --git a/ohos_interface/include/ohos_nweb/nweb_engine.h b/ohos_interface/include/ohos_nweb/nweb_engine.h index 5b23cc06bcbc799024241778a202665673a17d6d..5427fe9420bc0779efbc05ee6b01620918ddf27d 100644 --- a/ohos_interface/include/ohos_nweb/nweb_engine.h +++ b/ohos_interface/include/ohos_nweb/nweb_engine.h @@ -139,6 +139,8 @@ public: virtual void SetWebDestroyMode(WebDestroyMode mode) {} virtual void SetSocketIdleTimeout(int32_t timeout) {} + + virtual void SetScrollbarMode(ScrollbarMode mode) {} }; } // namespace OHOS::NWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.cpp index a7abe5dd8ef120664de09ac5176dec7ac7772884..9a1cb91f4b6fb234d3358fb10ac611c032d8b425 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.cpp @@ -332,4 +332,9 @@ void ArkWebEngineImpl::SetSocketIdleTimeout(int32_t timeout) nweb_engine_->SetSocketIdleTimeout(timeout); } +void ArkWebEngineImpl::SetScrollbarMode(int32_t mode) +{ + nweb_engine_->SetScrollbarMode(static_cast(mode)); +} + } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.h index 0db19f26ed45f24657748f23c6ac2a057486619a..7c64b45b4ee77963de2ebdd9aadbc4b3d1453671 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webcore/ark_web_engine_impl.h @@ -126,6 +126,8 @@ public: void SetSocketIdleTimeout(int32_t timeout) override; + void SetScrollbarMode(int32_t mode) override; + private: std::shared_ptr nweb_engine_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.cpp b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.cpp index 3951a4e9c9fe4dd105140ba92db8096e0f420700..d14064e1e8793680607803fff07826c6d61ac404 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.cpp +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.cpp @@ -388,4 +388,9 @@ void ArkWebEngineWrapper::SetSocketIdleTimeout(int32_t timeout) ark_web_engine_->SetSocketIdleTimeout(timeout); } +void ArkWebEngineWrapper::SetScrollbarMode(OHOS::NWeb::ScrollbarMode mode) +{ + ark_web_engine_->SetScrollbarMode(static_cast(mode)); +} + } // namespace OHOS::ArkWeb diff --git a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.h b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.h index 926124fa4347f5328919ace609ce8df9d9b002c0..0db634c00276d102a75f149e01d3d79b69b386f6 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.h +++ b/ohos_interface/ohos_glue/ohos_nweb/bridge/webview/ark_web_engine_wrapper.h @@ -127,6 +127,8 @@ public: void SetSocketIdleTimeout(int32_t timeout) override; + void SetScrollbarMode(OHOS::NWeb::ScrollbarMode mode) override; + private: ArkWebRefPtr ark_web_engine_; }; diff --git a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_engine.h b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_engine.h index b8b84ea1cce373a5112e5b0ac329a380ad3c1401..6c9e8d6da0dfa38c4d251eb7df9df2ba2c9f7757 100644 --- a/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_engine.h +++ b/ohos_interface/ohos_glue/ohos_nweb/include/ark_web_engine.h @@ -203,6 +203,9 @@ public: /*--ark web()--*/ virtual void SetSocketIdleTimeout(int32_t timeout) = 0; + + /*--ark web()--*/ + virtual void SetScrollbarMode(int32_t mode) = 0; }; } // namespace OHOS::ArkWeb diff --git a/ohos_nweb/include/nweb_helper.h b/ohos_nweb/include/nweb_helper.h index 8219dd7a7d3aa78ee3c9d065502960a7659cfe03..f76379c8eec1a8d3f62fe142bae8d138e8e9b0d9 100644 --- a/ohos_nweb/include/nweb_helper.h +++ b/ohos_nweb/include/nweb_helper.h @@ -166,6 +166,8 @@ public: int32_t GetSocketIdleTimeout(); + void SetScrollbarMode(ScrollbarMode mode); + private: NWebHelper() = default; bool GetWebEngine(bool fromArk); diff --git a/ohos_nweb/src/nweb_helper.cpp b/ohos_nweb/src/nweb_helper.cpp index d4c1716df4fc011d3474a4f3130000d01fed318b..d320d061d4dfa0686f9f5b77e9347208047d0aad 100644 --- a/ohos_nweb/src/nweb_helper.cpp +++ b/ohos_nweb/src/nweb_helper.cpp @@ -1407,4 +1407,13 @@ int32_t NWebHelper::GetSocketIdleTimeout() return socketIdleTimeout_; } +void NWebHelper::SetScrollbarMode(ScrollbarMode mode) +{ + if (nwebEngine_ == nullptr) { + WVLOG_E("web engine is nullptr"); + return; + } + nwebEngine_->SetScrollbarMode(mode); +} + } // namespace OHOS::NWeb diff --git a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp index 37483f0be322184442a61a8134cea3b5371f89f2..3577f1bf40e8209b9f71cbf457dc5f8621ea3faa 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_ex_test.cpp @@ -438,7 +438,7 @@ HWTEST_F(NwebHelperTest, NWebHelper_LoadWebEngine_008, TestSize.Level1) NWebHelper::Instance().PauseAllTimers(); NWebHelper::Instance().ResumeAllTimers(); NWebHelper::Instance().SetWebDestroyMode(WebDestroyMode::NORMAL_MODE); - + NWebHelper::Instance().SetScrollbarMode(ScrollbarMode::OVERLAY_LAYOUT_SCROLLBAR); auto nwebEngineMock = std::make_shared(); NWebHelper::Instance().nwebEngine_ = nwebEngineMock; NWebHelper::Instance().SetHttpDns(config); diff --git a/test/unittest/nweb_helper_test/nweb_helper_test.cpp b/test/unittest/nweb_helper_test/nweb_helper_test.cpp index 32e9f454fe0960ad54086e735ab3b7860cd4ed1d..23d30f211084211c986c5a5e4b46f0560e2de598 100644 --- a/test/unittest/nweb_helper_test/nweb_helper_test.cpp +++ b/test/unittest/nweb_helper_test/nweb_helper_test.cpp @@ -488,6 +488,7 @@ HWTEST_F(NwebHelperTest, NWebHelper_LoadWebEngine_008, TestSize.Level1) NWebHelper::Instance().PauseAllTimers(); NWebHelper::Instance().ResumeAllTimers(); NWebHelper::Instance().SetWebDestroyMode(WebDestroyMode::NORMAL_MODE); + NWebHelper::Instance().SetScrollbarMode(ScrollbarMode::OVERLAY_LAYOUT_SCROLLBAR); EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr); NWebHelper::Instance().LoadWebEngine(true, false); bool result = NWebHelper::Instance().GetWebEngine(true); @@ -510,6 +511,7 @@ HWTEST_F(NwebHelperTest, NWebHelper_LoadWebEngine_008, TestSize.Level1) NWebHelper::Instance().PauseAllTimers(); NWebHelper::Instance().ResumeAllTimers(); NWebHelper::Instance().SetWebDestroyMode(WebDestroyMode::NORMAL_MODE); + NWebHelper::Instance().SetScrollbarMode(ScrollbarMode::OVERLAY_LAYOUT_SCROLLBAR); NWebHelper::Instance().SetWebDebuggingAccess(true); NWebHelper::Instance().SetWebDebuggingAccessAndPort(true, 80); NWebHelper::Instance().SaveSchemeVector("web_test", 8080);