From f949b9e87e65163b5cf75ae0e7f0e22a6dea344f Mon Sep 17 00:00:00 2001 From: Otto Eotvos Date: Tue, 27 May 2025 10:15:44 +0200 Subject: [PATCH] Update hardcoded names affected by name mangling Issue: https://gitee.com/openharmony/window_window_manager/issues/ICT8OW Description: Swap hard-coded names to API calls when interacting with ANI. Signed-off-by: Otto Eotvos Change-Id: Ia5047fd415ca0d76593c3e1d254530c34aebc6cc --- .../display_ani/src/display_ani.cpp | 12 +- .../display_ani/src/display_ani_manager.cpp | 11 +- .../display_ani/src/display_ani_utils.cpp | 100 ++++---- .../kits/ani/embeddable_window_stage/BUILD.gn | 1 + .../ets/uiExtensionHost_entry.ets | 4 +- .../src/ani_extension_window.cpp | 35 +-- .../src/ani_extension_window_listener.cpp | 10 +- .../screen_ani/src/screen_ani_utils.cpp | 73 +++--- .../kits/ani/screenshot_runtime/BUILD.gn | 3 +- .../src/screenshot_ani_utils.cpp | 21 +- .../include/ani_window_utils.h | 4 +- .../src/ani_transition_controller.cpp | 7 +- .../window_stage_ani/src/ani_window_utils.cpp | 217 ++++++++++-------- 13 files changed, 297 insertions(+), 201 deletions(-) diff --git a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani.cpp b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani.cpp index a820d17488..75a6d28303 100644 --- a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani.cpp +++ b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani.cpp @@ -33,9 +33,11 @@ #include "refbase.h" #include "singleton_container.h" #include "window_manager_hilog.h" +#include namespace OHOS { namespace Rosen { +using namespace arkts::ani_signature; // construct, set registerManager. DisplayAni::DisplayAni(const sptr& display) : display_(display) @@ -53,7 +55,8 @@ void DisplayAni::GetCutoutInfo(ani_env* env, ani_object obj, ani_object cutoutIn std::vector rects = cutoutInfo->GetBoundingRects(); // bounding rects ani_ref boundingRects = nullptr; - ani_status status = env->Object_GetFieldByName_Ref(cutoutInfoObj, "boundingRects", &boundingRects); + ani_status status = env->Object_GetFieldByName_Ref(cutoutInfoObj, + Builder::BuildPropertyName("boundingRects").c_str(), &boundingRects); if (ANI_OK != status) { TLOGE(WmsLogTag::DMS, "[ANI] get field bounding rects fail, ani_status = %{public}d", status); } @@ -72,7 +75,8 @@ void DisplayAni::GetCutoutInfo(ani_env* env, ani_object obj, ani_object cutoutIn } // waterfall area ani_ref waterfallObj = nullptr; - env->Object_GetFieldByName_Ref(cutoutInfoObj, "waterfallDisplayAreaRects", &waterfallObj); + env->Object_GetFieldByName_Ref(cutoutInfoObj, Builder::BuildPropertyName("waterfallDisplayAreaRects").c_str(), + &waterfallObj); auto waterfallDisplayAreaRects = cutoutInfo->GetWaterfallDisplayAreaRects(); DisplayAniUtils::ConvertWaterArea(waterfallDisplayAreaRects, static_cast(waterfallObj), env); } @@ -106,7 +110,7 @@ void DisplayAni::GetAvailableArea(ani_env* env, ani_object obj, ani_object avail { TLOGI(WmsLogTag::DMS, "[ANI] begin"); ani_long id; - env->Object_GetFieldByName_Long(obj, "id", &id); + env->Object_GetFieldByName_Long(obj, Builder::BuildPropertyName("id").c_str(), &id); auto display = SingletonContainer::Get().GetDisplayById(id); if (display == nullptr) { TLOGE(WmsLogTag::DMS, "[ANI] can not find display."); @@ -128,7 +132,7 @@ ani_boolean DisplayAni::HasImmersiveWindow(ani_env* env, ani_object obj) { TLOGI(WmsLogTag::DMS, "[ANI] begin"); ani_long id; - env->Object_GetFieldByName_Long(obj, "id", &id); + env->Object_GetFieldByName_Long(obj, Builder::BuildPropertyName("id").c_str(), &id); auto display = SingletonContainer::Get().GetDisplayById(id); if (display == nullptr) { TLOGE(WmsLogTag::DMS, "[ANI]can not find display."); diff --git a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_manager.cpp b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_manager.cpp index 9736f4322d..eb0b981dd3 100644 --- a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_manager.cpp +++ b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_manager.cpp @@ -30,9 +30,12 @@ #include "refbase.h" #include "singleton_container.h" #include "window_manager_hilog.h" +#include "ani_err_utils.h" +#include namespace OHOS { namespace Rosen { +using namespace arkts::ani_signature; DisplayManagerAni::DisplayManagerAni() { @@ -182,11 +185,13 @@ void DisplayManagerAni::OnGetCurrentFoldCreaseRegion(ani_env* env, ani_object ob return; } TLOGI(WmsLogTag::DMS, "[ANI] DisplayManager GetCurrentFoldCreaseRegion success %{public}d", (int)displayId); - if (ANI_OK != env->Object_SetFieldByName_Long(obj, "displayId", (ani_long)displayId)) { + if (ANI_OK != env->Object_SetFieldByName_Long(obj, Builder::BuildPropertyName("displayId").c_str(), + (ani_long)displayId)) { TLOGE(WmsLogTag::DMS, "[ANI] set displayId field fail"); } ani_ref creaseRectsObj{}; - if (ANI_OK != env->Object_GetFieldByName_Ref(obj, "creaseRects", &creaseRectsObj)) { + if (ANI_OK != env->Object_GetFieldByName_Ref(obj, Builder::BuildPropertyName("creaseRects").c_str(), + &creaseRectsObj)) { TLOGE(WmsLogTag::DMS, "[ANI] get ani_array len fail"); } ani_int length; @@ -703,7 +708,7 @@ void DisplayManagerAni::OnFinalizerDisplay(ani_env* env, ani_object displayObj) { TLOGI(WmsLogTag::DMS, "[ANI] DMS FinalizerDisplayNative begin"); ani_long displayId; - if (ANI_OK != env->Object_GetFieldByName_Long(displayObj, "id", &displayId)) { + if (ANI_OK != env->Object_GetFieldByName_Long(displayObj, Builder::BuildPropertyName("id").c_str(), &displayId)) { TLOGE(WmsLogTag::DMS, "[ANI] DMS FinalizerDisplayNative get displayId failed"); return; } diff --git a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_utils.cpp b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_utils.cpp index 2224ac161d..22704ccc69 100644 --- a/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_utils.cpp +++ b/interfaces/kits/ani/display_runtime/display_ani/src/display_ani_utils.cpp @@ -26,9 +26,11 @@ #include "refbase.h" #include "singleton_container.h" #include "window_manager_hilog.h" +#include namespace OHOS { namespace Rosen { +using namespace arkts::ani_signature; static thread_local std::map> g_AniDisplayMap; std::recursive_mutex g_mutex; @@ -58,10 +60,10 @@ void DisplayAniUtils::ConvertRect(DMRect rect, ani_object rectObj, ani_env* env) { TLOGI(WmsLogTag::DMS, "[ANI] rect area info: %{public}d, %{public}d, %{public}u, %{public}u", rect.posX_, rect.posY_, rect.width_, rect.height_); - env->Object_SetFieldByName_Long(rectObj, "left", rect.posX_); - env->Object_SetFieldByName_Long(rectObj, "width", rect.width_); - env->Object_SetFieldByName_Long(rectObj, "top", rect.posY_); - env->Object_SetFieldByName_Long(rectObj, "height", rect.height_); + env->Object_SetFieldByName_Long(rectObj, Builder::BuildPropertyName("left").c_str(), rect.posX_); + env->Object_SetFieldByName_Long(rectObj, Builder::BuildPropertyName("width").c_str(), rect.width_); + env->Object_SetFieldByName_Long(rectObj, Builder::BuildPropertyName("top").c_str(), rect.posY_); + env->Object_SetFieldByName_Long(rectObj, Builder::BuildPropertyName("height").c_str(), rect.height_); } void DisplayAniUtils::ConvertWaterArea(WaterfallDisplayAreaRects waterfallDisplayAreaRects, @@ -72,10 +74,10 @@ void DisplayAniUtils::ConvertWaterArea(WaterfallDisplayAreaRects waterfallDispla ani_ref rightObj; ani_ref topObj; ani_ref bottomObj; - env->Object_GetFieldByName_Ref(waterfallObj, "left", &leftObj); - env->Object_GetFieldByName_Ref(waterfallObj, "right", &rightObj); - env->Object_GetFieldByName_Ref(waterfallObj, "top", &topObj); - env->Object_GetFieldByName_Ref(waterfallObj, "bottom", &bottomObj); + env->Object_GetFieldByName_Ref(waterfallObj, Builder::BuildPropertyName("left").c_str(), &leftObj); + env->Object_GetFieldByName_Ref(waterfallObj, Builder::BuildPropertyName("right").c_str(), &rightObj); + env->Object_GetFieldByName_Ref(waterfallObj, Builder::BuildPropertyName("top").c_str(), &topObj); + env->Object_GetFieldByName_Ref(waterfallObj, Builder::BuildPropertyName("bottom").c_str(), &bottomObj); ConvertRect(waterfallDisplayAreaRects.left, static_cast(leftObj), env); ConvertRect(waterfallDisplayAreaRects.right, static_cast(rightObj), env); ConvertRect(waterfallDisplayAreaRects.top, static_cast(topObj), env); @@ -93,10 +95,10 @@ void DisplayAniUtils::ConvertDisplayPhysicalResolution(std::vectorObject_CallMethodByName_Ref(arrayObj, "$_get", "i:C{std.core.Object}", &obj, (ani_int)i); env->Object_SetFieldByName_Int(static_cast(obj), "foldDisplayMode_", static_cast(displayPhysicalArray[i].foldDisplayMode_)); - env->Object_SetFieldByName_Long(static_cast(obj), "physicalWidth", - displayPhysicalArray[i].physicalWidth_); - env->Object_SetFieldByName_Long(static_cast(obj), "physicalHeight", - displayPhysicalArray[i].physicalHeight_); + env->Object_SetFieldByName_Long(static_cast(obj), + Builder::BuildPropertyName("physicalWidth").c_str(), displayPhysicalArray[i].physicalWidth_); + env->Object_SetFieldByName_Long(static_cast(obj), + Builder::BuildPropertyName("physicalHeight").c_str(), displayPhysicalArray[i].physicalHeight_); } } @@ -113,6 +115,11 @@ ani_enum_item DisplayAniUtils::CreateAniEnum(ani_env* env, const char* enum_desc return enumItem; } +const char *propName(const std::string_view &name) +{ + return Builder::BuildPropertyName(name).c_str(); +} + ani_status DisplayAniUtils::CvtDisplay(sptr display, ani_env* env, ani_object obj) { sptr info = display->GetDisplayInfoWithCache(); @@ -120,52 +127,51 @@ ani_status DisplayAniUtils::CvtDisplay(sptr display, ani_env* env, ani_ TLOGE(WmsLogTag::DMS, "[ANI] Failed to GetDisplayInfo"); return ANI_ERROR; } - int setfieldid = env->Object_SetFieldByName_Long(obj, "id", info->GetDisplayId()); + int setfieldid = env->Object_SetFieldByName_Long(obj, propName("id"), info->GetDisplayId()); if (ANI_OK != setfieldid) { TLOGE(WmsLogTag::DMS, "[ANI] set id failed: %{public}d", setfieldid); } - const ani_size stringLength = info->GetName().size(); TLOGI(WmsLogTag::DMS, "[ANI] display = %{public}u, name = %{public}s", static_cast(info->GetDisplayId()), info->GetName().c_str()); ani_string str = nullptr; - env->String_NewUTF8(info->GetName().data(), stringLength, &str); - env->Object_SetFieldByName_Ref(obj, "name", str); - env->Object_SetFieldByName_Boolean(obj, "alive", info->GetAliveStatus()); + env->String_NewUTF8(info->GetName().data(), info->GetName().size(), &str); + env->Object_SetFieldByName_Ref(obj, propName("name"), str); + env->Object_SetFieldByName_Boolean(obj, propName("alive"), info->GetAliveStatus()); if (NATIVE_TO_JS_DISPLAY_STATE_MAP.count(info->GetDisplayState()) != 0) { - env->Object_SetFieldByName_Ref(obj, "state", DisplayAniUtils::CreateAniEnum( + env->Object_SetFieldByName_Ref(obj, propName("state"), DisplayAniUtils::CreateAniEnum( env, "@ohos.display.display.DisplayState", static_cast(info->GetDisplayState()))); } else { - env->Object_SetFieldByName_Ref(obj, "state", DisplayAniUtils::CreateAniEnum( + env->Object_SetFieldByName_Ref(obj, propName("state"), DisplayAniUtils::CreateAniEnum( env, "@ohos.display.display.DisplayState", static_cast(0))); } - env->Object_SetFieldByName_Int(obj, "refreshRate", info->GetRefreshRate()); - env->Object_SetFieldByName_Int(obj, "rotation", static_cast(info->GetRotation())); - ani_status setfieldRes = env->Object_SetFieldByName_Double(obj, "width", + env->Object_SetFieldByName_Int(obj, propName("refreshRate"), info->GetRefreshRate()); + env->Object_SetFieldByName_Int(obj, propName("rotation"), static_cast(info->GetRotation())); + ani_status setfieldRes = env->Object_SetFieldByName_Double(obj, propName("width"), static_cast(info->GetWidth())); if (ANI_OK != setfieldRes) { TLOGE(WmsLogTag::DMS, "[ANI] set failed: %{public}d, %{public}u", info->GetWidth(), setfieldRes); } - env->Object_SetFieldByName_Long(obj, "height", display->GetHeight()); - env->Object_SetFieldByName_Long(obj, "availableWidth", info->GetAvailableWidth()); - env->Object_SetFieldByName_Long(obj, "availableHeight", info->GetAvailableHeight()); - env->Object_SetFieldByName_Double(obj, "densityDPI", info->GetVirtualPixelRatio() * DOT_PER_INCH); - env->Object_SetFieldByName_Ref(obj, "orientation", DisplayAniUtils::CreateAniEnum( + env->Object_SetFieldByName_Long(obj, propName("height"), display->GetHeight()); + env->Object_SetFieldByName_Long(obj, propName("availableWidth"), info->GetAvailableWidth()); + env->Object_SetFieldByName_Long(obj, propName("availableHeight"), info->GetAvailableHeight()); + env->Object_SetFieldByName_Double(obj, propName("densityDPI"), info->GetVirtualPixelRatio() * DOT_PER_INCH); + env->Object_SetFieldByName_Ref(obj, propName("orientation"), DisplayAniUtils::CreateAniEnum( env, "@ohos.display.display.Orientation", static_cast(info->GetDisplayOrientation()))); - env->Object_SetFieldByName_Double(obj, "densityPixels", info->GetVirtualPixelRatio()); - env->Object_SetFieldByName_Double(obj, "scaledDensity", info->GetVirtualPixelRatio()); - env->Object_SetFieldByName_Double(obj, "xDPI", info->GetXDpi()); - env->Object_SetFieldByName_Double(obj, "yDPI", info->GetYDpi()); - env->Object_SetFieldByName_Ref(obj, "screenShape", DisplayAniUtils::CreateAniEnum( + env->Object_SetFieldByName_Double(obj, propName("densityPixels"), info->GetVirtualPixelRatio()); + env->Object_SetFieldByName_Double(obj, propName("scaledDensity"), info->GetVirtualPixelRatio()); + env->Object_SetFieldByName_Double(obj, propName("xDPI"), info->GetXDpi()); + env->Object_SetFieldByName_Double(obj, propName("yDPI"), info->GetYDpi()); + env->Object_SetFieldByName_Ref(obj, propName("screenShape"), DisplayAniUtils::CreateAniEnum( env, "@ohos.display.display.ScreenShape", static_cast(info->GetScreenShape()))); if (info->GetDisplaySourceMode() == DisplaySourceMode::MAIN || info->GetDisplaySourceMode() == DisplaySourceMode::EXTEND) { - env->Object_SetFieldByName_Long(obj, "x", info->GetX()); - env->Object_SetFieldByName_Long(obj, "y", info->GetY()); + env->Object_SetFieldByName_Long(obj, propName("x"), info->GetX()); + env->Object_SetFieldByName_Long(obj, propName("y"), info->GetY()); } else { - env->Object_SetFieldByName_Ref(obj, "x", DisplayAniUtils::CreateAniUndefined(env)); - env->Object_SetFieldByName_Ref(obj, "y", DisplayAniUtils::CreateAniUndefined(env)); + env->Object_SetFieldByName_Ref(obj, propName("x"), DisplayAniUtils::CreateAniUndefined(env)); + env->Object_SetFieldByName_Ref(obj, propName("y"), DisplayAniUtils::CreateAniUndefined(env)); } - env->Object_SetFieldByName_Ref(obj, "sourceMode", DisplayAniUtils::CreateAniEnum( + env->Object_SetFieldByName_Ref(obj, propName("sourceMode"), DisplayAniUtils::CreateAniEnum( env, "@ohos.display.display.DisplaySourceMode", static_cast(info->GetDisplaySourceMode()))); auto colorSpaces = info->GetColorSpaces(); auto hdrFormats = info->GetHdrFormats(); @@ -173,17 +179,17 @@ ani_status DisplayAniUtils::CvtDisplay(sptr display, ani_env* env, ani_ if (colorSpaces.size() != 0) { ani_array colorSpacesAni; CreateAniArrayInt(env, colorSpaces.size(), &colorSpacesAni, colorSpaces); - env->Object_SetFieldByName_Ref(obj, "colorSpaces", static_cast(colorSpacesAni)); + env->Object_SetFieldByName_Ref(obj, propName("colorSpaces"), static_cast(colorSpacesAni)); } if (hdrFormats.size() != 0) { ani_array hdrFormatsAni; CreateAniArrayInt(env, hdrFormats.size(), &hdrFormatsAni, hdrFormats); - env->Object_SetFieldByName_Ref(obj, "hdrFormats", static_cast(hdrFormatsAni)); + env->Object_SetFieldByName_Ref(obj, propName("hdrFormats"), static_cast(hdrFormatsAni)); } if (supportedRefreshRates.size() != 0) { ani_array supportedRefreshRatesAni; CreateAniArrayInt(env, hdrFormats.size(), &supportedRefreshRatesAni, supportedRefreshRates); - env->Object_SetFieldByName_Ref(obj, "supportedRefreshRates", + env->Object_SetFieldByName_Ref(obj, propName("supportedRefreshRates"), static_cast(supportedRefreshRatesAni)); } return ANI_OK; @@ -322,20 +328,23 @@ DmErrorCode DisplayAniUtils::GetVirtualScreenOptionFromAni( ani_long height = 0; ani_double density = 0; ani_ref surfaceId = nullptr; - env->Object_GetPropertyByName_Ref(virtualScreenConfigObj, "name", &nameAni); + env->Object_GetPropertyByName_Ref(virtualScreenConfigObj, Builder::BuildPropertyName("name").c_str(), &nameAni); if (DisplayAniUtils::GetStdString(env, static_cast(nameAni), option.name_) != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to convert parameter to name."); return DmErrorCode::DM_ERROR_INVALID_PARAM; } - if (env->Object_GetPropertyByName_Long(virtualScreenConfigObj, "width", &width) != ANI_OK) { + if (env->Object_GetPropertyByName_Long(virtualScreenConfigObj, Builder::BuildPropertyName("width").c_str(), + &width) != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to convert parameter to width."); return DmErrorCode::DM_ERROR_INVALID_PARAM; } - if (env->Object_GetPropertyByName_Long(virtualScreenConfigObj, "height", &height) != ANI_OK) { + if (env->Object_GetPropertyByName_Long(virtualScreenConfigObj, Builder::BuildPropertyName("height").c_str(), + &height) != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to convert parameter to height."); return DmErrorCode::DM_ERROR_INVALID_PARAM; } - if (env->Object_GetPropertyByName_Double(virtualScreenConfigObj, "density", &density) != ANI_OK) { + if (env->Object_GetPropertyByName_Double(virtualScreenConfigObj, Builder::BuildPropertyName("density").c_str(), + &density) != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to convert parameter to density."); return DmErrorCode::DM_ERROR_INVALID_PARAM; } @@ -343,7 +352,8 @@ DmErrorCode DisplayAniUtils::GetVirtualScreenOptionFromAni( option.height_ = static_cast(height); option.density_ = static_cast(density); - env->Object_GetPropertyByName_Ref(virtualScreenConfigObj, "surfaceId", &surfaceId); + env->Object_GetPropertyByName_Ref(virtualScreenConfigObj, Builder::BuildPropertyName("surfaceId").c_str(), + &surfaceId); if (!DisplayAniUtils::GetSurfaceFromAni(env, static_cast(surfaceId), option.surface_)) { TLOGE(WmsLogTag::DMS, "[ANI] Failed to convert surface."); return DmErrorCode::DM_ERROR_INVALID_PARAM; diff --git a/interfaces/kits/ani/embeddable_window_stage/BUILD.gn b/interfaces/kits/ani/embeddable_window_stage/BUILD.gn index b549f887da..4e3877ba43 100644 --- a/interfaces/kits/ani/embeddable_window_stage/BUILD.gn +++ b/interfaces/kits/ani/embeddable_window_stage/BUILD.gn @@ -74,6 +74,7 @@ ohos_shared_library("embeddablewindowstageani_kit") { "hitrace:hitrace_meter", "napi:ace_napi", "runtime_core:ani", + "runtime_core:ani_helpers", ] innerapi_tags = [ "platformsdk" ] diff --git a/interfaces/kits/ani/embeddable_window_stage/ets/uiExtensionHost_entry.ets b/interfaces/kits/ani/embeddable_window_stage/ets/uiExtensionHost_entry.ets index cea4b79096..83d6f7d579 100644 --- a/interfaces/kits/ani/embeddable_window_stage/ets/uiExtensionHost_entry.ets +++ b/interfaces/kits/ani/embeddable_window_stage/ets/uiExtensionHost_entry.ets @@ -4,9 +4,9 @@ import window from '@ohos.window'; function main() { loadLibrary('embeddablewindowstageani_module.z') let win = uiExtensionHost.createExtentionWindow(0, 0); - console.println('test uiExtensionHostWindowProxyRect'); + console.println('test setter of uiExtensionHostWindowProxyRect'); - console.println('test uiExtensionHostWindowProxyRect' + win.properties); + console.println('test getter of uiExtensionHostWindowProxyRect' + win.properties); console.println('test getWindowAvoidArea CUT ' + win.getWindowAvoidArea(window.AvoidAreaType.TYPE_CUTOUT).visible); console.println('test getWindowAvoidArea SYS ' + win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).visible); diff --git a/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window.cpp b/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window.cpp index 7eb47a2713..2090fcd9ec 100644 --- a/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window.cpp +++ b/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window.cpp @@ -19,9 +19,11 @@ #include "ani_extension_window_register_manager.h" #include "extension_window_impl.h" #include "window_manager_hilog.h" +#include namespace OHOS { namespace Rosen { +using namespace arkts::ani_signature; AniExtensionWindow::AniExtensionWindow( const std::shared_ptr extensionWindow, int32_t hostWindowId) @@ -170,19 +172,23 @@ WMError AniExtensionWindow::GetRect(Rect& rect) static ani_int ExtWindowSetRect(ani_env* env, ani_object obj, OHOS::Rosen::Rect& rect) { ani_status ret {}; - if ((ret = env->Object_SetFieldByName_Double(obj, "left", rect.posX_)) != ANI_OK) { + if ((ret = env->Object_SetFieldByName_Double(obj, + Builder::BuildPropertyName("left").c_str(), rect.posX_)) != ANI_OK) { TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] set left field %{public}u", ret); return (ani_int)WMError::WM_DO_NOTHING; } - if ((ret = env->Object_SetFieldByName_Double(obj, "top", rect.posY_)) != ANI_OK) { + if ((ret = env->Object_SetFieldByName_Double(obj, + Builder::BuildPropertyName("top").c_str(), rect.posY_)) != ANI_OK) { TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] set top field %{public}u", ret); return (ani_int)WMError::WM_DO_NOTHING; } - if ((ret = env->Object_SetFieldByName_Double(obj, "width", rect.width_)) != ANI_OK) { + if ((ret = env->Object_SetFieldByName_Double(obj, + Builder::BuildPropertyName("width").c_str(), rect.width_)) != ANI_OK) { TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] set width field %{public}u", ret); return (ani_int)WMError::WM_DO_NOTHING; } - if ((ret = env->Object_SetFieldByName_Double(obj, "height", rect.height_)) != ANI_OK) { + if ((ret = env->Object_SetFieldByName_Double(obj, + Builder::BuildPropertyName("height").c_str(), rect.height_)) != ANI_OK) { TLOGE(WmsLogTag::WMS_UIEXT, "[ANI] set height field %{public}u", ret); return (ani_int)WMError::WM_DO_NOTHING; } @@ -208,7 +214,8 @@ static ani_int ExtWindowGetProperties(ani_env* env, ani_object obj, ani_long nat if ((retCode = aniExt->GetRect(rect)) != WMError::WM_OK) { return (ani_int)retCode; }; - return ExtWindowSetRectMember(env, propertyRef, "uiExtensionHostWindowProxyRect", rect); + return ExtWindowSetRectMember(env, propertyRef, + Builder::BuildPropertyName("uiExtensionHostWindowProxyRect").c_str(), rect); } static ani_int ExtWindowSetProperties(ani_env* env, ani_object obj, ani_long nativeObj, ani_object propertyRef) @@ -226,7 +233,8 @@ static ani_int ExtWindowGetWindowAvoidArea(ani_env* env, ani_object obj, ani_lon } AvoidArea avoidArea {}; ani_status ret {}; - ret = env->Object_SetFieldByName_Boolean(area, "visible", areaType != (int)AvoidAreaType::TYPE_CUTOUT); + ret = env->Object_SetFieldByName_Boolean(area, Builder::BuildPropertyName("visible").c_str(), + areaType != (int)AvoidAreaType::TYPE_CUTOUT); if (ret != ANI_OK) { TLOGI(WmsLogTag::WMS_UIEXT, "[ANI] set visible faild %{public}d", (int)ret); return (ani_int)WMError::WM_DO_NOTHING; @@ -236,20 +244,21 @@ static ani_int ExtWindowGetWindowAvoidArea(ani_env* env, ani_object obj, ani_lon if (retCode != WMError::WM_OK) { return (ani_int)retCode; } - if ((retCode = (WMError)ExtWindowSetRectMember(env, area, "leftRect", avoidArea.leftRect_)) != + if ((retCode = (WMError)ExtWindowSetRectMember(env, area, Builder::BuildPropertyName("leftRect").c_str(), + avoidArea.leftRect_)) != WMError::WM_OK) { return (ani_int)retCode; } - if ((retCode = (WMError)ExtWindowSetRectMember(env, area, "rightRect", avoidArea.rightRect_)) != - WMError::WM_OK) { + if ((retCode = (WMError)ExtWindowSetRectMember(env, area, Builder::BuildPropertyName("rightRect").c_str(), + avoidArea.rightRect_)) != WMError::WM_OK) { return (ani_int)retCode; } - if ((retCode = (WMError)ExtWindowSetRectMember(env, area, "topRect", avoidArea.topRect_)) != - WMError::WM_OK) { + if ((retCode = (WMError)ExtWindowSetRectMember(env, area, Builder::BuildPropertyName("topRect").c_str(), + avoidArea.topRect_)) != WMError::WM_OK) { return (ani_int)retCode; } - if ((retCode = (WMError)ExtWindowSetRectMember(env, area, "bottomRect", avoidArea.bottomRect_)) != - WMError::WM_OK) { + if ((retCode = (WMError)ExtWindowSetRectMember(env, area, Builder::BuildPropertyName("bottomRect").c_str(), + avoidArea.bottomRect_)) != WMError::WM_OK) { return (ani_int)retCode; } return (ani_int)WMError::WM_OK; diff --git a/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window_listener.cpp b/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window_listener.cpp index 64cb0cf7b5..821aebbf4b 100644 --- a/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window_listener.cpp +++ b/interfaces/kits/ani/embeddable_window_stage/src/ani_extension_window_listener.cpp @@ -21,10 +21,12 @@ #include "event_handler.h" #include "event_runner.h" #include "window_manager_hilog.h" +#include namespace OHOS { namespace Rosen { using namespace AbilityRuntime; +using namespace arkts::ani_signature; namespace { const std::string WINDOW_SIZE_CHANGE_CB = "windowSizeChange"; const std::string SYSTEM_AVOID_AREA_CHANGE_CB = "systemAvoidAreaChange"; @@ -80,13 +82,13 @@ void AniExtensionWindowListener::Callback() void AniExtensionWindowListener::SetSizeInfo(uint32_t width, uint32_t height) { ani_status ret {}; - if ((ret = env_->Object_SetFieldByName_Double((ani_object)callbackData_, "width", - (double)width)) != ANI_OK) { + if ((ret = env_->Object_SetFieldByName_Double((ani_object)callbackData_, + Builder::BuildPropertyName("width").c_str(), (double)width)) != ANI_OK) { TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]canot set width %{public}d", ret); return; }; - if ((ret = env_->Object_SetFieldByName_Double((ani_object)callbackData_, "height", - (double)height)) != ANI_OK) { + if ((ret = env_->Object_SetFieldByName_Double((ani_object)callbackData_, + Builder::BuildPropertyName("height").c_str(), (double)height)) != ANI_OK) { TLOGE(WmsLogTag::WMS_UIEXT, "[ANI]canot set height %{public}d", ret); return; } diff --git a/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_utils.cpp b/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_utils.cpp index 8e82c00def..76bfa8ffd6 100644 --- a/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_utils.cpp +++ b/interfaces/kits/ani/screen_runtime/screen_ani/src/screen_ani_utils.cpp @@ -27,9 +27,12 @@ #include "singleton_container.h" #include "window_manager_hilog.h" #include "surface_utils.h" +#include namespace OHOS { namespace Rosen { +using namespace arkts::ani_signature; + ani_status ScreenAniUtils::GetStdString(ani_env *env, ani_string ani_str, std::string &result) { ani_size strSize; @@ -65,14 +68,18 @@ ani_status ScreenAniUtils::ConvertScreen(ani_env *env, sptr screen, ani_ { sptr info = screen->GetScreenInfo(); TLOGI(WmsLogTag::DMS, "[ANI] convert screen id %{public}u", static_cast(info->GetScreenId())); - env->Object_SetFieldByName_Long(obj, "id", static_cast(info->GetScreenId())); - env->Object_SetFieldByName_Long(obj, "parent", static_cast(info->GetParentId())); - env->Object_SetFieldByName_Long(obj, "activeModeIndex", + env->Object_SetFieldByName_Long(obj, Builder::BuildPropertyName("id").c_str(), + static_cast(info->GetScreenId())); + env->Object_SetFieldByName_Long(obj, Builder::BuildPropertyName("parent").c_str(), + static_cast(info->GetParentId())); + env->Object_SetFieldByName_Long(obj, Builder::BuildPropertyName("activeModeIndex").c_str(), static_cast(info->GetModeId())); - env->Object_SetFieldByName_Ref(obj, "orientation", ScreenAniUtils::CreateAniEnum(env, - "@ohos.screen.screen.Orientation", static_cast(info->GetOrientation()))); - env->Object_SetFieldByName_Ref(obj, "sourceMode", ScreenAniUtils::CreateAniEnum(env, - "@ohos.screen.screen.ScreenSourceMode", static_cast(info->GetSourceMode()))); + env->Object_SetFieldByName_Ref(obj, Builder::BuildPropertyName("orientation").c_str(), + ScreenAniUtils::CreateAniEnum(env, "@ohos.screen.screen.Orientation", + static_cast(info->GetOrientation()))); + env->Object_SetFieldByName_Ref(obj, Builder::BuildPropertyName("sourceMode").c_str(), + ScreenAniUtils::CreateAniEnum(env, "@ohos.screen.screen.ScreenSourceMode", + static_cast(info->GetSourceMode()))); std::unique_ptr screenAni = std::make_unique(screen); if (ANI_OK != env->Object_SetFieldByName_Long(obj, "screenNativeObj", reinterpret_cast(screenAni.release()))) { @@ -92,7 +99,7 @@ ani_status ScreenAniUtils::ConvertScreen(ani_env *env, sptr screen, ani_ } index++; } - auto ret = env->Object_SetFieldByName_Ref(obj, "supportedModeInfo", + auto ret = env->Object_SetFieldByName_Ref(obj, Builder::BuildPropertyName("supportedModeInfo").c_str(), static_cast(screenModeInfos)); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "[ANI] get ScreenModeInfos fail, ret: %{public}d", ret); @@ -133,10 +140,14 @@ ani_object ScreenAniUtils::NewNativeObject(ani_env* env, const std::string& objN void ScreenAniUtils::ConvertScreenMode(ani_env* env, sptr mode, ani_object obj) { - env->Object_SetFieldByName_Long(obj, "id", static_cast(mode->id_)); - env->Object_SetFieldByName_Long(obj, "width", static_cast(mode->width_)); - env->Object_SetFieldByName_Long(obj, "height", static_cast(mode->height_)); - env->Object_SetFieldByName_Int(obj, "refreshRate", static_cast(mode->refreshRate_)); + env->Object_SetFieldByName_Long(obj, Builder::BuildPropertyName("id").c_str(), + static_cast(mode->id_)); + env->Object_SetFieldByName_Long(obj, Builder::BuildPropertyName("width").c_str(), + static_cast(mode->width_)); + env->Object_SetFieldByName_Long(obj, Builder::BuildPropertyName("height").c_str(), + static_cast(mode->height_)); + env->Object_SetFieldByName_Int(obj, Builder::BuildPropertyName("refreshRate").c_str(), + static_cast(mode->refreshRate_)); } ani_status ScreenAniUtils::ConvertScreens(ani_env *env, std::vector> screens, ani_object& screensAni) @@ -205,7 +216,7 @@ DmErrorCode ScreenAniUtils::GetVirtualScreenOption(ani_env* env, ani_object opti { TLOGI(WmsLogTag::DMS, "[ANI] start"); ani_ref nameRef = nullptr; - auto ret = env->Object_GetFieldByName_Ref(options, "name", &nameRef); + auto ret = env->Object_GetFieldByName_Ref(options, Builder::BuildPropertyName("name").c_str(), &nameRef); if (ret != ANI_OK || nameRef == nullptr) { TLOGE(WmsLogTag::DMS, "Failed to get nameRef, ret:%{public}d", ret); return DmErrorCode::DM_ERROR_INVALID_PARAM; @@ -217,14 +228,14 @@ DmErrorCode ScreenAniUtils::GetVirtualScreenOption(ani_env* env, ani_object opti } ani_long widthAni = 0; - ret = env->Object_GetFieldByName_Long(options, "width", &widthAni); + ret = env->Object_GetFieldByName_Long(options, Builder::BuildPropertyName("width").c_str(), &widthAni); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to get width, ret:%{public}d", ret); return DmErrorCode::DM_ERROR_INVALID_PARAM; } option.width_ = static_cast(widthAni); ani_long heightAni = 0; - ret = env->Object_GetFieldByName_Long(options, "height", &heightAni); + ret = env->Object_GetFieldByName_Long(options, Builder::BuildPropertyName("height").c_str(), &heightAni); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to get height, ret:%{public}d", ret); return DmErrorCode::DM_ERROR_INVALID_PARAM; @@ -232,7 +243,7 @@ DmErrorCode ScreenAniUtils::GetVirtualScreenOption(ani_env* env, ani_object opti option.height_ = static_cast(heightAni); ani_double densityAni = 0; - ret = env->Object_GetFieldByName_Double(options, "density", &densityAni); + ret = env->Object_GetFieldByName_Double(options, Builder::BuildPropertyName("density").c_str(), &densityAni); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to get density, ret:%{public}d", ret); return DmErrorCode::DM_ERROR_INVALID_PARAM; @@ -240,7 +251,7 @@ DmErrorCode ScreenAniUtils::GetVirtualScreenOption(ani_env* env, ani_object opti option.density_ = static_cast(densityAni); ani_ref surfaceIdRef = nullptr; - ret = env->Object_GetFieldByName_Ref(options, "surfaceId", &surfaceIdRef); + ret = env->Object_GetFieldByName_Ref(options, Builder::BuildPropertyName("surfaceId").c_str(), &surfaceIdRef); if (ret != ANI_OK || surfaceIdRef == nullptr) { TLOGE(WmsLogTag::DMS, "Failed to get surfaceIdRef, ret:%{public}d", ret); return DmErrorCode::DM_ERROR_INVALID_PARAM; @@ -278,7 +289,8 @@ ani_status ScreenAniUtils::GetMultiScreenPositionOptionsFromAni(ani_env* env, an { TLOGI(WmsLogTag::DMS, "[ANI] start"); ani_long screenIdAni = 0; - auto ret = env->Object_GetFieldByName_Long(screenOptionsAni, "id", &screenIdAni); + auto ret = env->Object_GetFieldByName_Long(screenOptionsAni, + Builder::BuildPropertyName("id").c_str(), &screenIdAni); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to get screenId, ret:%{public}d", ret); return ret; @@ -286,7 +298,8 @@ ani_status ScreenAniUtils::GetMultiScreenPositionOptionsFromAni(ani_env* env, an mainScreenOptions.screenId_ = static_cast(screenIdAni); ani_long startXAni = 0; - ret = env->Object_GetFieldByName_Long(screenOptionsAni, "startX", &startXAni); + ret = env->Object_GetFieldByName_Long(screenOptionsAni, + Builder::BuildPropertyName("startX").c_str(), &startXAni); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to get startX, ret:%{public}d", ret); return ret; @@ -294,7 +307,8 @@ ani_status ScreenAniUtils::GetMultiScreenPositionOptionsFromAni(ani_env* env, an mainScreenOptions.startX_ = static_cast(startXAni); ani_long startYAni = 0; - ret = env->Object_GetFieldByName_Long(screenOptionsAni, "startY", &startYAni); + ret = env->Object_GetFieldByName_Long(screenOptionsAni, + Builder::BuildPropertyName("startY").c_str(), &startYAni); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to get startY, ret:%{public}d", ret); return ret; @@ -352,7 +366,7 @@ ani_status ScreenAniUtils::GetRectFromAni(ani_env* env, ani_object mainScreenReg { TLOGI(WmsLogTag::DMS, "[ANI] start"); ani_long left = 0; - auto ret = env->Object_GetFieldByName_Long(mainScreenRegionAni, "left", &left); + auto ret = env->Object_GetFieldByName_Long(mainScreenRegionAni, Builder::BuildPropertyName("left").c_str(), &left); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to get left, ret:%{public}d", ret); return ret; @@ -360,7 +374,7 @@ ani_status ScreenAniUtils::GetRectFromAni(ani_env* env, ani_object mainScreenReg mainScreenRegion.posX_ = static_cast(left); ani_long top = 0; - ret = env->Object_GetFieldByName_Long(mainScreenRegionAni, "top", &top); + ret = env->Object_GetFieldByName_Long(mainScreenRegionAni, Builder::BuildPropertyName("top").c_str(), &top); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to get top, ret:%{public}d", ret); return ret; @@ -368,7 +382,7 @@ ani_status ScreenAniUtils::GetRectFromAni(ani_env* env, ani_object mainScreenReg mainScreenRegion.posY_ = static_cast(top); ani_long width = 0; - ret = env->Object_GetFieldByName_Long(mainScreenRegionAni, "width", &width); + ret = env->Object_GetFieldByName_Long(mainScreenRegionAni, Builder::BuildPropertyName("width").c_str(), &width); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to get width, ret:%{public}d", ret); return ret; @@ -376,7 +390,7 @@ ani_status ScreenAniUtils::GetRectFromAni(ani_env* env, ani_object mainScreenReg mainScreenRegion.width_ = static_cast(width); ani_long height = 0; - ret = env->Object_GetFieldByName_Long(mainScreenRegionAni, "height", &height); + ret = env->Object_GetFieldByName_Long(mainScreenRegionAni, Builder::BuildPropertyName("height").c_str(), &height); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to get height, ret:%{public}d", ret); return ret; @@ -419,7 +433,8 @@ ani_status ScreenAniUtils::GetExpandOptionFromAni(ani_env* env, ani_object optio { TLOGI(WmsLogTag::DMS, "[ANI] start"); ani_long screenId = 0; - ani_status ret = env->Object_GetFieldByName_Long(optionAniObj, "screenId", &screenId); + ani_status ret = env->Object_GetFieldByName_Long(optionAniObj, + Builder::BuildPropertyName("screenId").c_str(), &screenId); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to get screenId, ret:%{public}d", ret); return ret; @@ -427,7 +442,8 @@ ani_status ScreenAniUtils::GetExpandOptionFromAni(ani_env* env, ani_object optio expandOption.screenId_ = screenId; ani_long startX = 0; - ret = env->Object_GetFieldByName_Long(optionAniObj, "startX", &startX); + ret = env->Object_GetFieldByName_Long(optionAniObj, + Builder::BuildPropertyName("startX").c_str(), &startX); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to get startX, ret:%{public}d", ret); return ret; @@ -435,7 +451,8 @@ ani_status ScreenAniUtils::GetExpandOptionFromAni(ani_env* env, ani_object optio expandOption.startX_ = startX; ani_long startY = 0; - ret = env->Object_GetFieldByName_Long(optionAniObj, "startY", &startY); + ret = env->Object_GetFieldByName_Long(optionAniObj, + Builder::BuildPropertyName("startY").c_str(), &startY); if (ret != ANI_OK) { TLOGE(WmsLogTag::DMS, "Failed to get startY, ret:%{public}d", ret); return ret; @@ -444,4 +461,4 @@ ani_status ScreenAniUtils::GetExpandOptionFromAni(ani_env* env, ani_object optio return ANI_OK; } } -} \ No newline at end of file +} diff --git a/interfaces/kits/ani/screenshot_runtime/BUILD.gn b/interfaces/kits/ani/screenshot_runtime/BUILD.gn index 93efca549c..37d130bc54 100644 --- a/interfaces/kits/ani/screenshot_runtime/BUILD.gn +++ b/interfaces/kits/ani/screenshot_runtime/BUILD.gn @@ -74,6 +74,7 @@ ohos_shared_library("screenshotani_kit") { "image_framework:image_taihe", "image_framework:image_native", "runtime_core:ani", + "runtime_core:ani_helpers", ] innerapi_tags = [ "platformsdk" ] @@ -86,4 +87,4 @@ group("screenshot_ani") { ":screenshotani_kit", "screenshot_ani:screenshot_etc", ] -} \ No newline at end of file +} diff --git a/interfaces/kits/ani/screenshot_runtime/screenshot_ani/src/screenshot_ani_utils.cpp b/interfaces/kits/ani/screenshot_runtime/screenshot_ani/src/screenshot_ani_utils.cpp index d0a7bb5979..ff463ae10f 100644 --- a/interfaces/kits/ani/screenshot_runtime/screenshot_ani/src/screenshot_ani_utils.cpp +++ b/interfaces/kits/ani/screenshot_runtime/screenshot_ani/src/screenshot_ani_utils.cpp @@ -21,8 +21,11 @@ #include "window_manager_hilog.h" #include "dm_common.h" #include "refbase.h" - +#include + namespace OHOS::Rosen { +using namespace arkts::ani_signature; + ani_status ScreenshotAniUtils::GetStdString(ani_env* env, ani_string ani_str, std::string& result) { ani_size strSize; @@ -76,10 +79,10 @@ void ScreenshotAniUtils::ConvertRect(ani_env* env, Media::Rect rect, ani_object { TLOGI(WmsLogTag::DMS, "[ANI] rect area info: %{public}d, %{public}d, %{public}u, %{public}u", rect.left, rect.width, rect.top, rect.height); - env->Object_SetFieldByName_Long(rectObj, "left", rect.left); - env->Object_SetFieldByName_Long(rectObj, "top", rect.top); - env->Object_SetFieldByName_Long(rectObj, "width", rect.width); - env->Object_SetFieldByName_Long(rectObj, "height", rect.height); + env->Object_SetFieldByName_Long(rectObj, Builder::BuildPropertyName("left").c_str(), rect.left); + env->Object_SetFieldByName_Long(rectObj, Builder::BuildPropertyName("top").c_str(), rect.top); + env->Object_SetFieldByName_Long(rectObj, Builder::BuildPropertyName("width").c_str(), rect.width); + env->Object_SetFieldByName_Long(rectObj, Builder::BuildPropertyName("height").c_str(), rect.height); } ani_object ScreenshotAniUtils::CreateScreenshotPickInfo(ani_env* env, std::unique_ptr& param) @@ -104,10 +107,12 @@ ani_object ScreenshotAniUtils::CreateScreenshotPickInfo(ani_env* env, std::uniqu } ani_object rectObj = ScreenshotAniUtils::CreateRectObject(env); ScreenshotAniUtils::ConvertRect(env, param->imageRect, rectObj); - env->Object_SetFieldByName_Ref(pickInfoObj, "pickRect", static_cast(rectObj)); + env->Object_SetFieldByName_Ref(pickInfoObj, Builder::BuildPropertyName("pickRect").c_str(), + static_cast(rectObj)); auto nativePixelMap = Media::PixelMapTaiheAni::CreateEtsPixelMap(env, param->image); - env->Object_SetFieldByName_Ref(pickInfoObj, "pixelMap", static_cast(nativePixelMap)); + env->Object_SetFieldByName_Ref(pickInfoObj, Builder::BuildPropertyName("pixelMap").c_str(), + static_cast(nativePixelMap)); return pickInfoObj; } @@ -321,4 +326,4 @@ ani_status ScreenshotAniUtils::ReadOptionalBoolField(ani_env* env, ani_object ob } return result; } -} \ No newline at end of file +} 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..413153087c 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 @@ -59,6 +59,8 @@ public: static ani_object CreateAniWindowDensityInfo(ani_env* env, const WindowDensityInfo& info); static ani_object CreateAniWindowSystemBarProperties(ani_env* env, const SystemBarProperty& status, const SystemBarProperty& navigation); + static bool CreateNavBarColorProperties(ani_env* env, const SystemBarProperty& navigation, ani_class cls, + ani_object systemBarProperties, const SystemBarProperty& status); static ani_object CreateAniWindowLayoutInfo(ani_env* env, const WindowLayoutInfo& info); static ani_object CreateAniWindowLayoutInfoArray(ani_env* env, const std::vector>& infos); static ani_object CreateAniWindowInfo(ani_env* env, const WindowVisibilityInfo& info); @@ -133,4 +135,4 @@ public: }; } } -#endif \ No newline at end of file +#endif diff --git a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_transition_controller.cpp b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_transition_controller.cpp index 19f4fff232..2af46a15f7 100644 --- a/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_transition_controller.cpp +++ b/interfaces/kits/ani/window_runtime/window_stage_ani/src/ani_transition_controller.cpp @@ -19,10 +19,12 @@ #include "window_manager_hilog.h" #include "window_option.h" #include "permission.h" +#include namespace OHOS { namespace Rosen { using namespace AbilityRuntime; +using namespace arkts::ani_signature; static int g_aniTransContextConstructorCount = 0; static int g_aniTransContextDestructorCount = 0; @@ -136,7 +138,8 @@ ani_object AniTransitionContext::CreateAniObj(ani_env* env, ani_ref aniWindowObj } env->Object_CallMethod_Void(obj, objFunc, reinterpret_cast(transContext.release())); if (aniWindowObj != nullptr) { - AniWindowUtils::CallAniMethodVoid(env, obj, cls, "toWindow", nullptr, aniWindowObj); + AniWindowUtils::CallAniMethodVoid(env, obj, cls, Builder::BuildSetterName("toWindow").c_str(), nullptr, + aniWindowObj); } TLOGD(WmsLogTag::WMS_ANIMATION, "[ANI] Transition context create %{public}p success", reinterpret_cast(obj)); return obj; @@ -405,4 +408,4 @@ ani_status ANI_Transition_Controller_Constructor(ani_vm* vm, uint32_t *result) return ANI_OK; } } // Rosen -} // OHOS \ No newline at end of file +} // OHOS 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 5732af3744..0054543f7c 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 @@ -26,6 +26,7 @@ #include "foundation/arkui/ace_engine/interfaces/inner_api/ace/ui_content.h" #include "ipc_skeleton.h" #include "window_manager_hilog.h" +#include namespace OHOS { namespace Rosen { @@ -56,6 +57,8 @@ std::string GetHexColor(uint32_t color) } } +using namespace arkts::ani_signature; + template ani_status unbox(ani_env* env, ani_object obj, T* result) { @@ -403,8 +406,8 @@ ani_object AniWindowUtils::CreateAniSize(ani_env* env, int32_t width, int32_t he TLOGE(WmsLogTag::DEFAULT, "[ANI] fail to new obj"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, aniRect, aniClass, "width", nullptr, ani_int(width)); - CallAniMethodVoid(env, aniRect, aniClass, "height", nullptr, ani_int(height)); + CallAniMethodVoid(env, aniRect, aniClass, Builder::BuildSetterName("width").c_str(), nullptr, ani_int(width)); + CallAniMethodVoid(env, aniRect, aniClass, Builder::BuildSetterName("height").c_str(), nullptr, ani_int(height)); return aniRect; } @@ -429,18 +432,19 @@ ani_object AniWindowUtils::CreateAniDecorButtonStyle(ani_env* env, const DecorBu TLOGE(WmsLogTag::WMS_DECOR, "[ANI] fail to new obj"); return AniWindowUtils::CreateAniUndefined(env); } + CallAniMethodVoid(env, aniDecorButtonStyle, aniClass, Builder::BuildSetterName("colorMode").c_str(), + nullptr, ani_long(decorButtonStyle.colorMode)); + CallAniMethodVoid(env, aniDecorButtonStyle, aniClass, Builder::BuildSetterName("buttonBackgroundSize").c_str(), + nullptr, ani_int(decorButtonStyle.buttonBackgroundSize)); + CallAniMethodVoid(env, aniDecorButtonStyle, aniClass, Builder::BuildSetterName("spacingBetweenButtons").c_str(), + nullptr, ani_int(decorButtonStyle.spacingBetweenButtons)); + CallAniMethodVoid(env, aniDecorButtonStyle, aniClass, Builder::BuildSetterName("closeButtonRightMargin").c_str(), + nullptr, ani_int(decorButtonStyle.closeButtonRightMargin)); + CallAniMethodVoid(env, aniDecorButtonStyle, aniClass, Builder::BuildSetterName("buttonIconSize").c_str(), + nullptr, ani_int(decorButtonStyle.buttonIconSize)); CallAniMethodVoid(env, aniDecorButtonStyle, aniClass, - "colorMode", nullptr, ani_long(decorButtonStyle.colorMode)); - CallAniMethodVoid(env, aniDecorButtonStyle, aniClass, - "buttonBackgroundSize", nullptr, ani_int(decorButtonStyle.buttonBackgroundSize)); - CallAniMethodVoid(env, aniDecorButtonStyle, aniClass, - "spacingBetweenButtons", nullptr, ani_int(decorButtonStyle.spacingBetweenButtons)); - CallAniMethodVoid(env, aniDecorButtonStyle, aniClass, - "closeButtonRightMargin", nullptr, ani_int(decorButtonStyle.closeButtonRightMargin)); - CallAniMethodVoid(env, aniDecorButtonStyle, aniClass, - "buttonIconSize", nullptr, ani_int(decorButtonStyle.buttonIconSize)); - CallAniMethodVoid(env, aniDecorButtonStyle, aniClass, - "buttonBackgroundCornerRadius", nullptr, ani_int(decorButtonStyle.buttonBackgroundCornerRadius)); + Builder::BuildSetterName("buttonBackgroundCornerRadius").c_str(), + nullptr, ani_int(decorButtonStyle.buttonBackgroundCornerRadius)); return aniDecorButtonStyle; } @@ -465,10 +469,14 @@ ani_object AniWindowUtils::CreateAniTitleButtonRect(ani_env* env, const TitleBut TLOGE(WmsLogTag::WMS_DECOR, "[ANI] fail to new obj"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, aniTitleButtonRect, aniClass, "right", nullptr, ani_double(titleButtonRect.posX_)); - CallAniMethodVoid(env, aniTitleButtonRect, aniClass, "top", nullptr, ani_double(titleButtonRect.posY_)); - CallAniMethodVoid(env, aniTitleButtonRect, aniClass, "width", nullptr, ani_double(titleButtonRect.width_)); - CallAniMethodVoid(env, aniTitleButtonRect, aniClass, "height", nullptr, ani_double(titleButtonRect.height_)); + CallAniMethodVoid(env, aniTitleButtonRect, aniClass, Builder::BuildSetterName("right").c_str(), nullptr, + ani_double(titleButtonRect.posX_)); + CallAniMethodVoid(env, aniTitleButtonRect, aniClass, Builder::BuildSetterName("top").c_str(), nullptr, + ani_double(titleButtonRect.posY_)); + CallAniMethodVoid(env, aniTitleButtonRect, aniClass, Builder::BuildSetterName("width").c_str(), nullptr, + ani_double(titleButtonRect.width_)); + CallAniMethodVoid(env, aniTitleButtonRect, aniClass, Builder::BuildSetterName("height").c_str(), nullptr, + ani_double(titleButtonRect.height_)); return aniTitleButtonRect; } @@ -494,7 +502,8 @@ ani_object AniWindowUtils::CreateAniStatusBarProperty(ani_env* env, const System TLOGE(WmsLogTag::WMS_IMMS, "[ANI] create string failed"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, statusBarProperty, cls, "contentColor", nullptr, contentColor); + CallAniMethodVoid(env, statusBarProperty, cls, Builder::BuildSetterName("contentColor").c_str(), + nullptr, contentColor); return statusBarProperty; } @@ -515,11 +524,11 @@ ani_object AniWindowUtils::CreateAniWindowDensityInfo(ani_env* env, const Window TLOGE(WmsLogTag::WMS_ATTRIBUTE, "[ANI] fail to new obj"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, windowDensityInfo, cls, "systemDensity", nullptr, + CallAniMethodVoid(env, windowDensityInfo, cls, Builder::BuildSetterName("systemDensity").c_str(), nullptr, static_cast(info.systemDensity)); - CallAniMethodVoid(env, windowDensityInfo, cls, "defaultDensity", nullptr, + CallAniMethodVoid(env, windowDensityInfo, cls, Builder::BuildSetterName("defaultDensity").c_str(), nullptr, static_cast(info.defaultDensity)); - CallAniMethodVoid(env, windowDensityInfo, cls, "customDensity", nullptr, + CallAniMethodVoid(env, windowDensityInfo, cls, Builder::BuildSetterName("customDensity").c_str(), nullptr, static_cast(info.customDensity)); return windowDensityInfo; } @@ -547,34 +556,48 @@ ani_object AniWindowUtils::CreateAniWindowSystemBarProperties(ani_env* env, TLOGE(WmsLogTag::WMS_IMMS, "[ANI] create string failed"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, systemBarProperties, cls, "statusBarColor", nullptr, backgroundColor); + CallAniMethodVoid(env, systemBarProperties, cls, Builder::BuildSetterName("statusBarColor").c_str(), + nullptr, backgroundColor); ani_string statusBarContentColor; if (GetAniString(env, GetHexColor(status.contentColor_), &statusBarContentColor) != ANI_OK) { TLOGE(WmsLogTag::WMS_IMMS, "[ANI] create string failed"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, systemBarProperties, cls, "statusBarContentColor", nullptr, statusBarContentColor); - CallAniMethodVoid(env, systemBarProperties, cls, "isStatusBarLightIcon", nullptr, - status.contentColor_ == SYSTEM_COLOR_WHITE); - ani_string navigationBarColor; - if (GetAniString(env, GetHexColor(navi.backgroundColor_), &navigationBarColor) != ANI_OK) { + CallAniMethodVoid(env, systemBarProperties, cls, Builder::BuildSetterName("statusBarContentColor").c_str(), + nullptr, statusBarContentColor); + CallAniMethodVoid(env, systemBarProperties, cls, Builder::BuildSetterName("isStatusBarLightIcon").c_str(), + nullptr, status.contentColor_ == SYSTEM_COLOR_WHITE); + + if (!CreateNavBarColorProperties(env, navi, cls, systemBarProperties, status)) { TLOGE(WmsLogTag::WMS_IMMS, "[ANI] create string failed"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, systemBarProperties, cls, "navigationBarColor", nullptr, navigationBarColor); + + return systemBarProperties; +} + +bool AniWindowUtils::CreateNavBarColorProperties(ani_env* env, const SystemBarProperty& navi, ani_class cls, + ani_object systemBarProperties, const SystemBarProperty& status) +{ + ani_string navigationBarColor; + if (GetAniString(env, GetHexColor(navi.backgroundColor_), &navigationBarColor) != ANI_OK) { + return false; + } + CallAniMethodVoid(env, systemBarProperties, cls, Builder::BuildSetterName("navigationBarColor").c_str(), + nullptr, navigationBarColor); ani_string navigationBarContentColor; if (GetAniString(env, GetHexColor(navi.contentColor_), &navigationBarContentColor) != ANI_OK) { - TLOGE(WmsLogTag::WMS_IMMS, "[ANI] create string failed"); - return AniWindowUtils::CreateAniUndefined(env); + return false; } - CallAniMethodVoid(env, systemBarProperties, cls, "navigationBarContentColor", + CallAniMethodVoid(env, systemBarProperties, cls, Builder::BuildSetterName("navigationBarContentColor").c_str(), nullptr, navigationBarContentColor); - CallAniMethodVoid(env, systemBarProperties, cls, "isNavigationBarLightIcon", nullptr, - navi.contentColor_ == SYSTEM_COLOR_WHITE); - CallAniMethodVoid(env, systemBarProperties, cls, "enableStatusBarAnimation", nullptr, status.enableAnimation_); - CallAniMethodVoid(env, systemBarProperties, cls, "enableNavigationBarAnimation", nullptr, - navi.enableAnimation_); - return systemBarProperties; + CallAniMethodVoid(env, systemBarProperties, cls, Builder::BuildSetterName("isNavigationBarLightIcon").c_str(), + nullptr, navi.contentColor_ == SYSTEM_COLOR_WHITE); + CallAniMethodVoid(env, systemBarProperties, cls, Builder::BuildSetterName("enableStatusBarAnimation").c_str(), + nullptr, status.enableAnimation_); + CallAniMethodVoid(env, systemBarProperties, cls, Builder::BuildSetterName("enableNavigationBarAnimation").c_str(), + nullptr, navi.enableAnimation_); + return true; } ani_object AniWindowUtils::CreateAniWindowLayoutInfo(ani_env* env, const WindowLayoutInfo& info) @@ -594,7 +617,8 @@ ani_object AniWindowUtils::CreateAniWindowLayoutInfo(ani_env* env, const WindowL TLOGE(WmsLogTag::WMS_ATTRIBUTE, "[ANI] fail to new obj"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, windowLayoutInfo, cls, "windowRect", nullptr, CreateAniRect(env, info.rect)); + CallAniMethodVoid(env, windowLayoutInfo, cls, Builder::BuildSetterName("windowRect").c_str(), + nullptr, CreateAniRect(env, info.rect)); return windowLayoutInfo; } @@ -632,22 +656,23 @@ ani_object AniWindowUtils::CreateAniWindowInfo(ani_env* env, const WindowVisibil TLOGE(WmsLogTag::WMS_ATTRIBUTE, "[ANI] fail to new obj"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, windowInfo, cls, "rect", nullptr, CreateAniRect(env, info.GetRect())); - CallAniMethodVoid(env, windowInfo, cls, "globalDisplayRect", nullptr, + CallAniMethodVoid(env, windowInfo, cls, Builder::BuildSetterName("rect").c_str(), nullptr, + CreateAniRect(env, info.GetRect())); + CallAniMethodVoid(env, windowInfo, cls, Builder::BuildSetterName("globalDisplayRect").c_str(), nullptr, CreateAniRect(env, info.GetGlobalDisplayRect())); ani_string bundleName; if (GetAniString(env, info.GetBundleName(), &bundleName) != ANI_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "[ANI] create string failed"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, windowInfo, cls, "bundleName", nullptr, bundleName); + CallAniMethodVoid(env, windowInfo, cls, Builder::BuildSetterName("bundleName").c_str(), nullptr, bundleName); ani_string abilityName; if (GetAniString(env, info.GetAbilityName(), &abilityName) != ANI_OK) { TLOGE(WmsLogTag::WMS_ATTRIBUTE, "[ANI] create string failed"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, windowInfo, cls, "abilityName", nullptr, abilityName); - CallAniMethodVoid(env, windowInfo, cls, "windowId", nullptr, info.GetWindowId()); + CallAniMethodVoid(env, windowInfo, cls, Builder::BuildSetterName("abilityName").c_str(), nullptr, abilityName); + CallAniMethodVoid(env, windowInfo, cls, Builder::BuildSetterName("windowId").c_str(), nullptr, info.GetWindowId()); env->Object_SetFieldByName_Int(windowInfo, "windowStatusTypeInternal", ani_int(info.GetWindowStatus())); env->Object_SetFieldByName_Boolean(windowInfo, "isFocusedInternal", ani_boolean(info.IsFocused())); return windowInfo; @@ -709,10 +734,14 @@ ani_object AniWindowUtils::CreateAniRect(ani_env* env, const Rect& rect) TLOGE(WmsLogTag::DEFAULT, "[ANI] fail to create new obj"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, aniRect, aniClass, "left", nullptr, ani_int(rect.posX_)); - CallAniMethodVoid(env, aniRect, aniClass, "top", nullptr, ani_int(rect.posY_)); - CallAniMethodVoid(env, aniRect, aniClass, "width", nullptr, ani_int(rect.width_)); - CallAniMethodVoid(env, aniRect, aniClass, "height", nullptr, ani_int(rect.height_)); + CallAniMethodVoid(env, aniRect, aniClass, Builder::BuildSetterName("left").c_str(), nullptr, + ani_int(rect.posX_)); + CallAniMethodVoid(env, aniRect, aniClass, Builder::BuildSetterName("top").c_str(), nullptr, + ani_int(rect.posY_)); + CallAniMethodVoid(env, aniRect, aniClass, Builder::BuildSetterName("width").c_str(), nullptr, + ani_int(rect.width_)); + CallAniMethodVoid(env, aniRect, aniClass, Builder::BuildSetterName("height").c_str(), nullptr, + ani_int(rect.height_)); return aniRect; } @@ -737,15 +766,15 @@ ani_object AniWindowUtils::CreateAniAvoidArea(ani_env* env, const AvoidArea& avo TLOGE(WmsLogTag::DEFAULT, "[ANI] fail to new obj"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, aniAvoidArea, aniClass, "visible", nullptr, + CallAniMethodVoid(env, aniAvoidArea, aniClass, Builder::BuildSetterName("visible").c_str(), nullptr, ani_boolean(type != AvoidAreaType::TYPE_CUTOUT)); - CallAniMethodVoid(env, aniAvoidArea, aniClass, "leftRect", nullptr, + CallAniMethodVoid(env, aniAvoidArea, aniClass, Builder::BuildSetterName("leftRect").c_str(), nullptr, CreateAniRect(env, avoidArea.leftRect_)); - CallAniMethodVoid(env, aniAvoidArea, aniClass, "topRect", nullptr, + CallAniMethodVoid(env, aniAvoidArea, aniClass, Builder::BuildSetterName("topRect").c_str(), nullptr, CreateAniRect(env, avoidArea.topRect_)); - CallAniMethodVoid(env, aniAvoidArea, aniClass, "rightRect", nullptr, + CallAniMethodVoid(env, aniAvoidArea, aniClass, Builder::BuildSetterName("rightRect").c_str(), nullptr, CreateAniRect(env, avoidArea.rightRect_)); - CallAniMethodVoid(env, aniAvoidArea, aniClass, "bottomRect", nullptr, + CallAniMethodVoid(env, aniAvoidArea, aniClass, Builder::BuildSetterName("bottomRect").c_str(), nullptr, CreateAniRect(env, avoidArea.bottomRect_)); return aniAvoidArea; } @@ -771,9 +800,9 @@ ani_object AniWindowUtils::CreateAniKeyboardInfo(ani_env* env, const KeyboardPan TLOGE(WmsLogTag::WMS_KEYBOARD, "[ANI] failed to new obj"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, keyboardInfo, aniClass, "beginRect", nullptr, + CallAniMethodVoid(env, keyboardInfo, aniClass, Builder::BuildSetterName("beginRect").c_str(), nullptr, CreateAniRect(env, keyboardPanelInfo.beginRect_)); - CallAniMethodVoid(env, keyboardInfo, aniClass, "endRect", nullptr, + CallAniMethodVoid(env, keyboardInfo, aniClass, Builder::BuildSetterName("endRect").c_str(), nullptr, CreateAniRect(env, keyboardPanelInfo.endRect_)); return keyboardInfo; } @@ -797,7 +826,8 @@ ani_object AniWindowUtils::CreateAniSystemBarTintState(ani_env* env, DisplayId d TLOGE(WmsLogTag::DEFAULT, "[ANI] fail to new obj"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, state, aniClass, "displayId", nullptr, static_cast(displayId)); + CallAniMethodVoid(env, state, aniClass, Builder::BuildSetterName("displayId").c_str(), nullptr, + static_cast(displayId)); ani_array regionTintArray = nullptr; if (env->Array_New(tints.size(), CreateAniUndefined(env), ®ionTintArray) != ANI_OK) { @@ -810,7 +840,7 @@ ani_object AniWindowUtils::CreateAniSystemBarTintState(ani_env* env, DisplayId d return AniWindowUtils::CreateAniUndefined(env); } } - CallAniMethodVoid(env, state, aniClass, "regionTint", nullptr, regionTintArray); + CallAniMethodVoid(env, state, aniClass, Builder::BuildSetterName("regionTint").c_str(), nullptr, regionTintArray); return state; } @@ -832,25 +862,30 @@ ani_object AniWindowUtils::CreateAniSystemBarRegionTint(ani_env* env, const Syst return AniWindowUtils::CreateAniUndefined(env); } if (NATIVE_JS_TO_WINDOW_TYPE_MAP.count(tint.type_) != 0) { - CallAniMethodVoid(env, regionTint, regionTintCls, "type", nullptr, + CallAniMethodVoid(env, regionTint, regionTintCls, Builder::BuildSetterName("type").c_str(), nullptr, ani_long(NATIVE_JS_TO_WINDOW_TYPE_MAP.at(tint.type_))); } else { - CallAniMethodVoid(env, regionTint, regionTintCls, "type", nullptr, ani_long(tint.type_)); + CallAniMethodVoid(env, regionTint, regionTintCls, Builder::BuildSetterName("type").c_str(), nullptr, + ani_long(tint.type_)); } - CallAniMethodVoid(env, regionTint, regionTintCls, "isEnable", nullptr, ani_boolean(tint.prop_.enable_)); + CallAniMethodVoid(env, regionTint, regionTintCls, Builder::BuildSetterName("isEnable").c_str(), nullptr, + ani_boolean(tint.prop_.enable_)); ani_string backgroundColor; if (GetAniString(env, GetHexColor(tint.prop_.backgroundColor_), &backgroundColor) != ANI_OK) { TLOGE(WmsLogTag::DEFAULT, "[ANI] create string failed"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, regionTint, regionTintCls, "backgroundColor", nullptr, backgroundColor); + CallAniMethodVoid(env, regionTint, regionTintCls, Builder::BuildSetterName("backgroundColor").c_str(), nullptr, + backgroundColor); ani_string contentColor; if (GetAniString(env, GetHexColor(tint.prop_.contentColor_), &contentColor) != ANI_OK) { TLOGE(WmsLogTag::DEFAULT, "[ANI] create string failed"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, regionTint, regionTintCls, "contentColor", nullptr, contentColor); - CallAniMethodVoid(env, regionTint, regionTintCls, "region", nullptr, CreateAniRect(env, tint.region_)); + CallAniMethodVoid(env, regionTint, regionTintCls, Builder::BuildSetterName("contentColor").c_str(), nullptr, + contentColor); + CallAniMethodVoid(env, regionTint, regionTintCls, Builder::BuildSetterName("region").c_str(), nullptr, + CreateAniRect(env, tint.region_)); return regionTint; } @@ -889,13 +924,13 @@ ani_object AniWindowUtils::CreateAniRotationChangeInfo(ani_env* env, const Rotat TLOGE(WmsLogTag::WMS_ROTATION, "[ANI] Enum_GetEnumItemByName failed"); return AniWindowUtils::CreateAniUndefined(env); } - CallAniMethodVoid(env, RotationChangeInfo, aniClass, "type", nullptr, + CallAniMethodVoid(env, RotationChangeInfo, aniClass, Builder::BuildSetterName("type").c_str(), nullptr, rotationChangeTypeItem); - CallAniMethodVoid(env, RotationChangeInfo, aniClass, "orientation", nullptr, + CallAniMethodVoid(env, RotationChangeInfo, aniClass, Builder::BuildSetterName("orientation").c_str(), nullptr, ani_int(info.orientation_)); - CallAniMethodVoid(env, RotationChangeInfo, aniClass, "displayId", nullptr, + CallAniMethodVoid(env, RotationChangeInfo, aniClass, Builder::BuildSetterName("displayId").c_str(), nullptr, ani_long(info.displayId_)); - CallAniMethodVoid(env, RotationChangeInfo, aniClass, "displayRect", nullptr, + CallAniMethodVoid(env, RotationChangeInfo, aniClass, Builder::BuildSetterName("displayRect").c_str(), nullptr, CreateAniRect(env, info.displayRect_)); return RotationChangeInfo; } @@ -1033,50 +1068,52 @@ ani_object AniWindowUtils::CreateWindowsProperties(ani_env* env, const WindowPro { TLOGI(WmsLogTag::DEFAULT, "[ANI]"); static const char* clsName = "@ohos.window.window.WindowPropertiesInternal"; - ani_object aniSystemProperties; - NewAniObjectNoParams(env, clsName, &aniSystemProperties); - CallAniMethodVoid(env, aniSystemProperties, clsName, "windowRect", nullptr, + ani_object aniSysProps; + NewAniObjectNoParams(env, clsName, &aniSysProps); + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("windowRect").c_str(), nullptr, CreateAniRect(env, windowPropertyInfo.windowRect)); - CallAniMethodVoid(env, aniSystemProperties, clsName, "drawableRect", nullptr, + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("drawableRect").c_str(), nullptr, CreateAniRect(env, windowPropertyInfo.drawableRect)); WindowType aniWindowType = windowPropertyInfo.type; if (NATIVE_JS_TO_WINDOW_TYPE_MAP.count(aniWindowType) != 0) { - env->Object_SetFieldByName_Int(aniSystemProperties, "typeInternal", + env->Object_SetFieldByName_Int(aniSysProps, "typeInternal", ani_int(NATIVE_JS_TO_WINDOW_TYPE_MAP.at(aniWindowType))); } else { - env->Object_SetFieldByName_Int(aniSystemProperties, "typeInternal", ani_int(aniWindowType)); + env->Object_SetFieldByName_Int(aniSysProps, "typeInternal", ani_int(aniWindowType)); } - CallAniMethodVoid(env, aniSystemProperties, clsName, "isLayoutFullScreen", nullptr, + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("isLayoutFullScreen").c_str(), nullptr, ani_boolean(windowPropertyInfo.isLayoutFullScreen)); - CallAniMethodVoid(env, aniSystemProperties, clsName, "isFullScreen", nullptr, + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("isFullScreen").c_str(), nullptr, ani_boolean(windowPropertyInfo.isFullScreen)); - CallAniMethodVoid(env, aniSystemProperties, clsName, "touchable", nullptr, + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("touchable").c_str(), nullptr, ani_boolean(windowPropertyInfo.isTouchable)); - std::string windowName = windowPropertyInfo.name; ani_string aniWindowName; - if (ANI_OK == GetAniString(env, windowName, &aniWindowName)) { - CallAniMethodVoid(env, aniSystemProperties, clsName, "name", nullptr, aniWindowName); + if (ANI_OK == GetAniString(env, windowPropertyInfo.name, &aniWindowName)) { + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("name").c_str(), nullptr, aniWindowName); } - CallAniMethodVoid(env, aniSystemProperties, clsName, "focusable", nullptr, + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("focusable").c_str(), nullptr, ani_boolean(windowPropertyInfo.isFocusable)); - CallAniMethodVoid(env, aniSystemProperties, clsName, "isPrivacyMode", nullptr, + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("isPrivacyMode").c_str(), nullptr, ani_boolean(windowPropertyInfo.isPrivacyMode)); - CallAniMethodVoid(env, aniSystemProperties, clsName, "isKeepScreenOn", nullptr, + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("isKeepScreenOn").c_str(), nullptr, ani_boolean(windowPropertyInfo.isKeepScreenOn)); - CallAniMethodVoid(env, aniSystemProperties, clsName, "brightness", nullptr, + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("brightness").c_str(), nullptr, ani_float(windowPropertyInfo.brightness)); - CallAniMethodVoid(env, aniSystemProperties, clsName, "isTransparent", nullptr, + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("isTransparent").c_str(), nullptr, ani_boolean(windowPropertyInfo.isTransparent)); - CallAniMethodVoid(env, aniSystemProperties, clsName, "isRoundCorner", nullptr, ani_boolean(false)); - CallAniMethodVoid(env, aniSystemProperties, clsName, "dimBehindValue", nullptr, ani_int(0)); - CallAniMethodVoid(env, aniSystemProperties, clsName, "id", nullptr, ani_int(windowPropertyInfo.id)); - CallAniMethodVoid(env, aniSystemProperties, clsName, "displayIdInternal", nullptr, + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("isRoundCorner").c_str(), nullptr, + ani_boolean(false)); + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("dimBehindValue").c_str(), nullptr, + ani_int(0)); + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("id").c_str(), nullptr, + ani_int(windowPropertyInfo.id)); + CallAniMethodVoid(env, aniSysProps, clsName, Builder::BuildSetterName("displayIdInternal").c_str(), nullptr, ani_long(windowPropertyInfo.displayId)); - if (aniSystemProperties == nullptr) { - TLOGE(WmsLogTag::DEFAULT, "[ANI] AniSystemProperties is nullptr"); + if (aniSysProps == nullptr) { + TLOGE(WmsLogTag::DEFAULT, "[ANI] aniSysProps is nullptr"); return AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); } - return aniSystemProperties; + return aniSysProps; } ani_object AniWindowUtils::CreateProperties(ani_env* env, const sptr& window) -- Gitee