From bdbc1134787b3b0c957bec16112f7c683fb3168d Mon Sep 17 00:00:00 2001 From: dongzhili Date: Sat, 13 Sep 2025 17:15:07 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=B8=89=E9=98=B6=E6=AE=B5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E9=AA=8C=E8=AF=81=20getSubWindow/toggleShwonStateForA?= =?UTF-8?q?llAppWindows/bindDialogTarget/CreateSubWindowWithOptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dongzhili --- interfaces/kits/ani/window_runtime/BUILD.gn | 2 + .../window_stage_ani/ets/@ohos.window.ets | 136 ++++++++++++++- .../window_stage_ani/include/ani_window.h | 10 ++ .../include/ani_window_manager.h | 2 + .../include/ani_window_stage.h | 7 +- .../window_stage_ani/src/ani_window.cpp | 164 ++++++++++++++++++ .../src/ani_window_manager.cpp | 25 +++ .../window_stage_ani/src/ani_window_stage.cpp | 89 ++++++++++ .../src/ani_window_stage_module.cpp | 5 + .../window_stage_ani/src/ani_window_utils.cpp | 132 ++++++++++++++ wm/src/window_session_impl.cpp | 11 +- 11 files changed, 578 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/ani/window_runtime/BUILD.gn b/interfaces/kits/ani/window_runtime/BUILD.gn index 9f31495230..d8cdf37df8 100644 --- a/interfaces/kits/ani/window_runtime/BUILD.gn +++ b/interfaces/kits/ani/window_runtime/BUILD.gn @@ -88,6 +88,7 @@ ohos_shared_library("windowstageani_kit") { "ipc:ipc_napi", "ipc:ipc_single", "napi:ace_napi", + "ipc:rpc_ani", "runtime_core:ani", "runtime_core:ani_helpers", ] @@ -144,6 +145,7 @@ ohos_shared_library("windowstageani_module") { "ipc:ipc_napi", "ipc:ipc_single", "napi:ace_napi", + "ipc:rpc_ani", "runtime_core:ani", ] diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/ets/@ohos.window.ets b/interfaces/kits/ani/window_runtime/window_stage_ani/ets/@ohos.window.ets index a036640b9a..9be086b98a 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/ets/@ohos.window.ets +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/ets/@ohos.window.ets @@ -20,6 +20,8 @@ import image from '@ohos.multimedia.image'; import BaseContext from 'application.BaseContext'; import hilog from '@ohos.hilog'; import { ColorMetrics } from '@ohos.arkui.node'; +import rpc from '@ohos.rpc'; +import dialogRequest from '@ohos.app.ability.dialogRequest'; export type AsyncCallbackVoid = (err: BusinessError) => void; export type WindowEventCallback = (data: window.WindowEventType) => void; export type WindowRectCallback = (data: window.Rect) => void; @@ -2014,6 +2016,8 @@ export class WindowStageInternal implements WindowStage { public native createSubWindowSync(nativeObj: long, name: String): Window; public native setCustomDensitySync(nativeObj: long, density: double): void; public native setDefaultDensityEnabledSync(nativeObj: long, enabled: boolean): void; + public native getSubWindowSync(nativeObj: long): Array; + public native createSubWindowWithOptionsSync(nativeObj: long, name: string, options: SubWindowOptions): Window; native onSync(nativeObj: long, eventType: 'windowStageEvent', callback: Object): void; native offSync(nativeObj: long, eventType: 'windowStageEvent', callback?: Object): void; @@ -2191,6 +2195,41 @@ export class WindowStageInternal implements WindowStage { }); } + public getSubWindow(): Promise> { + return new Promise>((resolve: (value: Array) => void, + reject: (error: BusinessError) => void) => { + taskpool.execute((): Array => { + return this.getSubWindowSync(this.nativeObj); + }).then((ret: NullishType) => { + resolve(ret as Array); + }).catch((err: NullishType) => { + reject(err as BusinessError); + }); + }); + } + + public getSubWindow(callback: AsyncCallback | undefined>): void { + taskpool.execute((): Array => { + return this.getSubWindowSync(this.nativeObj); + }).then((ret: NullishType) => { + callback(new BusinessError(), ret as Array); + }).catch((err: NullishType) => { + callback(err as BusinessError, undefined); + }); + } + + public createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise { + return new Promise((resolve: (value: Window) => void, reject: (error: BusinessError) => void) => { + taskpool.execute((): Window => { + return this.createSubWindowWithOptionsSync(this.nativeObj, name, options); + }).then((ret: NullishType) => { + resolve(ret as Window); + }).catch((err: NullishType) => { + reject(err as BusinessError); + }); + }); + } + public on(eventType: 'windowStageEvent', callback: Callback): void { this.onSync(this.nativeObj, eventType, callback); } @@ -2215,6 +2254,9 @@ export interface WindowStage { createSubWindow(name: string, callback: AsyncCallback): void; disableWindowDecor(): void; setShowOnLockScreen(showOnLockScreen: boolean): void; + getSubWindow(): Promise>; + getSubWindow(callback: AsyncCallback | undefined>): void; + createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise; setWindowModal(isModal: boolean): Promise; setCustomDensity(density: double): void; setDefaultDensityEnabled(enabled: boolean): void; @@ -2347,6 +2389,11 @@ export class WindowInternal implements Window { private native setWindowMaskSync(nativeObj: long, windowMask: Array>): void; private native onNoInteractionDetected(nativeObj: long, type: string, timeout: long, callback: Object): void; private native keepKeyboardOnFocusSync(nativeObj: long, enable: boolean): void; + private native bindDialogTargetWithRemoteObjectSync(nativeObj: long, token: rpc.RemoteObject, + deathCallback: object): void; + private native bindDialogTargetWithRequestInfoSync(nativeObj: long, requestInfo: dialogRequest.RequestInfo, + deathCallback: object): void; + private native createSubWindowWithOptionsSync(nativeObj: long, name: string, options: SubWindowOptions): Window; private native onSync(nativeObj: long, type: string, callback: object): void; private native offSync(nativeObj: long, type: string, callback?: object): void; @@ -2444,7 +2491,7 @@ export class WindowInternal implements Window { } public setWindowTopmost(isWindowTopmost: boolean): Promise { - return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { + return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void ): void => { taskpool.execute((): void => { this.setWindowTopmost(this.nativeObj, isWindowTopmost); }).then((ret: NullishType): void => { @@ -3447,6 +3494,64 @@ export class WindowInternal implements Window { }); } + public bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback): Promise { + return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { + taskpool.execute((): void => { + this.bindDialogTargetWithRemoteObjectSync(this.nativeObj, token, deathCallback); + }).then((ret: NullishType) => { + resolve(undefined); + }).catch((err: NullishType) => { + reject(err as BusinessError); + }); + }); + } + + public bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback, callback: AsyncCallback): void + { + taskpool.execute((): void => { + this.bindDialogTargetWithRemoteObjectSync(this.nativeObj, token, deathCallback); + }).then((ret: NullishType) => { + callback(new BusinessError(), undefined); + }).catch((err: NullishType) => { + callback(err as BusinessError, undefined); + }); + } + + public bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback): Promise { + return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { + taskpool.execute((): void => { + this.bindDialogTargetWithRequestInfoSync(this.nativeObj, requestInfo, deathCallback); + }).then((ret: NullishType) => { + resolve(undefined); + }).catch((err: NullishType) => { + reject(err as BusinessError); + }); + }); + } + + public bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback, callback: AsyncCallback): void + { + taskpool.execute((): void => { + this.bindDialogTargetWithRequestInfoSync(this.nativeObj, requestInfo, deathCallback); + }).then((ret: NullishType) => { + callback(new BusinessError(), undefined); + }).catch((err: NullishType) => { + callback(err as BusinessError, undefined); + }); + } + + public createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise { + return new Promise((resolve: (value: Window) => void, reject: (error: BusinessError) => void) => { + taskpool.execute((): Window => { + return this.createSubWindowWithOptionsSync(this.nativeObj, name, options); + }).then((ret: NullishType) => { + resolve(ret as Window); + }).catch((err: NullishType) => { + reject(err as BusinessError); + }); + }); + } + public setWindowBrightness(brightness: double): Promise { return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { taskpool.execute((): void => { @@ -3721,6 +3826,12 @@ export interface Window { setGestureBackEnabled(enabled: boolean): Promise; setSingleFrameComposerEnabled(enabled: boolean): Promise; getTransitionController(): TransitionController; + bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback): Promise; + bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback, callback: AsyncCallback): void; + bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback): Promise; + bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback, + callback: AsyncCallback): void; + createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise; on(type: string, callback: Callback): void; on(type: 'noInteractionDetected', timeout: long, callback: Callback): void; off(type: string, callback?: Callback): void; @@ -3750,6 +3861,7 @@ native function getSnapshot(nativeObj: long, windowId: number): image.PixelMap; native function getVisibleWindowInfo(nativeObj: long): Array; native function setGestureNavigationEnabled(nativeObj: long, enabled: boolean): void; native function setWaterMarkImage(nativeObj: long, pixelMap: image.PixelMap, enabled: boolean): void; +native function toggleShownStateForAllAppWindowsSync(nativeObj: long): void; export function getLastWindow(ctx: BaseContext): Promise { return new Promise((resolve: (value: Window) => void, reject: (error: BusinessError) => void) => { @@ -3981,6 +4093,28 @@ function runAvoidAreaChangeCallback(cb: object, area: object, type: int): void { func({type: type as AvoidAreaType, area: area as AvoidArea}); } +export function toggleShownStateForAllAppWindows(callback: AsyncCallback): void { + taskpool.execute((): void => { + toggleShownStateForAllAppWindowsSync(nativeObj); + }).then((ret: NullishType) => { + callback(new BusinessError(), undefined); + }).catch((err: NullishType) => { + callback(err as BusinessError, undefined); + }); +} + +export function toggleShownStateForAllAppWindows(): Promise { + return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { + taskpool.execute((): void => { + return toggleShownStateForAllAppWindowsSync(nativeObj); + }).then((ret: NullishType) => { + resolve(undefined); + }).catch((err: NullishType) => { + reject(err as BusinessError); + }); + }); +} + export function shiftAppWindowFocus(sourceWindowId: int, targetWindowId: int): Promise { return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { taskpool.execute((): void => { diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window.h b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window.h index cf46015fb9..42958f339b 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window.h +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window.h @@ -18,6 +18,7 @@ #include "ani.h" #include "ani_window_register_manager.h" +#include "ani_remote_object.h" #include "window.h" namespace OHOS { @@ -101,6 +102,12 @@ public: static void SetWindowShadowRadius(ani_env* env, ani_object obj, ani_long nativeObj, ani_double radius); static void Finalizer(ani_env* env, ani_long nativeObj); static ani_object GetTransitionController(ani_env* env, ani_object obj, ani_long nativeObj); + static void BindDialogTarget(ani_env* env, ani_object obj, ani_long nativeObj, + ani_object token, ani_ref deathCallback); + static void BindDialogTargetNew(ani_env* env, ani_object obj, ani_long nativeObj, + ani_object requestInfo, ani_ref deathCallback); + static ani_object CreateSubWindowWithOptions(ani_env* env, ani_object obj, ani_long nativeObj, + ani_string name, ani_object options); void SetFollowParentWindowLayoutEnabled(ani_env* env, ani_boolean enabled); void SetWindowDelayRaiseOnDrag(ani_env* env, ani_boolean isEnabled); @@ -209,6 +216,9 @@ private: void OnRotate(ani_env* env, ani_object rotateOptions); void OnSetShadow(ani_env* env, ani_double radius, ani_string color, ani_object offsetX, ani_object offsetY); void OnSetCornerRadius(ani_env* env, ani_double cornerRadius); + void OnBindDialogTarget(ani_env* env, ani_object token, ani_ref deathCallback); + void OnBindDialogTargetNew(ani_env* env, ani_object requestInfo, ani_ref deathCallback); + ani_object OnCreateSubWindowWithOptions(ani_env* env, ani_string name, ani_object options); static bool ParseScaleOption(ani_env* env, ani_object scaleOptions, Transform& trans); static bool ParseTranslateOption(ani_env* env, ani_object translateOptions, Transform& trans); static bool ParseRotateOption(ani_env* env, ani_object rotateOptions, Transform& trans); diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_manager.h b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_manager.h index f92a8cf076..fee7b21d5c 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_manager.h +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_manager.h @@ -50,6 +50,7 @@ public: static ani_object GetVisibleWindowInfo(ani_env* env, ani_long nativeObj); static void SetGestureNavigationEnabled(ani_env* env, ani_long nativeObj, ani_boolean enabled); static void SetWaterMarkImage(ani_env* env, ani_long nativeObj, ani_object nativePixelMap, ani_boolean enabled); + static void ToggleShownStateForAllAppWindows(ani_env* env, ani_long nativeObj); private: ani_object OnGetWindowsByCoordinate(ani_env* env, ani_object getWindowsParam); ani_ref OnGetLastWindow(ani_env* env, ani_object context); @@ -66,6 +67,7 @@ private: ani_object OnGetVisibleWindowInfo(ani_env* env); void OnSetGestureNavigationEnabled(ani_env* env, ani_boolean enabled); void OnSetWaterMarkImage(ani_env* env, ani_object nativePixelMap, ani_boolean enabled); + void OnToggleShownStateForAllAppWindows(ani_env* env); std::unique_ptr registerManager_ = nullptr; }; diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_stage.h b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_stage.h index 7aafe9ae15..2e2b8440e5 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_stage.h +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_stage.h @@ -45,7 +45,10 @@ class AniWindowStage { ani_ref callback); static void SetCustomDensity(ani_env* env, ani_object obj, ani_long nativeObj, ani_double density); static void SetDefaultDensityEnabled(ani_env* env, ani_object obj, ani_long nativeObj, ani_boolean enabled); - + static ani_object GetSubWindow(ani_env* env, ani_object obj, ani_long nativeObj); + static ani_object CreateSubWindowWithOptions(ani_env* env, ani_object obj, ani_long nativeObj, + ani_string name, ani_object options); + void SetWindowRectAutoSave(ani_env* env, ani_boolean enabled, ani_boolean isSaveBySpecifiedFlag); ani_boolean IsWindowRectAutoSave(ani_env* env); void RemoveStartingWindow(ani_env* env); @@ -62,6 +65,8 @@ private: void OnSetWindowModal(ani_env* env, ani_boolean isModal); void OnRegisterWindowCallback(ani_env* env, ani_string type, ani_ref callback); void OnUnregisterWindowCallback(ani_env* env, ani_string type, ani_ref callback); + ani_object OnGetSubWindow(ani_env* env); + ani_object OnCreateSubWindowWithOptions(ani_env* env, ani_string name, ani_object options); std::weak_ptr windowScene_; std::unique_ptr registerManager_ = nullptr; }; diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp index b1ea1e1df3..26c8f237d0 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp @@ -3483,6 +3483,161 @@ void AniWindow::SetSingleFrameComposerEnabled(ani_env* env, ani_boolean enabled) windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), enabled); } +void AniWindow::BindDialogTarget(ani_env* env, ani_object obj, ani_long nativeObj, + ani_object token, ani_ref deathCallback) +{ + TLOGI(WmsLogTag::WMS_DIALOG, "[ANI]"); + AniWindow* aniWindow = reinterpret_cast(nativeObj); + if (aniWindow != nullptr) { + ani->OnbindDialogTarget(env, token, deathCallback); + } else { + TLOGE(WmsLogTag::WMS_DIALOG, "[ANI] aniWindow is nullptr"); + } +} + +void AniWindow::OnBindDialogTarget(ani_env* env, ani_object token, ani_ref deathCallback) +{ + TLOGI(WmsLogTag::WMS_DIALOG, "[ANI] OnBindDialogTarget in"); + if (windowToken_ == nullptr) { + TLOGE(WmsLogTag::WMS_DIALOG, "[ANI] window is nullptr"); + AniWindowUtils::AniThrowError(env, WMErrorCode::WM_ERROR_STATE_ABNORMALLY); + return; + } + if (!Permission::IsSystemCalling()) { + TLOGE(WmsLogTag::WMS_DIALOG, "Permission denied, require system application!"); + AniWindowUtils::AniThrowError(env, WMErrorCode::WM_ERROR_NOT_SYSTEM_APP); + return; + } + + sptr token_go = AniGetNativeRemoteObject(env, token); + if (token_go == nullptr) { + TLOGE(WmsLogTag::WMS_DIALOG, "token is null"); + AniWindowUtils::AniThrowError(env, WMErrorCode::WM_ERROR_INVALID_PARAM); + return; + } + + registerManager_->RegisterListener(windowToken_, "dialogDeathRecipient", + CaseType::CASE_WINDOW, env, deathCallback, 0.0); + wptr weakToken(windowToken_); + auto window = weakToken.promote(); + WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->BindDialogTarget(token_go)); + if (ret != WMErrorCode::WM_OK) { + AniWindowUtils::AniThrowError(env, ret, "Bind Dialog Target failed"); + } + TLOGI(WmsLogTag::WMS_SYSTEM, "BindDialogTarget end, window [%{public}u, %{public}s]", + weakToken->GetWindowId(), weakToken->GetWindowName().c_str()); +} + +void AniWindow::BindDialogTargetNew(ani_env* env, ani_object obj, ani_long nativeObj, + ani_object requestInfo, ani_ref deathCallback) +{ + TLOGI(WmsLogTag::WMS_DIALOG, "[ANI]"); + AniWindow* aniWindow = reinterpret_cast(nativeObj); + if (aniWindow != nullptr) { + ani->OnbindDialogTargetNew(env, requestInfo, deathCallback); + } else { + TLOGE(WmsLogTag::WMS_DIALOG, "[ANI] aniWindow is nullptr"); + } +} + +void AniWindow::OnBindDialogTargetNew(ani_env* env, ani_object requestInfo, ani_ref deathCallback) +{ + TLOGI(WmsLogTag::WMS_DIALOG, "[ANI] OnBindDialogTarget in"); + if (windowToken_ == nullptr) { + TLOGE(WmsLogTag::WMS_DIALOG, "[ANI] window is nullptr"); + AniWindowUtils::AniThrowError(env, WMErrorCode::WM_ERROR_STATE_ABNORMALLY); + return; + } + if (!Permission::IsSystemCalling()) { + TLOGE(WmsLogTag::WMS_DIALOG, "Permission denied, require system application!"); + AniWindowUtils::AniThrowError(env, WMErrorCode::WM_ERROR_NOT_SYSTEM_APP); + return; + } + + sptr token_go = AniGetNativeRemoteObject(env, requestInfo); + if (token_go == nullptr) { + TLOGE(WmsLogTag::WMS_DIALOG, "token is null"); + AniWindowUtils::AniThrowError(env, WMErrorCode::WM_ERROR_INVALID_PARAM); + return; + } + + registerManager_->RegisterListener(windowToken_, "dialogDeathRecipient", + CaseType::CASE_WINDOW, env, deathCallback, 0.0); + wptr weakToken(windowToken_); + auto window = weakToken.promote(); + WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->BindDialogTarget(token_go)); + if (ret != WMErrorCode::WM_OK) { + AniWindowUtils::AniThrowError(env, ret, "Bind Dialog Target failed"); + } + TLOGI(WmsLogTag::WMS_SYSTEM, "BindDialogTarget end, window [%{public}u, %{public}s]", + weakToken->GetWindowId(), weakToken->GetWindowName().c_str()); +} + +ani_object AniWindow::CreateSubWindowWithOptions(ani_env* env, ani_object obj, ani_long nativeObj, + ani_stirng name, ani_object options) +{ + TLOGD(WmsLogTag::WMS_SUB, "[ANI]"); + AniWindow* aniWindow = reinterpret_cast(nativeObj); + if(aniWindow!= nullptr) { + return AniWindowUtils::OnCreateSubWindowWithOptions(env, name, options); + } else { + TLOGE(WmsLogTag::WMS_SUB, "[ANI] aniWindow is nullptr"); + return AniWindowUtils::CreateAniUndefined(env); + } +} + +ani_object AniWindow::OnCreateSubWindowWithOptions(ani_env* env, ani_stirng name, ani_object options) +{ + TLOGI(WmsLogTag::WMS_SUB, "[ANI] OnCreateSubWindowWithOptions in"); + if (windowToken_ == nullptr) { + TLOGE(WmsLogTag::WMS_SUB, "window is null, device not support"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + return AniWindowUtils::CreateAniUndefined(env); + } + if (!windowToken_->IsPcOrFreeMultiWindowCapabilityEnabled()) { + TLOGE(WmsLogTag::WMS_SUB, "device not support"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT); + return AniWindowUtils::CreateAniUndefined(env); + } + str::string windowName; + AniWindowUtils::GetStdString(env, name, windowName); + sptr windowOption = new WindowOption(); + if (!AniWindowUtils::ParseSubWindowOption(env, options, windowOption)) { + TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to options"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return AniWindowUtils::CreateAniUndefined(env); + } + if ((windowOption->GetWindowFlags() & static_cast(WindowFlage::WINDOW_FLAG_IS_APPLICATION_MODAL)) && + !windowToken_->IsPcOrPadFreeMultiWindowMode()) { + TLOGE(WmsLogTag::WMS_SUB, "device not support"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP); + return AniWindowUtils::CreateAniUndefined(env); + } + if (windowOption->GetWindowTopmost() && !Permission::IsSystemCalling() && Permission::IsStartByHdcd()) { + TLOGE(WmsLogTag::WMS_SUB, "Modal subWindow has topmost, but no system permission"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_DEVICE_NOT_SYSTEM_APP); + return AniWindowUtils::CreateAniUndefined(env); + } + if (!WindowHelper::IsFloatOrSubWindow(windowToken_->GetType()) && + !WindowHelper::IsMainWindow(windowToken_->GetType())) { + TLOGE(WmsLogTag::WMS_SUB, "%{public}d", windowToken_.GetType()); + return AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, + "invalid window type"); + } + windowOption->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); + windowOption->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + windowOption->SetOnlySupportSceneBoard(true); + windowOption->SetParentId(windowToken_->GetWindowId()); + windowOption->SetWindowTag(WindowTag::SUB_WINDOW); + auto subWindow = Window::Create(windowName, windowOption, windowToken_->GetContext()); + if (subWindow == nullptr) { + TLOGE(WmsLogTag::WMS_SUB, "create sub window failed"); + return AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, + "create sub window failed"); + } + TLOGI(WmsLogTag::WMS_SUB, "Create sub window %{public}s end", windowName.c_str()); + return static_castCreateAniWindowObject(env, subWindow); +} } // namespace Rosen } // namespace OHOS @@ -4505,6 +4660,15 @@ ani_status OHOS::Rosen::ANI_Window_Constructor(ani_vm *vm, uint32_t *result) reinterpret_cast(SetSingleFrameComposerEnabled)}, ani_native_function {"getTransitionControllerSync", "l:C{@ohos.window.window.TransitionController}", reinterpret_cast(AniWindow::GetTransitionController)}, + ani_native_function {"bindDialogTargetWithRemoteObjectInfoSync", nullptr, + reinterpret_cast(AniWindow::bindDialogTarget)}, + ani_native_function {"bindDialogTargetWithRequestInfoSync", nullptr, + reinterpret_cast(AniWindow::bindDialogTargetNew)}, + ani_native_function {"createSubWindowSync", "lC{@ohos.window.window.TransitionController}:", + reinterpret_cast(AniWindow::GetTransitionController)}, + ani_native_function {"createSubWindowWithOptionsSync", + "lC{std.core.String}C{@ohos.window.window.SubWindowOptions}:C{@ohos.window.window.Window}", + reinterpret_cast(CreateSubWindowWithOptions)}, }; for (auto method : methods) { if ((ret = env->Class_BindNativeMethods(cls, &method, 1u)) != ANI_OK) { diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_manager.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_manager.cpp index f979be7d5d..8fdd5d7415 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_manager.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_manager.cpp @@ -91,6 +91,8 @@ ani_status AniWindowManager::AniWindowManagerInit(ani_env* env) reinterpret_cast(AniWindowManager::SetGestureNavigationEnabled)}, ani_native_function {"setWaterMarkImage", "lC{@ohos.multimedia.image.image.PixelMap}z:", reinterpret_cast(AniWindowManager::SetWaterMarkImage)}, + ani_native_function {"toggleShownStateForAllAppWindowsSync", "l:", + reinterpret_cast(AniWindowManager::ToggleShownStateForAllAppWindows)}, }; if ((ret = env->Namespace_BindNativeFunctions(ns, functions.data(), functions.size())) != ANI_OK) { TLOGE(WmsLogTag::DEFAULT, "[ANI] bind ns func %{public}u", ret); @@ -654,5 +656,28 @@ void AniWindowManager::OnSetWaterMarkImage(ani_env* env, ani_object nativePixelM } RSInterfaces::GetInstance().ShowWatermark(pixelMap, enable); } + +void AniWindowManager::OnToggleShownStateForAllAppWindows(ani_env* env) +{ + TLOGI(WmsLogTag::DEFAULT, "[ANI]"); + WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at( + SingletonContainer::Get().ToggleShownStateForAllAppWindows()); + if(ret != WmErrorCode::WM_OK) { + AniWindowUtils::AniThrowError(env, ret, "ToggleShownStateForAllAppWindows failed."); + } + return ; +} + +void AniWindowManager::ToggleShownStateForAllAppWindows(ani_env* env, ani_long nativeObj) +{ + TLOGI(WmsLogTag::DEFAULT, "[ANI]"); + AniWindowManager* aniWindowManager = reinterpret_cast(nativeObj); + if (aniWindowManager != nullptr) { + return aniWindowManager->OnToggleShownStateForAllAppWindows(env); + } else { + TLOGE(WmsLogTag::DEFAULT, "[ANI] aniWindowManager is nullptr"); + return; + } +} } // namespace Rosen } // namespace OHOS diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage.cpp index 4057478afb..d4f9a44779 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage.cpp @@ -582,6 +582,95 @@ void AniWindowStage::OnSetDefaultDensityEnabled(ani_env* env, ani_boolean enable TLOGI(WmsLogTag::WMS_ATTRIBUTE, "Window [%{public}u,%{public}s] enabled=%{public}u ret=%{public}d", window->GetWindowId(), window->GetWindowName().c_str(), enabled, ret); } + +ani_object AniWindowStage::GetSubWindow(ani_env* env, ani_object obj, ani_long nativeObj) +{ + TLOGD(WmsLogTag::WMS_LIFE, "[ANI]"); + AniWindowStage* aniWindowStage = reinterpret_cast(nativeObj); + if (aniWindowStage == nullptr || aniWindowStage->GetMainWindow(env) == nullptr) { + TLOGE(WmsLogTag::WMS_LIFE, "[ANI] aniWindowStage is nullptr!"); + return AniWindowUtils::CreateAniUndefined(env); + } + return aniWindowStage->OnGetSubWindow(env); +} + +ani_object AniWindowStage::OnGetSubWindow(ani_env* env) +{ + TLOGI(WmsLogTag::WMS_LIFE, "[ANI]"); + auto windowScene = GetWindowScene().lock(); + if (windowScene == nullptr) { + TLOGE(WmsLogTag::WMS_LIFE, "[ANI] Window scene is nullptr"); + return AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + std::vector> subWindowVec = windowScene->GetSubWindow(); + TLOGI(WmsLogTag::WMS_LIFE, "Get sub windows, size = %{public}zu", subWindowVec.size()); + + std::vector windows(subWindowVec.size()); + for (size_t i = 0; i < subWindowVec.size(); i++) { + windows[i] = CreateAniWindowObject(env, subWindowVec[i]); + } + return AniWindowUtils::CreateAniWindowArray(env, windows); +} + +ani_object AniWindowStage::CreateSubWindowWithOptions(ani_env* env, ani_object obj, ani_long nativeObj, + ani_string name, ani_object options) +{ + TLOGI(WmsLogTag::WMS_SUB, "[ANI]"); + AniWindowStage* aniWindowStage = reinterpret_cast(nativeObj); + if (aniWindowStage != nullptr) { + return aniWindowStage->OnCreateSubWindowWithOptions(env, name, options); + } else { + TLOGE(WmsLogTag::WMS_SUB, "[ANI] aniWindowStage is nullptr"); + return AniWindowUtils::CreateAniUndefined(env); + } +} + +ani_object AniWindowStage::OnCreateSubWindowWithOptions(ani_env* env, ani_string name, ani_object options) +{ + TLOGI(WmsLogTag::WMS_SUB, "[ANI] OnCreateSubWindowWithOptions in"); + auto windowScene = GetWindowScene().lock(); + if (windowScene == nullptr) { + TLOGE(WmsLogTag::WMS_SUB, "WindowScene is null"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return AniWindowUtils::CreateAniUndefined(env); + } + std::string windowName; + ani_status window_name = AniWindowUtils::GetStdString(env, name, windowName); + if (window_name != ANI_OK) { + TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to windowName"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return AniWindowUtils::CreateAniUndefined(env); + } + sptr windowOption = sptr::MakeSptr(); + if (!AniWindowUtils::ParseSubWindowOption(env, options, windowOption)) { + TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to options"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); + return AniWindowUtils::CreateAniUndefined(env); + } + if ((windowOption->GetWindowFlags() & static_cast(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL)) && + !windowScene->GetMainWindow()->IsPcOrPadFreeMultiWindowMode()) { + TLOGE(WmsLogTag::WMS_SUB, "device not support"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT); + return AniWindowUtils::CreateAniUndefined(env); + } + + if (windowOption->GetWindowTopmost() && !Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) { + TLOGE(WmsLogTag::WMS_SUB, "Modal subWindow has topmost, but no system permission"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP); + return AniWindowUtils::CreateAniUndefined(env); + } + windowOption->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); + windowOption->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); + windowOption->SetOnlySupportSceneBoard(true); + auto window = windowScene->CreateWindow(windowName, windowOption); + if (window == nullptr) { + TLOGE(WmsLogTag::WMS_SUB, "create window failed"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY, "get window failed"); + return AniWindowUtils::CreateAniUndefined(env); + } + TLOGI(WmsLogTag::WMS_SUB, "Create sub window %{public}s end", windowName.c_str()); + return static_cast(CreateAniWindowObject(env, window)); +} } // namespace Rosen } // namespace OHOS diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage_module.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage_module.cpp index edda21a6af..6e137e69b0 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage_module.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage_module.cpp @@ -124,6 +124,11 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) reinterpret_cast(WindowGetMainWindow)}, ani_native_function {"createSubWindowSync", "lC{std.core.String}:C{@ohos.window.window.Window}", reinterpret_cast(CreateSubWindow)}, + ani_native_function {"getSubWindowSync", "l:C{escompat.Array}", + reinterpret_cast(AniWindowStage::GetSubWindow)}, + ani_native_function {"createSubWindowWithOptionsSync", + "lC{std.core.String}C{@ohos.window.window.SubWindowOptions}:C{@ohos.window.window.Window}", + reinterpret_cast(AniWindowStage::CreateSubWindowWithOptions)}, ani_native_function {"onSync", nullptr, reinterpret_cast(AniWindowStage::RegisterWindowCallback)}, ani_native_function {"offSync", nullptr, diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp index 208e82e0f5..52ced9a380 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp @@ -1519,5 +1519,137 @@ bool AniWindowUtils::ParseAndCheckRect(ani_env* env, ani_object rect, const Rect } return true; } + +bool AniWindowUtils::ParseModalityParams(ani_env* env, ani_object jsObject, const sptr& windowOption) +{ + ani_boolean isModal { false }; + env->Object_GetPropertyByName_Boolean(jsObject, "isModal", &isModal); + if (isModal) { + windowOption->AddWindowFlag(WindowFlag::WINDOW_FLAG_ISMODAL); + } + ani_boolean isTopmost { false }; + env->Object_GetPropertyByName_Boolean(jsObject, "isTopmost", &isTopmost); + if (!isMoDal && isTopmost) { + TLOGE(WmsLogTag::WMS_SUB, "Normal subwindow not support topmost"); + return false; + } + windowOption->SetWindowTopmost(isTopmost); + ani_int aniModalityType { 0 }; + auto ret = env->Object_GetPropertyByName_Int(jsObject, "modealityType", &aniModalityType); + ApiModalityType apiModalityType = static_cast(static_cast(aniModalityType)); + if (ret == ANI_OK) { + if(!isModal) { + TLOGE(WmsLogTag::WMS_SUB, "Normal sunwindow not support modalityType"); + return false; + } + using T = std::underlying_type_t; + T modalityType = static_cast(apiModalityType); + if (modalityType >= static_cast(ApiModalityType::BEGIN) && + modalityType <= static_cast(ApiModalityType::END)) { + auto type = JS_TO_NATIVE_MODALITY_MAP.at(apiModalityType); + if (type == ModalityType::APPLICATION_MODALITY) { + windowOption->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL); + } + } else { + TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to modlaityType"); + return false; + } + } + TLOGI(WmsLogTag::WMS_SUB, "isModal: %{public}d, isTopmost: %{public}d, WindowFlag: %{public}d", + isModal, isTopmost, windowOption->GetWindowFlags()); + return; +} + +bool AniWindowUtils::ParseZlevelParams(ani_env* env, ani_object jsObject, const sptr& windowOption) +{ + ani_int zLevel { 0 }; + ani_status ani_zLevel = env->Object_GetPropertyByName_Int(jsObejct, "zLevel", &zLevel); + ani_boolean isModal { 0 }; + ani_status ani_isModal = env->Object_GetPropertyByName_Boolean(jsObejct, "isModal", &isModal); + if(ani_zLevel == ANI_OK) { + if (zLevel < MINIMUM_Z_LEVEL || zLevel > MAXIMUM_Z_LEVEL) { + TLOGE(WmsLogTag::WMS_SUB, "zLevel value %{public}d exceeds vcalid range [-10000, 10000]!", zLevel); + return false; + } + if (ani_isModal == ANI_OK) { + if (isModal) { + TLOGE(WmsLogTag::WMS_SUB, "modal window not support custom zLevel"); + return false; + } + } + windowOption->SetSubWindowZLevel(zLevel); + } + TLOGI(WmsLogTag::WMS_SUB, "zLevel: %{public}d", zLevel); + return true; +} + +bool AniWindowUtils::ParseRectParms(ani_env* env, ani_object jsObject, const sptr& windowOption) +{ + ani_ref rectRef; + if (ANI_OK != env->Object_GetPropertyByName_Ref(jsObject, "windowRect", &rectRef)) { + TLOGE(WmsLogTag::WMS_SUB, "get windowRect fail"); + return false; + } + ani_boolean isUndefined; + if (ANI_OK != env->Reference_IsUndefined(rectRef, &isUndefined) || isUndefined) { + TLOGE(WmsLogTag::WMS_SUB, "windowRect is undefined"); + return false; + } + Rect windowRect; + if (!GetPropertyRectObject(env, "windowRect", (ani_object)rectRef, windowRect)) { + return false; + } + if (windowRect.Width_ <= 0 || windowRect.height_ <= 0) { + TLOGE(WmsLogTag::WMS_SUB, "width or height should greater than 0!"); + return false; + } + TLOGI(WmsLogTag::WMS_SUB, "windowRect: %{public}s", windowRect.ToString().c_str()); + windowOption->SetWindowRect(windowRect); + return true; +} + +bool AniWindowUtils::ParseSubWindowOption(ani_env* env, ani_object jsObject, const sptr& windowOption) +{ + if (env == nullptr) { + TLOGE(WmsLogTag::DEFAULT, "[ANI] null env"); + return false; + } + if (jsObject == nullptr || windowOption == nullptr) { + TLOGE(WmsLogTag::WMS_SUB, "jsObject is null"); + return false; + } + if (windowOption == nullptr) { + TLOGE(WmsLogTag::WMS_SUB, "windowOption is null"); + return false; + } + std::string title; + ani_ref result; + ani_status titleResult = env->Object_GetPropertyByName_Ref(jsObject, "title", &titleResult); + if (titleResult != ANI_OK) { + TLOGE(WmsLogTag::WMS_SUB, "Failed to get title"); + return false; + } + ani_string aniResult = reinterpret_cast(result); + ani_status OptionFirst = AniWindowUtils::GetStdString(env, aniResult, title); + if (OptionFirst == ANI_OK) { + TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to title"); + return false; + } + ani_boolean decorEnabled; + ani_status ret = env->Object_GetPropertyByName_Boolean(jsObject, "decorEnabled", &decorEnabled); + if (ret == ANI_OK) { + TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to decorEnabled"); + return false; + } + windowOption->SetSubWindowTitle(title); + windowOption->SetSubWindowDecorEnabled(decorEnabled); + if (!ParseRectParams(env, jsObejct, windowOption)) { + return false; + } + if (!ParseModalityParams(env, jsObejct, windowOption)) { + return false; + } + return ParseZLevelParams(env, jsObejct, windowOption); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index 401c35854a..5ee6c15858 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -1848,9 +1848,14 @@ void WindowSessionImpl::HideTitleButton(bool& hideSplitButton, bool& hideMaximiz WMError WindowSessionImpl::NapiSetUIContent(const std::string& contentInfo, ani_env* env, ani_object storage, BackupAndRestoreType type, sptr token, AppExecFwk::Ability* ability) { - return SetUIContentInner(contentInfo, env, storage, - type == BackupAndRestoreType::NONE ? WindowSetUIContentType::DEFAULT : WindowSetUIContentType::RESTORE, - type, ability, 1u); + WindowSetUIContentType setUIContentType; + if (!navDestinationInfo_.empty()) { + setUIContentType = WindowSetUIContentType::BY_SHARED; + } else { + setUIContentType = + type == BackupAndRestoreType::NONE ? WindowSetUIContentType::DEFAULT : WindowSetUIContentType::RESTORE; + } + return SetUIContentInner(contentInfo, env, storage, setUIContentType, type, ability, 1u); } WMError WindowSessionImpl::NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage, -- Gitee From f2d319919886edc006f9687d211f3753ecfe96a0 Mon Sep 17 00:00:00 2001 From: dongzhili Date: Sat, 13 Sep 2025 18:30:11 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E7=BC=A9=E8=BF=9B=E3=80=81=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=B1=BB=E5=9E=8B=E3=80=81=E7=BB=91=E5=AE=9A=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dongzhili --- .../window_stage_ani/ets/@ohos.window.ets | 123 +++++++++--------- .../window_stage_ani/src/ani_window.cpp | 59 ++++----- .../src/ani_window_manager.cpp | 2 - 3 files changed, 89 insertions(+), 95 deletions(-) diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/ets/@ohos.window.ets b/interfaces/kits/ani/window_runtime/window_stage_ani/ets/@ohos.window.ets index 9be086b98a..2396eba57e 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/ets/@ohos.window.ets +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/ets/@ohos.window.ets @@ -2196,38 +2196,38 @@ export class WindowStageInternal implements WindowStage { } public getSubWindow(): Promise> { - return new Promise>((resolve: (value: Array) => void, - reject: (error: BusinessError) => void) => { - taskpool.execute((): Array => { - return this.getSubWindowSync(this.nativeObj); - }).then((ret: NullishType) => { - resolve(ret as Array); - }).catch((err: NullishType) => { - reject(err as BusinessError); - }); - }); - } - - public getSubWindow(callback: AsyncCallback | undefined>): void { + return new Promise>((resolve: (value: Array) => void, + reject: (error: BusinessError) => void) => { taskpool.execute((): Array => { return this.getSubWindowSync(this.nativeObj); }).then((ret: NullishType) => { - callback(new BusinessError(), ret as Array); + resolve(ret as Array); }).catch((err: NullishType) => { - callback(err as BusinessError, undefined); + reject(err as BusinessError); }); + }); + } + + public getSubWindow(callback: AsyncCallback>): void { + taskpool.execute((): Array => { + return this.getSubWindowSync(this.nativeObj); + }).then((ret: NullishType) => { + callback(new BusinessError(), ret as Array); + }).catch((err: NullishType) => { + callback(err as BusinessError, undefined); + }); } public createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise { - return new Promise((resolve: (value: Window) => void, reject: (error: BusinessError) => void) => { - taskpool.execute((): Window => { - return this.createSubWindowWithOptionsSync(this.nativeObj, name, options); - }).then((ret: NullishType) => { - resolve(ret as Window); - }).catch((err: NullishType) => { - reject(err as BusinessError); - }); - }); + return new Promise((resolve: (value: Window) => void, reject: (error: BusinessError) => void) => { + taskpool.execute((): Window => { + return this.createSubWindowWithOptionsSync(this.nativeObj, name, options); + }).then((ret: NullishType) => { + resolve(ret as Window); + }).catch((err: NullishType) => { + reject(err as BusinessError); + }); + }); } public on(eventType: 'windowStageEvent', callback: Callback): void { @@ -2255,7 +2255,7 @@ export interface WindowStage { disableWindowDecor(): void; setShowOnLockScreen(showOnLockScreen: boolean): void; getSubWindow(): Promise>; - getSubWindow(callback: AsyncCallback | undefined>): void; + getSubWindow(callback: AsyncCallback>): void; createSubWindowWithOptions(name: string, options: SubWindowOptions): Promise; setWindowModal(isModal: boolean): Promise; setCustomDensity(density: double): void; @@ -3506,19 +3506,20 @@ export class WindowInternal implements Window { }); } - public bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback, callback: AsyncCallback): void - { - taskpool.execute((): void => { - this.bindDialogTargetWithRemoteObjectSync(this.nativeObj, token, deathCallback); - }).then((ret: NullishType) => { - callback(new BusinessError(), undefined); - }).catch((err: NullishType) => { - callback(err as BusinessError, undefined); + public bindDialogTarget(token: rpc.RemoteObject, deathCallback: Callback, + callback: AsyncCallback): void { + taskpool.execute((): void => { + this.bindDialogTargetWithRemoteObjectSync(this.nativeObj, token, deathCallback); + }).then((ret: NullishType) => { + callback(new BusinessError(), undefined); + }).catch((err: NullishType) => { + callback(err as BusinessError, undefined); }); } public bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback): Promise { - return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { + return new Promise((resolve: (value: undefined) => void, + reject: (error: BusinessError) => void): void => { taskpool.execute((): void => { this.bindDialogTargetWithRequestInfoSync(this.nativeObj, requestInfo, deathCallback); }).then((ret: NullishType) => { @@ -3529,14 +3530,14 @@ export class WindowInternal implements Window { }); } - public bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback, callback: AsyncCallback): void - { - taskpool.execute((): void => { - this.bindDialogTargetWithRequestInfoSync(this.nativeObj, requestInfo, deathCallback); - }).then((ret: NullishType) => { - callback(new BusinessError(), undefined); - }).catch((err: NullishType) => { - callback(err as BusinessError, undefined); + public bindDialogTarget(requestInfo: dialogRequest.RequestInfo, deathCallback: Callback, + callback: AsyncCallback): void { + taskpool.execute((): void => { + this.bindDialogTargetWithRequestInfoSync(this.nativeObj, requestInfo, deathCallback); + }).then((ret: NullishType) => { + callback(new BusinessError(), undefined); + }).catch((err: NullishType) => { + callback(err as BusinessError, undefined); }); } @@ -4093,6 +4094,18 @@ function runAvoidAreaChangeCallback(cb: object, area: object, type: int): void { func({type: type as AvoidAreaType, area: area as AvoidArea}); } +export function shiftAppWindowFocus(sourceWindowId: int, targetWindowId: int): Promise { + return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { + taskpool.execute((): void => { + return shiftAppWindowFocusSync(nativeObj, sourceWindowId, targetWindowId); + }).then((ret: NullishType) => { + resolve(undefined); + }).catch((err: NullishType) => { + reject(err as BusinessError); + }); + }); +} + export function toggleShownStateForAllAppWindows(callback: AsyncCallback): void { taskpool.execute((): void => { toggleShownStateForAllAppWindowsSync(nativeObj); @@ -4105,25 +4118,13 @@ export function toggleShownStateForAllAppWindows(callback: AsyncCallback): export function toggleShownStateForAllAppWindows(): Promise { return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { - taskpool.execute((): void => { - return toggleShownStateForAllAppWindowsSync(nativeObj); - }).then((ret: NullishType) => { - resolve(undefined); - }).catch((err: NullishType) => { - reject(err as BusinessError); - }); - }); -} - -export function shiftAppWindowFocus(sourceWindowId: int, targetWindowId: int): Promise { - return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void): void => { - taskpool.execute((): void => { - return shiftAppWindowFocusSync(nativeObj, sourceWindowId, targetWindowId); - }).then((ret: NullishType) => { - resolve(undefined); - }).catch((err: NullishType) => { - reject(err as BusinessError); - }); + taskpool.execute((): void => { + return toggleShownStateForAllAppWindowsSync(nativeObj); + }).then((ret: NullishType) => { + resolve(undefined); + }).catch((err: NullishType) => { + reject(err as BusinessError); + }); }); } diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp index 26c8f237d0..9e2381d13a 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp @@ -3489,7 +3489,7 @@ void AniWindow::BindDialogTarget(ani_env* env, ani_object obj, ani_long nativeOb TLOGI(WmsLogTag::WMS_DIALOG, "[ANI]"); AniWindow* aniWindow = reinterpret_cast(nativeObj); if (aniWindow != nullptr) { - ani->OnbindDialogTarget(env, token, deathCallback); + aniWindow->OnBindDialogTarget(env, token, deathCallback); } else { TLOGE(WmsLogTag::WMS_DIALOG, "[ANI] aniWindow is nullptr"); } @@ -3497,22 +3497,21 @@ void AniWindow::BindDialogTarget(ani_env* env, ani_object obj, ani_long nativeOb void AniWindow::OnBindDialogTarget(ani_env* env, ani_object token, ani_ref deathCallback) { - TLOGI(WmsLogTag::WMS_DIALOG, "[ANI] OnBindDialogTarget in"); if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_DIALOG, "[ANI] window is nullptr"); - AniWindowUtils::AniThrowError(env, WMErrorCode::WM_ERROR_STATE_ABNORMALLY); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); return; } if (!Permission::IsSystemCalling()) { - TLOGE(WmsLogTag::WMS_DIALOG, "Permission denied, require system application!"); - AniWindowUtils::AniThrowError(env, WMErrorCode::WM_ERROR_NOT_SYSTEM_APP); + TLOGE(WmsLogTag::WMS_DIALOG, "permission denied, require system application!"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP); return; } sptr token_go = AniGetNativeRemoteObject(env, token); if (token_go == nullptr) { TLOGE(WmsLogTag::WMS_DIALOG, "token is null"); - AniWindowUtils::AniThrowError(env, WMErrorCode::WM_ERROR_INVALID_PARAM); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); return; } @@ -3521,7 +3520,7 @@ void AniWindow::OnBindDialogTarget(ani_env* env, ani_object token, ani_ref death wptr weakToken(windowToken_); auto window = weakToken.promote(); WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->BindDialogTarget(token_go)); - if (ret != WMErrorCode::WM_OK) { + if (ret != WmErrorCode::WM_OK) { AniWindowUtils::AniThrowError(env, ret, "Bind Dialog Target failed"); } TLOGI(WmsLogTag::WMS_SYSTEM, "BindDialogTarget end, window [%{public}u, %{public}s]", @@ -3534,7 +3533,7 @@ void AniWindow::BindDialogTargetNew(ani_env* env, ani_object obj, ani_long nativ TLOGI(WmsLogTag::WMS_DIALOG, "[ANI]"); AniWindow* aniWindow = reinterpret_cast(nativeObj); if (aniWindow != nullptr) { - ani->OnbindDialogTargetNew(env, requestInfo, deathCallback); + aniWindow->OnBindDialogTargetNew(env, requestInfo, deathCallback); } else { TLOGE(WmsLogTag::WMS_DIALOG, "[ANI] aniWindow is nullptr"); } @@ -3542,22 +3541,21 @@ void AniWindow::BindDialogTargetNew(ani_env* env, ani_object obj, ani_long nativ void AniWindow::OnBindDialogTargetNew(ani_env* env, ani_object requestInfo, ani_ref deathCallback) { - TLOGI(WmsLogTag::WMS_DIALOG, "[ANI] OnBindDialogTarget in"); if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_DIALOG, "[ANI] window is nullptr"); - AniWindowUtils::AniThrowError(env, WMErrorCode::WM_ERROR_STATE_ABNORMALLY); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); return; } if (!Permission::IsSystemCalling()) { - TLOGE(WmsLogTag::WMS_DIALOG, "Permission denied, require system application!"); - AniWindowUtils::AniThrowError(env, WMErrorCode::WM_ERROR_NOT_SYSTEM_APP); + TLOGE(WmsLogTag::WMS_DIALOG, "permission denied, require system application!"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP); return; } sptr token_go = AniGetNativeRemoteObject(env, requestInfo); if (token_go == nullptr) { TLOGE(WmsLogTag::WMS_DIALOG, "token is null"); - AniWindowUtils::AniThrowError(env, WMErrorCode::WM_ERROR_INVALID_PARAM); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); return; } @@ -3566,7 +3564,7 @@ void AniWindow::OnBindDialogTargetNew(ani_env* env, ani_object requestInfo, ani_ wptr weakToken(windowToken_); auto window = weakToken.promote(); WmErrorCode ret = WM_JS_TO_ERROR_CODE_MAP.at(window->BindDialogTarget(token_go)); - if (ret != WMErrorCode::WM_OK) { + if (ret != WmErrorCode::WM_OK) { AniWindowUtils::AniThrowError(env, ret, "Bind Dialog Target failed"); } TLOGI(WmsLogTag::WMS_SYSTEM, "BindDialogTarget end, window [%{public}u, %{public}s]", @@ -3574,21 +3572,20 @@ void AniWindow::OnBindDialogTargetNew(ani_env* env, ani_object requestInfo, ani_ } ani_object AniWindow::CreateSubWindowWithOptions(ani_env* env, ani_object obj, ani_long nativeObj, - ani_stirng name, ani_object options) + ani_string name, ani_object options) { TLOGD(WmsLogTag::WMS_SUB, "[ANI]"); AniWindow* aniWindow = reinterpret_cast(nativeObj); if(aniWindow!= nullptr) { - return AniWindowUtils::OnCreateSubWindowWithOptions(env, name, options); + return aniWindow->OnCreateSubWindowWithOptions(env, name, options); } else { TLOGE(WmsLogTag::WMS_SUB, "[ANI] aniWindow is nullptr"); - return AniWindowUtils::CreateAniUndefined(env); + return aniWindowUtils::CreateAniUndefined(env); } } -ani_object AniWindow::OnCreateSubWindowWithOptions(ani_env* env, ani_stirng name, ani_object options) +ani_object AniWindow::OnCreateSubWindowWithOptions(ani_env* env, ani_string name, ani_object options) { - TLOGI(WmsLogTag::WMS_SUB, "[ANI] OnCreateSubWindowWithOptions in"); if (windowToken_ == nullptr) { TLOGE(WmsLogTag::WMS_SUB, "window is null, device not support"); AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); @@ -3599,7 +3596,7 @@ ani_object AniWindow::OnCreateSubWindowWithOptions(ani_env* env, ani_stirng name AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT); return AniWindowUtils::CreateAniUndefined(env); } - str::string windowName; + std::string windowName; AniWindowUtils::GetStdString(env, name, windowName); sptr windowOption = new WindowOption(); if (!AniWindowUtils::ParseSubWindowOption(env, options, windowOption)) { @@ -3607,20 +3604,20 @@ ani_object AniWindow::OnCreateSubWindowWithOptions(ani_env* env, ani_stirng name AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_INVALID_PARAM); return AniWindowUtils::CreateAniUndefined(env); } - if ((windowOption->GetWindowFlags() & static_cast(WindowFlage::WINDOW_FLAG_IS_APPLICATION_MODAL)) && + if ((windowOption->GetWindowFlags() & static_cast(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL)) && !windowToken_->IsPcOrPadFreeMultiWindowMode()) { TLOGE(WmsLogTag::WMS_SUB, "device not support"); AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP); return AniWindowUtils::CreateAniUndefined(env); } - if (windowOption->GetWindowTopmost() && !Permission::IsSystemCalling() && Permission::IsStartByHdcd()) { - TLOGE(WmsLogTag::WMS_SUB, "Modal subWindow has topmost, but no system permission"); - AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_DEVICE_NOT_SYSTEM_APP); + if (windowOption->GetWindowTopmost() && !Permission::IsSystemCalling() && !Permission::IsStartByHdcd()) { + TLOGE(WmsLogTag::WMS_SUB, "Modal subwindow has topmost, but no system permission"); + AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_NOT_SYSTEM_APP); return AniWindowUtils::CreateAniUndefined(env); } if (!WindowHelper::IsFloatOrSubWindow(windowToken_->GetType()) && !WindowHelper::IsMainWindow(windowToken_->GetType())) { - TLOGE(WmsLogTag::WMS_SUB, "%{public}d", windowToken_.GetType()); + TLOGE(WmsLogTag::WMS_SUB, "%{public}d", windowToken_->GetType()); return AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_INVALID_CALLING, "invalid window type"); } @@ -3636,7 +3633,7 @@ ani_object AniWindow::OnCreateSubWindowWithOptions(ani_env* env, ani_stirng name "create sub window failed"); } TLOGI(WmsLogTag::WMS_SUB, "Create sub window %{public}s end", windowName.c_str()); - return static_castCreateAniWindowObject(env, subWindow); + return static_cast(CreateAniWindowObject(env, subWindow)); } } // namespace Rosen } // namespace OHOS @@ -4661,14 +4658,12 @@ ani_status OHOS::Rosen::ANI_Window_Constructor(ani_vm *vm, uint32_t *result) ani_native_function {"getTransitionControllerSync", "l:C{@ohos.window.window.TransitionController}", reinterpret_cast(AniWindow::GetTransitionController)}, ani_native_function {"bindDialogTargetWithRemoteObjectInfoSync", nullptr, - reinterpret_cast(AniWindow::bindDialogTarget)}, - ani_native_function {"bindDialogTargetWithRequestInfoSync", nullptr, - reinterpret_cast(AniWindow::bindDialogTargetNew)}, - ani_native_function {"createSubWindowSync", "lC{@ohos.window.window.TransitionController}:", - reinterpret_cast(AniWindow::GetTransitionController)}, + reinterpret_cast(AniWindow::BindDialogTarget)}, + ani_native_function {"bindDialogTargetWithRequestSync", nullptr, + reinterpret_cast(AniWindow::BindDialogTargetNew)}, ani_native_function {"createSubWindowWithOptionsSync", "lC{std.core.String}C{@ohos.window.window.SubWindowOptions}:C{@ohos.window.window.Window}", - reinterpret_cast(CreateSubWindowWithOptions)}, + reinterpret_cast(AniWindow::CreateSubWindowWithOptions)}, }; for (auto method : methods) { if ((ret = env->Class_BindNativeMethods(cls, &method, 1u)) != ANI_OK) { diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_manager.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_manager.cpp index 8fdd5d7415..0c73856cdd 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_manager.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_manager.cpp @@ -665,7 +665,6 @@ void AniWindowManager::OnToggleShownStateForAllAppWindows(ani_env* env) if(ret != WmErrorCode::WM_OK) { AniWindowUtils::AniThrowError(env, ret, "ToggleShownStateForAllAppWindows failed."); } - return ; } void AniWindowManager::ToggleShownStateForAllAppWindows(ani_env* env, ani_long nativeObj) @@ -676,7 +675,6 @@ void AniWindowManager::ToggleShownStateForAllAppWindows(ani_env* env, ani_long n return aniWindowManager->OnToggleShownStateForAllAppWindows(env); } else { TLOGE(WmsLogTag::DEFAULT, "[ANI] aniWindowManager is nullptr"); - return; } } } // namespace Rosen -- Gitee From 314c2b73eb117ee261af5528835a47a236375771 Mon Sep 17 00:00:00 2001 From: dongzhili Date: Sat, 13 Sep 2025 18:49:41 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E7=BC=A9=E8=BF=9B=E3=80=81=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=B1=BB=E5=9E=8B=E3=80=81=E7=BB=91=E5=AE=9A=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dongzhili --- .../include/ani_window_utils.h | 6 +++ .../window_stage_ani/src/ani_window_utils.cpp | 48 +++++++++---------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_utils.h b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_utils.h index 09d7e3e11c..4b6e38d134 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_utils.h +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_utils.h @@ -130,6 +130,12 @@ public: * @return Corresponding WmErrorCode or defaultCode if unmapped. */ static WmErrorCode ToErrorCode(WMError error, WmErrorCode defaultCode = WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + bool AniWindowUtils::ParseSubWindowOption(ani_env* env, ani_object jsObject, const sptr& windowOption); + bool AniWindowUtils::ParseRectParams(ani_env* env, ani_object jsObject, const sptr& windowOption); + bool AniWindowUtils::ParseModalityParams(ani_env* env, ani_object jsObject, const sptr& windowOption) + bool AniWindowUtils::ParseZLevelParams(ani_env* env, ani_object jsObject, const sptr& windowOption); + + }; } } diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp index 52ced9a380..b5138fe918 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp @@ -1525,50 +1525,50 @@ bool AniWindowUtils::ParseModalityParams(ani_env* env, ani_object jsObject, cons ani_boolean isModal { false }; env->Object_GetPropertyByName_Boolean(jsObject, "isModal", &isModal); if (isModal) { - windowOption->AddWindowFlag(WindowFlag::WINDOW_FLAG_ISMODAL); + windowOption->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_MODAL); } ani_boolean isTopmost { false }; env->Object_GetPropertyByName_Boolean(jsObject, "isTopmost", &isTopmost); - if (!isMoDal && isTopmost) { + if (!isModal && isTopmost) { TLOGE(WmsLogTag::WMS_SUB, "Normal subwindow not support topmost"); return false; } windowOption->SetWindowTopmost(isTopmost); ani_int aniModalityType { 0 }; - auto ret = env->Object_GetPropertyByName_Int(jsObject, "modealityType", &aniModalityType); + auto ret = env->Object_GetPropertyByName_Int(jsObject, "modalityType", &aniModalityType); ApiModalityType apiModalityType = static_cast(static_cast(aniModalityType)); if (ret == ANI_OK) { if(!isModal) { - TLOGE(WmsLogTag::WMS_SUB, "Normal sunwindow not support modalityType"); + TLOGE(WmsLogTag::WMS_SUB, "Normal subwindow not support modalityType"); return false; } using T = std::underlying_type_t; T modalityType = static_cast(apiModalityType); if (modalityType >= static_cast(ApiModalityType::BEGIN) && modalityType <= static_cast(ApiModalityType::END)) { - auto type = JS_TO_NATIVE_MODALITY_MAP.at(apiModalityType); + auto type = JS_TO_NATIVE_MODALITY_TYPE_MAP.at(apiModalityType); if (type == ModalityType::APPLICATION_MODALITY) { windowOption->AddWindowFlag(WindowFlag::WINDOW_FLAG_IS_APPLICATION_MODAL); } } else { - TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to modlaityType"); + TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to modalityType"); return false; } } TLOGI(WmsLogTag::WMS_SUB, "isModal: %{public}d, isTopmost: %{public}d, WindowFlag: %{public}d", isModal, isTopmost, windowOption->GetWindowFlags()); - return; + return true; } -bool AniWindowUtils::ParseZlevelParams(ani_env* env, ani_object jsObject, const sptr& windowOption) +bool AniWindowUtils::ParseZLevelParams(ani_env* env, ani_object jsObject, const sptr& windowOption) { ani_int zLevel { 0 }; - ani_status ani_zLevel = env->Object_GetPropertyByName_Int(jsObejct, "zLevel", &zLevel); + ani_status ani_zLevel = env->Object_GetPropertyByName_Int(jsObject, "zLevel", &zLevel); ani_boolean isModal { 0 }; - ani_status ani_isModal = env->Object_GetPropertyByName_Boolean(jsObejct, "isModal", &isModal); + ani_status ani_isModal = env->Object_GetPropertyByName_Boolean(jsObject, "isModal", &isModal); if(ani_zLevel == ANI_OK) { if (zLevel < MINIMUM_Z_LEVEL || zLevel > MAXIMUM_Z_LEVEL) { - TLOGE(WmsLogTag::WMS_SUB, "zLevel value %{public}d exceeds vcalid range [-10000, 10000]!", zLevel); + TLOGE(WmsLogTag::WMS_SUB, "zLevel value %{public}d exceeds valid range [-10000, 10000]!", zLevel); return false; } if (ani_isModal == ANI_OK) { @@ -1583,12 +1583,12 @@ bool AniWindowUtils::ParseZlevelParams(ani_env* env, ani_object jsObject, const return true; } -bool AniWindowUtils::ParseRectParms(ani_env* env, ani_object jsObject, const sptr& windowOption) +bool AniWindowUtils::ParseRectParams(ani_env* env, ani_object jsObject, const sptr& windowOption) { ani_ref rectRef; if (ANI_OK != env->Object_GetPropertyByName_Ref(jsObject, "windowRect", &rectRef)) { - TLOGE(WmsLogTag::WMS_SUB, "get windowRect fail"); - return false; + TLOGI(WmsLogTag::WMS_SUB, "get windowRect fail"); + return true; } ani_boolean isUndefined; if (ANI_OK != env->Reference_IsUndefined(rectRef, &isUndefined) || isUndefined) { @@ -1599,7 +1599,7 @@ bool AniWindowUtils::ParseRectParms(ani_env* env, ani_object jsObject, const spt if (!GetPropertyRectObject(env, "windowRect", (ani_object)rectRef, windowRect)) { return false; } - if (windowRect.Width_ <= 0 || windowRect.height_ <= 0) { + if (windowRect.width_ <= 0 || windowRect.height_ <= 0) { TLOGE(WmsLogTag::WMS_SUB, "width or height should greater than 0!"); return false; } @@ -1624,32 +1624,32 @@ bool AniWindowUtils::ParseSubWindowOption(ani_env* env, ani_object jsObject, con } std::string title; ani_ref result; - ani_status titleResult = env->Object_GetPropertyByName_Ref(jsObject, "title", &titleResult); + ani_status titleResult = env->Object_GetPropertyByName_Ref(jsObject, "title", &result); if (titleResult != ANI_OK) { TLOGE(WmsLogTag::WMS_SUB, "Failed to get title"); return false; } ani_string aniResult = reinterpret_cast(result); - ani_status OptionFirst = AniWindowUtils::GetStdString(env, aniResult, title); - if (OptionFirst == ANI_OK) { + ani_status optionFirst = AniWindowUtils::GetStdString(env, aniResult, title); + if (optionFirst != ANI_OK) { TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to title"); return false; } ani_boolean decorEnabled; - ani_status ret = env->Object_GetPropertyByName_Boolean(jsObject, "decorEnabled", &decorEnabled); - if (ret == ANI_OK) { + auto ret = env->Object_GetPropertyByName_Boolean(jsObject, "decorEnabled", &decorEnabled); + if (ret != ANI_OK) { TLOGE(WmsLogTag::WMS_SUB, "Failed to convert parameter to decorEnabled"); return false; } windowOption->SetSubWindowTitle(title); - windowOption->SetSubWindowDecorEnabled(decorEnabled); - if (!ParseRectParams(env, jsObejct, windowOption)) { + windowOption->SetSubWindowDecorEnable(decorEnabled); + if (!ParseRectParams(env, jsObject, windowOption)) { return false; } - if (!ParseModalityParams(env, jsObejct, windowOption)) { + if (!ParseModalityParams(env, jsObject, windowOption)) { return false; } - return ParseZLevelParams(env, jsObejct, windowOption); + return ParseZLevelParams(env, jsObject, windowOption); } } // namespace Rosen } // namespace OHOS -- Gitee From 3d11267cc83d829564744101f2435a0798afbd3e Mon Sep 17 00:00:00 2001 From: dongzhili Date: Sat, 13 Sep 2025 18:55:32 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E7=BC=A9=E8=BF=9B=E3=80=81=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=B1=BB=E5=9E=8B=E3=80=81=E7=BB=91=E5=AE=9A=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dongzhili --- .../window_stage_ani/include/ani_window_utils.h | 8 ++++---- .../window_stage_ani/src/ani_window_utils.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_utils.h b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_utils.h index 4b6e38d134..213bc8d3fe 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_utils.h +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_utils.h @@ -130,10 +130,10 @@ public: * @return Corresponding WmErrorCode or defaultCode if unmapped. */ static WmErrorCode ToErrorCode(WMError error, WmErrorCode defaultCode = WmErrorCode::WM_ERROR_STATE_ABNORMALLY); - bool AniWindowUtils::ParseSubWindowOption(ani_env* env, ani_object jsObject, const sptr& windowOption); - bool AniWindowUtils::ParseRectParams(ani_env* env, ani_object jsObject, const sptr& windowOption); - bool AniWindowUtils::ParseModalityParams(ani_env* env, ani_object jsObject, const sptr& windowOption) - bool AniWindowUtils::ParseZLevelParams(ani_env* env, ani_object jsObject, const sptr& windowOption); + static bool ParseSubWindowOption(ani_env* env, ani_object jsObject, const sptr& windowOption); + static bool ParseRectParams(ani_env* env, ani_object jsObject, const sptr& windowOption); + static bool ParseModalityParams(ani_env* env, ani_object jsObject, const sptr& windowOption); + static bool ParseZLevelParams(ani_env* env, ani_object jsObject, const sptr& windowOption); }; diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp index b5138fe918..4101475433 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_utils.cpp @@ -1538,7 +1538,7 @@ bool AniWindowUtils::ParseModalityParams(ani_env* env, ani_object jsObject, cons auto ret = env->Object_GetPropertyByName_Int(jsObject, "modalityType", &aniModalityType); ApiModalityType apiModalityType = static_cast(static_cast(aniModalityType)); if (ret == ANI_OK) { - if(!isModal) { + if (!isModal) { TLOGE(WmsLogTag::WMS_SUB, "Normal subwindow not support modalityType"); return false; } @@ -1566,7 +1566,7 @@ bool AniWindowUtils::ParseZLevelParams(ani_env* env, ani_object jsObject, const ani_status ani_zLevel = env->Object_GetPropertyByName_Int(jsObject, "zLevel", &zLevel); ani_boolean isModal { 0 }; ani_status ani_isModal = env->Object_GetPropertyByName_Boolean(jsObject, "isModal", &isModal); - if(ani_zLevel == ANI_OK) { + if (ani_zLevel == ANI_OK) { if (zLevel < MINIMUM_Z_LEVEL || zLevel > MAXIMUM_Z_LEVEL) { TLOGE(WmsLogTag::WMS_SUB, "zLevel value %{public}d exceeds valid range [-10000, 10000]!", zLevel); return false; @@ -1587,13 +1587,13 @@ bool AniWindowUtils::ParseRectParams(ani_env* env, ani_object jsObject, const sp { ani_ref rectRef; if (ANI_OK != env->Object_GetPropertyByName_Ref(jsObject, "windowRect", &rectRef)) { - TLOGI(WmsLogTag::WMS_SUB, "get windowRect fail"); - return true; + TLOGE(WmsLogTag::WMS_SUB, "get windowRect fail"); + return false; } ani_boolean isUndefined; if (ANI_OK != env->Reference_IsUndefined(rectRef, &isUndefined) || isUndefined) { - TLOGE(WmsLogTag::WMS_SUB, "windowRect is undefined"); - return false; + TLOGI(WmsLogTag::WMS_SUB, "windowRect is undefined"); + return true; } Rect windowRect; if (!GetPropertyRectObject(env, "windowRect", (ani_object)rectRef, windowRect)) { -- Gitee From ae0a1c97291d86829f0a3018f66f9ce7ed041dfb Mon Sep 17 00:00:00 2001 From: dongzhili Date: Sat, 13 Sep 2025 20:06:14 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=E7=BC=A9=E8=BF=9B=E3=80=81=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=B1=BB=E5=9E=8B=E3=80=81=E7=BB=91=E5=AE=9A=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dongzhili --- .../ani/window_runtime/window_stage_ani/src/ani_window_stage.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage.cpp index d4f9a44779..e6697f3ea5 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_window_stage.cpp @@ -627,7 +627,6 @@ ani_object AniWindowStage::CreateSubWindowWithOptions(ani_env* env, ani_object o ani_object AniWindowStage::OnCreateSubWindowWithOptions(ani_env* env, ani_string name, ani_object options) { - TLOGI(WmsLogTag::WMS_SUB, "[ANI] OnCreateSubWindowWithOptions in"); auto windowScene = GetWindowScene().lock(); if (windowScene == nullptr) { TLOGE(WmsLogTag::WMS_SUB, "WindowScene is null"); -- Gitee