123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2023 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#include "node_model.h" 1723b3eb3cSopenharmony_ci 1823b3eb3cSopenharmony_ci 1923b3eb3cSopenharmony_ci#include "event_converter.h" 2023b3eb3cSopenharmony_ci#include "interfaces/native/event/ui_input_event_impl.h" 2123b3eb3cSopenharmony_ci#include "node_extened.h" 2223b3eb3cSopenharmony_ci#include "style_modifier.h" 2323b3eb3cSopenharmony_ci 2423b3eb3cSopenharmony_ci#include "base/error/error_code.h" 2523b3eb3cSopenharmony_ci#include "base/utils/utils.h" 2623b3eb3cSopenharmony_ci 2723b3eb3cSopenharmony_cinamespace OHOS::Ace::NodeModel { 2823b3eb3cSopenharmony_cinamespace { 2923b3eb3cSopenharmony_ci#if defined(WINDOWS_PLATFORM) 3023b3eb3cSopenharmony_ci#include <windows.h> 3123b3eb3cSopenharmony_ci// Here we need to find module where GetArkUINodeAPI() 3223b3eb3cSopenharmony_ci// function is implemented. 3323b3eb3cSopenharmony_civoid* FindModule() 3423b3eb3cSopenharmony_ci{ 3523b3eb3cSopenharmony_ci // To find from main exe 3623b3eb3cSopenharmony_ci HMODULE result = nullptr; 3723b3eb3cSopenharmony_ci const char libname[] = "libace_compatible.dll"; 3823b3eb3cSopenharmony_ci GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN, libname, &result); 3923b3eb3cSopenharmony_ci if (result) { 4023b3eb3cSopenharmony_ci return result; 4123b3eb3cSopenharmony_ci } 4223b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "Cannot find module!"); 4323b3eb3cSopenharmony_ci return nullptr; 4423b3eb3cSopenharmony_ci} 4523b3eb3cSopenharmony_civoid* FindFunction(void* library, const char* name) 4623b3eb3cSopenharmony_ci{ 4723b3eb3cSopenharmony_ci return (void*)GetProcAddress(reinterpret_cast<HMODULE>(library), name); 4823b3eb3cSopenharmony_ci} 4923b3eb3cSopenharmony_ci#else 5023b3eb3cSopenharmony_ci#include <dlfcn.h> 5123b3eb3cSopenharmony_civoid* FindModule() 5223b3eb3cSopenharmony_ci{ 5323b3eb3cSopenharmony_ci const char libname[] = "libace_compatible.z.so"; 5423b3eb3cSopenharmony_ci void* result = dlopen(libname, RTLD_LAZY | RTLD_LOCAL); 5523b3eb3cSopenharmony_ci if (result) { 5623b3eb3cSopenharmony_ci return result; 5723b3eb3cSopenharmony_ci } 5823b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "Cannot load libace: %{public}s", dlerror()); 5923b3eb3cSopenharmony_ci return nullptr; 6023b3eb3cSopenharmony_ci} 6123b3eb3cSopenharmony_ci 6223b3eb3cSopenharmony_civoid* FindFunction(void* library, const char* name) 6323b3eb3cSopenharmony_ci{ 6423b3eb3cSopenharmony_ci return dlsym(library, name); 6523b3eb3cSopenharmony_ci} 6623b3eb3cSopenharmony_ci#endif 6723b3eb3cSopenharmony_ci 6823b3eb3cSopenharmony_ciArkUIFullNodeAPI* impl = nullptr; 6923b3eb3cSopenharmony_ci 7023b3eb3cSopenharmony_cibool InitialFullNodeImpl(int version) 7123b3eb3cSopenharmony_ci{ 7223b3eb3cSopenharmony_ci if (!impl) { 7323b3eb3cSopenharmony_ci typedef ArkUIAnyAPI* (*GetAPI_t)(int); 7423b3eb3cSopenharmony_ci GetAPI_t getAPI = nullptr; 7523b3eb3cSopenharmony_ci void* module = FindModule(); 7623b3eb3cSopenharmony_ci if (module == nullptr) { 7723b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "fail to get module"); 7823b3eb3cSopenharmony_ci return false; 7923b3eb3cSopenharmony_ci } 8023b3eb3cSopenharmony_ci // Note, that RTLD_DEFAULT is ((void *) 0). 8123b3eb3cSopenharmony_ci getAPI = reinterpret_cast<GetAPI_t>(FindFunction(module, "GetArkUIAnyFullNodeAPI")); 8223b3eb3cSopenharmony_ci if (!getAPI) { 8323b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "Cannot find GetArkUIAnyFullNodeAPI()"); 8423b3eb3cSopenharmony_ci return false; 8523b3eb3cSopenharmony_ci } 8623b3eb3cSopenharmony_ci 8723b3eb3cSopenharmony_ci impl = reinterpret_cast<ArkUIFullNodeAPI*>((*getAPI)(version)); 8823b3eb3cSopenharmony_ci if (!impl) { 8923b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "getAPI() returned null"); 9023b3eb3cSopenharmony_ci return false; 9123b3eb3cSopenharmony_ci } 9223b3eb3cSopenharmony_ci 9323b3eb3cSopenharmony_ci if (impl->version != version) { 9423b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, 9523b3eb3cSopenharmony_ci "API version mismatch: expected %{public}d, but get the version %{public}d", version, impl->version); 9623b3eb3cSopenharmony_ci return false; 9723b3eb3cSopenharmony_ci } 9823b3eb3cSopenharmony_ci } 9923b3eb3cSopenharmony_ci 10023b3eb3cSopenharmony_ci impl->getBasicAPI()->registerNodeAsyncEventReceiver(OHOS::Ace::NodeModel::HandleInnerEvent); 10123b3eb3cSopenharmony_ci impl->getExtendedAPI()->registerCustomNodeAsyncEventReceiver(OHOS::Ace::NodeModel::HandleInnerCustomEvent); 10223b3eb3cSopenharmony_ci return true; 10323b3eb3cSopenharmony_ci} 10423b3eb3cSopenharmony_ci} // namespace 10523b3eb3cSopenharmony_ci 10623b3eb3cSopenharmony_ciArkUIFullNodeAPI* GetFullImpl() 10723b3eb3cSopenharmony_ci{ 10823b3eb3cSopenharmony_ci return impl; 10923b3eb3cSopenharmony_ci} 11023b3eb3cSopenharmony_ci 11123b3eb3cSopenharmony_cibool InitialFullImpl() 11223b3eb3cSopenharmony_ci{ 11323b3eb3cSopenharmony_ci return InitialFullNodeImpl(ARKUI_NODE_API_VERSION); 11423b3eb3cSopenharmony_ci} 11523b3eb3cSopenharmony_ci 11623b3eb3cSopenharmony_cistruct InnerEventExtraParam { 11723b3eb3cSopenharmony_ci int32_t targetId; 11823b3eb3cSopenharmony_ci ArkUI_NodeHandle nodePtr; 11923b3eb3cSopenharmony_ci void* userData; 12023b3eb3cSopenharmony_ci}; 12123b3eb3cSopenharmony_ci 12223b3eb3cSopenharmony_cistruct ExtraData { 12323b3eb3cSopenharmony_ci std::unordered_map<int64_t, InnerEventExtraParam*> eventMap; 12423b3eb3cSopenharmony_ci}; 12523b3eb3cSopenharmony_ci 12623b3eb3cSopenharmony_cistd::set<ArkUI_NodeHandle> g_nodeSet; 12723b3eb3cSopenharmony_ci 12823b3eb3cSopenharmony_cibool IsValidArkUINode(ArkUI_NodeHandle nodePtr) 12923b3eb3cSopenharmony_ci{ 13023b3eb3cSopenharmony_ci if (!nodePtr || g_nodeSet.count(nodePtr) == 0) { 13123b3eb3cSopenharmony_ci return false; 13223b3eb3cSopenharmony_ci } 13323b3eb3cSopenharmony_ci return true; 13423b3eb3cSopenharmony_ci} 13523b3eb3cSopenharmony_ci 13623b3eb3cSopenharmony_ciArkUI_NodeHandle CreateNode(ArkUI_NodeType type) 13723b3eb3cSopenharmony_ci{ 13823b3eb3cSopenharmony_ci static const ArkUINodeType nodes[] = { ARKUI_CUSTOM, ARKUI_TEXT, ARKUI_SPAN, ARKUI_IMAGE_SPAN, ARKUI_IMAGE, 13923b3eb3cSopenharmony_ci ARKUI_TOGGLE, ARKUI_LOADING_PROGRESS, ARKUI_TEXT_INPUT, ARKUI_TEXTAREA, ARKUI_BUTTON, ARKUI_PROGRESS, 14023b3eb3cSopenharmony_ci ARKUI_CHECKBOX, ARKUI_XCOMPONENT, ARKUI_DATE_PICKER, ARKUI_TIME_PICKER, ARKUI_TEXT_PICKER, 14123b3eb3cSopenharmony_ci ARKUI_CALENDAR_PICKER, ARKUI_SLIDER, ARKUI_RADIO, ARKUI_IMAGE_ANIMATOR, ARKUI_STACK, ARKUI_SWIPER, 14223b3eb3cSopenharmony_ci ARKUI_SCROLL, ARKUI_LIST, ARKUI_LIST_ITEM, ARKUI_LIST_ITEM_GROUP, ARKUI_COLUMN, ARKUI_ROW, ARKUI_FLEX, 14323b3eb3cSopenharmony_ci ARKUI_REFRESH, ARKUI_WATER_FLOW, ARKUI_FLOW_ITEM, ARKUI_RELATIVE_CONTAINER, ARKUI_GRID, ARKUI_GRID_ITEM, 14423b3eb3cSopenharmony_ci ARKUI_CUSTOM_SPAN }; 14523b3eb3cSopenharmony_ci // already check in entry point. 14623b3eb3cSopenharmony_ci uint32_t nodeType = type < MAX_NODE_SCOPE_NUM ? type : (type - MAX_NODE_SCOPE_NUM + BASIC_COMPONENT_NUM); 14723b3eb3cSopenharmony_ci auto* impl = GetFullImpl(); 14823b3eb3cSopenharmony_ci if (nodeType >= sizeof(nodes) / sizeof(ArkUINodeType)) { 14923b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "node type: %{public}d NOT IMPLEMENT", type); 15023b3eb3cSopenharmony_ci return nullptr; 15123b3eb3cSopenharmony_ci } 15223b3eb3cSopenharmony_ci 15323b3eb3cSopenharmony_ci ArkUI_Int32 id = ARKUI_AUTO_GENERATE_NODE_ID; 15423b3eb3cSopenharmony_ci auto* uiNode = impl->getBasicAPI()->createNode(nodes[nodeType], id, ARKUI_NODE_FLAG_C); 15523b3eb3cSopenharmony_ci if (!uiNode) { 15623b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "node type: %{public}d can not find in full impl", type); 15723b3eb3cSopenharmony_ci return nullptr; 15823b3eb3cSopenharmony_ci } 15923b3eb3cSopenharmony_ci impl->getBasicAPI()->markDirty(uiNode, ARKUI_DIRTY_FLAG_ATTRIBUTE_DIFF); 16023b3eb3cSopenharmony_ci ArkUI_Node* arkUINode = new ArkUI_Node({ type, uiNode }); 16123b3eb3cSopenharmony_ci impl->getExtendedAPI()->setAttachNodePtr(uiNode, reinterpret_cast<void*>(arkUINode)); 16223b3eb3cSopenharmony_ci g_nodeSet.emplace(arkUINode); 16323b3eb3cSopenharmony_ci return arkUINode; 16423b3eb3cSopenharmony_ci} 16523b3eb3cSopenharmony_ci 16623b3eb3cSopenharmony_civoid DisposeNativeSource(ArkUI_NodeHandle nativePtr) 16723b3eb3cSopenharmony_ci{ 16823b3eb3cSopenharmony_ci CHECK_NULL_VOID(nativePtr); 16923b3eb3cSopenharmony_ci if (nativePtr->customEventListeners) { 17023b3eb3cSopenharmony_ci auto eventListenersSet = reinterpret_cast<std::set<void (*)(ArkUI_NodeCustomEvent*)>*>( 17123b3eb3cSopenharmony_ci nativePtr->customEventListeners); 17223b3eb3cSopenharmony_ci if (eventListenersSet) { 17323b3eb3cSopenharmony_ci eventListenersSet->clear(); 17423b3eb3cSopenharmony_ci } 17523b3eb3cSopenharmony_ci delete eventListenersSet; 17623b3eb3cSopenharmony_ci nativePtr->customEventListeners = nullptr; 17723b3eb3cSopenharmony_ci } 17823b3eb3cSopenharmony_ci if (nativePtr->eventListeners) { 17923b3eb3cSopenharmony_ci auto eventListenersSet = reinterpret_cast<std::set<void (*)(ArkUI_NodeEvent*)>*>( 18023b3eb3cSopenharmony_ci nativePtr->eventListeners); 18123b3eb3cSopenharmony_ci if (eventListenersSet) { 18223b3eb3cSopenharmony_ci eventListenersSet->clear(); 18323b3eb3cSopenharmony_ci } 18423b3eb3cSopenharmony_ci delete eventListenersSet; 18523b3eb3cSopenharmony_ci nativePtr->eventListeners = nullptr; 18623b3eb3cSopenharmony_ci } 18723b3eb3cSopenharmony_ci if (nativePtr->areaChangeRadio) { 18823b3eb3cSopenharmony_ci delete[] nativePtr->areaChangeRadio->value; 18923b3eb3cSopenharmony_ci delete nativePtr->areaChangeRadio; 19023b3eb3cSopenharmony_ci nativePtr->areaChangeRadio = nullptr; 19123b3eb3cSopenharmony_ci } 19223b3eb3cSopenharmony_ci} 19323b3eb3cSopenharmony_ci 19423b3eb3cSopenharmony_civoid DisposeNode(ArkUI_NodeHandle nativePtr) 19523b3eb3cSopenharmony_ci{ 19623b3eb3cSopenharmony_ci CHECK_NULL_VOID(nativePtr); 19723b3eb3cSopenharmony_ci // already check in entry point. 19823b3eb3cSopenharmony_ci auto* impl = GetFullImpl(); 19923b3eb3cSopenharmony_ci impl->getBasicAPI()->disposeNode(nativePtr->uiNodeHandle); 20023b3eb3cSopenharmony_ci DisposeNativeSource(nativePtr); 20123b3eb3cSopenharmony_ci g_nodeSet.erase(nativePtr); 20223b3eb3cSopenharmony_ci delete nativePtr; 20323b3eb3cSopenharmony_ci nativePtr = nullptr; 20423b3eb3cSopenharmony_ci} 20523b3eb3cSopenharmony_ci 20623b3eb3cSopenharmony_ciint32_t AddChild(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode) 20723b3eb3cSopenharmony_ci{ 20823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentNode, ERROR_CODE_PARAM_INVALID); 20923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(childNode, ERROR_CODE_PARAM_INVALID); 21023b3eb3cSopenharmony_ci if (parentNode->type == -1) { 21123b3eb3cSopenharmony_ci return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR; 21223b3eb3cSopenharmony_ci } 21323b3eb3cSopenharmony_ci auto* impl = GetFullImpl(); 21423b3eb3cSopenharmony_ci // already check in entry point. 21523b3eb3cSopenharmony_ci impl->getBasicAPI()->addChild(parentNode->uiNodeHandle, childNode->uiNodeHandle); 21623b3eb3cSopenharmony_ci impl->getBasicAPI()->markDirty(parentNode->uiNodeHandle, ARKUI_DIRTY_FLAG_MEASURE_BY_CHILD_REQUEST); 21723b3eb3cSopenharmony_ci return ERROR_CODE_NO_ERROR; 21823b3eb3cSopenharmony_ci} 21923b3eb3cSopenharmony_ci 22023b3eb3cSopenharmony_ciint32_t RemoveChild(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode) 22123b3eb3cSopenharmony_ci{ 22223b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentNode, ERROR_CODE_PARAM_INVALID); 22323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(childNode, ERROR_CODE_PARAM_INVALID); 22423b3eb3cSopenharmony_ci // already check in entry point. 22523b3eb3cSopenharmony_ci if (parentNode->type == -1) { 22623b3eb3cSopenharmony_ci return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR; 22723b3eb3cSopenharmony_ci } 22823b3eb3cSopenharmony_ci auto* impl = GetFullImpl(); 22923b3eb3cSopenharmony_ci impl->getBasicAPI()->removeChild(parentNode->uiNodeHandle, childNode->uiNodeHandle); 23023b3eb3cSopenharmony_ci impl->getBasicAPI()->markDirty(parentNode->uiNodeHandle, ARKUI_DIRTY_FLAG_MEASURE_BY_CHILD_REQUEST); 23123b3eb3cSopenharmony_ci return ERROR_CODE_NO_ERROR; 23223b3eb3cSopenharmony_ci} 23323b3eb3cSopenharmony_ci 23423b3eb3cSopenharmony_ciint32_t InsertChildAfter(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode, ArkUI_NodeHandle siblingNode) 23523b3eb3cSopenharmony_ci{ 23623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentNode, ERROR_CODE_PARAM_INVALID); 23723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(childNode, ERROR_CODE_PARAM_INVALID); 23823b3eb3cSopenharmony_ci // already check in entry point. 23923b3eb3cSopenharmony_ci if (parentNode->type == -1) { 24023b3eb3cSopenharmony_ci return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR; 24123b3eb3cSopenharmony_ci } 24223b3eb3cSopenharmony_ci auto* impl = GetFullImpl(); 24323b3eb3cSopenharmony_ci impl->getBasicAPI()->insertChildAfter( 24423b3eb3cSopenharmony_ci parentNode->uiNodeHandle, childNode->uiNodeHandle, siblingNode ? siblingNode->uiNodeHandle : nullptr); 24523b3eb3cSopenharmony_ci impl->getBasicAPI()->markDirty(parentNode->uiNodeHandle, ARKUI_DIRTY_FLAG_MEASURE_BY_CHILD_REQUEST); 24623b3eb3cSopenharmony_ci return ERROR_CODE_NO_ERROR; 24723b3eb3cSopenharmony_ci} 24823b3eb3cSopenharmony_ci 24923b3eb3cSopenharmony_ciint32_t InsertChildBefore(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode, ArkUI_NodeHandle siblingNode) 25023b3eb3cSopenharmony_ci{ 25123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentNode, ERROR_CODE_PARAM_INVALID); 25223b3eb3cSopenharmony_ci CHECK_NULL_RETURN(childNode, ERROR_CODE_PARAM_INVALID); 25323b3eb3cSopenharmony_ci // already check in entry point. 25423b3eb3cSopenharmony_ci if (parentNode->type == -1) { 25523b3eb3cSopenharmony_ci return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR; 25623b3eb3cSopenharmony_ci } 25723b3eb3cSopenharmony_ci auto* impl = GetFullImpl(); 25823b3eb3cSopenharmony_ci impl->getBasicAPI()->insertChildBefore( 25923b3eb3cSopenharmony_ci parentNode->uiNodeHandle, childNode->uiNodeHandle, siblingNode ? siblingNode->uiNodeHandle : nullptr); 26023b3eb3cSopenharmony_ci impl->getBasicAPI()->markDirty(parentNode->uiNodeHandle, ARKUI_DIRTY_FLAG_MEASURE_BY_CHILD_REQUEST); 26123b3eb3cSopenharmony_ci return ERROR_CODE_NO_ERROR; 26223b3eb3cSopenharmony_ci} 26323b3eb3cSopenharmony_ci 26423b3eb3cSopenharmony_ciint32_t InsertChildAt(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode, int32_t position) 26523b3eb3cSopenharmony_ci{ 26623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentNode, ERROR_CODE_PARAM_INVALID); 26723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(childNode, ERROR_CODE_PARAM_INVALID); 26823b3eb3cSopenharmony_ci // already check in entry point. 26923b3eb3cSopenharmony_ci if (parentNode->type == -1) { 27023b3eb3cSopenharmony_ci return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR; 27123b3eb3cSopenharmony_ci } 27223b3eb3cSopenharmony_ci auto* impl = GetFullImpl(); 27323b3eb3cSopenharmony_ci impl->getBasicAPI()->insertChildAt(parentNode->uiNodeHandle, childNode->uiNodeHandle, position); 27423b3eb3cSopenharmony_ci impl->getBasicAPI()->markDirty(parentNode->uiNodeHandle, ARKUI_DIRTY_FLAG_MEASURE_BY_CHILD_REQUEST); 27523b3eb3cSopenharmony_ci return ERROR_CODE_NO_ERROR; 27623b3eb3cSopenharmony_ci} 27723b3eb3cSopenharmony_ci 27823b3eb3cSopenharmony_civoid SetAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType attribute, const char* value) 27923b3eb3cSopenharmony_ci{ 28023b3eb3cSopenharmony_ci SetNodeAttribute(node, attribute, value); 28123b3eb3cSopenharmony_ci} 28223b3eb3cSopenharmony_ci 28323b3eb3cSopenharmony_ciint32_t SetAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType attribute, const ArkUI_AttributeItem* value) 28423b3eb3cSopenharmony_ci{ 28523b3eb3cSopenharmony_ci if (node == nullptr) { 28623b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 28723b3eb3cSopenharmony_ci } 28823b3eb3cSopenharmony_ci if (node->type == -1 && attribute != NODE_LAYOUT_RECT) { 28923b3eb3cSopenharmony_ci return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR; 29023b3eb3cSopenharmony_ci } 29123b3eb3cSopenharmony_ci return SetNodeAttribute(node, attribute, value); 29223b3eb3cSopenharmony_ci} 29323b3eb3cSopenharmony_ci 29423b3eb3cSopenharmony_ciint32_t ResetAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType attribute) 29523b3eb3cSopenharmony_ci{ 29623b3eb3cSopenharmony_ci if (node == nullptr) { 29723b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 29823b3eb3cSopenharmony_ci } 29923b3eb3cSopenharmony_ci if (node->type == -1 && attribute != NODE_LAYOUT_RECT) { 30023b3eb3cSopenharmony_ci return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR; 30123b3eb3cSopenharmony_ci } 30223b3eb3cSopenharmony_ci return ResetNodeAttribute(node, attribute); 30323b3eb3cSopenharmony_ci} 30423b3eb3cSopenharmony_ci 30523b3eb3cSopenharmony_ciconst ArkUI_AttributeItem* GetAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType attribute) 30623b3eb3cSopenharmony_ci{ 30723b3eb3cSopenharmony_ci if (node == nullptr) { 30823b3eb3cSopenharmony_ci return nullptr; 30923b3eb3cSopenharmony_ci } 31023b3eb3cSopenharmony_ci return GetNodeAttribute(node, attribute); 31123b3eb3cSopenharmony_ci} 31223b3eb3cSopenharmony_ci 31323b3eb3cSopenharmony_ciint32_t RegisterNodeEvent(ArkUI_NodeHandle nodePtr, ArkUI_NodeEventType eventType, int32_t targetId) 31423b3eb3cSopenharmony_ci{ 31523b3eb3cSopenharmony_ci return RegisterNodeEvent(nodePtr, eventType, targetId, nullptr); 31623b3eb3cSopenharmony_ci} 31723b3eb3cSopenharmony_ci 31823b3eb3cSopenharmony_ciint32_t RegisterNodeEvent(ArkUI_NodeHandle nodePtr, ArkUI_NodeEventType eventType, int32_t targetId, void* userData) 31923b3eb3cSopenharmony_ci{ 32023b3eb3cSopenharmony_ci if (nodePtr == nullptr) { 32123b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 32223b3eb3cSopenharmony_ci } 32323b3eb3cSopenharmony_ci auto originEventType = ConvertOriginEventType(eventType, nodePtr->type); 32423b3eb3cSopenharmony_ci if (originEventType < 0) { 32523b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "event is not supported %{public}d", eventType); 32623b3eb3cSopenharmony_ci return ERROR_CODE_NATIVE_IMPL_TYPE_NOT_SUPPORTED; 32723b3eb3cSopenharmony_ci } 32823b3eb3cSopenharmony_ci // already check in entry point. 32923b3eb3cSopenharmony_ci if (nodePtr->type == -1) { 33023b3eb3cSopenharmony_ci return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR; 33123b3eb3cSopenharmony_ci } 33223b3eb3cSopenharmony_ci auto* impl = GetFullImpl(); 33323b3eb3cSopenharmony_ci auto* extraParam = new InnerEventExtraParam({ targetId, nodePtr, userData }); 33423b3eb3cSopenharmony_ci if (nodePtr->extraData) { 33523b3eb3cSopenharmony_ci auto* extraData = reinterpret_cast<ExtraData*>(nodePtr->extraData); 33623b3eb3cSopenharmony_ci auto result = extraData->eventMap.try_emplace(eventType, extraParam); 33723b3eb3cSopenharmony_ci if (!result.second) { 33823b3eb3cSopenharmony_ci result.first->second->targetId = targetId; 33923b3eb3cSopenharmony_ci result.first->second->userData = userData; 34023b3eb3cSopenharmony_ci delete extraParam; 34123b3eb3cSopenharmony_ci } 34223b3eb3cSopenharmony_ci } else { 34323b3eb3cSopenharmony_ci nodePtr->extraData = new ExtraData(); 34423b3eb3cSopenharmony_ci auto* extraData = reinterpret_cast<ExtraData*>(nodePtr->extraData); 34523b3eb3cSopenharmony_ci extraData->eventMap[eventType] = extraParam; 34623b3eb3cSopenharmony_ci } 34723b3eb3cSopenharmony_ci if (eventType == NODE_EVENT_ON_VISIBLE_AREA_CHANGE) { 34823b3eb3cSopenharmony_ci ArkUI_AttributeItem* radio = nodePtr->areaChangeRadio; 34923b3eb3cSopenharmony_ci radio = radio ? radio : static_cast<ArkUI_AttributeItem*>(userData); 35023b3eb3cSopenharmony_ci if (!radio) { 35123b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 35223b3eb3cSopenharmony_ci } 35323b3eb3cSopenharmony_ci ArkUI_Int32 radioLength = radio->size; 35423b3eb3cSopenharmony_ci if (radioLength <= 0) { 35523b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 35623b3eb3cSopenharmony_ci } 35723b3eb3cSopenharmony_ci ArkUI_Float32 radioList[radioLength]; 35823b3eb3cSopenharmony_ci for (int i = 0; i < radioLength; ++i) { 35923b3eb3cSopenharmony_ci if (LessNotEqual(radio->value[i].f32, 0.0f) || GreatNotEqual(radio->value[i].f32, 1.0f)) { 36023b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 36123b3eb3cSopenharmony_ci } 36223b3eb3cSopenharmony_ci radioList[i] = radio->value[i].f32; 36323b3eb3cSopenharmony_ci } 36423b3eb3cSopenharmony_ci impl->getNodeModifiers()->getCommonModifier()->setOnVisibleAreaChange( 36523b3eb3cSopenharmony_ci nodePtr->uiNodeHandle, reinterpret_cast<int64_t>(nodePtr), radioList, radioLength); 36623b3eb3cSopenharmony_ci } else { 36723b3eb3cSopenharmony_ci impl->getBasicAPI()->registerNodeAsyncEvent( 36823b3eb3cSopenharmony_ci nodePtr->uiNodeHandle, static_cast<ArkUIEventSubKind>(originEventType), reinterpret_cast<int64_t>(nodePtr)); 36923b3eb3cSopenharmony_ci } 37023b3eb3cSopenharmony_ci return ERROR_CODE_NO_ERROR; 37123b3eb3cSopenharmony_ci} 37223b3eb3cSopenharmony_ci 37323b3eb3cSopenharmony_civoid UnregisterNodeEvent(ArkUI_NodeHandle nodePtr, ArkUI_NodeEventType eventType) 37423b3eb3cSopenharmony_ci{ 37523b3eb3cSopenharmony_ci if (nodePtr == nullptr) { 37623b3eb3cSopenharmony_ci return; 37723b3eb3cSopenharmony_ci } 37823b3eb3cSopenharmony_ci if (!nodePtr->extraData) { 37923b3eb3cSopenharmony_ci return; 38023b3eb3cSopenharmony_ci } 38123b3eb3cSopenharmony_ci if (nodePtr->type == -1) { 38223b3eb3cSopenharmony_ci return; 38323b3eb3cSopenharmony_ci } 38423b3eb3cSopenharmony_ci auto* extraData = reinterpret_cast<ExtraData*>(nodePtr->extraData); 38523b3eb3cSopenharmony_ci auto& eventMap = extraData->eventMap; 38623b3eb3cSopenharmony_ci auto innerEventExtraParam = eventMap.find(eventType); 38723b3eb3cSopenharmony_ci if (innerEventExtraParam == eventMap.end()) { 38823b3eb3cSopenharmony_ci return; 38923b3eb3cSopenharmony_ci } 39023b3eb3cSopenharmony_ci delete innerEventExtraParam->second; 39123b3eb3cSopenharmony_ci eventMap.erase(innerEventExtraParam); 39223b3eb3cSopenharmony_ci if (eventMap.empty()) { 39323b3eb3cSopenharmony_ci delete extraData; 39423b3eb3cSopenharmony_ci nodePtr->extraData = nullptr; 39523b3eb3cSopenharmony_ci } 39623b3eb3cSopenharmony_ci auto originEventType = ConvertOriginEventType(eventType, nodePtr->type); 39723b3eb3cSopenharmony_ci if (originEventType < 0) { 39823b3eb3cSopenharmony_ci return; 39923b3eb3cSopenharmony_ci } 40023b3eb3cSopenharmony_ci impl->getBasicAPI()->unRegisterNodeAsyncEvent( 40123b3eb3cSopenharmony_ci nodePtr->uiNodeHandle, static_cast<ArkUIEventSubKind>(originEventType)); 40223b3eb3cSopenharmony_ci} 40323b3eb3cSopenharmony_ci 40423b3eb3cSopenharmony_civoid (*g_compatibleEventReceiver)(ArkUI_CompatibleNodeEvent* event) = nullptr; 40523b3eb3cSopenharmony_civoid RegisterOnEvent(void (*eventReceiver)(ArkUI_CompatibleNodeEvent* event)) 40623b3eb3cSopenharmony_ci{ 40723b3eb3cSopenharmony_ci g_compatibleEventReceiver = eventReceiver; 40823b3eb3cSopenharmony_ci} 40923b3eb3cSopenharmony_ci 41023b3eb3cSopenharmony_civoid (*g_eventReceiver)(ArkUI_NodeEvent* event) = nullptr; 41123b3eb3cSopenharmony_civoid RegisterOnEvent(void (*eventReceiver)(ArkUI_NodeEvent* event)) 41223b3eb3cSopenharmony_ci{ 41323b3eb3cSopenharmony_ci g_eventReceiver = eventReceiver; 41423b3eb3cSopenharmony_ci} 41523b3eb3cSopenharmony_ci 41623b3eb3cSopenharmony_civoid UnregisterOnEvent() 41723b3eb3cSopenharmony_ci{ 41823b3eb3cSopenharmony_ci g_eventReceiver = nullptr; 41923b3eb3cSopenharmony_ci} 42023b3eb3cSopenharmony_ci 42123b3eb3cSopenharmony_civoid HandleInnerNodeEvent(ArkUINodeEvent* innerEvent) 42223b3eb3cSopenharmony_ci{ 42323b3eb3cSopenharmony_ci if (!innerEvent) { 42423b3eb3cSopenharmony_ci return; 42523b3eb3cSopenharmony_ci } 42623b3eb3cSopenharmony_ci auto nativeNodeEventType = GetNativeNodeEventType(innerEvent); 42723b3eb3cSopenharmony_ci if (nativeNodeEventType == -1) { 42823b3eb3cSopenharmony_ci return; 42923b3eb3cSopenharmony_ci } 43023b3eb3cSopenharmony_ci auto eventType = static_cast<ArkUI_NodeEventType>(nativeNodeEventType); 43123b3eb3cSopenharmony_ci auto* nodePtr = reinterpret_cast<ArkUI_NodeHandle>(innerEvent->extraParam); 43223b3eb3cSopenharmony_ci auto extraData = reinterpret_cast<ExtraData*>(nodePtr->extraData); 43323b3eb3cSopenharmony_ci if (!extraData) { 43423b3eb3cSopenharmony_ci return; 43523b3eb3cSopenharmony_ci } 43623b3eb3cSopenharmony_ci auto innerEventExtraParam = extraData->eventMap.find(eventType); 43723b3eb3cSopenharmony_ci if (innerEventExtraParam == extraData->eventMap.end()) { 43823b3eb3cSopenharmony_ci return; 43923b3eb3cSopenharmony_ci } 44023b3eb3cSopenharmony_ci ArkUI_NodeEvent event; 44123b3eb3cSopenharmony_ci event.node = nodePtr; 44223b3eb3cSopenharmony_ci event.eventId = innerEventExtraParam->second->targetId; 44323b3eb3cSopenharmony_ci event.userData = innerEventExtraParam->second->userData; 44423b3eb3cSopenharmony_ci if (!g_eventReceiver && !g_compatibleEventReceiver && (!(event.node) || 44523b3eb3cSopenharmony_ci (event.node && !(event.node->eventListeners)))) { 44623b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "event receiver is not register"); 44723b3eb3cSopenharmony_ci return; 44823b3eb3cSopenharmony_ci } 44923b3eb3cSopenharmony_ci if ((g_eventReceiver || (event.node && event.node->eventListeners)) && ConvertEvent(innerEvent, &event)) { 45023b3eb3cSopenharmony_ci event.targetId = innerEvent->nodeId; 45123b3eb3cSopenharmony_ci ArkUI_UIInputEvent uiEvent; 45223b3eb3cSopenharmony_ci if (eventType == NODE_TOUCH_EVENT || eventType == NODE_ON_TOUCH_INTERCEPT) { 45323b3eb3cSopenharmony_ci uiEvent.inputType = ARKUI_UIINPUTEVENT_TYPE_TOUCH; 45423b3eb3cSopenharmony_ci uiEvent.eventTypeId = C_TOUCH_EVENT_ID; 45523b3eb3cSopenharmony_ci uiEvent.inputEvent = &(innerEvent->touchEvent); 45623b3eb3cSopenharmony_ci event.origin = &uiEvent; 45723b3eb3cSopenharmony_ci } else if (eventType == NODE_ON_MOUSE) { 45823b3eb3cSopenharmony_ci uiEvent.inputType = ARKUI_UIINPUTEVENT_TYPE_MOUSE; 45923b3eb3cSopenharmony_ci uiEvent.eventTypeId = C_MOUSE_EVENT_ID; 46023b3eb3cSopenharmony_ci uiEvent.inputEvent = &(innerEvent->mouseEvent); 46123b3eb3cSopenharmony_ci event.origin = &uiEvent; 46223b3eb3cSopenharmony_ci } else { 46323b3eb3cSopenharmony_ci event.origin = innerEvent; 46423b3eb3cSopenharmony_ci } 46523b3eb3cSopenharmony_ci HandleNodeEvent(&event); 46623b3eb3cSopenharmony_ci } 46723b3eb3cSopenharmony_ci if (g_compatibleEventReceiver) { 46823b3eb3cSopenharmony_ci ArkUI_CompatibleNodeEvent event; 46923b3eb3cSopenharmony_ci event.node = nodePtr; 47023b3eb3cSopenharmony_ci event.eventId = innerEventExtraParam->second->targetId; 47123b3eb3cSopenharmony_ci if (ConvertEvent(innerEvent, &event)) { 47223b3eb3cSopenharmony_ci g_compatibleEventReceiver(&event); 47323b3eb3cSopenharmony_ci ConvertEventResult(&event, innerEvent); 47423b3eb3cSopenharmony_ci } 47523b3eb3cSopenharmony_ci } 47623b3eb3cSopenharmony_ci} 47723b3eb3cSopenharmony_ci 47823b3eb3cSopenharmony_ciint32_t GetNativeNodeEventType(ArkUINodeEvent* innerEvent) 47923b3eb3cSopenharmony_ci{ 48023b3eb3cSopenharmony_ci int32_t invalidType = -1; 48123b3eb3cSopenharmony_ci auto* nodePtr = reinterpret_cast<ArkUI_NodeHandle>(innerEvent->extraParam); 48223b3eb3cSopenharmony_ci if (!nodePtr || g_nodeSet.count(nodePtr) == 0) { 48323b3eb3cSopenharmony_ci return invalidType; 48423b3eb3cSopenharmony_ci } 48523b3eb3cSopenharmony_ci if (!nodePtr->extraData) { 48623b3eb3cSopenharmony_ci return invalidType; 48723b3eb3cSopenharmony_ci } 48823b3eb3cSopenharmony_ci auto extraData = reinterpret_cast<ExtraData*>(nodePtr->extraData); 48923b3eb3cSopenharmony_ci ArkUIEventSubKind subKind = static_cast<ArkUIEventSubKind>(-1); 49023b3eb3cSopenharmony_ci switch (innerEvent->kind) { 49123b3eb3cSopenharmony_ci case COMPONENT_ASYNC_EVENT: 49223b3eb3cSopenharmony_ci subKind = static_cast<ArkUIEventSubKind>(innerEvent->componentAsyncEvent.subKind); 49323b3eb3cSopenharmony_ci break; 49423b3eb3cSopenharmony_ci case TEXT_INPUT: 49523b3eb3cSopenharmony_ci subKind = static_cast<ArkUIEventSubKind>(innerEvent->textInputEvent.subKind); 49623b3eb3cSopenharmony_ci break; 49723b3eb3cSopenharmony_ci case TOUCH_EVENT: 49823b3eb3cSopenharmony_ci subKind = static_cast<ArkUIEventSubKind>(innerEvent->touchEvent.subKind); 49923b3eb3cSopenharmony_ci break; 50023b3eb3cSopenharmony_ci case MOUSE_INPUT_EVENT: 50123b3eb3cSopenharmony_ci subKind = static_cast<ArkUIEventSubKind>(innerEvent->mouseEvent.subKind); 50223b3eb3cSopenharmony_ci break; 50323b3eb3cSopenharmony_ci case MIXED_EVENT: 50423b3eb3cSopenharmony_ci subKind = static_cast<ArkUIEventSubKind>(innerEvent->mixedEvent.subKind); 50523b3eb3cSopenharmony_ci break; 50623b3eb3cSopenharmony_ci case DRAG_EVENT: 50723b3eb3cSopenharmony_ci subKind = static_cast<ArkUIEventSubKind>(innerEvent->dragEvent.subKind); 50823b3eb3cSopenharmony_ci break; 50923b3eb3cSopenharmony_ci default: 51023b3eb3cSopenharmony_ci break; /* Empty */ 51123b3eb3cSopenharmony_ci } 51223b3eb3cSopenharmony_ci ArkUI_NodeEventType eventType = static_cast<ArkUI_NodeEventType>(ConvertToNodeEventType(subKind)); 51323b3eb3cSopenharmony_ci auto innerEventExtraParam = extraData->eventMap.find(eventType); 51423b3eb3cSopenharmony_ci if (innerEventExtraParam == extraData->eventMap.end()) { 51523b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "the event of %{public}d is not register", eventType); 51623b3eb3cSopenharmony_ci return invalidType; 51723b3eb3cSopenharmony_ci } 51823b3eb3cSopenharmony_ci return static_cast<int32_t>(eventType); 51923b3eb3cSopenharmony_ci} 52023b3eb3cSopenharmony_ci 52123b3eb3cSopenharmony_civoid HandleNodeEvent(ArkUI_NodeEvent* event) 52223b3eb3cSopenharmony_ci{ 52323b3eb3cSopenharmony_ci if (!event) { 52423b3eb3cSopenharmony_ci return; 52523b3eb3cSopenharmony_ci } 52623b3eb3cSopenharmony_ci if (event->node && event->node->eventListeners) { 52723b3eb3cSopenharmony_ci auto eventListenersSet = reinterpret_cast<std::set<void (*)(ArkUI_NodeEvent*)>*>(event->node->eventListeners); 52823b3eb3cSopenharmony_ci TriggerNodeEvent(event, eventListenersSet); 52923b3eb3cSopenharmony_ci } 53023b3eb3cSopenharmony_ci if (g_eventReceiver) { 53123b3eb3cSopenharmony_ci g_eventReceiver(event); 53223b3eb3cSopenharmony_ci } 53323b3eb3cSopenharmony_ci} 53423b3eb3cSopenharmony_ci 53523b3eb3cSopenharmony_civoid TriggerNodeEvent(ArkUI_NodeEvent* event, std::set<void (*)(ArkUI_NodeEvent*)>* eventListenersSet) 53623b3eb3cSopenharmony_ci{ 53723b3eb3cSopenharmony_ci if (!eventListenersSet) { 53823b3eb3cSopenharmony_ci return; 53923b3eb3cSopenharmony_ci } 54023b3eb3cSopenharmony_ci if (eventListenersSet->size() == 1) { 54123b3eb3cSopenharmony_ci auto eventListener = eventListenersSet->begin(); 54223b3eb3cSopenharmony_ci (*eventListener)(event); 54323b3eb3cSopenharmony_ci } else if (eventListenersSet->size() > 1) { 54423b3eb3cSopenharmony_ci for (const auto& eventListener : *eventListenersSet) { 54523b3eb3cSopenharmony_ci (*eventListener)(event); 54623b3eb3cSopenharmony_ci if (!IsValidArkUINode(event->node)) { 54723b3eb3cSopenharmony_ci break; 54823b3eb3cSopenharmony_ci } 54923b3eb3cSopenharmony_ci } 55023b3eb3cSopenharmony_ci } 55123b3eb3cSopenharmony_ci} 55223b3eb3cSopenharmony_ci 55323b3eb3cSopenharmony_ciint32_t CheckEvent(ArkUI_NodeEvent* event) 55423b3eb3cSopenharmony_ci{ 55523b3eb3cSopenharmony_ci return 0; 55623b3eb3cSopenharmony_ci} 55723b3eb3cSopenharmony_ci 55823b3eb3cSopenharmony_ciint32_t SetUserData(ArkUI_NodeHandle node, void* userData) 55923b3eb3cSopenharmony_ci{ 56023b3eb3cSopenharmony_ci if (!node) { 56123b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 56223b3eb3cSopenharmony_ci } 56323b3eb3cSopenharmony_ci if (!userData) { 56423b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 56523b3eb3cSopenharmony_ci } 56623b3eb3cSopenharmony_ci node->userData = userData; 56723b3eb3cSopenharmony_ci return ERROR_CODE_NO_ERROR; 56823b3eb3cSopenharmony_ci} 56923b3eb3cSopenharmony_ci 57023b3eb3cSopenharmony_civoid* GetUserData(ArkUI_NodeHandle node) 57123b3eb3cSopenharmony_ci{ 57223b3eb3cSopenharmony_ci return node->userData; 57323b3eb3cSopenharmony_ci} 57423b3eb3cSopenharmony_ci 57523b3eb3cSopenharmony_ciint32_t SetLengthMetricUnit(ArkUI_NodeHandle nodePtr, ArkUI_LengthMetricUnit unit) 57623b3eb3cSopenharmony_ci{ 57723b3eb3cSopenharmony_ci if (!nodePtr) { 57823b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 57923b3eb3cSopenharmony_ci } 58023b3eb3cSopenharmony_ci if (!InRegion(static_cast<int32_t>(ARKUI_LENGTH_METRIC_UNIT_DEFAULT), 58123b3eb3cSopenharmony_ci static_cast<int32_t>(ARKUI_LENGTH_METRIC_UNIT_FP), static_cast<int32_t>(unit))) { 58223b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 58323b3eb3cSopenharmony_ci } 58423b3eb3cSopenharmony_ci nodePtr->lengthMetricUnit = unit; 58523b3eb3cSopenharmony_ci return ERROR_CODE_NO_ERROR; 58623b3eb3cSopenharmony_ci} 58723b3eb3cSopenharmony_ci 58823b3eb3cSopenharmony_civoid ApplyModifierFinish(ArkUI_NodeHandle nodePtr) 58923b3eb3cSopenharmony_ci{ 59023b3eb3cSopenharmony_ci // already check in entry point. 59123b3eb3cSopenharmony_ci if (!nodePtr) { 59223b3eb3cSopenharmony_ci return; 59323b3eb3cSopenharmony_ci } 59423b3eb3cSopenharmony_ci auto* impl = GetFullImpl(); 59523b3eb3cSopenharmony_ci impl->getBasicAPI()->applyModifierFinish(nodePtr->uiNodeHandle); 59623b3eb3cSopenharmony_ci} 59723b3eb3cSopenharmony_ci 59823b3eb3cSopenharmony_civoid MarkDirty(ArkUI_NodeHandle nodePtr, ArkUI_NodeDirtyFlag dirtyFlag) 59923b3eb3cSopenharmony_ci{ 60023b3eb3cSopenharmony_ci // spanNode inherited from UINode 60123b3eb3cSopenharmony_ci if (!nodePtr) { 60223b3eb3cSopenharmony_ci return; 60323b3eb3cSopenharmony_ci } 60423b3eb3cSopenharmony_ci ArkUIDirtyFlag flag = ARKUI_DIRTY_FLAG_MEASURE; 60523b3eb3cSopenharmony_ci switch (dirtyFlag) { 60623b3eb3cSopenharmony_ci case NODE_NEED_MEASURE: { 60723b3eb3cSopenharmony_ci flag = ARKUI_DIRTY_FLAG_MEASURE_SELF_AND_PARENT; 60823b3eb3cSopenharmony_ci break; 60923b3eb3cSopenharmony_ci } 61023b3eb3cSopenharmony_ci case NODE_NEED_LAYOUT: { 61123b3eb3cSopenharmony_ci flag = ARKUI_DIRTY_FLAG_LAYOUT; 61223b3eb3cSopenharmony_ci break; 61323b3eb3cSopenharmony_ci } 61423b3eb3cSopenharmony_ci case NODE_NEED_RENDER: { 61523b3eb3cSopenharmony_ci flag = ARKUI_DIRTY_FLAG_RENDER; 61623b3eb3cSopenharmony_ci break; 61723b3eb3cSopenharmony_ci } 61823b3eb3cSopenharmony_ci default: { 61923b3eb3cSopenharmony_ci flag = ARKUI_DIRTY_FLAG_MEASURE; 62023b3eb3cSopenharmony_ci } 62123b3eb3cSopenharmony_ci } 62223b3eb3cSopenharmony_ci // already check in entry point. 62323b3eb3cSopenharmony_ci auto* impl = GetFullImpl(); 62423b3eb3cSopenharmony_ci impl->getBasicAPI()->markDirty(nodePtr->uiNodeHandle, flag); 62523b3eb3cSopenharmony_ci} 62623b3eb3cSopenharmony_ci 62723b3eb3cSopenharmony_ciint32_t AddNodeEventReceiver(ArkUI_NodeHandle nodePtr, void (*eventReceiver)(ArkUI_NodeEvent* event)) 62823b3eb3cSopenharmony_ci{ 62923b3eb3cSopenharmony_ci if (!nodePtr || !eventReceiver) { 63023b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 63123b3eb3cSopenharmony_ci } 63223b3eb3cSopenharmony_ci if (!nodePtr->eventListeners) { 63323b3eb3cSopenharmony_ci nodePtr->eventListeners = new std::set<void (*)(ArkUI_NodeEvent*)>(); 63423b3eb3cSopenharmony_ci } 63523b3eb3cSopenharmony_ci auto eventListenersSet = reinterpret_cast<std::set<void (*)(ArkUI_NodeEvent*)>*>(nodePtr->eventListeners); 63623b3eb3cSopenharmony_ci if (!eventListenersSet) { 63723b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 63823b3eb3cSopenharmony_ci } 63923b3eb3cSopenharmony_ci eventListenersSet->emplace(eventReceiver); 64023b3eb3cSopenharmony_ci return ERROR_CODE_NO_ERROR; 64123b3eb3cSopenharmony_ci} 64223b3eb3cSopenharmony_ci 64323b3eb3cSopenharmony_ciint32_t RemoveNodeEventReceiver(ArkUI_NodeHandle nodePtr, void (*eventReceiver)(ArkUI_NodeEvent* event)) 64423b3eb3cSopenharmony_ci{ 64523b3eb3cSopenharmony_ci if (!nodePtr || !eventReceiver || !nodePtr->eventListeners) { 64623b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 64723b3eb3cSopenharmony_ci } 64823b3eb3cSopenharmony_ci auto eventListenersSet = reinterpret_cast<std::set<void (*)(ArkUI_NodeEvent*)>*>(nodePtr->eventListeners); 64923b3eb3cSopenharmony_ci if (!eventListenersSet) { 65023b3eb3cSopenharmony_ci return ERROR_CODE_PARAM_INVALID; 65123b3eb3cSopenharmony_ci } 65223b3eb3cSopenharmony_ci eventListenersSet->erase(eventReceiver); 65323b3eb3cSopenharmony_ci if (eventListenersSet->empty()) { 65423b3eb3cSopenharmony_ci delete eventListenersSet; 65523b3eb3cSopenharmony_ci nodePtr->eventListeners = nullptr; 65623b3eb3cSopenharmony_ci } 65723b3eb3cSopenharmony_ci return ERROR_CODE_NO_ERROR; 65823b3eb3cSopenharmony_ci} 65923b3eb3cSopenharmony_ci 66023b3eb3cSopenharmony_civoid* GetParseJsMedia() 66123b3eb3cSopenharmony_ci{ 66223b3eb3cSopenharmony_ci void* module = FindModule(); 66323b3eb3cSopenharmony_ci if (!module) { 66423b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "fail to get module"); 66523b3eb3cSopenharmony_ci return nullptr; 66623b3eb3cSopenharmony_ci } 66723b3eb3cSopenharmony_ci void (*parseJsMedia)(void* value, void* resource) = nullptr; 66823b3eb3cSopenharmony_ci parseJsMedia = reinterpret_cast<void (*)(void*, void*)>( 66923b3eb3cSopenharmony_ci FindFunction(module, "OHOS_ACE_ParseJsMedia")); 67023b3eb3cSopenharmony_ci if (!parseJsMedia) { 67123b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "Cannot find OHOS_ACE_ParseJsMedia"); 67223b3eb3cSopenharmony_ci return nullptr; 67323b3eb3cSopenharmony_ci } 67423b3eb3cSopenharmony_ci return reinterpret_cast<void*>(parseJsMedia); 67523b3eb3cSopenharmony_ci} 67623b3eb3cSopenharmony_ci} // namespace OHOS::Ace::NodeModel 67723b3eb3cSopenharmony_ci 67823b3eb3cSopenharmony_ci#ifdef __cplusplus 67923b3eb3cSopenharmony_ciextern "C" { 68023b3eb3cSopenharmony_ci#endif 68123b3eb3cSopenharmony_ci 68223b3eb3cSopenharmony_ciint32_t OH_ArkUI_NodeContent_AddNode(ArkUI_NodeContentHandle content, ArkUI_NodeHandle node) 68323b3eb3cSopenharmony_ci{ 68423b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 68523b3eb3cSopenharmony_ci CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_NATIVE_IMPL_LIBRARY_NOT_FOUND); 68623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(node, OHOS::Ace::ERROR_CODE_PARAM_INVALID); 68723b3eb3cSopenharmony_ci return impl->getNodeModifiers()->getNodeContentModifier()->addChild( 68823b3eb3cSopenharmony_ci reinterpret_cast<ArkUINodeContentHandle>(content), node->uiNodeHandle); 68923b3eb3cSopenharmony_ci} 69023b3eb3cSopenharmony_ci 69123b3eb3cSopenharmony_ciint32_t OH_ArkUI_NodeContent_InsertNode(ArkUI_NodeContentHandle content, ArkUI_NodeHandle node, int32_t position) 69223b3eb3cSopenharmony_ci{ 69323b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 69423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_NATIVE_IMPL_LIBRARY_NOT_FOUND); 69523b3eb3cSopenharmony_ci CHECK_NULL_RETURN(node, OHOS::Ace::ERROR_CODE_PARAM_INVALID); 69623b3eb3cSopenharmony_ci return impl->getNodeModifiers()->getNodeContentModifier()->insertChild( 69723b3eb3cSopenharmony_ci reinterpret_cast<ArkUINodeContentHandle>(content), node->uiNodeHandle, position); 69823b3eb3cSopenharmony_ci} 69923b3eb3cSopenharmony_ci 70023b3eb3cSopenharmony_ciint32_t OH_ArkUI_NodeContent_RemoveNode(ArkUI_NodeContentHandle content, ArkUI_NodeHandle node) 70123b3eb3cSopenharmony_ci{ 70223b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 70323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_NATIVE_IMPL_LIBRARY_NOT_FOUND); 70423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(node, OHOS::Ace::ERROR_CODE_PARAM_INVALID); 70523b3eb3cSopenharmony_ci return impl->getNodeModifiers()->getNodeContentModifier()->removeChild( 70623b3eb3cSopenharmony_ci reinterpret_cast<ArkUINodeContentHandle>(content), node->uiNodeHandle); 70723b3eb3cSopenharmony_ci} 70823b3eb3cSopenharmony_ci 70923b3eb3cSopenharmony_ciint32_t OH_ArkUI_NodeContent_RegisterCallback(ArkUI_NodeContentHandle content, ArkUI_NodeContentCallback callback) 71023b3eb3cSopenharmony_ci{ 71123b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 71223b3eb3cSopenharmony_ci CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_NATIVE_IMPL_LIBRARY_NOT_FOUND); 71323b3eb3cSopenharmony_ci auto innerCallback = reinterpret_cast<void (*)(ArkUINodeContentEvent* event)>(callback); 71423b3eb3cSopenharmony_ci return impl->getNodeModifiers()->getNodeContentModifier()->registerEvent( 71523b3eb3cSopenharmony_ci reinterpret_cast<ArkUINodeContentHandle>(content), nullptr, innerCallback); 71623b3eb3cSopenharmony_ci} 71723b3eb3cSopenharmony_ci 71823b3eb3cSopenharmony_ciArkUI_NodeContentEventType OH_ArkUI_NodeContentEvent_GetEventType(ArkUI_NodeContentEvent* event) 71923b3eb3cSopenharmony_ci{ 72023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(event, static_cast<ArkUI_NodeContentEventType>(-1)); 72123b3eb3cSopenharmony_ci auto* innerEvent = reinterpret_cast<ArkUINodeContentEvent*>(event); 72223b3eb3cSopenharmony_ci return static_cast<ArkUI_NodeContentEventType>(innerEvent->type); 72323b3eb3cSopenharmony_ci} 72423b3eb3cSopenharmony_ci 72523b3eb3cSopenharmony_ciArkUI_NodeContentHandle OH_ArkUI_NodeContentEvent_GetNodeContentHandle(ArkUI_NodeContentEvent* event) 72623b3eb3cSopenharmony_ci{ 72723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(event, nullptr); 72823b3eb3cSopenharmony_ci auto* innerEvent = reinterpret_cast<ArkUINodeContentEvent*>(event); 72923b3eb3cSopenharmony_ci return reinterpret_cast<ArkUI_NodeContentHandle>(innerEvent->nodeContent); 73023b3eb3cSopenharmony_ci} 73123b3eb3cSopenharmony_ci 73223b3eb3cSopenharmony_ciint32_t OH_ArkUI_NodeContent_SetUserData(ArkUI_NodeContentHandle content, void* userData) 73323b3eb3cSopenharmony_ci{ 73423b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 73523b3eb3cSopenharmony_ci CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_NATIVE_IMPL_LIBRARY_NOT_FOUND); 73623b3eb3cSopenharmony_ci return impl->getNodeModifiers()->getNodeContentModifier()->setUserData( 73723b3eb3cSopenharmony_ci reinterpret_cast<ArkUINodeContentHandle>(content), userData); 73823b3eb3cSopenharmony_ci} 73923b3eb3cSopenharmony_ci 74023b3eb3cSopenharmony_civoid* OH_ArkUI_NodeContent_GetUserData(ArkUI_NodeContentHandle content) 74123b3eb3cSopenharmony_ci{ 74223b3eb3cSopenharmony_ci auto* impl = OHOS::Ace::NodeModel::GetFullImpl(); 74323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(impl, nullptr); 74423b3eb3cSopenharmony_ci return impl->getNodeModifiers()->getNodeContentModifier()->getUserData( 74523b3eb3cSopenharmony_ci reinterpret_cast<ArkUINodeContentHandle>(content)); 74623b3eb3cSopenharmony_ci} 74723b3eb3cSopenharmony_ci 74823b3eb3cSopenharmony_ci#ifdef __cplusplus 74923b3eb3cSopenharmony_ci}; 75023b3eb3cSopenharmony_ci#endif 751