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 #include "node_extened.h"
20
21 #include "base/utils/utils.h"
22 #include "base/error/error_code.h"
23 #include "core/common/container_consts.h"
24 #include "core/components_v2/inspector/inspector_constants.h"
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
OH_ArkUI_NodeUtils_GetLayoutSize(ArkUI_NodeHandle node,ArkUI_IntSize * size)30 int32_t OH_ArkUI_NodeUtils_GetLayoutSize(ArkUI_NodeHandle node, ArkUI_IntSize* size)
31 {
32 if (node == nullptr) {
33 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
34 }
35 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
36 ArkUI_Int32* tempSize = new ArkUI_Int32[2];
37 impl->getNodeModifiers()->getFrameNodeModifier()->getLayoutSize(node->uiNodeHandle, tempSize);
38 size->width = tempSize[0];
39 size->height = tempSize[1];
40 return OHOS::Ace::ERROR_CODE_NO_ERROR;
41 }
42
OH_ArkUI_NodeUtils_GetLayoutPosition(ArkUI_NodeHandle node,ArkUI_IntOffset * localOffset)43 int32_t OH_ArkUI_NodeUtils_GetLayoutPosition(ArkUI_NodeHandle node, ArkUI_IntOffset* localOffset)
44 {
45 if (node == nullptr) {
46 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
47 }
48 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
49 auto value = impl->getNodeModifiers()->getFrameNodeModifier()->getLayoutPositionWithoutMargin(node->uiNodeHandle);
50 localOffset->x = static_cast<int32_t>(value[0]);
51 localOffset->y = static_cast<int32_t>(value[1]);
52
53 return OHOS::Ace::ERROR_CODE_NO_ERROR;
54 }
55
OH_ArkUI_NodeUtils_GetLayoutPositionInWindow(ArkUI_NodeHandle node,ArkUI_IntOffset * globalOffset)56 int32_t OH_ArkUI_NodeUtils_GetLayoutPositionInWindow(ArkUI_NodeHandle node, ArkUI_IntOffset* globalOffset)
57 {
58 if (node == nullptr) {
59 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
60 }
61 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
62 ArkUI_Float32 tempOffset[2];
63 impl->getNodeModifiers()->getFrameNodeModifier()->getPositionToWindow(node->uiNodeHandle, &tempOffset, false);
64 globalOffset->x = tempOffset[0];
65 globalOffset->y = tempOffset[1];
66
67 return OHOS::Ace::ERROR_CODE_NO_ERROR;
68 }
69
OH_ArkUI_NodeUtils_GetLayoutPositionInScreen(ArkUI_NodeHandle node,ArkUI_IntOffset * screenOffset)70 int32_t OH_ArkUI_NodeUtils_GetLayoutPositionInScreen(ArkUI_NodeHandle node, ArkUI_IntOffset* screenOffset)
71 {
72 if (node == nullptr) {
73 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
74 }
75 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
76 ArkUI_Float32 tempOffset[2];
77 impl->getNodeModifiers()->getFrameNodeModifier()->getPositionToScreen(node->uiNodeHandle, &tempOffset, false);
78 screenOffset->x = tempOffset[0];
79 screenOffset->y = tempOffset[1];
80
81 return OHOS::Ace::ERROR_CODE_NO_ERROR;
82 }
83
OH_ArkUI_NodeUtils_GetLayoutPositionInGlobalDisplay(ArkUI_NodeHandle node,ArkUI_IntOffset * offset)84 int32_t OH_ArkUI_NodeUtils_GetLayoutPositionInGlobalDisplay(ArkUI_NodeHandle node, ArkUI_IntOffset* offset)
85 {
86 CHECK_NULL_RETURN(node, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
87 CHECK_NULL_RETURN(offset, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
88 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
89 ArkUI_Float32 tempOffset[2];
90 impl->getNodeModifiers()->getFrameNodeModifier()->getGlobalPositionOnDisplay(
91 node->uiNodeHandle, &tempOffset, false);
92 offset->x = tempOffset[0];
93 offset->y = tempOffset[1];
94
95 return OHOS::Ace::ERROR_CODE_NO_ERROR;
96 }
97
OH_ArkUI_NodeUtils_GetPositionWithTranslateInWindow(ArkUI_NodeHandle node,ArkUI_IntOffset * translateOffset)98 int32_t OH_ArkUI_NodeUtils_GetPositionWithTranslateInWindow(ArkUI_NodeHandle node, ArkUI_IntOffset* translateOffset)
99 {
100 if (node == nullptr) {
101 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
102 }
103 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
104 ArkUI_Float32 tempOffset[2];
105 impl->getNodeModifiers()->getFrameNodeModifier()->getPositionToWindowWithTransform(
106 node->uiNodeHandle, &tempOffset, false);
107 translateOffset->x = tempOffset[0];
108 translateOffset->y = tempOffset[1];
109
110 return OHOS::Ace::ERROR_CODE_NO_ERROR;
111 }
112
OH_ArkUI_NodeUtils_GetPositionWithTranslateInScreen(ArkUI_NodeHandle node,ArkUI_IntOffset * translateOffset)113 int32_t OH_ArkUI_NodeUtils_GetPositionWithTranslateInScreen(ArkUI_NodeHandle node, ArkUI_IntOffset* translateOffset)
114 {
115 if (node == nullptr) {
116 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
117 }
118 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
119 ArkUI_Float32 tempOffset[2];
120 impl->getNodeModifiers()->getFrameNodeModifier()->getPositionToScreenWithTransform(
121 node->uiNodeHandle, &tempOffset, false);
122 translateOffset->x = tempOffset[0];
123 translateOffset->y = tempOffset[1];
124
125 return OHOS::Ace::ERROR_CODE_NO_ERROR;
126 }
127
OH_ArkUI_RegisterSystemColorModeChangeEvent(ArkUI_NodeHandle node,void * userData,void (* onColorModeChange)(ArkUI_SystemColorMode colorMode,void * userData))128 int32_t OH_ArkUI_RegisterSystemColorModeChangeEvent(
129 ArkUI_NodeHandle node, void* userData, void (*onColorModeChange)(ArkUI_SystemColorMode colorMode, void* userData))
130 {
131 if (node == nullptr) {
132 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
133 }
134 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
135 impl->getNodeModifiers()->getFrameNodeModifier()->setSystemColorModeChangeEvent(
136 node->uiNodeHandle, userData, reinterpret_cast<void*>(onColorModeChange));
137
138 return OHOS::Ace::ERROR_CODE_NO_ERROR;
139 }
140
OH_ArkUI_UnregisterSystemColorModeChangeEvent(ArkUI_NodeHandle node)141 void OH_ArkUI_UnregisterSystemColorModeChangeEvent(ArkUI_NodeHandle node)
142 {
143 if (node == nullptr) {
144 return;
145 }
146 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
147 impl->getNodeModifiers()->getFrameNodeModifier()->resetSystemColorModeChangeEvent(node->uiNodeHandle);
148 }
149
OH_ArkUI_RegisterDrawCallbackOnNodeHandle(ArkUI_NodeHandle node,void * userData,void (* onDrawCompleted)(void * userData))150 int32_t OH_ArkUI_RegisterDrawCallbackOnNodeHandle(
151 ArkUI_NodeHandle node, void* userData, void (*onDrawCompleted)(void* userData))
152 {
153 if (node == nullptr) {
154 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
155 }
156 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
157 impl->getNodeModifiers()->getFrameNodeModifier()->setDrawCompleteEvent(
158 node->uiNodeHandle, userData, reinterpret_cast<void*>(onDrawCompleted));
159
160 return OHOS::Ace::ERROR_CODE_NO_ERROR;
161 }
162
163
OH_ArkUI_UnregisterDrawCallbackOnNodeHandle(ArkUI_NodeHandle node)164 int32_t OH_ArkUI_UnregisterDrawCallbackOnNodeHandle(ArkUI_NodeHandle node)
165 {
166 if (node == nullptr) {
167 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
168 }
169 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
170 impl->getNodeModifiers()->getFrameNodeModifier()->resetDrawCompleteEvent(node->uiNodeHandle);
171 return OHOS::Ace::ERROR_CODE_NO_ERROR;
172 }
173
OH_ArkUI_RegisterLayoutCallbackOnNodeHandle(ArkUI_NodeHandle node,void * userData,void (* onLayoutCompleted)(void * userData))174 int32_t OH_ArkUI_RegisterLayoutCallbackOnNodeHandle(
175 ArkUI_NodeHandle node, void* userData, void (*onLayoutCompleted)(void* userData))
176 {
177 if (node == nullptr) {
178 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
179 }
180 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
181 impl->getNodeModifiers()->getFrameNodeModifier()->setLayoutEvent(
182 node->uiNodeHandle, userData, reinterpret_cast<void*>(onLayoutCompleted));
183
184 return OHOS::Ace::ERROR_CODE_NO_ERROR;
185 }
186
187
OH_ArkUI_UnregisterLayoutCallbackOnNodeHandle(ArkUI_NodeHandle node)188 int32_t OH_ArkUI_UnregisterLayoutCallbackOnNodeHandle(ArkUI_NodeHandle node)
189 {
190 if (node == nullptr) {
191 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
192 }
193 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
194 impl->getNodeModifiers()->getFrameNodeModifier()->resetLayoutEvent(node->uiNodeHandle);
195 return OHOS::Ace::ERROR_CODE_NO_ERROR;
196 }
197
OH_ArkUI_RegisterSystemFontStyleChangeEvent(ArkUI_NodeHandle node,void * userData,void (* onFontStyleChange)(ArkUI_SystemFontStyleEvent * event,void * userData))198 int32_t OH_ArkUI_RegisterSystemFontStyleChangeEvent(
199 ArkUI_NodeHandle node, void* userData, void (*onFontStyleChange)(ArkUI_SystemFontStyleEvent* event, void* userData))
200 {
201 if (node == nullptr) {
202 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
203 }
204 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
205 impl->getNodeModifiers()->getFrameNodeModifier()->setSystemFontStyleChangeEvent(
206 node->uiNodeHandle, userData, reinterpret_cast<void*>(onFontStyleChange));
207
208 return OHOS::Ace::ERROR_CODE_NO_ERROR;
209 }
210
OH_ArkUI_UnregisterSystemFontStyleChangeEvent(ArkUI_NodeHandle node)211 void OH_ArkUI_UnregisterSystemFontStyleChangeEvent(ArkUI_NodeHandle node)
212 {
213 if (node == nullptr) {
214 return;
215 }
216 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
217 impl->getNodeModifiers()->getFrameNodeModifier()->resetSystemFontStyleChangeEvent(node->uiNodeHandle);
218 }
219
OH_ArkUI_SystemFontStyleEvent_GetFontSizeScale(const ArkUI_SystemFontStyleEvent * event)220 float OH_ArkUI_SystemFontStyleEvent_GetFontSizeScale(const ArkUI_SystemFontStyleEvent* event)
221 {
222 return event->fontSize;
223 }
224
OH_ArkUI_SystemFontStyleEvent_GetFontWeightScale(const ArkUI_SystemFontStyleEvent * event)225 float OH_ArkUI_SystemFontStyleEvent_GetFontWeightScale(const ArkUI_SystemFontStyleEvent* event)
226 {
227 return event->fontWeight;
228 }
229
OH_ArkUI_NodeUtils_AddCustomProperty(ArkUI_NodeHandle node,const char * name,const char * value)230 void OH_ArkUI_NodeUtils_AddCustomProperty(ArkUI_NodeHandle node, const char* name, const char* value)
231 {
232 if (node == nullptr || !OHOS::Ace::NodeModel::CheckIsCNode(node)) {
233 return;
234 }
235 if (name == nullptr || value == nullptr) {
236 LOGF_ABORT("AddCustomProperty input params name or value is nullptr");
237 }
238 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
239 impl->getNodeModifiers()->getFrameNodeModifier()->addCustomProperty(node->uiNodeHandle, name, value);
240 }
241
OH_ArkUI_NodeUtils_RemoveCustomProperty(ArkUI_NodeHandle node,const char * name)242 void OH_ArkUI_NodeUtils_RemoveCustomProperty(ArkUI_NodeHandle node, const char* name)
243 {
244 if (node == nullptr) {
245 return;
246 }
247 if (name == nullptr) {
248 LOGF_ABORT("RemoveCustomProperty input params name is nullptr");
249 }
250 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
251 impl->getNodeModifiers()->getFrameNodeModifier()->removeCustomProperty(node->uiNodeHandle, name);
252 }
253
OH_ArkUI_NodeUtils_GetCustomProperty(ArkUI_NodeHandle node,const char * name,ArkUI_CustomProperty ** handle)254 int32_t OH_ArkUI_NodeUtils_GetCustomProperty(ArkUI_NodeHandle node, const char* name, ArkUI_CustomProperty** handle)
255 {
256 if (node == nullptr || name == nullptr) {
257 return ARKUI_ERROR_CODE_PARAM_INVALID;
258 }
259 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
260 char* value = nullptr;
261 impl->getNodeModifiers()->getFrameNodeModifier()->getCustomProperty(node->uiNodeHandle, name, &value);
262 *handle = new ArkUI_CustomProperty({ .value = value });
263
264 return OHOS::Ace::ERROR_CODE_NO_ERROR;
265 }
266
OH_ArkUI_NodeUtils_GetActiveChildrenInfo(ArkUI_NodeHandle head,ArkUI_ActiveChildrenInfo ** handle)267 int32_t OH_ArkUI_NodeUtils_GetActiveChildrenInfo(ArkUI_NodeHandle head, ArkUI_ActiveChildrenInfo** handle)
268 {
269 CHECK_NULL_RETURN(head, ARKUI_ERROR_CODE_PARAM_INVALID);
270 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
271 CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_PARAM_INVALID);
272 ArkUINodeHandle* innerNodes = nullptr;
273 int32_t totalSize = 0;
274 impl->getNodeModifiers()->getFrameNodeModifier()->getActiveChildrenInfo(
275 head->uiNodeHandle, &innerNodes, &totalSize);
276 *handle = new ArkUI_ActiveChildrenInfo({ .nodeList = nullptr, .nodeCount = totalSize });
277 (*handle)->nodeCount = totalSize;
278 if (totalSize > 0) {
279 (*handle)->nodeList = new ArkUI_NodeHandle[totalSize] {};
280 for (int32_t i = 0; i < totalSize; i++) {
281 ((*handle)->nodeList[i]) = OHOS::Ace::NodeModel::GetArkUINode(innerNodes[i]);
282 }
283 }
284 delete[] innerNodes;
285 return OHOS::Ace::ERROR_CODE_NO_ERROR;
286 }
287
OH_ArkUI_NodeUtils_GetParentInPageTree(ArkUI_NodeHandle node)288 ArkUI_NodeHandle OH_ArkUI_NodeUtils_GetParentInPageTree(ArkUI_NodeHandle node)
289 {
290 if (node == nullptr) {
291 return nullptr;
292 }
293 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
294 auto* attachNode = impl->getNodeModifiers()->getFrameNodeModifier()->getParent(node->uiNodeHandle);
295 return OHOS::Ace::NodeModel::GetArkUINode(attachNode);
296 }
297
OH_ArkUI_NodeUtils_GetCurrentPageRootNode(ArkUI_NodeHandle node)298 ArkUI_NodeHandle OH_ArkUI_NodeUtils_GetCurrentPageRootNode(ArkUI_NodeHandle node)
299 {
300 if (node == nullptr) {
301 return nullptr;
302 }
303 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
304 auto* attachNode = impl->getNodeModifiers()->getFrameNodeModifier()->getCurrentPageRootNode(node->uiNodeHandle);
305 return OHOS::Ace::NodeModel::GetArkUINode(attachNode);
306 }
307
OH_ArkUI_NodeUtils_IsCreatedByNDK(ArkUI_NodeHandle node)308 bool OH_ArkUI_NodeUtils_IsCreatedByNDK(ArkUI_NodeHandle node)
309 {
310 if (node == nullptr) {
311 return 0;
312 }
313 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
314 return impl->getNodeModifiers()->getFrameNodeModifier()->getNodeTag(node->uiNodeHandle);
315 }
316
OH_ArkUI_NodeUtils_GetNodeType(ArkUI_NodeHandle node)317 int32_t OH_ArkUI_NodeUtils_GetNodeType(ArkUI_NodeHandle node)
318 {
319 if (node == nullptr) {
320 return -1;
321 }
322 if (node->type != -1) {
323 return node->type;
324 }
325
326 return OHOS::Ace::NodeModel::GetNodeTypeByTag(node);
327 }
328
OH_ArkUI_NodeUtils_GetWindowInfo(ArkUI_NodeHandle node,ArkUI_HostWindowInfo ** info)329 int32_t OH_ArkUI_NodeUtils_GetWindowInfo(ArkUI_NodeHandle node, ArkUI_HostWindowInfo** info)
330 {
331 CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
332 CHECK_NULL_RETURN(info, ARKUI_ERROR_CODE_PARAM_INVALID);
333 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
334 CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_PARAM_INVALID);
335 char* name = nullptr;
336 int32_t error = impl->getNodeModifiers()->getFrameNodeModifier()->getWindowInfoByNode(node->uiNodeHandle, &name);
337 *info = new ArkUI_HostWindowInfo({ .name = name });
338 return error;
339 }
340
OH_ArkUI_HostWindowInfo_GetName(ArkUI_HostWindowInfo * info)341 const char* OH_ArkUI_HostWindowInfo_GetName(ArkUI_HostWindowInfo* info)
342 {
343 if (!info) {
344 LOGF_ABORT("HostWindowInfo is nullptr");
345 }
346 return info->name;
347 }
348
OH_ArkUI_HostWindowInfo_Destroy(ArkUI_HostWindowInfo * info)349 void OH_ArkUI_HostWindowInfo_Destroy(ArkUI_HostWindowInfo* info)
350 {
351 delete[] info->name;
352 info->name = nullptr;
353 delete info;
354 info = nullptr;
355 }
356
OH_ArkUI_CustomProperty_Destroy(ArkUI_CustomProperty * handle)357 void OH_ArkUI_CustomProperty_Destroy(ArkUI_CustomProperty* handle)
358 {
359 delete[] handle->value;
360 handle->value = nullptr;
361 delete handle;
362 handle = nullptr;
363 }
364
OH_ArkUI_CustomProperty_GetStringValue(ArkUI_CustomProperty * handle)365 const char* OH_ArkUI_CustomProperty_GetStringValue(ArkUI_CustomProperty* handle)
366 {
367 if (!handle) {
368 LOGF_ABORT("CustomProperty is nullptr");
369 }
370 return handle->value;
371 }
372
OH_ArkUI_ActiveChildrenInfo_Destroy(ArkUI_ActiveChildrenInfo * handle)373 void OH_ArkUI_ActiveChildrenInfo_Destroy(ArkUI_ActiveChildrenInfo* handle)
374 {
375 delete[] handle->nodeList;
376 handle->nodeList = nullptr;
377 delete handle;
378 handle = nullptr;
379 }
380
OH_ArkUI_ActiveChildrenInfo_GetNodeByIndex(ArkUI_ActiveChildrenInfo * handle,int32_t index)381 ArkUI_NodeHandle OH_ArkUI_ActiveChildrenInfo_GetNodeByIndex(ArkUI_ActiveChildrenInfo* handle, int32_t index)
382 {
383 if (!handle) {
384 LOGF_ABORT("ActiveChildrenInfo is nullptr");
385 }
386 if (index < handle->nodeCount && index >= 0) {
387 return handle->nodeList[index];
388 }
389 return nullptr;
390 }
391
OH_ArkUI_ActiveChildrenInfo_GetCount(ArkUI_ActiveChildrenInfo * handle)392 int32_t OH_ArkUI_ActiveChildrenInfo_GetCount(ArkUI_ActiveChildrenInfo* handle)
393 {
394 if (!handle) {
395 LOGF_ABORT("ActiveChildrenInfo is nullptr");
396 }
397 return handle->nodeCount;
398 }
399
OH_ArkUI_NodeUtils_GetAttachedNodeHandleById(const char * id,ArkUI_NodeHandle * node)400 int32_t OH_ArkUI_NodeUtils_GetAttachedNodeHandleById(const char* id, ArkUI_NodeHandle* node)
401 {
402 CHECK_NULL_RETURN(id, ARKUI_ERROR_CODE_PARAM_INVALID);
403 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
404 CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_PARAM_INVALID);
405 auto nodePtr = impl->getNodeModifiers()->getFrameNodeModifier()->getAttachedFrameNodeById(id);
406 CHECK_NULL_RETURN(nodePtr, ARKUI_ERROR_CODE_PARAM_INVALID);
407 *node = OHOS::Ace::NodeModel::GetArkUINode(nodePtr);
408 return ARKUI_ERROR_CODE_NO_ERROR;
409 }
410
OH_ArkUI_NodeUtils_GetNodeHandleByUniqueId(const uint32_t uniqueId,ArkUI_NodeHandle * node)411 int32_t OH_ArkUI_NodeUtils_GetNodeHandleByUniqueId(const uint32_t uniqueId, ArkUI_NodeHandle* node)
412 {
413 CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
414 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
415 CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_CAPI_INIT_ERROR);
416 auto nodePtr = impl->getNodeModifiers()->getFrameNodeModifier()->getFrameNodeByUniqueId(uniqueId);
417 *node = OHOS::Ace::NodeModel::GetArkUINode(nodePtr);
418 CHECK_NULL_RETURN(*node, ARKUI_ERROR_CODE_PARAM_INVALID);
419 return ARKUI_ERROR_CODE_NO_ERROR;
420 }
421
OH_ArkUI_NodeUtils_GetNodeUniqueId(ArkUI_NodeHandle node,int32_t * uniqueId)422 int32_t OH_ArkUI_NodeUtils_GetNodeUniqueId(ArkUI_NodeHandle node, int32_t* uniqueId)
423 {
424 if (node == nullptr) {
425 *uniqueId = -1;
426 return ARKUI_ERROR_CODE_PARAM_INVALID;
427 }
428 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
429 CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_CAPI_INIT_ERROR);
430 auto id = impl->getNodeModifiers()->getFrameNodeModifier()->getIdByNodePtr(node->uiNodeHandle);
431 *uniqueId = id;
432 if (*uniqueId < 0) {
433 return ARKUI_ERROR_CODE_PARAM_INVALID;
434 }
435 return ARKUI_ERROR_CODE_NO_ERROR;
436 }
437
OH_ArkUI_NodeUtils_SetCrossLanguageOption(ArkUI_NodeHandle node,ArkUI_CrossLanguageOption * option)438 int32_t OH_ArkUI_NodeUtils_SetCrossLanguageOption(ArkUI_NodeHandle node, ArkUI_CrossLanguageOption* option)
439 {
440 if (node == nullptr || option == nullptr || node->cNode == false) {
441 return ARKUI_ERROR_CODE_PARAM_INVALID;
442 }
443 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
444 CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_PARAM_INVALID);
445 auto errorCode = impl->getNodeModifiers()->getFrameNodeModifier()->setCrossLanguageOptions(
446 node->uiNodeHandle, option->attributeSetting);
447 return errorCode;
448 }
449
OH_ArkUI_NodeUtils_GetCrossLanguageOption(ArkUI_NodeHandle node,ArkUI_CrossLanguageOption * option)450 int32_t OH_ArkUI_NodeUtils_GetCrossLanguageOption(ArkUI_NodeHandle node, ArkUI_CrossLanguageOption* option)
451 {
452 if (node == nullptr || option == nullptr) {
453 return ARKUI_ERROR_CODE_PARAM_INVALID;
454 }
455 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
456 CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_PARAM_INVALID);
457 bool isCross = impl->getNodeModifiers()->getFrameNodeModifier()->getCrossLanguageOptions(node->uiNodeHandle);
458 option->attributeSetting = isCross;
459 return ARKUI_ERROR_CODE_NO_ERROR;
460 }
461
OH_ArkUI_CrossLanguageOption_Create(void)462 ArkUI_CrossLanguageOption* OH_ArkUI_CrossLanguageOption_Create(void)
463 {
464 ArkUI_CrossLanguageOption* option = new ArkUI_CrossLanguageOption {
465 .attributeSetting = false
466 };
467 return option;
468 }
469
OH_ArkUI_CrossLanguageOption_Destroy(ArkUI_CrossLanguageOption * option)470 void OH_ArkUI_CrossLanguageOption_Destroy(ArkUI_CrossLanguageOption* option)
471 {
472 if (option == nullptr) {
473 return;
474 }
475 delete option;
476 }
477
OH_ArkUI_CrossLanguageOption_SetAttributeSettingStatus(ArkUI_CrossLanguageOption * option,bool enable)478 void OH_ArkUI_CrossLanguageOption_SetAttributeSettingStatus(ArkUI_CrossLanguageOption* option, bool enable)
479 {
480 if (option == nullptr) {
481 return;
482 }
483 option->attributeSetting = enable;
484 }
485
OH_ArkUI_CrossLanguageOption_GetAttributeSettingStatus(ArkUI_CrossLanguageOption * option)486 bool OH_ArkUI_CrossLanguageOption_GetAttributeSettingStatus(ArkUI_CrossLanguageOption* option)
487 {
488 if (option == nullptr) {
489 return false;
490 }
491 return option->attributeSetting;
492 }
493
OH_ArkUI_NodeUtils_MoveTo(ArkUI_NodeHandle node,ArkUI_NodeHandle target_parent,int32_t index)494 int32_t OH_ArkUI_NodeUtils_MoveTo(ArkUI_NodeHandle node, ArkUI_NodeHandle target_parent, int32_t index)
495 {
496 if (node == nullptr || target_parent == nullptr
497 || !OHOS::Ace::NodeModel::CheckIsCNode(node) || !OHOS::Ace::NodeModel::CheckIsCNode(target_parent)) {
498 return ARKUI_ERROR_CODE_PARAM_INVALID;
499 }
500 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
501 CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_CAPI_INIT_ERROR);
502 int32_t errorCode = impl->getNodeModifiers()->getFrameNodeModifier()->moveNodeTo(node->uiNodeHandle,
503 target_parent->uiNodeHandle, index);
504 return errorCode;
505 }
506
OH_ArkUI_NativeModule_InvalidateAttributes(ArkUI_NodeHandle node)507 int32_t OH_ArkUI_NativeModule_InvalidateAttributes(ArkUI_NodeHandle node)
508 {
509 if (node == nullptr || !OHOS::Ace::NodeModel::CheckIsCNode(node)) {
510 return ARKUI_ERROR_CODE_PARAM_INVALID;
511 }
512 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
513 CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_CAPI_INIT_ERROR);
514 impl->getNodeModifiers()->getFrameNodeModifier()->applyAttributesFinish(node->uiNodeHandle);
515 return ARKUI_ERROR_CODE_NO_ERROR;
516 }
517
OH_ArkUI_NodeUtils_GetFirstChildIndexWithoutExpand(ArkUI_NodeHandle node,uint32_t * index)518 int32_t OH_ArkUI_NodeUtils_GetFirstChildIndexWithoutExpand(ArkUI_NodeHandle node, uint32_t* index)
519 {
520 if (node == nullptr) {
521 return ARKUI_ERROR_CODE_PARAM_INVALID;
522 }
523 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
524 CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_PARAM_INVALID);
525 int32_t errorCode = impl->getNodeModifiers()->getFrameNodeModifier()->getFirstChildIndexWithoutExpand(
526 node->uiNodeHandle, index);
527 return errorCode;
528 }
529
OH_ArkUI_NodeUtils_GetLastChildIndexWithoutExpand(ArkUI_NodeHandle node,uint32_t * index)530 int32_t OH_ArkUI_NodeUtils_GetLastChildIndexWithoutExpand(ArkUI_NodeHandle node, uint32_t* index)
531 {
532 if (node == nullptr) {
533 return ARKUI_ERROR_CODE_PARAM_INVALID;
534 }
535 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
536 CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_PARAM_INVALID);
537 int32_t errorCode = impl->getNodeModifiers()->getFrameNodeModifier()->getLastChildIndexWithoutExpand(
538 node->uiNodeHandle, index);
539 return errorCode;
540 }
541
OH_ArkUI_NodeUtils_GetChildWithExpandMode(ArkUI_NodeHandle node,int32_t position,ArkUI_NodeHandle * subnode,uint32_t expandMode)542 int32_t OH_ArkUI_NodeUtils_GetChildWithExpandMode(ArkUI_NodeHandle node, int32_t position,
543 ArkUI_NodeHandle* subnode, uint32_t expandMode)
544 {
545 if (node == nullptr) {
546 return ARKUI_ERROR_CODE_PARAM_INVALID;
547 }
548 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
549 CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_PARAM_INVALID);
550 auto nodePtr = impl->getNodeModifiers()->getFrameNodeModifier()->getChild(
551 node->uiNodeHandle, position, expandMode);
552 CHECK_NULL_RETURN(nodePtr, ARKUI_ERROR_CODE_PARAM_INVALID);
553 *subnode = OHOS::Ace::NodeModel::GetArkUINode(nodePtr);
554 return ARKUI_ERROR_CODE_NO_ERROR;
555 }
556
OH_ArkUI_NodeUtils_GetPositionToParent(ArkUI_NodeHandle node,ArkUI_IntOffset * globalOffset)557 int32_t OH_ArkUI_NodeUtils_GetPositionToParent(ArkUI_NodeHandle node, ArkUI_IntOffset* globalOffset)
558 {
559 if (node == nullptr) {
560 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
561 }
562 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
563 ArkUI_Float32 tempOffset[2];
564 impl->getNodeModifiers()->getFrameNodeModifier()->getPositionToParent(node->uiNodeHandle, &tempOffset, false);
565 globalOffset->x = tempOffset[0];
566 globalOffset->y = tempOffset[1];
567
568 return OHOS::Ace::ERROR_CODE_NO_ERROR;
569 }
570
OH_ArkUI_RunTaskInScope(ArkUI_ContextHandle uiContext,void * userData,void (* callback)(void * userData))571 int32_t OH_ArkUI_RunTaskInScope(ArkUI_ContextHandle uiContext, void* userData, void(*callback)(void* userData))
572 {
573 CHECK_NULL_RETURN(uiContext, ARKUI_ERROR_CODE_UI_CONTEXT_INVALID);
574 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
575 CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_CAPI_INIT_ERROR);
576 CHECK_NULL_RETURN(callback, ARKUI_ERROR_CODE_CALLBACK_INVALID);
577 auto* context = reinterpret_cast<ArkUI_Context*>(uiContext);
578 impl->getNodeModifiers()->getFrameNodeModifier()->runScopedTask(context->id, userData, callback);
579 return ARKUI_ERROR_CODE_NO_ERROR;
580 }
581
OH_ArkUI_AddSupportedUIStates(ArkUI_NodeHandle node,int32_t uiStates,void (statesChangeHandler)(int32_t currentStates,void * userData),bool excludeInner,void * userData)582 ArkUI_ErrorCode OH_ArkUI_AddSupportedUIStates(ArkUI_NodeHandle node, int32_t uiStates,
583 void (statesChangeHandler)(int32_t currentStates, void* userData), bool excludeInner, void* userData)
584 {
585 if (node == nullptr) {
586 return ARKUI_ERROR_CODE_PARAM_INVALID;
587 }
588 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
589 impl->getNodeModifiers()->getFrameNodeModifier()->addSupportedUIStates(node->uiNodeHandle, uiStates,
590 reinterpret_cast<void*>(statesChangeHandler), excludeInner, userData);
591 return ARKUI_ERROR_CODE_NO_ERROR;
592 }
593
OH_ArkUI_RemoveSupportedUIStates(ArkUI_NodeHandle node,int32_t uiStates)594 ArkUI_ErrorCode OH_ArkUI_RemoveSupportedUIStates(ArkUI_NodeHandle node, int32_t uiStates)
595 {
596 if (node == nullptr) {
597 return ARKUI_ERROR_CODE_PARAM_INVALID;
598 }
599 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
600 impl->getNodeModifiers()->getFrameNodeModifier()->removeSupportedUIStates(node->uiNodeHandle, uiStates);
601 return ARKUI_ERROR_CODE_NO_ERROR;
602 }
603
OH_ArkUI_SetForceDarkConfig(ArkUI_ContextHandle uiContext,bool forceDark,ArkUI_NodeType nodeType,uint32_t (* colorInvertFunc)(uint32_t color))604 int32_t OH_ArkUI_SetForceDarkConfig(
605 ArkUI_ContextHandle uiContext, bool forceDark, ArkUI_NodeType nodeType, uint32_t (*colorInvertFunc)(uint32_t color))
606 {
607 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
608 CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_CAPI_INIT_ERROR);
609 int32_t instanceId = OHOS::Ace::INSTANCE_ID_UNDEFINED;
610 if (uiContext) {
611 auto* context = reinterpret_cast<ArkUI_Context*>(uiContext);
612 instanceId = context->id;
613 }
614 int32_t errorCode = impl->getNodeModifiers()->getFrameNodeModifier()->setForceDarkConfig(
615 instanceId, forceDark, OHOS::Ace::NodeModel::ConvertNodeTypeToTag(nodeType).c_str(), colorInvertFunc);
616 return errorCode;
617 }
618
619 #ifdef __cplusplus
620 };
621 #endif
622