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 411e693a36c51544c5c797d96c02f8087c2a2921..09d7e3e11c742017f07c90ade6495179be4e7b50 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 @@ -81,7 +81,7 @@ public: const char* method, const char* signature, ...); static ani_status GetAniString(ani_env* env, const std::string& str, ani_string* result); static void* GetAbilityContext(ani_env *env, ani_object aniObj); - static ani_object CreateWindowsProperties(ani_env* env, const sptr& window); + static ani_object CreateWindowsProperties(ani_env* env, const WindowPropertyInfo& windowPropertyInfo); static ani_object CreateProperties(ani_env* env, const sptr& window); static uint32_t GetColorFromAni(ani_env* env, const char* name, uint32_t defaultColor, bool& flag, const ani_object& aniObject); @@ -130,40 +130,6 @@ public: * @return Corresponding WmErrorCode or defaultCode if unmapped. */ static WmErrorCode ToErrorCode(WMError error, WmErrorCode defaultCode = WmErrorCode::WM_ERROR_STATE_ABNORMALLY); - -private: - static void SetSystemPropertiesWindowRect(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesDrawableRect(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesWindowType(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesWindowIsLayoutFullScreen(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesWindowIsFullScreen(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesWindowTouchable(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesWindowFousable(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesWindowIsPrivacyMode(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesWindowIsKeepScreenOn(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesWindowBrightness(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesWindowIsTransparent(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesWindowIsRoundCorner(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesWindowDimBehindValue(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesWindowId(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesDisplayId(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); - static void SetSystemPropertiesWindowName(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName); }; } } 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 ae0417599434fbf65ba8df0544d0813b930560ae..077b48e9de39f16d95614dee5dd1dc481a6df624 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 @@ -2832,7 +2832,13 @@ ani_object AniWindow::GetWindowPropertiesSync(ani_env* env) TLOGE(WmsLogTag::WMS_ATTRIBUTE, "[ANI] windowToken_ is nullptr"); return AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); } - auto objValue = AniWindowUtils::CreateWindowsProperties(env, windowToken_); + WindowPropertyInfo windowPropertyInfo; + WMError ret = windowToken_->GetWindowPropertyInfo(windowPropertyInfo); + if (ret != WMError::WM_OK) { + TLOGE(WmsLogTag::WMS_ATTRIBUTE, "get window properties failed"); + return AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); + } + auto objValue = AniWindowUtils::CreateWindowsProperties(env, windowPropertyInfo); if (objValue == nullptr) { return AniWindowUtils::AniThrowError(env, WMError::WM_ERROR_NULLPTR, "[ANI] Window get properties failed"); } 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 c3d300fdcb962ea7c4616071ccc4b410b6aac7e3..5e3589da4e761706f692c28bd484111822933e79 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 @@ -1047,209 +1047,53 @@ ani_status AniWindowUtils::GetAniString(ani_env* env, const std::string& str, an return env->String_NewUTF8(str.c_str(), static_cast(str.size()), result); } -void AniWindowUtils::SetSystemPropertiesWindowRect(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - Rect rect = window->GetRect(); - ani_object aniWindowRect = CreateAniRect(env, rect); - CallAniMethodVoid(env, systemProperties, clsName, "windowRect", nullptr, aniWindowRect); -} - -void AniWindowUtils::SetSystemPropertiesDrawableRect(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::DEFAULT, "[ANI]"); - Ace::UIContent* uiContent = window->GetUIContent(); - Rect drawableRect = g_emptyRect; - if (uiContent == nullptr) { - TLOGE(WmsLogTag::DEFAULT, "[ANI] uicontent is nullptr"); - } else { - uiContent->GetWindowPaintSize(drawableRect); - } - - ani_object aniDrawableRect = CreateAniRect(env, drawableRect); - if (aniDrawableRect == nullptr) { - TLOGE(WmsLogTag::DEFAULT, "[ANI] GetDrawableRect failed!"); - return; - } - - CallAniMethodVoid(env, systemProperties, clsName, "drawableRect", nullptr, aniDrawableRect); -} - -void AniWindowUtils::SetSystemPropertiesWindowType(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) +ani_object AniWindowUtils::CreateWindowsProperties(ani_env* env, const WindowPropertyInfo& windowPropertyInfo) { TLOGI(WmsLogTag::DEFAULT, "[ANI]"); - WindowType aniWindowType = window->GetType(); + static const char* clsName = "@ohos.window.window.WindowPropertiesInternal"; + ani_object aniSystemProperties; + NewAniObjectNoParams(env, clsName, &aniSystemProperties); + CallAniMethodVoid(env, aniSystemProperties, clsName, "windowRect", nullptr, + CreateAniRect(env, windowPropertyInfo.windowRect)); + CallAniMethodVoid(env, aniSystemProperties, clsName, "drawableRect", nullptr, + CreateAniRect(env, windowPropertyInfo.drawableRect)); + WindowType aniWindowType = windowPropertyInfo.type; if (NATIVE_JS_TO_WINDOW_TYPE_MAP.count(aniWindowType) != 0) { - env->Object_SetFieldByName_Int(systemProperties, "typeInternal", + env->Object_SetFieldByName_Int(aniSystemProperties, "typeInternal", ani_int(NATIVE_JS_TO_WINDOW_TYPE_MAP.at(aniWindowType))); } else { - env->Object_SetFieldByName_Int(systemProperties, "typeInternal", ani_int(aniWindowType)); - } -} - -void AniWindowUtils::SetSystemPropertiesWindowIsLayoutFullScreen(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::DEFAULT, "[ANI]"); - bool isLayotFullScreen = window->IsLayoutFullScreen(); - CallAniMethodVoid(env, systemProperties, clsName, "isLayoutFullScreen", nullptr, - static_cast(isLayotFullScreen)); -} - - -void AniWindowUtils::SetSystemPropertiesWindowIsFullScreen(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::DEFAULT, "[ANI]"); - bool isFullScreen = window->IsFullScreen(); - CallAniMethodVoid(env, systemProperties, clsName, "isFullScreen", nullptr, - static_cast(isFullScreen)); -} - -void AniWindowUtils::SetSystemPropertiesWindowTouchable(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::DEFAULT, "[ANI]"); - bool windowTouchable = window->GetTouchable(); - CallAniMethodVoid(env, systemProperties, clsName, "touchable", nullptr, - static_cast(windowTouchable)); -} - -void AniWindowUtils::SetSystemPropertiesWindowFousable(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::DEFAULT, "[ANI]"); - bool windowFousable = window->GetFocusable(); - CallAniMethodVoid(env, systemProperties, clsName, "focusable", nullptr, - static_cast(windowFousable)); -} - -void AniWindowUtils::SetSystemPropertiesWindowIsPrivacyMode(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::WMS_ATTRIBUTE, "[ANI]"); - bool windowIsPrivacyMode = window->IsPrivacyMode(); - CallAniMethodVoid(env, systemProperties, clsName, "isPrivacyMode", nullptr, - static_cast(windowIsPrivacyMode)); -} - -void AniWindowUtils::SetSystemPropertiesWindowIsKeepScreenOn(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::WMS_ATTRIBUTE, "[ANI]"); - bool windowIsKeepScreenOn = window->IsKeepScreenOn(); - CallAniMethodVoid(env, systemProperties, clsName, "isKeepScreenOn", nullptr, - static_cast(windowIsKeepScreenOn)); -} - -void AniWindowUtils::SetSystemPropertiesWindowBrightness(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::WMS_ATTRIBUTE, "[ANI]"); - float windowBrightness = window->GetBrightness(); - CallAniMethodVoid(env, systemProperties, clsName, "brightness", nullptr, - static_cast(windowBrightness)); -} - - -void AniWindowUtils::SetSystemPropertiesWindowIsTransparent(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::WMS_ATTRIBUTE, "[ANI]"); - bool isTransparent = window->IsTransparent(); - CallAniMethodVoid(env, systemProperties, clsName, "isTransparent", nullptr, - static_cast(isTransparent)); -} - - -void AniWindowUtils::SetSystemPropertiesWindowIsRoundCorner(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::WMS_ATTRIBUTE, "[ANI]"); - bool windowIsRoundCorner {false}; - CallAniMethodVoid(env, systemProperties, clsName, "isRoundCorner", nullptr, - static_cast(windowIsRoundCorner)); -} - - -void AniWindowUtils::SetSystemPropertiesWindowDimBehindValue(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::WMS_ATTRIBUTE, "[ANI]"); - int windowDimBehindValue {0}; - CallAniMethodVoid(env, systemProperties, clsName, "dimBehindValue", nullptr, - static_cast(windowDimBehindValue)); -} - - -void AniWindowUtils::SetSystemPropertiesWindowId(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::WMS_ATTRIBUTE, "[ANI]"); - uint32_t windowId = window->GetWindowId(); - CallAniMethodVoid(env, systemProperties, clsName, "id", nullptr, - static_cast(windowId)); -} - -void AniWindowUtils::SetSystemPropertiesDisplayId(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::WMS_ATTRIBUTE, "[ANI]"); - uint32_t displayId = window->GetDisplayId(); - env->Object_SetFieldByName_Long(systemProperties, "displayIdInternal", ani_long(displayId)); -} - -void AniWindowUtils::SetSystemPropertiesWindowName(ani_env* env, const sptr& window, - ani_object& systemProperties, const char* clsName) -{ - TLOGI(WmsLogTag::WMS_ATTRIBUTE, "[ANI]"); - std::string windowName = window->GetWindowName(); + env->Object_SetFieldByName_Int(aniSystemProperties, "typeInternal", ani_int(aniWindowType)); + } + CallAniMethodVoid(env, aniSystemProperties, clsName, "isLayoutFullScreen", nullptr, + ani_boolean(windowPropertyInfo.isLayoutFullScreen)); + CallAniMethodVoid(env, aniSystemProperties, clsName, "isFullScreen", nullptr, + ani_boolean(windowPropertyInfo.isFullScreen)); + CallAniMethodVoid(env, aniSystemProperties, clsName, "touchable", nullptr, + ani_boolean(windowPropertyInfo.isTouchable)); + std::string windowName = windowPropertyInfo.name; ani_string aniWindowName; - if (ANI_OK != GetAniString(env, windowName, &aniWindowName)) { - TLOGE(WmsLogTag::WMS_ATTRIBUTE, "get ANI string failed"); - return; - } - CallAniMethodVoid(env, systemProperties, clsName, "name", nullptr, aniWindowName); -} - -ani_object AniWindowUtils::CreateWindowsProperties(ani_env* env, const sptr& window) -{ - TLOGI(WmsLogTag::DEFAULT, "[ANI]"); - if (window == nullptr) { - TLOGE(WmsLogTag::DEFAULT, "window is nullptr or get invalid param"); - return AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); - } - - static const char* clsName = "@ohos.window.window.WindowPropertiesInternal"; - ani_object aniSystemProperties; - - NewAniObjectNoParams(env, clsName, &aniSystemProperties); - SetSystemPropertiesWindowRect(env, window, aniSystemProperties, clsName); - SetSystemPropertiesDrawableRect(env, window, aniSystemProperties, clsName); - SetSystemPropertiesWindowType(env, window, aniSystemProperties, clsName); - SetSystemPropertiesWindowIsLayoutFullScreen(env, window, aniSystemProperties, clsName); - SetSystemPropertiesWindowIsFullScreen(env, window, aniSystemProperties, clsName); - SetSystemPropertiesWindowTouchable(env, window, aniSystemProperties, clsName); - SetSystemPropertiesWindowFousable(env, window, aniSystemProperties, clsName); - SetSystemPropertiesWindowIsPrivacyMode(env, window, aniSystemProperties, clsName); - SetSystemPropertiesWindowIsKeepScreenOn(env, window, aniSystemProperties, clsName); - SetSystemPropertiesWindowBrightness(env, window, aniSystemProperties, clsName); - SetSystemPropertiesWindowIsTransparent(env, window, aniSystemProperties, clsName); - SetSystemPropertiesWindowIsRoundCorner(env, window, aniSystemProperties, clsName); - SetSystemPropertiesWindowDimBehindValue(env, window, aniSystemProperties, clsName); - SetSystemPropertiesDisplayId(env, window, aniSystemProperties, clsName); - SetSystemPropertiesWindowId(env, window, aniSystemProperties, clsName); - SetSystemPropertiesWindowName(env, window, aniSystemProperties, clsName); - - TLOGI(WmsLogTag::DEFAULT, "[ANI] Window [%{public}u, %{public}s] get properties end", window->GetWindowId(), - window->GetWindowName().c_str()); + if (ANI_OK == GetAniString(env, windowName, &aniWindowName)) { + CallAniMethodVoid(env, aniSystemProperties, clsName, "name", nullptr, aniWindowName); + } + CallAniMethodVoid(env, aniSystemProperties, clsName, "focusable", nullptr, + ani_boolean(windowPropertyInfo.isFocusable)); + CallAniMethodVoid(env, aniSystemProperties, clsName, "isPrivacyMode", nullptr, + ani_boolean(windowPropertyInfo.isPrivacyMode)); + CallAniMethodVoid(env, aniSystemProperties, clsName, "isKeepScreenOn", nullptr, + ani_boolean(windowPropertyInfo.isKeepScreenOn)); + CallAniMethodVoid(env, aniSystemProperties, clsName, "brightness", nullptr, + ani_float(windowPropertyInfo.brightness)); + CallAniMethodVoid(env, aniSystemProperties, clsName, "isTransparent", 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, + ani_long(windowPropertyInfo.displayId)); if (aniSystemProperties == nullptr) { TLOGE(WmsLogTag::DEFAULT, "[ANI] AniSystemProperties is nullptr"); return AniWindowUtils::AniThrowError(env, WmErrorCode::WM_ERROR_STATE_ABNORMALLY); } - return aniSystemProperties; }