123b3eb3cSopenharmony_ci/*
223b3eb3cSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License.
523b3eb3cSopenharmony_ci * You may obtain a copy of the License at
623b3eb3cSopenharmony_ci *
723b3eb3cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
823b3eb3cSopenharmony_ci *
923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and
1323b3eb3cSopenharmony_ci * limitations under the License.
1423b3eb3cSopenharmony_ci */
1523b3eb3cSopenharmony_ci
1623b3eb3cSopenharmony_ci
1723b3eb3cSopenharmony_ci#include <cstdlib>
1823b3eb3cSopenharmony_ci#include "node_model.h"
1923b3eb3cSopenharmony_ci
2023b3eb3cSopenharmony_ci#include "base/utils/utils.h"
2123b3eb3cSopenharmony_ci#include "base/error/error_code.h"
2223b3eb3cSopenharmony_ci
2323b3eb3cSopenharmony_ci#ifdef __cplusplus
2423b3eb3cSopenharmony_ciextern "C" {
2523b3eb3cSopenharmony_ci#endif
2623b3eb3cSopenharmony_ci
2723b3eb3cSopenharmony_ciint32_t OH_ArkUI_NodeUtils_GetLayoutSize(ArkUI_NodeHandle node, ArkUI_IntSize* size)
2823b3eb3cSopenharmony_ci{
2923b3eb3cSopenharmony_ci    if (node == nullptr) {
3023b3eb3cSopenharmony_ci        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
3123b3eb3cSopenharmony_ci    }
3223b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
3323b3eb3cSopenharmony_ci    ArkUI_Int32* tempSize = new ArkUI_Int32[2];
3423b3eb3cSopenharmony_ci    impl->getNodeModifiers()->getFrameNodeModifier()->getLayoutSize(node->uiNodeHandle, tempSize);
3523b3eb3cSopenharmony_ci    size->width = tempSize[0];
3623b3eb3cSopenharmony_ci    size->height = tempSize[1];
3723b3eb3cSopenharmony_ci    return OHOS::Ace::ERROR_CODE_NO_ERROR;
3823b3eb3cSopenharmony_ci}
3923b3eb3cSopenharmony_ci
4023b3eb3cSopenharmony_ciint32_t OH_ArkUI_NodeUtils_GetLayoutPosition(ArkUI_NodeHandle node, ArkUI_IntOffset* localOffset)
4123b3eb3cSopenharmony_ci{
4223b3eb3cSopenharmony_ci    if (node == nullptr) {
4323b3eb3cSopenharmony_ci        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
4423b3eb3cSopenharmony_ci    }
4523b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
4623b3eb3cSopenharmony_ci    auto value = impl->getNodeModifiers()->getFrameNodeModifier()->getLayoutPositionWithoutMargin(node->uiNodeHandle);
4723b3eb3cSopenharmony_ci    localOffset->x = static_cast<int32_t>(value[0]);
4823b3eb3cSopenharmony_ci    localOffset->y = static_cast<int32_t>(value[1]);
4923b3eb3cSopenharmony_ci
5023b3eb3cSopenharmony_ci    return OHOS::Ace::ERROR_CODE_NO_ERROR;
5123b3eb3cSopenharmony_ci}
5223b3eb3cSopenharmony_ci
5323b3eb3cSopenharmony_ciint32_t OH_ArkUI_NodeUtils_GetLayoutPositionInWindow(ArkUI_NodeHandle node, ArkUI_IntOffset* globalOffset)
5423b3eb3cSopenharmony_ci{
5523b3eb3cSopenharmony_ci    if (node == nullptr) {
5623b3eb3cSopenharmony_ci        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
5723b3eb3cSopenharmony_ci    }
5823b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
5923b3eb3cSopenharmony_ci    ArkUI_Float32 tempOffset[2];
6023b3eb3cSopenharmony_ci    impl->getNodeModifiers()->getFrameNodeModifier()->getPositionToWindow(node->uiNodeHandle, &tempOffset, false);
6123b3eb3cSopenharmony_ci    globalOffset->x = tempOffset[0];
6223b3eb3cSopenharmony_ci    globalOffset->y = tempOffset[1];
6323b3eb3cSopenharmony_ci
6423b3eb3cSopenharmony_ci    return OHOS::Ace::ERROR_CODE_NO_ERROR;
6523b3eb3cSopenharmony_ci}
6623b3eb3cSopenharmony_ci
6723b3eb3cSopenharmony_ciint32_t OH_ArkUI_NodeUtils_GetLayoutPositionInScreen(ArkUI_NodeHandle node, ArkUI_IntOffset* screenOffset)
6823b3eb3cSopenharmony_ci{
6923b3eb3cSopenharmony_ci    if (node == nullptr) {
7023b3eb3cSopenharmony_ci        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
7123b3eb3cSopenharmony_ci    }
7223b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
7323b3eb3cSopenharmony_ci    ArkUI_Float32 tempOffset[2];
7423b3eb3cSopenharmony_ci    impl->getNodeModifiers()->getFrameNodeModifier()->getPositionToScreen(node->uiNodeHandle, &tempOffset, false);
7523b3eb3cSopenharmony_ci    screenOffset->x = tempOffset[0];
7623b3eb3cSopenharmony_ci    screenOffset->y = tempOffset[1];
7723b3eb3cSopenharmony_ci
7823b3eb3cSopenharmony_ci    return OHOS::Ace::ERROR_CODE_NO_ERROR;
7923b3eb3cSopenharmony_ci}
8023b3eb3cSopenharmony_ci
8123b3eb3cSopenharmony_ciint32_t OH_ArkUI_NodeUtils_GetPositionWithTranslateInWindow(ArkUI_NodeHandle node, ArkUI_IntOffset* translateOffset)
8223b3eb3cSopenharmony_ci{
8323b3eb3cSopenharmony_ci    if (node == nullptr) {
8423b3eb3cSopenharmony_ci        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
8523b3eb3cSopenharmony_ci    }
8623b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
8723b3eb3cSopenharmony_ci    ArkUI_Float32 tempOffset[2];
8823b3eb3cSopenharmony_ci    impl->getNodeModifiers()->getFrameNodeModifier()->getPositionToWindowWithTransform(
8923b3eb3cSopenharmony_ci        node->uiNodeHandle, &tempOffset, false);
9023b3eb3cSopenharmony_ci    translateOffset->x = tempOffset[0];
9123b3eb3cSopenharmony_ci    translateOffset->y = tempOffset[1];
9223b3eb3cSopenharmony_ci
9323b3eb3cSopenharmony_ci    return OHOS::Ace::ERROR_CODE_NO_ERROR;
9423b3eb3cSopenharmony_ci}
9523b3eb3cSopenharmony_ci
9623b3eb3cSopenharmony_ciint32_t OH_ArkUI_NodeUtils_GetPositionWithTranslateInScreen(ArkUI_NodeHandle node, ArkUI_IntOffset* translateOffset)
9723b3eb3cSopenharmony_ci{
9823b3eb3cSopenharmony_ci    if (node == nullptr) {
9923b3eb3cSopenharmony_ci        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
10023b3eb3cSopenharmony_ci    }
10123b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
10223b3eb3cSopenharmony_ci    ArkUI_Float32 tempOffset[2];
10323b3eb3cSopenharmony_ci    impl->getNodeModifiers()->getFrameNodeModifier()->getPositionToScreenWithTransform(
10423b3eb3cSopenharmony_ci        node->uiNodeHandle, &tempOffset, false);
10523b3eb3cSopenharmony_ci    translateOffset->x = tempOffset[0];
10623b3eb3cSopenharmony_ci    translateOffset->y = tempOffset[1];
10723b3eb3cSopenharmony_ci
10823b3eb3cSopenharmony_ci    return OHOS::Ace::ERROR_CODE_NO_ERROR;
10923b3eb3cSopenharmony_ci}
11023b3eb3cSopenharmony_ci
11123b3eb3cSopenharmony_ciint32_t OH_ArkUI_RegisterSystemColorModeChangeEvent(
11223b3eb3cSopenharmony_ci    ArkUI_NodeHandle node, void* userData, void (*onColorModeChange)(ArkUI_SystemColorMode colorMode, void* userData))
11323b3eb3cSopenharmony_ci{
11423b3eb3cSopenharmony_ci    if (node == nullptr) {
11523b3eb3cSopenharmony_ci        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
11623b3eb3cSopenharmony_ci    }
11723b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
11823b3eb3cSopenharmony_ci    impl->getNodeModifiers()->getFrameNodeModifier()->setSystemColorModeChangeEvent(
11923b3eb3cSopenharmony_ci        node->uiNodeHandle, userData, reinterpret_cast<void*>(onColorModeChange));
12023b3eb3cSopenharmony_ci
12123b3eb3cSopenharmony_ci    return OHOS::Ace::ERROR_CODE_NO_ERROR;
12223b3eb3cSopenharmony_ci}
12323b3eb3cSopenharmony_ci
12423b3eb3cSopenharmony_civoid OH_ArkUI_UnregisterSystemColorModeChangeEvent(ArkUI_NodeHandle node)
12523b3eb3cSopenharmony_ci{
12623b3eb3cSopenharmony_ci    if (node == nullptr) {
12723b3eb3cSopenharmony_ci        return;
12823b3eb3cSopenharmony_ci    }
12923b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
13023b3eb3cSopenharmony_ci    impl->getNodeModifiers()->getFrameNodeModifier()->resetSystemColorModeChangeEvent(node->uiNodeHandle);
13123b3eb3cSopenharmony_ci}
13223b3eb3cSopenharmony_ci
13323b3eb3cSopenharmony_ciint32_t OH_ArkUI_RegisterSystemFontStyleChangeEvent(
13423b3eb3cSopenharmony_ci    ArkUI_NodeHandle node, void* userData, void (*onFontStyleChange)(ArkUI_SystemFontStyleEvent* event, void* userData))
13523b3eb3cSopenharmony_ci{
13623b3eb3cSopenharmony_ci    if (node == nullptr) {
13723b3eb3cSopenharmony_ci        return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
13823b3eb3cSopenharmony_ci    }
13923b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
14023b3eb3cSopenharmony_ci    impl->getNodeModifiers()->getFrameNodeModifier()->setSystemFontStyleChangeEvent(
14123b3eb3cSopenharmony_ci        node->uiNodeHandle, userData, reinterpret_cast<void*>(onFontStyleChange));
14223b3eb3cSopenharmony_ci
14323b3eb3cSopenharmony_ci    return OHOS::Ace::ERROR_CODE_NO_ERROR;
14423b3eb3cSopenharmony_ci}
14523b3eb3cSopenharmony_ci
14623b3eb3cSopenharmony_civoid OH_ArkUI_UnregisterSystemFontStyleChangeEvent(ArkUI_NodeHandle node)
14723b3eb3cSopenharmony_ci{
14823b3eb3cSopenharmony_ci    if (node == nullptr) {
14923b3eb3cSopenharmony_ci        return;
15023b3eb3cSopenharmony_ci    }
15123b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
15223b3eb3cSopenharmony_ci    impl->getNodeModifiers()->getFrameNodeModifier()->resetSystemFontStyleChangeEvent(node->uiNodeHandle);
15323b3eb3cSopenharmony_ci}
15423b3eb3cSopenharmony_ci
15523b3eb3cSopenharmony_cifloat OH_ArkUI_SystemFontStyleEvent_GetFontSizeScale(const ArkUI_SystemFontStyleEvent* event)
15623b3eb3cSopenharmony_ci{
15723b3eb3cSopenharmony_ci    return event->fontSize;
15823b3eb3cSopenharmony_ci}
15923b3eb3cSopenharmony_ci
16023b3eb3cSopenharmony_cifloat OH_ArkUI_SystemFontStyleEvent_GetFontWeightScale(const ArkUI_SystemFontStyleEvent* event)
16123b3eb3cSopenharmony_ci{
16223b3eb3cSopenharmony_ci    return event->fontWeight;
16323b3eb3cSopenharmony_ci}
16423b3eb3cSopenharmony_ci
16523b3eb3cSopenharmony_civoid OH_ArkUI_NodeUtils_AddCustomProperty(ArkUI_NodeHandle node, const char* name, const char* value)
16623b3eb3cSopenharmony_ci{
16723b3eb3cSopenharmony_ci    if (node == nullptr) {
16823b3eb3cSopenharmony_ci        return;
16923b3eb3cSopenharmony_ci    }
17023b3eb3cSopenharmony_ci    if (name == nullptr || value == nullptr) {
17123b3eb3cSopenharmony_ci        LOGF("AddCustomProperty input params name or value is nullptr");
17223b3eb3cSopenharmony_ci        abort();
17323b3eb3cSopenharmony_ci    }
17423b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
17523b3eb3cSopenharmony_ci    impl->getNodeModifiers()->getFrameNodeModifier()->addCustomProperty(node->uiNodeHandle, name, value);
17623b3eb3cSopenharmony_ci}
17723b3eb3cSopenharmony_ci
17823b3eb3cSopenharmony_civoid OH_ArkUI_NodeUtils_RemoveCustomProperty(ArkUI_NodeHandle node, const char* name)
17923b3eb3cSopenharmony_ci{
18023b3eb3cSopenharmony_ci    if (node == nullptr) {
18123b3eb3cSopenharmony_ci        return;
18223b3eb3cSopenharmony_ci    }
18323b3eb3cSopenharmony_ci    if (name == nullptr) {
18423b3eb3cSopenharmony_ci        LOGF("RemoveCustomProperty input params name is nullptr");
18523b3eb3cSopenharmony_ci        abort();
18623b3eb3cSopenharmony_ci    }
18723b3eb3cSopenharmony_ci    auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
18823b3eb3cSopenharmony_ci    impl->getNodeModifiers()->getFrameNodeModifier()->removeCustomProperty(node->uiNodeHandle, name);
18923b3eb3cSopenharmony_ci}
19023b3eb3cSopenharmony_ci
19123b3eb3cSopenharmony_ci#ifdef __cplusplus
19223b3eb3cSopenharmony_ci};
19323b3eb3cSopenharmony_ci#endif
194