1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 17#include <cstdlib> 18#include "node_model.h" 19 20#include "base/utils/utils.h" 21#include "base/error/error_code.h" 22 23#ifdef __cplusplus 24extern "C" { 25#endif 26 27int32_t OH_ArkUI_NodeUtils_GetLayoutSize(ArkUI_NodeHandle node, ArkUI_IntSize* size) 28{ 29 if (node == nullptr) { 30 return OHOS::Ace::ERROR_CODE_PARAM_INVALID; 31 } 32 auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 33 ArkUI_Int32* tempSize = new ArkUI_Int32[2]; 34 impl->getNodeModifiers()->getFrameNodeModifier()->getLayoutSize(node->uiNodeHandle, tempSize); 35 size->width = tempSize[0]; 36 size->height = tempSize[1]; 37 return OHOS::Ace::ERROR_CODE_NO_ERROR; 38} 39 40int32_t OH_ArkUI_NodeUtils_GetLayoutPosition(ArkUI_NodeHandle node, ArkUI_IntOffset* localOffset) 41{ 42 if (node == nullptr) { 43 return OHOS::Ace::ERROR_CODE_PARAM_INVALID; 44 } 45 auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 46 auto value = impl->getNodeModifiers()->getFrameNodeModifier()->getLayoutPositionWithoutMargin(node->uiNodeHandle); 47 localOffset->x = static_cast<int32_t>(value[0]); 48 localOffset->y = static_cast<int32_t>(value[1]); 49 50 return OHOS::Ace::ERROR_CODE_NO_ERROR; 51} 52 53int32_t OH_ArkUI_NodeUtils_GetLayoutPositionInWindow(ArkUI_NodeHandle node, ArkUI_IntOffset* globalOffset) 54{ 55 if (node == nullptr) { 56 return OHOS::Ace::ERROR_CODE_PARAM_INVALID; 57 } 58 auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 59 ArkUI_Float32 tempOffset[2]; 60 impl->getNodeModifiers()->getFrameNodeModifier()->getPositionToWindow(node->uiNodeHandle, &tempOffset, false); 61 globalOffset->x = tempOffset[0]; 62 globalOffset->y = tempOffset[1]; 63 64 return OHOS::Ace::ERROR_CODE_NO_ERROR; 65} 66 67int32_t OH_ArkUI_NodeUtils_GetLayoutPositionInScreen(ArkUI_NodeHandle node, ArkUI_IntOffset* screenOffset) 68{ 69 if (node == nullptr) { 70 return OHOS::Ace::ERROR_CODE_PARAM_INVALID; 71 } 72 auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 73 ArkUI_Float32 tempOffset[2]; 74 impl->getNodeModifiers()->getFrameNodeModifier()->getPositionToScreen(node->uiNodeHandle, &tempOffset, false); 75 screenOffset->x = tempOffset[0]; 76 screenOffset->y = tempOffset[1]; 77 78 return OHOS::Ace::ERROR_CODE_NO_ERROR; 79} 80 81int32_t OH_ArkUI_NodeUtils_GetPositionWithTranslateInWindow(ArkUI_NodeHandle node, ArkUI_IntOffset* translateOffset) 82{ 83 if (node == nullptr) { 84 return OHOS::Ace::ERROR_CODE_PARAM_INVALID; 85 } 86 auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 87 ArkUI_Float32 tempOffset[2]; 88 impl->getNodeModifiers()->getFrameNodeModifier()->getPositionToWindowWithTransform( 89 node->uiNodeHandle, &tempOffset, false); 90 translateOffset->x = tempOffset[0]; 91 translateOffset->y = tempOffset[1]; 92 93 return OHOS::Ace::ERROR_CODE_NO_ERROR; 94} 95 96int32_t OH_ArkUI_NodeUtils_GetPositionWithTranslateInScreen(ArkUI_NodeHandle node, ArkUI_IntOffset* translateOffset) 97{ 98 if (node == nullptr) { 99 return OHOS::Ace::ERROR_CODE_PARAM_INVALID; 100 } 101 auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 102 ArkUI_Float32 tempOffset[2]; 103 impl->getNodeModifiers()->getFrameNodeModifier()->getPositionToScreenWithTransform( 104 node->uiNodeHandle, &tempOffset, false); 105 translateOffset->x = tempOffset[0]; 106 translateOffset->y = tempOffset[1]; 107 108 return OHOS::Ace::ERROR_CODE_NO_ERROR; 109} 110 111int32_t OH_ArkUI_RegisterSystemColorModeChangeEvent( 112 ArkUI_NodeHandle node, void* userData, void (*onColorModeChange)(ArkUI_SystemColorMode colorMode, void* userData)) 113{ 114 if (node == nullptr) { 115 return OHOS::Ace::ERROR_CODE_PARAM_INVALID; 116 } 117 auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 118 impl->getNodeModifiers()->getFrameNodeModifier()->setSystemColorModeChangeEvent( 119 node->uiNodeHandle, userData, reinterpret_cast<void*>(onColorModeChange)); 120 121 return OHOS::Ace::ERROR_CODE_NO_ERROR; 122} 123 124void OH_ArkUI_UnregisterSystemColorModeChangeEvent(ArkUI_NodeHandle node) 125{ 126 if (node == nullptr) { 127 return; 128 } 129 auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 130 impl->getNodeModifiers()->getFrameNodeModifier()->resetSystemColorModeChangeEvent(node->uiNodeHandle); 131} 132 133int32_t OH_ArkUI_RegisterSystemFontStyleChangeEvent( 134 ArkUI_NodeHandle node, void* userData, void (*onFontStyleChange)(ArkUI_SystemFontStyleEvent* event, void* userData)) 135{ 136 if (node == nullptr) { 137 return OHOS::Ace::ERROR_CODE_PARAM_INVALID; 138 } 139 auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 140 impl->getNodeModifiers()->getFrameNodeModifier()->setSystemFontStyleChangeEvent( 141 node->uiNodeHandle, userData, reinterpret_cast<void*>(onFontStyleChange)); 142 143 return OHOS::Ace::ERROR_CODE_NO_ERROR; 144} 145 146void OH_ArkUI_UnregisterSystemFontStyleChangeEvent(ArkUI_NodeHandle node) 147{ 148 if (node == nullptr) { 149 return; 150 } 151 auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 152 impl->getNodeModifiers()->getFrameNodeModifier()->resetSystemFontStyleChangeEvent(node->uiNodeHandle); 153} 154 155float OH_ArkUI_SystemFontStyleEvent_GetFontSizeScale(const ArkUI_SystemFontStyleEvent* event) 156{ 157 return event->fontSize; 158} 159 160float OH_ArkUI_SystemFontStyleEvent_GetFontWeightScale(const ArkUI_SystemFontStyleEvent* event) 161{ 162 return event->fontWeight; 163} 164 165void OH_ArkUI_NodeUtils_AddCustomProperty(ArkUI_NodeHandle node, const char* name, const char* value) 166{ 167 if (node == nullptr) { 168 return; 169 } 170 if (name == nullptr || value == nullptr) { 171 LOGF("AddCustomProperty input params name or value is nullptr"); 172 abort(); 173 } 174 auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 175 impl->getNodeModifiers()->getFrameNodeModifier()->addCustomProperty(node->uiNodeHandle, name, value); 176} 177 178void OH_ArkUI_NodeUtils_RemoveCustomProperty(ArkUI_NodeHandle node, const char* name) 179{ 180 if (node == nullptr) { 181 return; 182 } 183 if (name == nullptr) { 184 LOGF("RemoveCustomProperty input params name is nullptr"); 185 abort(); 186 } 187 auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 188 impl->getNodeModifiers()->getFrameNodeModifier()->removeCustomProperty(node->uiNodeHandle, name); 189} 190 191#ifdef __cplusplus 192}; 193#endif 194