From d2d7d4068580b89fb8936c7ef6c4d337742921da Mon Sep 17 00:00:00 2001 From: fenggechang Date: Tue, 2 Sep 2025 15:55:29 +0800 Subject: [PATCH] ArkTS1.2 add AvoidVisibleViewportBottom Signed-off-by: fenggechang --- .../ani/webview/ets/@ohos.web.webview.ets | 1 + .../webviewcontroller/webview_controller.cpp | 10 +++++++++ .../webviewcontroller/webview_controller.h | 2 ++ .../ani_webview_controller.cpp | 21 +++++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets b/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets index 63fd68044..60fb2b60d 100644 --- a/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets +++ b/interfaces/kits/ani/webview/ets/@ohos.web.webview.ets @@ -783,6 +783,7 @@ export default namespace webview { native resumeAllMedia(): void; native setAudioMuted(mute: boolean): void; native getMediaPlaybackState(): MediaPlaybackState; + native avoidVisibleViewportBottom(avoidHeight: int): void; native innerCompleteWindowNew(parentNwebId:int): void; innerGetThisVar(): long { return this.nativePtr; diff --git a/interfaces/kits/ani/webview/native/webviewcontroller/webview_controller.cpp b/interfaces/kits/ani/webview/native/webviewcontroller/webview_controller.cpp index 796cda471..5c84eed45 100644 --- a/interfaces/kits/ani/webview/native/webviewcontroller/webview_controller.cpp +++ b/interfaces/kits/ani/webview/native/webviewcontroller/webview_controller.cpp @@ -1303,6 +1303,16 @@ int WebviewController::GetMediaPlaybackState() return nweb_ptr->GetMediaPlaybackState(); } +ErrCode WebviewController::AvoidVisibleViewportBottom(int32_t avoidHeight) +{ + auto nweb_ptr = NWebHelper::Instance().GetNWeb(nwebId_); + if (!nweb_ptr) { + return INIT_ERROR; + } + nweb_ptr->AvoidVisibleViewportBottom(avoidHeight); + return NWebError::NO_ERROR; +} + int WebviewController::GetSecurityLevel() { auto nweb_ptr = NWebHelper::Instance().GetNWeb(nwebId_); diff --git a/interfaces/kits/ani/webview/native/webviewcontroller/webview_controller.h b/interfaces/kits/ani/webview/native/webviewcontroller/webview_controller.h index a7880f1f8..021389b4c 100644 --- a/interfaces/kits/ani/webview/native/webviewcontroller/webview_controller.h +++ b/interfaces/kits/ani/webview/native/webviewcontroller/webview_controller.h @@ -303,6 +303,8 @@ public: int GetMediaPlaybackState(); + ErrCode AvoidVisibleViewportBottom(int32_t avoidHeight); + void EnableIntelligentTrackingPrevention(bool enable); bool IsIntelligentTrackingPreventionEnabled() const; diff --git a/interfaces/kits/ani/webview/src/webviewcontroller/ani_webview_controller.cpp b/interfaces/kits/ani/webview/src/webviewcontroller/ani_webview_controller.cpp index cbb630739..3b8252ab6 100644 --- a/interfaces/kits/ani/webview/src/webviewcontroller/ani_webview_controller.cpp +++ b/interfaces/kits/ani/webview/src/webviewcontroller/ani_webview_controller.cpp @@ -3770,6 +3770,25 @@ void OnCreateNativeMediaPlayer(ani_env* env, ani_object object, ani_fn_object ca controller->OnCreateNativeMediaPlayer(g_vm, callback); } +static void AvoidVisibleViewportBottom(ani_env* env, ani_object object, ani_int avoidHeight) +{ + if (env == nullptr) { + WVLOG_E("env is nullptr"); + return; + } + auto* controller = reinterpret_cast(AniParseUtils::Unwrap(env, object)); + if (!controller || !controller->IsInit()) { + AniBusinessError::ThrowErrorByErrCode(env, INIT_ERROR); + return; + } + + ErrCode ret = controller->AvoidVisibleViewportBottom(avoidHeight); + if (ret != NO_ERROR) { + AniBusinessError::ThrowErrorByErrCode(env, ret); + } + return; +} + bool ParseJsLengthDoubleToInt(ani_env* env, ani_ref ref, int32_t& outValue) { if (!env) { @@ -6105,6 +6124,8 @@ ani_status StsWebviewControllerInit(ani_env *env) ani_native_function { "resumeAllMedia", nullptr, reinterpret_cast(ResumeAllMedia) }, ani_native_function { "setAudioMuted", nullptr, reinterpret_cast(SetAudioMuted) }, ani_native_function { "getMediaPlaybackState", nullptr, reinterpret_cast(GetMediaPlaybackState) }, + ani_native_function { "avoidVisibleViewportBottom", nullptr, + reinterpret_cast(AvoidVisibleViewportBottom) }, ani_native_function { "webPageSnapshot", nullptr, reinterpret_cast(WebPageSnapshot) }, ani_native_function { "innerCompleteWindowNew", nullptr, reinterpret_cast(InnerCompleteWindowNew) }, ani_native_function { "setWebSchemeHandler", nullptr, reinterpret_cast(SetWebSchemeHandler) }, -- Gitee