From 63db7a3d5253dc78e0b40b7948aba493c00726e6 Mon Sep 17 00:00:00 2001 From: wangzilin Date: Fri, 1 Aug 2025 11:58:05 +0800 Subject: [PATCH 1/4] transfer window Signed-off-by: wangzilin --- interfaces/kits/ani/window_runtime/BUILD.gn | 1 + .../window_stage_ani/ets/@ohos.window.ets | 13 + .../window_stage_ani/include/ani_window.h | 4 + .../include/ani_window_listener.h | 26 -- .../include/ani_window_register_manager.h | 29 --- .../include/ani_window_utils.h | 228 +----------------- .../window_stage_ani/src/ani_window.cpp | 63 +++++ .../window_runtime/window_napi/js_window.h | 1 + 8 files changed, 85 insertions(+), 280 deletions(-) diff --git a/interfaces/kits/ani/window_runtime/BUILD.gn b/interfaces/kits/ani/window_runtime/BUILD.gn index c2589ba485..d86087773a 100644 --- a/interfaces/kits/ani/window_runtime/BUILD.gn +++ b/interfaces/kits/ani/window_runtime/BUILD.gn @@ -64,6 +64,7 @@ ohos_shared_library("windowstageani_kit") { "../../../../utils:libwmutil_base", "../../../../wm:libwm", "../../../../interfaces/kits/napi/window_runtime:windowstage_kit", + "../../../../interfaces/kits/napi/window_runtime:window_native_kit", ] external_deps = [ 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 a394f0e289..33e5446e7d 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 @@ -1960,6 +1960,9 @@ export class WindowInternal implements Window { this.nativeObj = nativeObject; } + private static native nativeTransferStatic(input: ESValue): Object; + private static native nativeTransferDynamic(nativeObj: long): ESValue; + private native setFollowParentWindowLayoutEnabled(nativeObj: long, enabled: boolean): void; private native setWindowDelayRaiseOnDrag(nativeObj: long, isEnabled: boolean): void; private native getParentWindow(nativeObj: long): Window; @@ -2029,6 +2032,16 @@ export class WindowInternal implements Window { private native keepKeyboardOnFocusSync(nativeObj: long, enable: boolean): void; private native onSync(nativeObj: long, type: string, callback: object): void; private native offSync(nativeObj: long, type: string, callback?: object): void; + + public static transferStatic(input: Any): Object { + hilog.info(DOMAIN, TAG, 'window transfer static, input:' + input); + return WindowInternal.nativeTransferStatic(ESValue.wrap(input)); + } + + public static transferDynamic(input: Object): Any { + hilog.info(DOMAIN, TAG, 'window transfer dynamic, input:' + input); + return WindowInternal.nativeTransferDynamic((input as WindowInternal).nativeObj).unwrap(); + } public setFollowParentWindowLayoutEnabled(enabled: boolean): Promise { return new Promise((resolve: (value: undefined) => void, reject: (error: BusinessError) => void ): 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 b3ad206cd0..02b5f71367 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 @@ -37,6 +37,10 @@ public: ani_ref GetAniRef() { return aniRef_; } void SetAniRef(const ani_ref& aniRef) { aniRef_ = aniRef; } + // transfer + static ani_object NativeTransferStatic(ani_env* aniEnv, ani_class cls, ani_object input); + static ani_object NativeTransferDynamic(ani_env* aniEnv, ani_class cls, ani_long nativeObj); + /* window obj stored in ANI */ static AniWindow* GetWindowObjectFromEnv(ani_env* env, ani_object obj); diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_listener.h b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_listener.h index 52a4b7aa83..0379019bfb 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_listener.h +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_listener.h @@ -29,32 +29,6 @@ namespace OHOS { namespace Rosen { -const std::string WINDOW_SIZE_CHANGE_CB = "windowSizeChange"; -const std::string SYSTEM_BAR_TINT_CHANGE_CB = "systemBarTintChange"; -const std::string SYSTEM_AVOID_AREA_CHANGE_CB = "systemAvoidAreaChange"; -const std::string AVOID_AREA_CHANGE_CB = "avoidAreaChange"; -const std::string LIFECYCLE_EVENT_CB = "lifeCycleEvent"; -const std::string WINDOW_STAGE_EVENT_CB = "windowStageEvent"; -const std::string WINDOW_EVENT_CB = "windowEvent"; -const std::string KEYBOARD_HEIGHT_CHANGE_CB = "keyboardHeightChange"; -const std::string KEYBOARD_DID_SHOW_CB = "keyboardDidShow"; -const std::string KEYBOARD_DID_HIDE_CB = "keyboardDidHide"; -const std::string TOUCH_OUTSIDE_CB = "touchOutside"; -const std::string SCREENSHOT_EVENT_CB = "screenshot"; -const std::string DIALOG_TARGET_TOUCH_CB = "dialogTargetTouch"; -const std::string DIALOG_DEATH_RECIPIENT_CB = "dialogDeathRecipient"; -const std::string GESTURE_NAVIGATION_ENABLED_CHANGE_CB = "gestureNavigationEnabledChange"; -const std::string WATER_MARK_FLAG_CHANGE_CB = "waterMarkFlagChange"; -const std::string WINDOW_VISIBILITY_CHANGE_CB = "windowVisibilityChange"; -const std::string WINDOW_STATUS_CHANGE_CB = "windowStatusChange"; -const std::string WINDOW_TITLE_BUTTON_RECT_CHANGE_CB = "windowTitleButtonRectChange"; -const std::string WINDOW_NO_INTERACTION_DETECT_CB = "noInteractionDetected"; -const std::string WINDOW_RECT_CHANGE_CB = "windowRectChange"; -const std::string SUB_WINDOW_CLOSE_CB = "subWindowClose"; -const std::string WINDOW_HIGHLIGHT_CHANGE_CB = "windowHighlightChange"; -const std::string WINDOW_STAGE_CLOSE_CB = "windowStageClose"; -const std::string SYSTEM_DENSITY_CHANGE_CB = "systemDensityChange"; -const std::string WINDOW_DISPLAYID_CHANGE_CB = "displayIdChange"; class AniWindowListener : public IWindowChangeListener, public ISystemBarChangedListener, diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_register_manager.h b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_register_manager.h index 73c62e4fab..ae2dd5ed29 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_register_manager.h +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/include/ani_window_register_manager.h @@ -24,35 +24,6 @@ namespace OHOS { namespace Rosen { -enum class RegisterListenerType : uint32_t { - SYSTEM_BAR_TINT_CHANGE_CB, - GESTURE_NAVIGATION_ENABLED_CHANGE_CB, - WATER_MARK_FLAG_CHANGE_CB, - WINDOW_SIZE_CHANGE_CB, - SYSTEM_AVOID_AREA_CHANGE_CB, - AVOID_AREA_CHANGE_CB, - LIFECYCLE_EVENT_CB, - WINDOW_EVENT_CB, - KEYBOARD_HEIGHT_CHANGE_CB, - KEYBOARD_DID_SHOW_CB, - KEYBOARD_DID_HIDE_CB, - TOUCH_OUTSIDE_CB, - SCREENSHOT_EVENT_CB, - DIALOG_TARGET_TOUCH_CB, - DIALOG_DEATH_RECIPIENT_CB, - WINDOW_STATUS_CHANGE_CB, - WINDOW_TITLE_BUTTON_RECT_CHANGE_CB, - WINDOW_VISIBILITY_CHANGE_CB, - WINDOW_NO_INTERACTION_DETECT_CB, - WINDOW_RECT_CHANGE_CB, - SUB_WINDOW_CLOSE_CB, - WINDOW_HIGHLIGHT_CHANGE_CB, - WINDOW_STAGE_EVENT_CB, - WINDOW_STAGE_CLOSE_CB, - SYSTEM_DENSITY_CHANGE_CB, - WINDOW_DISPLAYID_CHANGE_CB, -}; - class AniWindowRegisterManager { public: AniWindowRegisterManager(); 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 eed09e859c..3540894031 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 @@ -13,13 +13,14 @@ * limitations under the License. */ -#ifndef OHOS_JS_WINDOW_UTILS_H -#define OHOS_JS_WINDOW_UTILS_H +#ifndef OHOS_ANI_WINDOW_UTILS_H +#define OHOS_ANI_WINDOW_UTILS_H #include #include "ani.h" #include "native_engine/native_engine.h" #include "native_engine/native_value.h" #include "window.h" +#include "js_window.h" #ifndef WINDOW_PREVIEW #include "window_manager.h" @@ -33,230 +34,7 @@ namespace OHOS { namespace Rosen { -constexpr int32_t RGB_LENGTH = 6; -constexpr int32_t RGBA_LENGTH = 8; constexpr Rect g_emptyRect = {0, 0, 0, 0}; - -enum class ApiWindowType : uint32_t { - TYPE_BASE, - TYPE_APP = TYPE_BASE, - TYPE_SYSTEM_ALERT, - TYPE_INPUT_METHOD, - TYPE_STATUS_BAR, - TYPE_PANEL, - TYPE_KEYGUARD, - TYPE_VOLUME_OVERLAY, - TYPE_NAVIGATION_BAR, - TYPE_FLOAT, - TYPE_WALLPAPER, - TYPE_DESKTOP, - TYPE_LAUNCHER_RECENT, - TYPE_LAUNCHER_DOCK, - TYPE_VOICE_INTERACTION, - TYPE_POINTER, - TYPE_FLOAT_CAMERA, - TYPE_DIALOG, - TYPE_SCREENSHOT, - TYPE_SYSTEM_TOAST, - TYPE_DIVIDER, - TYPE_GLOBAL_SEARCH, - TYPE_HANDWRITE, - TYPE_END -}; - -enum class LifeCycleEventType : uint32_t { - FOREGROUND = 1, - ACTIVE, - INACTIVE, - BACKGROUND, - RESUMED, - PAUSED, - DESTROYED, -}; - -const std::map NATIVE_JS_TO_WINDOW_TYPE_MAP { - { WindowType::WINDOW_TYPE_APP_SUB_WINDOW, ApiWindowType::TYPE_APP }, - { WindowType::WINDOW_TYPE_DIALOG, ApiWindowType::TYPE_DIALOG }, - { WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, ApiWindowType::TYPE_SYSTEM_ALERT }, - { WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT, ApiWindowType::TYPE_INPUT_METHOD }, - { WindowType::WINDOW_TYPE_STATUS_BAR, ApiWindowType::TYPE_STATUS_BAR }, - { WindowType::WINDOW_TYPE_PANEL, ApiWindowType::TYPE_PANEL }, - { WindowType::WINDOW_TYPE_KEYGUARD, ApiWindowType::TYPE_KEYGUARD }, - { WindowType::WINDOW_TYPE_VOLUME_OVERLAY, ApiWindowType::TYPE_VOLUME_OVERLAY }, - { WindowType::WINDOW_TYPE_NAVIGATION_BAR, ApiWindowType::TYPE_NAVIGATION_BAR }, - { WindowType::WINDOW_TYPE_FLOAT, ApiWindowType::TYPE_FLOAT }, - { WindowType::WINDOW_TYPE_FLOAT_CAMERA, ApiWindowType::TYPE_FLOAT_CAMERA }, - { WindowType::WINDOW_TYPE_WALLPAPER, ApiWindowType::TYPE_WALLPAPER }, - { WindowType::WINDOW_TYPE_DESKTOP, ApiWindowType::TYPE_DESKTOP }, - { WindowType::WINDOW_TYPE_LAUNCHER_RECENT, ApiWindowType::TYPE_LAUNCHER_RECENT }, - { WindowType::WINDOW_TYPE_LAUNCHER_DOCK, ApiWindowType::TYPE_LAUNCHER_DOCK }, - { WindowType::WINDOW_TYPE_VOICE_INTERACTION, ApiWindowType::TYPE_VOICE_INTERACTION }, - { WindowType::WINDOW_TYPE_POINTER, ApiWindowType::TYPE_POINTER }, - { WindowType::WINDOW_TYPE_SCREENSHOT, ApiWindowType::TYPE_SCREENSHOT }, - { WindowType::WINDOW_TYPE_SYSTEM_TOAST, ApiWindowType::TYPE_SYSTEM_TOAST }, - { WindowType::WINDOW_TYPE_DOCK_SLICE, ApiWindowType::TYPE_DIVIDER }, - { WindowType::WINDOW_TYPE_GLOBAL_SEARCH, ApiWindowType::TYPE_GLOBAL_SEARCH }, - { WindowType::WINDOW_TYPE_HANDWRITE, ApiWindowType::TYPE_HANDWRITE }, -}; - -const std::map JS_TO_NATIVE_WINDOW_TYPE_MAP { - { ApiWindowType::TYPE_APP, WindowType::WINDOW_TYPE_APP_SUB_WINDOW }, - { ApiWindowType::TYPE_DIALOG, WindowType::WINDOW_TYPE_DIALOG }, - { ApiWindowType::TYPE_SYSTEM_ALERT, WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW }, - { ApiWindowType::TYPE_INPUT_METHOD, WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT }, - { ApiWindowType::TYPE_STATUS_BAR, WindowType::WINDOW_TYPE_STATUS_BAR }, - { ApiWindowType::TYPE_PANEL, WindowType::WINDOW_TYPE_PANEL }, - { ApiWindowType::TYPE_KEYGUARD, WindowType::WINDOW_TYPE_KEYGUARD }, - { ApiWindowType::TYPE_VOLUME_OVERLAY, WindowType::WINDOW_TYPE_VOLUME_OVERLAY }, - { ApiWindowType::TYPE_NAVIGATION_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR }, - { ApiWindowType::TYPE_FLOAT, WindowType::WINDOW_TYPE_FLOAT }, - { ApiWindowType::TYPE_FLOAT_CAMERA, WindowType::WINDOW_TYPE_FLOAT_CAMERA }, - { ApiWindowType::TYPE_WALLPAPER, WindowType::WINDOW_TYPE_WALLPAPER }, - { ApiWindowType::TYPE_DESKTOP, WindowType::WINDOW_TYPE_DESKTOP }, - { ApiWindowType::TYPE_LAUNCHER_RECENT, WindowType::WINDOW_TYPE_LAUNCHER_RECENT }, - { ApiWindowType::TYPE_LAUNCHER_DOCK, WindowType::WINDOW_TYPE_LAUNCHER_DOCK }, - { ApiWindowType::TYPE_VOICE_INTERACTION, WindowType::WINDOW_TYPE_VOICE_INTERACTION }, - { ApiWindowType::TYPE_POINTER, WindowType::WINDOW_TYPE_POINTER }, - { ApiWindowType::TYPE_SCREENSHOT, WindowType::WINDOW_TYPE_SCREENSHOT }, - { ApiWindowType::TYPE_SYSTEM_TOAST, WindowType::WINDOW_TYPE_SYSTEM_TOAST }, - { ApiWindowType::TYPE_DIVIDER, WindowType::WINDOW_TYPE_DOCK_SLICE }, - { ApiWindowType::TYPE_GLOBAL_SEARCH, WindowType::WINDOW_TYPE_GLOBAL_SEARCH }, - { ApiWindowType::TYPE_HANDWRITE, WindowType::WINDOW_TYPE_HANDWRITE }, -}; - -enum class ApiWindowMode : uint32_t { - UNDEFINED = 1, - FULLSCREEN, - PRIMARY, - SECONDARY, - FLOATING, - MODE_END = FLOATING -}; - -const std::map NATIVE_TO_JS_WINDOW_MODE_MAP { - { WindowMode::WINDOW_MODE_UNDEFINED, ApiWindowMode::UNDEFINED }, - { WindowMode::WINDOW_MODE_FULLSCREEN, ApiWindowMode::FULLSCREEN }, - { WindowMode::WINDOW_MODE_SPLIT_PRIMARY, ApiWindowMode::PRIMARY }, - { WindowMode::WINDOW_MODE_SPLIT_SECONDARY, ApiWindowMode::SECONDARY }, - { WindowMode::WINDOW_MODE_FLOATING, ApiWindowMode::FLOATING }, -}; - -const std::map JS_TO_NATIVE_WINDOW_MODE_MAP { - {ApiWindowMode::UNDEFINED, WindowMode::WINDOW_MODE_UNDEFINED }, - {ApiWindowMode::FULLSCREEN, WindowMode::WINDOW_MODE_FULLSCREEN }, - {ApiWindowMode::PRIMARY, WindowMode::WINDOW_MODE_SPLIT_PRIMARY }, - {ApiWindowMode::SECONDARY, WindowMode::WINDOW_MODE_SPLIT_SECONDARY }, - {ApiWindowMode::FLOATING, WindowMode::WINDOW_MODE_FLOATING }, -}; - -enum class ApiOrientation : uint32_t { - BEGIN = 0, - UNSPECIFIED = BEGIN, - PORTRAIT = 1, - LANDSCAPE = 2, - PORTRAIT_INVERTED = 3, - LANDSCAPE_INVERTED = 4, - AUTO_ROTATION = 5, - AUTO_ROTATION_PORTRAIT = 6, - AUTO_ROTATION_LANDSCAPE = 7, - AUTO_ROTATION_RESTRICTED = 8, - AUTO_ROTATION_PORTRAIT_RESTRICTED = 9, - AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10, - LOCKED = 11, - AUTO_ROTATION_UNSPECIFIED = 12, - USER_ROTATION_PORTRAIT = 13, - USER_ROTATION_LANDSCAPE = 14, - USER_ROTATION_PORTRAIT_INVERTED = 15, - USER_ROTATION_LANDSCAPE_INVERTED = 16, - FOLLOW_DESKTOP = 17, - END = FOLLOW_DESKTOP, -}; - -const std::map JS_TO_NATIVE_ORIENTATION_MAP { - {ApiOrientation::UNSPECIFIED, Orientation::UNSPECIFIED }, - {ApiOrientation::PORTRAIT, Orientation::VERTICAL }, - {ApiOrientation::LANDSCAPE, Orientation::HORIZONTAL }, - {ApiOrientation::PORTRAIT_INVERTED, Orientation::REVERSE_VERTICAL }, - {ApiOrientation::LANDSCAPE_INVERTED, Orientation::REVERSE_HORIZONTAL }, - {ApiOrientation::AUTO_ROTATION, Orientation::SENSOR }, - {ApiOrientation::AUTO_ROTATION_PORTRAIT, Orientation::SENSOR_VERTICAL }, - {ApiOrientation::AUTO_ROTATION_LANDSCAPE, Orientation::SENSOR_HORIZONTAL }, - {ApiOrientation::AUTO_ROTATION_RESTRICTED, Orientation::AUTO_ROTATION_RESTRICTED }, - {ApiOrientation::AUTO_ROTATION_PORTRAIT_RESTRICTED, Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED }, - {ApiOrientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED, Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED }, - {ApiOrientation::LOCKED, Orientation::LOCKED }, - {ApiOrientation::AUTO_ROTATION_UNSPECIFIED, Orientation::AUTO_ROTATION_UNSPECIFIED }, - {ApiOrientation::USER_ROTATION_PORTRAIT, Orientation::USER_ROTATION_PORTRAIT }, - {ApiOrientation::USER_ROTATION_LANDSCAPE, Orientation::USER_ROTATION_LANDSCAPE }, - {ApiOrientation::USER_ROTATION_PORTRAIT_INVERTED, Orientation::USER_ROTATION_PORTRAIT_INVERTED }, - {ApiOrientation::USER_ROTATION_LANDSCAPE_INVERTED, Orientation::USER_ROTATION_LANDSCAPE_INVERTED }, - {ApiOrientation::FOLLOW_DESKTOP, Orientation::FOLLOW_DESKTOP }, -}; - -const std::map NATIVE_TO_JS_ORIENTATION_MAP { - {Orientation::UNSPECIFIED, ApiOrientation::UNSPECIFIED }, - {Orientation::VERTICAL, ApiOrientation::PORTRAIT }, - {Orientation::HORIZONTAL, ApiOrientation::LANDSCAPE }, - {Orientation::REVERSE_VERTICAL, ApiOrientation::PORTRAIT_INVERTED }, - {Orientation::REVERSE_HORIZONTAL, ApiOrientation::LANDSCAPE_INVERTED }, - {Orientation::SENSOR, ApiOrientation::AUTO_ROTATION }, - {Orientation::SENSOR_VERTICAL, ApiOrientation::AUTO_ROTATION_PORTRAIT }, - {Orientation::SENSOR_HORIZONTAL, ApiOrientation::AUTO_ROTATION_LANDSCAPE }, - {Orientation::AUTO_ROTATION_RESTRICTED, ApiOrientation::AUTO_ROTATION_RESTRICTED }, - {Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED, ApiOrientation::AUTO_ROTATION_PORTRAIT_RESTRICTED }, - {Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED, ApiOrientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED }, - {Orientation::LOCKED, ApiOrientation::LOCKED }, - {Orientation::FOLLOW_RECENT, ApiOrientation::UNSPECIFIED }, - {Orientation::AUTO_ROTATION_UNSPECIFIED, ApiOrientation::AUTO_ROTATION_UNSPECIFIED }, - {Orientation::USER_ROTATION_PORTRAIT, ApiOrientation::USER_ROTATION_PORTRAIT }, - {Orientation::USER_ROTATION_LANDSCAPE, ApiOrientation::USER_ROTATION_LANDSCAPE }, - {Orientation::USER_ROTATION_PORTRAIT_INVERTED, ApiOrientation::USER_ROTATION_PORTRAIT_INVERTED }, - {Orientation::USER_ROTATION_LANDSCAPE_INVERTED, ApiOrientation::USER_ROTATION_LANDSCAPE_INVERTED }, - {Orientation::FOLLOW_DESKTOP, ApiOrientation::FOLLOW_DESKTOP }, -}; - -enum class RectChangeReason : uint32_t { - UNDEFINED = 0, - MAXIMIZE, - RECOVER, - MOVE, - DRAG, - DRAG_START, - DRAG_END, -}; - -const std::map JS_SIZE_CHANGE_REASON { - { WindowSizeChangeReason::UNDEFINED, RectChangeReason::UNDEFINED }, - { WindowSizeChangeReason::MAXIMIZE, RectChangeReason::MAXIMIZE }, - { WindowSizeChangeReason::RECOVER, RectChangeReason::RECOVER }, - { WindowSizeChangeReason::ROTATION, RectChangeReason::UNDEFINED }, - { WindowSizeChangeReason::DRAG, RectChangeReason::DRAG }, - { WindowSizeChangeReason::DRAG_START, RectChangeReason::DRAG_START }, - { WindowSizeChangeReason::DRAG_END, RectChangeReason::DRAG_END }, - { WindowSizeChangeReason::RESIZE, RectChangeReason::UNDEFINED }, - { WindowSizeChangeReason::MOVE, RectChangeReason::MOVE }, - { WindowSizeChangeReason::HIDE, RectChangeReason::UNDEFINED }, - { WindowSizeChangeReason::TRANSFORM, RectChangeReason::UNDEFINED }, - { WindowSizeChangeReason::CUSTOM_ANIMATION_SHOW, RectChangeReason::UNDEFINED }, - { WindowSizeChangeReason::FULL_TO_SPLIT, RectChangeReason::UNDEFINED }, - { WindowSizeChangeReason::SPLIT_TO_FULL, RectChangeReason::UNDEFINED }, - { WindowSizeChangeReason::FULL_TO_FLOATING, RectChangeReason::UNDEFINED }, - { WindowSizeChangeReason::FLOATING_TO_FULL, RectChangeReason::UNDEFINED }, - { WindowSizeChangeReason::END, RectChangeReason::UNDEFINED }, -}; - -enum class ApiModalityType : uint32_t { - BEGIN = 0, - WINDOW_MODALITY = BEGIN, - APPLICATION_MODALITY, - END = APPLICATION_MODALITY, -}; - -inline const std::map JS_TO_NATIVE_MODALITY_TYPE_MAP { - { ApiModalityType::WINDOW_MODALITY, ModalityType::WINDOW_MODALITY }, - { ApiModalityType::APPLICATION_MODALITY, ModalityType::APPLICATION_MODALITY }, -}; - class AniWindowUtils { public: static ani_status GetStdString(ani_env* env, ani_string ani_str, std::string& result); 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 ed3373ec35..7d788ed64f 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 @@ -23,6 +23,10 @@ #include "ani.h" #include "ani_err_utils.h" #include "ani_window_utils.h" +#include "interop_js/arkts_esvalue.h" +#include "interop_js/arkts_interop_js_api.h" +#include "interop_js/hybridgref_ani.h" +#include "interop_js/hybridgref_napi.h" #include "permission.h" #include "pixel_map.h" #include "pixel_map_taihe_ani.h" @@ -71,6 +75,61 @@ AniWindow* AniWindow::GetWindowObjectFromEnv(ani_env* env, ani_object obj) return reinterpret_cast(nativeObj); } +ani_object AniWindow::NativeTransferStatic(ani_env* aniEnv, ani_class cls, ani_object input) +{ + TLOGI(WmsLogTag::DEFAULT, "[ANI]"); + void *unwrapResult = nullptr; + if (!arkts_esvalue_unwrap(aniEnv, input, &unwrapResult)) { + TLOGE(WmsLogTag::DEFAULT, "[ANI] fail to unwrap input"); + return AniWindowUtils::CreateAniUndefined(aniEnv); + } + if (unwrapResult == nullptr) { + TLOGE(WmsLogTag::DEFAULT, "[ANI] unwrapResult is nullptr"); + return AniWindowUtils::CreateAniUndefined(aniEnv); + } + JsWindow* jsWindow = static_cast(unwrapResult); + if (jsWindow == nullptr) { + TLOGE(WmsLogTag::DEFAULT, "[ANI] jsWindow is nullptr"); + return AniWindowUtils::CreateAniUndefined(aniEnv); + } + sptr windowToken_ = jsWindow->GetWindow(); + return static_cast(CreateAniWindowObject(aniEnv, windowToken)); +} + +ani_object AniWindow::NativeTransferDynamic(ani_env* aniEnv, ani_class cls, ani_long nativeObj) +{ + TLOGI(WmsLogTag::DEFAULT, "[ANI]"); + AniWindow* aniWindow = reinterpret_cast(nativeObj); + if (aniWindow == nullptr) { + TLOGE(WmsLogTag::DEFAULT, "[ANI] aniWindow is nullptr"); + return AniWindowUtils::CreateAniUndefined(aniEnv); + } + napi_env napiEnv {}; + if (!arkts_napi_scope_open(aniEnv, &napiEnv)) { + TLOGE(WmsLogTag::DEFAULT, "[ANI] napi scope open fail"); + return AniWindowUtils::CreateAniUndefined(aniEnv); + } + napi_value jsWindow = CreateJsWindowObject(napiEnv, aniWindow->GetWindow()); + hybridgref ref {}; + if (!hybridgref_create_from_napi(napiEnv, jsWindow, &ref)) { + TLOGE(WmsLogTag::DEFAULT, "[ANI] create hybridgref fail"); + return AniWindowUtils::CreateAniUndefined(aniEnv); + } + ani_object result {}; + if (!hybridgref_get_esvalue(aniEnv, ref, &result)) { + TLOGE(WmsLogTag::DEFAULT, "[ANI] get esvalue fail"); + return AniWindowUtils::CreateAniUndefined(aniEnv); + } + if (!hybridgref_delete_from_napi(napiEnv, ref)) { + TLOGE(WmsLogTag::DEFAULT, "[ANI] delete hybridgref fail"); + } + if (!arkts_napi_scope_close_n(napiEnv, 0, nullptr, nullptr)) { + TLOGE(WmsLogTag::DEFAULT, "[ANI] napi close scope fail"); + return AniWindowUtils::CreateAniUndefined(aniEnv); + } + return result; +} + void AniWindow::SetWindowColorSpace(ani_env* env, ani_object obj, ani_long nativeObj, ani_int colorSpace) { TLOGI(WmsLogTag::DEFAULT, "[ANI] colorSpace:%{public}d", static_cast(colorSpace)); @@ -2754,6 +2813,10 @@ ani_status OHOS::Rosen::ANI_Window_Constructor(ani_vm *vm, uint32_t *result) reinterpret_cast(AniWindow::HideWithAnimation)}, ani_native_function {"showWithAnimationSync", nullptr, reinterpret_cast(AniWindow::ShowWithAnimation)}, + ani_native_function {"nativeTransferStatic", "Lstd/interop/ESValue;:Lstd/core/Object;", + reinterpret_cast(AniWindow::NativeTransferStatic)}, + ani_native_function {"nativeTransferDynamic", "J:Lstd/interop/ESValue;", + reinterpret_cast(AniWindow::NativeTransferDynamic)}, }; for (auto method : methods) { if ((ret = env->Class_BindNativeMethods(cls, &method, 1u)) != ANI_OK) { diff --git a/interfaces/kits/napi/window_runtime/window_napi/js_window.h b/interfaces/kits/napi/window_runtime/window_napi/js_window.h index d2b29df191..ef3ba55df5 100644 --- a/interfaces/kits/napi/window_runtime/window_napi/js_window.h +++ b/interfaces/kits/napi/window_runtime/window_napi/js_window.h @@ -43,6 +43,7 @@ class JsWindow final { public: explicit JsWindow(const sptr& window); ~JsWindow(); + sptr GetWindow() { return windowToken_; } static void Finalizer(napi_env env, void* data, void* hint); static napi_value Show(napi_env env, napi_callback_info info); static napi_value ShowWindow(napi_env env, napi_callback_info info); -- Gitee From 5c0c0df0d7b83508333b3661948a4b2329e4d92e Mon Sep 17 00:00:00 2001 From: wangzilin Date: Fri, 1 Aug 2025 14:18:29 +0800 Subject: [PATCH 2/4] transfer Signed-off-by: wangzilin --- interfaces/kits/ani/window_runtime/BUILD.gn | 1 + .../window_runtime/window_stage_ani/include/ani_window_utils.h | 2 +- .../kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/ani/window_runtime/BUILD.gn b/interfaces/kits/ani/window_runtime/BUILD.gn index d86087773a..52d564af1d 100644 --- a/interfaces/kits/ani/window_runtime/BUILD.gn +++ b/interfaces/kits/ani/window_runtime/BUILD.gn @@ -120,6 +120,7 @@ ohos_shared_library("windowstageani_module") { "../../../../utils:libwmutil_base", "../../../../wm:libwm", ":windowstageani_kit", + "../../../../interfaces/kits/napi/window_runtime:window_native_kit", ] external_deps = [ 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 3540894031..2d4eccc4ec 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 @@ -17,10 +17,10 @@ #define OHOS_ANI_WINDOW_UTILS_H #include #include "ani.h" +#include "js_window.h" #include "native_engine/native_engine.h" #include "native_engine/native_value.h" #include "window.h" -#include "js_window.h" #ifndef WINDOW_PREVIEW #include "window_manager.h" 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 7d788ed64f..4e5365b6fb 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 @@ -92,7 +92,7 @@ ani_object AniWindow::NativeTransferStatic(ani_env* aniEnv, ani_class cls, ani_o TLOGE(WmsLogTag::DEFAULT, "[ANI] jsWindow is nullptr"); return AniWindowUtils::CreateAniUndefined(aniEnv); } - sptr windowToken_ = jsWindow->GetWindow(); + sptr windowToken = jsWindow->GetWindow(); return static_cast(CreateAniWindowObject(aniEnv, windowToken)); } -- Gitee From 654faabf1e06a70719d8b406ab9ddad2f31c6d71 Mon Sep 17 00:00:00 2001 From: wangzilin Date: Fri, 1 Aug 2025 14:54:18 +0800 Subject: [PATCH 3/4] fix bug Signed-off-by: wangzilin --- .../kits/ani/window_runtime/window_stage_ani/src/ani_window.cpp | 1 + 1 file changed, 1 insertion(+) 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 4e5365b6fb..82d10fcf2f 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 @@ -109,6 +109,7 @@ ani_object AniWindow::NativeTransferDynamic(ani_env* aniEnv, ani_class cls, ani_ TLOGE(WmsLogTag::DEFAULT, "[ANI] napi scope open fail"); return AniWindowUtils::CreateAniUndefined(aniEnv); } + sptr aniWindowToken = aniWindow->GetWindow(); napi_value jsWindow = CreateJsWindowObject(napiEnv, aniWindow->GetWindow()); hybridgref ref {}; if (!hybridgref_create_from_napi(napiEnv, jsWindow, &ref)) { -- Gitee From e184f054075d602b09222185a02cc51ca331df9c Mon Sep 17 00:00:00 2001 From: wangzilin Date: Fri, 1 Aug 2025 15:20:50 +0800 Subject: [PATCH 4/4] fix bug Signed-off-by: wangzilin --- .../ani/window_runtime/window_stage_ani/src/ani_window.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 82d10fcf2f..6e29fa6dbd 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 @@ -109,8 +109,8 @@ ani_object AniWindow::NativeTransferDynamic(ani_env* aniEnv, ani_class cls, ani_ TLOGE(WmsLogTag::DEFAULT, "[ANI] napi scope open fail"); return AniWindowUtils::CreateAniUndefined(aniEnv); } - sptr aniWindowToken = aniWindow->GetWindow(); - napi_value jsWindow = CreateJsWindowObject(napiEnv, aniWindow->GetWindow()); + sptr windowToken = aniWindow->GetWindow(); + napi_value jsWindow = CreateJsWindowObject(napiEnv, windowToken); hybridgref ref {}; if (!hybridgref_create_from_napi(napiEnv, jsWindow, &ref)) { TLOGE(WmsLogTag::DEFAULT, "[ANI] create hybridgref fail"); -- Gitee