自定义属性和遍历树能力加强代码

Signed-off-by: zoulinken <zoulinken1@huawei.com>
This commit is contained in:
zoulinken 2024-11-06 18:08:34 +08:00
parent c88cdb74cd
commit 5a9ce8fdb6
16 changed files with 508 additions and 58 deletions

View File

@ -5964,4 +5964,27 @@ bool FrameNode::IsDebugInspectorId()
auto debugInspectorId = SystemProperties::GetDebugInspectorId();
return debugInspectorId == GetInspectorId().value_or("");
}
RefPtr<UINode> FrameNode::GetCurrentPageRootNode()
{
auto pageNode = GetPageNode();
CHECK_NULL_RETURN(pageNode, nullptr);
auto jsView = pageNode->GetChildAtIndex(0);
CHECK_NULL_RETURN(jsView, nullptr);
auto rootNode = jsView->GetChildAtIndex(0);
CHECK_NULL_RETURN(rootNode, nullptr);
return rootNode;
}
std::list<RefPtr<FrameNode>> FrameNode::GetActiveChildren()
{
std::list<RefPtr<FrameNode>> list;
for (int32_t i = 0; i < TotalChildCount(); i++) {
auto child = GetFrameNodeChildByIndex(i, false, false);
if (child->IsActive()) {
list.emplace_back(Referenced::Claim(child));
}
}
return list;
}
} // namespace OHOS::Ace::NG

View File

@ -1130,6 +1130,10 @@ public:
return exposeInnerGestureFlag_;
}
RefPtr<UINode> GetCurrentPageRootNode();
std::list<RefPtr<FrameNode>> GetActiveChildren();
protected:
void DumpInfo() override;
std::unordered_map<std::string, std::function<void()>> destroyCallbacksMap_;

View File

@ -4391,7 +4391,7 @@ Alignment ViewAbstract::GetAlign(FrameNode *frameNode)
Dimension ViewAbstract::GetWidth(FrameNode* frameNode)
{
Dimension value = Dimension(-1.0f);
Dimension value = Dimension(0.0f);
const auto& layoutProperty = frameNode->GetLayoutProperty();
CHECK_NULL_RETURN(layoutProperty, value);
const auto& property = layoutProperty->GetCalcLayoutConstraint();
@ -4408,7 +4408,7 @@ Dimension ViewAbstract::GetWidth(FrameNode* frameNode)
Dimension ViewAbstract::GetHeight(FrameNode* frameNode)
{
Dimension value = Dimension(-1.0f);
Dimension value = Dimension(0.0f);
const auto& layoutProperty = frameNode->GetLayoutProperty();
CHECK_NULL_RETURN(layoutProperty, value);
const auto& property = layoutProperty->GetCalcLayoutConstraint();

View File

@ -4872,6 +4872,10 @@ struct ArkUIFrameNodeModifier {
void (*addCustomProperty)(ArkUINodeHandle node, ArkUI_CharPtr key, ArkUI_CharPtr value);
void (*removeCustomProperty)(ArkUINodeHandle node, ArkUI_CharPtr key);
void (*freeCustomPropertyCharPtr)(char* value, ArkUI_Uint32 size);
ArkUINodeHandle (*getCurrentPageRootNode)(ArkUINodeHandle node);
ArkUI_Int32 (*getNodeTag)(ArkUINodeHandle node);
void (*getActiveChildrenInfo)(ArkUINodeHandle handle, ArkUINodeHandle** items, ArkUI_Uint32* size);
void (*getCustomProperty)(ArkUINodeHandle node, ArkUI_CharPtr key, char** value);
};
struct ArkUINodeContentEvent {

View File

@ -57,9 +57,8 @@ RefPtr<FrameNode> GetParentNode(UINode* node)
while (parent != nullptr && !AceType::InstanceOf<FrameNode>(parent)) {
parent = parent->GetParent();
}
return (parent == nullptr || parent->GetTag() == "page" || parent->GetTag() == "stage")
? nullptr
: AceType::DynamicCast<FrameNode>(parent);
return (parent == nullptr || parent->GetTag() == V2::PAGE_ETS_TAG || parent->GetTag() == V2::STAGE_ETS_TAG)
? nullptr : AceType::DynamicCast<FrameNode>(parent);
}
ArkUI_Bool AppendChildInFrameNode(ArkUINodeHandle node, ArkUINodeHandle child)
@ -548,6 +547,50 @@ void RemoveCustomProperty(ArkUINodeHandle node, ArkUI_CharPtr key)
ViewAbstract::RemoveCustomProperty(frameNode, key);
}
ArkUINodeHandle GetCurrentPageRootNode(ArkUINodeHandle node)
{
auto frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_RETURN(frameNode, nullptr);
auto rootNode = frameNode->GetCurrentPageRootNode();
return reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(rootNode));
}
ArkUI_Int32 GetNodeTag(ArkUINodeHandle node)
{
auto uiNode = reinterpret_cast<UINode*>(node);
CHECK_NULL_RETURN(uiNode, 0);
return uiNode->IsCNode();
}
void GetActiveChildrenInfo(ArkUINodeHandle handle, ArkUINodeHandle** items, ArkUI_Uint32* size)
{
auto* frameNode = reinterpret_cast<FrameNode*>(handle);
CHECK_NULL_VOID(frameNode);
auto childList = frameNode->GetActiveChildren();
*size = childList.size();
*items = new ArkUINodeHandle[*size];
int i = 0;
for (auto& child : childList) {
(*items)[i++] = reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(child));
}
}
void GetCustomProperty(ArkUINodeHandle node, ArkUI_CharPtr key, char** value)
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
std::string capiCustomProperty;
if (frameNode->IsCNode()) {
frameNode->GetCapiCustomProperty(key, capiCustomProperty);
} else {
frameNode->GetJSCustomProperty(key, capiCustomProperty);
}
auto size = capiCustomProperty.size();
*value = new char[size + 1];
capiCustomProperty.copy(*value, size);
(*value)[size] = '\0';
}
namespace NodeModifier {
const ArkUIFrameNodeModifier* GetFrameNodeModifier()
{
@ -560,7 +603,8 @@ const ArkUIFrameNodeModifier* GetFrameNodeModifier()
GetFrameNodeByKey, GetAttachedFrameNodeById, PropertyUpdate, GetLast, GetFirstUINode, GetLayoutSize,
GetLayoutPositionWithoutMargin, SetSystemColorModeChangeEvent, ResetSystemColorModeChangeEvent,
SetSystemFontStyleChangeEvent, ResetSystemFontStyleChangeEvent, GetCustomPropertyCapiByKey,
SetCustomPropertyModiferByKey, AddCustomProperty, RemoveCustomProperty, FreeCustomPropertyCharPtr };
SetCustomPropertyModiferByKey, AddCustomProperty, RemoveCustomProperty, FreeCustomPropertyCharPtr,
GetCurrentPageRootNode, GetNodeTag, GetActiveChildrenInfo, GetCustomProperty };
return &modifier;
}

View File

@ -55,6 +55,7 @@ ohos_shared_library("ace_ndk") {
"//foundation/arkui/ace_engine/frameworks/core/accessibility/native_interface_accessibility_provider.cpp",
"//foundation/arkui/ace_engine/frameworks/core/components/common/properties/color.cpp",
"//foundation/arkui/ace_engine/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.cpp",
"//foundation/arkui/ace_engine/frameworks/core/components_v2/inspector/inspector_constants.cpp",
"event/drag_and_drop_impl.cpp",
"event/key_event_impl.cpp",
"event/ui_input_event.cpp",

View File

@ -1427,6 +1427,50 @@
"first_introduced": "13",
"name": "OH_ArkUI_NodeUtils_RemoveCustomProperty"
},
{
"first_introduced": "14",
"name": "OH_ArkUI_NodeUtils_GetCustomProperty"
},
{
"first_introduced": "14",
"name": "OH_ArkUI_CustomProperty_Destroy"
},
{
"first_introduced": "14",
"name": "OH_ArkUI_CustomProperty_GetStringValue"
},
{
"first_introduced": "14",
"name": "OH_ArkUI_NodeUtils_GetParentInPageTree"
},
{
"first_introduced": "14",
"name": "OH_ArkUI_NodeUtils_GetActiveChildrenInfo"
},
{
"first_introduced": "14",
"name": "OH_ArkUI_NodeUtils_GetCurrentPageRootNode"
},
{
"first_introduced": "14",
"name": "OH_ArkUI_NodeUtils_IsCreatedByNDK"
},
{
"first_introduced": "14",
"name": "OH_ArkUI_NodeUtils_GetNodeType"
},
{
"first_introduced": "14",
"name": "OH_ArkUI_ActiveChildrenInfo_Destroy"
},
{
"first_introduced": "14",
"name": "OH_ArkUI_ActiveChildrenInfo_GetNodeByIndex"
},
{
"first_introduced": "14",
"name": "OH_ArkUI_ActiveChildrenInfo_GetCount"
},
{
"first_introduced": "12",
"name": "OH_ArkUI_ListChildrenMainSizeOption_Create"

View File

@ -7452,6 +7452,69 @@ void OH_ArkUI_NodeUtils_AddCustomProperty(ArkUI_NodeHandle node, const char* nam
*/
void OH_ArkUI_NodeUtils_RemoveCustomProperty(ArkUI_NodeHandle node, const char* name);
/**
* @brief Get the value of the custom property of the component.
*
* @param node ArkUI-NodeHandle pointer.
* @param name The name of the custom attribute.
* @param handle The structure of the custom attribute corresponding to the key parameter name obtained.
* @return Error code.
* {@link ARKUI_ERROR_CODE_NO_ERROR} success.
* {@link ARKUI_ERROR_CODE_PARAM_INVALID} Function parameter exception.
* @since 14
*/
int32_t OH_ArkUI_NodeUtils_GetCustomProperty(ArkUI_NodeHandle node, const char* name, ArkUI_CustomProperty** handle);
/**
* @brief Get the parent node to obtain the component nodes created by ArkTs.
*
* @param node Target node object.
* @return Return the pointer of the component.
* @since 14
*/
ArkUI_NodeHandle OH_ArkUI_NodeUtils_GetParentInPageTree(ArkUI_NodeHandle node);
/**
* @brief Retrieve all active child nodes of a node.
*
* @param head Pass in the node that needs to be obtained.
* @param handle The structure corresponding to the sub node information of the head node.
* @return Error code.
* {@link ARKUI_ERROR_CODE_NO_ERROR} success.
* {@link ARKUI_ERROR_CODE_PARAM_INVALID} Function parameter exception.
* @since 14
*/
int32_t OH_ArkUI_NodeUtils_GetActiveChildrenInfo(ArkUI_NodeHandle head, ArkUI_ActiveChildrenInfo** handle);
/**
* @brief Retrieve the root node of the current page.
*
* @param node Target node object.
* @return Return the pointer of the component.
* @since 14
*/
ArkUI_NodeHandle OH_ArkUI_NodeUtils_GetCurrentPageRootNode(ArkUI_NodeHandle node);
/**
* @brief Retrieve whether the component is labeled by C-API.
*
* @param node Target node object.
* @return Return whether the node is a Tag created by C-API,
* true represents created by C-API, false represents not created by C-API.
* @since 14
*/
bool OH_ArkUI_NodeUtils_IsCreatedByNDK(ArkUI_NodeHandle node);
/**
* @brief Get the type of node.
*
* @param node Target node object.
* @return Return the type of the node.
* For specific open types, refer to {@link ArkUI_NodeType}. For unopened nodes, return -1.
* @since 14
*/
int32_t OH_ArkUI_NodeUtils_GetNodeType(ArkUI_NodeHandle node);
/**
* @brief The event called when the sliding operation offset changes.
*

View File

@ -189,6 +189,20 @@ typedef struct ArkUI_ImageAnimatorFrameInfo ArkUI_ImageAnimatorFrameInfo;
*/
typedef struct ArkUI_ListChildrenMainSize ArkUI_ListChildrenMainSize;
/**
* @brief Define the information of the Custom Property class for custom properties.
*
* @since 14
*/
struct ArkUI_CustomProperty;
/**
* @brief Define ActiveChildenInfo class information.
*
* @since 14
*/
struct ArkUI_ActiveChildrenInfo;
/**
* @brief Provides the number types of ArkUI in the native code.
*
@ -3747,6 +3761,49 @@ float OH_ArkUI_CustomSpanDrawInfo_GetLineBottom(ArkUI_CustomSpanDrawInfo* info);
* @since 12
*/
float OH_ArkUI_CustomSpanDrawInfo_GetBaseline(ArkUI_CustomSpanDrawInfo* info);
/**
* @brief Destroy the instance of Customs Property.
*
* @param handle The instance of Customs Property to be destroyed.
* @since 14
*/
void OH_ArkUI_CustomProperty_Destroy(ArkUI_CustomProperty* handle);
/**
* @brief Get custom attribute value information.
*
* @param handle Custom attribute object pointer.
* @return Customize the value information within the attribute structure.
* @since 14
*/
const char* OH_ArkUI_CustomProperty_GetStringValue(ArkUI_CustomProperty* handle);
/**
* @brief Destroy ActiveChildenInfo instance.
*
* @param handle ActiveChild instance to be destroyed.
* @since 14
*/
void OH_ArkUI_ActiveChildrenInfo_Destroy(ArkUI_ActiveChildrenInfo* handle);
/**
* @brief Retrieve the child nodes of ActiveChildenInfo with the structure index.
*
* @param handle The ActiveChildenInfo instance for obtaining information.
* @return The child node pointer corresponding to the index. Return nullptr in case of exception
* @since 14
*/
ArkUI_NodeHandle OH_ArkUI_ActiveChildrenInfo_GetNodeByIndex(ArkUI_ActiveChildrenInfo* handle, int32_t index);
/**
* @brief Retrieve the number of nodes within the structure of ActiveChildenInfo.
*
* @param handle The ActiveChildenInfo instance for obtaining information.
* @return Number of child nodes. Default value:0.
* @since 14
*/
int32_t OH_ArkUI_ActiveChildrenInfo_GetCount(ArkUI_ActiveChildrenInfo* handle);
#ifdef __cplusplus
};
#endif

View File

@ -45,7 +45,10 @@ int32_t OH_ArkUI_GetNodeHandleFromNapiValue(napi_env env, napi_value value, ArkU
}
auto* uiNodePtr = reinterpret_cast<OHOS::Ace::NG::UINode*>(nativePtr);
uiNodePtr->IncRefCount();
*handle = new ArkUI_Node({ .type = -1, .uiNodeHandle = reinterpret_cast<ArkUINodeHandle>(nativePtr) });
*handle = new ArkUI_Node({ .type = -1,
.uiNodeHandle = reinterpret_cast<ArkUINodeHandle>(nativePtr),
.cNode = false,
.buildNode = true });
if (impl) {
impl->getExtendedAPI()->setAttachNodePtr((*handle)->uiNodeHandle, reinterpret_cast<void*>(*handle));
}
@ -92,7 +95,10 @@ int32_t OH_ArkUI_GetNodeHandleFromNapiValue(napi_env env, napi_value value, ArkU
frameNode = reinterpret_cast<OHOS::Ace::NG::FrameNode*>(child);
}
frameNode->IncRefCount();
*handle = new ArkUI_Node({ .type = -1, .uiNodeHandle = reinterpret_cast<ArkUINodeHandle>(frameNode) });
*handle = new ArkUI_Node({ .type = -1,
.uiNodeHandle = reinterpret_cast<ArkUINodeHandle>(frameNode),
.cNode = false,
.buildNode = true });
if (impl) {
impl->getExtendedAPI()->setAttachNodePtr((*handle)->uiNodeHandle, reinterpret_cast<void*>(*handle));
}

View File

@ -51,7 +51,7 @@ void NodeAddExtraData(ArkUI_NodeHandle node, ArkUI_NodeCustomEventType eventType
int32_t RegisterNodeCustomEvent(ArkUI_NodeHandle node, ArkUI_NodeCustomEventType eventType, int32_t targetId, void* userData)
{
if (!node) {
if (!node || !CheckIsCNode(node)) {
return ERROR_CODE_PARAM_INVALID;
}
if (eventType <= 0) {
@ -115,7 +115,7 @@ void NodeRemoveExtraData(ArkUI_NodeHandle node, ArkUI_NodeCustomEventType eventT
void UnregisterNodeCustomEvent(ArkUI_NodeHandle node, ArkUI_NodeCustomEventType eventType)
{
if (node == nullptr || !node->extraCustomData) {
if (node == nullptr || !node->extraCustomData || !CheckIsCNode(node)) {
return;
}
auto* impl = GetFullImpl();
@ -204,7 +204,7 @@ void HandleCustomEvent(ArkUI_NodeCustomEvent* event)
int32_t AddNodeCustomEventReceiver(ArkUI_NodeHandle nodePtr, void (*eventReceiver)(ArkUI_NodeCustomEvent* event))
{
if (!nodePtr || !eventReceiver) {
if (!nodePtr || !eventReceiver || !CheckIsCNode(nodePtr)) {
return ERROR_CODE_PARAM_INVALID;
}
if (!nodePtr->customEventListeners) {
@ -222,7 +222,7 @@ int32_t AddNodeCustomEventReceiver(ArkUI_NodeHandle nodePtr, void (*eventReceive
int32_t RemoveNodeCustomEventReceiver(ArkUI_NodeHandle nodePtr,
void (*eventReceiver)(ArkUI_NodeCustomEvent* event))
{
if (!nodePtr || !eventReceiver || !nodePtr->customEventListeners) {
if (!nodePtr || !eventReceiver || !nodePtr->customEventListeners || !CheckIsCNode(nodePtr)) {
return ERROR_CODE_PARAM_INVALID;
}
auto eventListenersSet = reinterpret_cast<std::set<void (*)(ArkUI_NodeCustomEvent*)>*>(
@ -240,7 +240,7 @@ int32_t RemoveNodeCustomEventReceiver(ArkUI_NodeHandle nodePtr,
int32_t SetMeasuredSize(ArkUI_NodeHandle node, int32_t width, int32_t height)
{
if (node == nullptr) {
if (node == nullptr || !CheckIsCNode(node)) {
return ERROR_CODE_PARAM_INVALID;
}
auto* impl = GetFullImpl();
@ -251,7 +251,7 @@ int32_t SetMeasuredSize(ArkUI_NodeHandle node, int32_t width, int32_t height)
int32_t SetLayoutPosition(ArkUI_NodeHandle node, int32_t positionX, int32_t positionY)
{
if (node == nullptr) {
if (node == nullptr || !CheckIsCNode(node)) {
return ERROR_CODE_PARAM_INVALID;
}
auto* impl = GetFullImpl();
@ -262,7 +262,7 @@ int32_t SetLayoutPosition(ArkUI_NodeHandle node, int32_t positionX, int32_t posi
int32_t GetLayoutConstraint(ArkUI_NodeHandle node, ArkUI_LayoutConstraint* layoutConstraint)
{
if (node == nullptr || layoutConstraint == nullptr) {
if (node == nullptr || layoutConstraint == nullptr || !CheckIsCNode(node)) {
return ERROR_CODE_PARAM_INVALID;
}
auto* impl = GetFullImpl();
@ -310,7 +310,7 @@ ArkUI_IntOffset GetLayoutPosition(ArkUI_NodeHandle node)
int32_t MeasureNode(ArkUI_NodeHandle node, ArkUI_LayoutConstraint* constraint)
{
if (node == nullptr || constraint == nullptr) {
if (node == nullptr || constraint == nullptr || !CheckIsCNode(node)) {
return ERROR_CODE_PARAM_INVALID;
}
auto* impl = GetFullImpl();
@ -334,7 +334,7 @@ int32_t MeasureNode(ArkUI_NodeHandle node, ArkUI_LayoutConstraint* constraint)
int32_t LayoutNode(ArkUI_NodeHandle node, int32_t positionX, int32_t positionY)
{
if (node == nullptr) {
if (node == nullptr || !CheckIsCNode(node)) {
return ERROR_CODE_PARAM_INVALID;
}
auto* impl = GetFullImpl();
@ -357,18 +357,27 @@ uint32_t GetTotalChildCount(ArkUI_NodeHandle node)
return impl->getNodeModifiers()->getFrameNodeModifier()->getChildrenCount(node->uiNodeHandle, true);
}
ArkUI_NodeHandle GetArkUINode(ArkUINodeHandle node)
{
CHECK_NULL_RETURN(node, nullptr);
const auto* impl = GetFullImpl();
void* attachNode = impl->getExtendedAPI()->getAttachNodePtr(node);
if (attachNode) {
return reinterpret_cast<ArkUI_NodeHandle>(attachNode);
}
ArkUI_Node* arkUINode = new ArkUI_Node({ 0, node, false });
impl->getExtendedAPI()->setAttachNodePtr((arkUINode)->uiNodeHandle, reinterpret_cast<void*>(arkUINode));
return reinterpret_cast<ArkUI_NodeHandle>(arkUINode);
}
ArkUI_NodeHandle GetChildAt(ArkUI_NodeHandle node, int32_t position)
{
if (node == nullptr) {
return nullptr;
}
auto* impl = GetFullImpl();
auto* value = impl->getNodeModifiers()->getFrameNodeModifier()->getChild(node->uiNodeHandle, position, true);
void* attachNode = impl->getExtendedAPI()->getAttachNodePtr(value);
if (attachNode) {
return reinterpret_cast<ArkUI_NodeHandle>(attachNode);
}
return nullptr;
auto* attachNode = impl->getNodeModifiers()->getFrameNodeModifier()->getChild(node->uiNodeHandle, position, true);
return GetArkUINode(attachNode);
}
ArkUI_NodeHandle GetFirstChild(ArkUI_NodeHandle node)
@ -377,12 +386,8 @@ ArkUI_NodeHandle GetFirstChild(ArkUI_NodeHandle node)
return nullptr;
}
auto* impl = GetFullImpl();
auto* value = impl->getNodeModifiers()->getFrameNodeModifier()->getFirst(node->uiNodeHandle, true);
void* attachNode = impl->getExtendedAPI()->getAttachNodePtr(value);
if (attachNode) {
return reinterpret_cast<ArkUI_NodeHandle>(attachNode);
}
return nullptr;
auto* attachNode = impl->getNodeModifiers()->getFrameNodeModifier()->getFirst(node->uiNodeHandle, true);
return GetArkUINode(attachNode);
}
ArkUI_NodeHandle GetLastChild(ArkUI_NodeHandle node)
@ -391,12 +396,8 @@ ArkUI_NodeHandle GetLastChild(ArkUI_NodeHandle node)
return nullptr;
}
auto* impl = GetFullImpl();
auto* value = impl->getNodeModifiers()->getFrameNodeModifier()->getLast(node->uiNodeHandle, true);
void* attachNode = impl->getExtendedAPI()->getAttachNodePtr(value);
if (attachNode) {
return reinterpret_cast<ArkUI_NodeHandle>(attachNode);
}
return nullptr;
auto* attachNode = impl->getNodeModifiers()->getFrameNodeModifier()->getLast(node->uiNodeHandle, true);
return GetArkUINode(attachNode);
}
ArkUI_NodeHandle GetPreviousSibling(ArkUI_NodeHandle node)
@ -405,12 +406,8 @@ ArkUI_NodeHandle GetPreviousSibling(ArkUI_NodeHandle node)
return nullptr;
}
auto* impl = GetFullImpl();
auto* value = impl->getNodeModifiers()->getFrameNodeModifier()->getPreviousSibling(node->uiNodeHandle, true);
void* attachNode = impl->getExtendedAPI()->getAttachNodePtr(value);
if (attachNode) {
return reinterpret_cast<ArkUI_NodeHandle>(attachNode);
}
return nullptr;
auto* attachNode = impl->getNodeModifiers()->getFrameNodeModifier()->getPreviousSibling(node->uiNodeHandle, true);
return GetArkUINode(attachNode);
}
ArkUI_NodeHandle GetNextSibling(ArkUI_NodeHandle node)
@ -419,12 +416,8 @@ ArkUI_NodeHandle GetNextSibling(ArkUI_NodeHandle node)
return nullptr;
}
auto* impl = GetFullImpl();
auto* value = impl->getNodeModifiers()->getFrameNodeModifier()->getNextSibling(node->uiNodeHandle, true);
void* attachNode = impl->getExtendedAPI()->getAttachNodePtr(value);
if (attachNode) {
return reinterpret_cast<ArkUI_NodeHandle>(attachNode);
}
return nullptr;
auto* attachNode = impl->getNodeModifiers()->getFrameNodeModifier()->getNextSibling(node->uiNodeHandle, true);
return GetArkUINode(attachNode);
}
ArkUI_NodeHandle GetParent(ArkUI_NodeHandle node)

View File

@ -21,11 +21,11 @@
#include "native_type.h"
#include "resource.h"
#include "core/components_v2/inspector/inspector_constants.h"
#include "frameworks/core/interfaces/arkoala/arkoala_api.h"
#include "interfaces/inner_api/drawable_descriptor/drawable_descriptor.h"
#include "pixelmap_native_impl.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -156,6 +156,15 @@ struct ArkUI_CustomSpanDrawInfo {
float optionsBaseLine;
};
struct ArkUI_CustomProperty {
char* value;
};
struct ArkUI_ActiveChildrenInfo {
ArkUI_NodeHandle* nodeList;
int32_t nodeCount;
};
#ifdef __cplusplus
};
#endif

View File

@ -157,7 +157,7 @@ ArkUI_NodeHandle CreateNode(ArkUI_NodeType type)
return nullptr;
}
impl->getBasicAPI()->markDirty(uiNode, ARKUI_DIRTY_FLAG_ATTRIBUTE_DIFF);
ArkUI_Node* arkUINode = new ArkUI_Node({ type, uiNode });
ArkUI_Node* arkUINode = new ArkUI_Node({ type, uiNode, true });
impl->getExtendedAPI()->setAttachNodePtr(uiNode, reinterpret_cast<void*>(arkUINode));
g_nodeSet.emplace(arkUINode);
return arkUINode;
@ -166,6 +166,9 @@ ArkUI_NodeHandle CreateNode(ArkUI_NodeType type)
void DisposeNativeSource(ArkUI_NodeHandle nativePtr)
{
CHECK_NULL_VOID(nativePtr);
if (!CheckIsCNode(nativePtr)) {
return;
}
if (nativePtr->customEventListeners) {
auto eventListenersSet = reinterpret_cast<std::set<void (*)(ArkUI_NodeCustomEvent*)>*>(
nativePtr->customEventListeners);
@ -194,6 +197,9 @@ void DisposeNativeSource(ArkUI_NodeHandle nativePtr)
void DisposeNode(ArkUI_NodeHandle nativePtr)
{
CHECK_NULL_VOID(nativePtr);
if (!CheckIsCNode(nativePtr)) {
return;
}
// already check in entry point.
auto* impl = GetFullImpl();
impl->getBasicAPI()->disposeNode(nativePtr->uiNodeHandle);
@ -207,6 +213,10 @@ int32_t AddChild(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode)
{
CHECK_NULL_RETURN(parentNode, ERROR_CODE_PARAM_INVALID);
CHECK_NULL_RETURN(childNode, ERROR_CODE_PARAM_INVALID);
if (!CheckIsCNode(parentNode) || !CheckIsCNode(childNode)) {
return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR;
}
// a
if (parentNode->type == -1) {
return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR;
}
@ -221,6 +231,9 @@ int32_t RemoveChild(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode)
{
CHECK_NULL_RETURN(parentNode, ERROR_CODE_PARAM_INVALID);
CHECK_NULL_RETURN(childNode, ERROR_CODE_PARAM_INVALID);
if (!CheckIsCNode(parentNode) || !CheckIsCNode(childNode)) {
return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR;
}
// already check in entry point.
if (parentNode->type == -1) {
return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR;
@ -235,6 +248,9 @@ int32_t InsertChildAfter(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode
{
CHECK_NULL_RETURN(parentNode, ERROR_CODE_PARAM_INVALID);
CHECK_NULL_RETURN(childNode, ERROR_CODE_PARAM_INVALID);
if (!CheckIsCNode(parentNode) || !CheckIsCNode(childNode)) {
return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR;
}
// already check in entry point.
if (parentNode->type == -1) {
return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR;
@ -250,6 +266,9 @@ int32_t InsertChildBefore(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNod
{
CHECK_NULL_RETURN(parentNode, ERROR_CODE_PARAM_INVALID);
CHECK_NULL_RETURN(childNode, ERROR_CODE_PARAM_INVALID);
if (!CheckIsCNode(parentNode) || !CheckIsCNode(childNode)) {
return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR;
}
// already check in entry point.
if (parentNode->type == -1) {
return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR;
@ -265,6 +284,9 @@ int32_t InsertChildAt(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode, i
{
CHECK_NULL_RETURN(parentNode, ERROR_CODE_PARAM_INVALID);
CHECK_NULL_RETURN(childNode, ERROR_CODE_PARAM_INVALID);
if (!CheckIsCNode(parentNode) || !CheckIsCNode(childNode)) {
return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR;
}
// already check in entry point.
if (parentNode->type == -1) {
return ERROR_CODE_NATIVE_IMPL_BUILDER_NODE_ERROR;
@ -317,7 +339,7 @@ int32_t RegisterNodeEvent(ArkUI_NodeHandle nodePtr, ArkUI_NodeEventType eventTyp
int32_t RegisterNodeEvent(ArkUI_NodeHandle nodePtr, ArkUI_NodeEventType eventType, int32_t targetId, void* userData)
{
if (nodePtr == nullptr) {
if (nodePtr == nullptr || !CheckIsCNode(nodePtr)) {
return ERROR_CODE_PARAM_INVALID;
}
auto originEventType = ConvertOriginEventType(eventType, nodePtr->type);
@ -372,7 +394,7 @@ int32_t RegisterNodeEvent(ArkUI_NodeHandle nodePtr, ArkUI_NodeEventType eventTyp
void UnregisterNodeEvent(ArkUI_NodeHandle nodePtr, ArkUI_NodeEventType eventType)
{
if (nodePtr == nullptr) {
if (nodePtr == nullptr || !CheckIsCNode(nodePtr)) {
return;
}
if (!nodePtr->extraData) {
@ -563,7 +585,7 @@ int32_t CheckEvent(ArkUI_NodeEvent* event)
int32_t SetUserData(ArkUI_NodeHandle node, void* userData)
{
if (!node) {
if (!node || !CheckIsCNode(node)) {
return ERROR_CODE_PARAM_INVALID;
}
if (!userData) {
@ -580,7 +602,7 @@ void* GetUserData(ArkUI_NodeHandle node)
int32_t SetLengthMetricUnit(ArkUI_NodeHandle nodePtr, ArkUI_LengthMetricUnit unit)
{
if (!nodePtr) {
if (!nodePtr || !CheckIsCNode(nodePtr)) {
return ERROR_CODE_PARAM_INVALID;
}
if (!InRegion(static_cast<int32_t>(ARKUI_LENGTH_METRIC_UNIT_DEFAULT),
@ -604,7 +626,7 @@ void ApplyModifierFinish(ArkUI_NodeHandle nodePtr)
void MarkDirty(ArkUI_NodeHandle nodePtr, ArkUI_NodeDirtyFlag dirtyFlag)
{
// spanNode inherited from UINode
if (!nodePtr) {
if (!nodePtr || !CheckIsCNode(nodePtr)) {
return;
}
ArkUIDirtyFlag flag = ARKUI_DIRTY_FLAG_MEASURE;
@ -632,7 +654,7 @@ void MarkDirty(ArkUI_NodeHandle nodePtr, ArkUI_NodeDirtyFlag dirtyFlag)
int32_t AddNodeEventReceiver(ArkUI_NodeHandle nodePtr, void (*eventReceiver)(ArkUI_NodeEvent* event))
{
if (!nodePtr || !eventReceiver) {
if (!nodePtr || !eventReceiver || !CheckIsCNode(nodePtr)) {
return ERROR_CODE_PARAM_INVALID;
}
if (!nodePtr->eventListeners) {
@ -648,7 +670,7 @@ int32_t AddNodeEventReceiver(ArkUI_NodeHandle nodePtr, void (*eventReceiver)(Ark
int32_t RemoveNodeEventReceiver(ArkUI_NodeHandle nodePtr, void (*eventReceiver)(ArkUI_NodeEvent* event))
{
if (!nodePtr || !eventReceiver || !nodePtr->eventListeners) {
if (!nodePtr || !eventReceiver || !nodePtr->eventListeners || !CheckIsCNode(nodePtr)) {
return ERROR_CODE_PARAM_INVALID;
}
auto eventListenersSet = reinterpret_cast<std::set<void (*)(ArkUI_NodeEvent*)>*>(nodePtr->eventListeners);
@ -679,6 +701,14 @@ void* GetParseJsMedia()
}
return reinterpret_cast<void*>(parseJsMedia);
}
bool CheckIsCNode(ArkUI_NodeHandle node)
{
if (node->cNode || node->buildNode) {
return true;
}
return false;
}
} // namespace OHOS::Ace::NodeModel
#ifdef __cplusplus

View File

@ -34,6 +34,8 @@ extern "C" {
struct ArkUI_Node {
int32_t type;
ArkUINodeHandle uiNodeHandle = nullptr;
bool cNode = false;
bool buildNode = false;
void* extraData = nullptr;
void* extraCustomData = nullptr;
ArkUI_LengthMetricUnit lengthMetricUnit = ARKUI_LENGTH_METRIC_UNIT_DEFAULT;
@ -156,5 +158,6 @@ int32_t SetLengthMetricUnit(ArkUI_NodeHandle nodePtr, ArkUI_LengthMetricUnit uni
int32_t AddNodeEventReceiver(ArkUI_NodeHandle node, void (*eventReceiver)(ArkUI_NodeEvent* event));
int32_t RemoveNodeEventReceiver(ArkUI_NodeHandle node, void (*eventReceiver)(ArkUI_NodeEvent* event));
void* GetParseJsMedia();
bool CheckIsCNode(ArkUI_NodeHandle node);
}; // namespace OHOS::Ace::NodeModel
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_NODE_MODEL_H

View File

@ -16,9 +16,11 @@
#include <cstdlib>
#include "node_model.h"
#include "node_extened.h"
#include "base/utils/utils.h"
#include "base/error/error_code.h"
#include "core/components_v2/inspector/inspector_constants.h"
#ifdef __cplusplus
extern "C" {
@ -188,6 +190,173 @@ void OH_ArkUI_NodeUtils_RemoveCustomProperty(ArkUI_NodeHandle node, const char*
impl->getNodeModifiers()->getFrameNodeModifier()->removeCustomProperty(node->uiNodeHandle, name);
}
int32_t OH_ArkUI_NodeUtils_GetCustomProperty(ArkUI_NodeHandle node, const char* name, ArkUI_CustomProperty** handle)
{
if (node == nullptr || name == nullptr) {
return ARKUI_ERROR_CODE_PARAM_INVALID;
}
const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
char* value = nullptr;
impl->getNodeModifiers()->getFrameNodeModifier()->getCustomProperty(node->uiNodeHandle, name, &value);
*handle = new ArkUI_CustomProperty({ .value = value });
return 0;
}
ArkUI_NodeHandle GetArkUINode(ArkUINodeHandle node)
{
CHECK_NULL_RETURN(node, nullptr);
const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
void* attachNode = impl->getExtendedAPI()->getAttachNodePtr(node);
if (attachNode) {
return reinterpret_cast<ArkUI_NodeHandle>(attachNode);
}
ArkUI_Node* arkUINode = new ArkUI_Node({ 0, node, false });
impl->getExtendedAPI()->setAttachNodePtr((arkUINode)->uiNodeHandle, reinterpret_cast<void*>(arkUINode));
return reinterpret_cast<ArkUI_NodeHandle>(arkUINode);
}
int32_t OH_ArkUI_NodeUtils_GetActiveChildrenInfo(ArkUI_NodeHandle head, ArkUI_ActiveChildrenInfo** handle)
{
CHECK_NULL_RETURN(head, ARKUI_ERROR_CODE_PARAM_INVALID);
const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
CHECK_NULL_RETURN(impl, ARKUI_ERROR_CODE_PARAM_INVALID);
ArkUINodeHandle* innerNodes = nullptr;
uint32_t totalSize = 0;
impl->getNodeModifiers()->getFrameNodeModifier()->getActiveChildrenInfo(
head->uiNodeHandle, &innerNodes, &totalSize);
if (totalSize == 0) {
return ARKUI_ERROR_CODE_PARAM_INVALID;
}
*handle = new ArkUI_ActiveChildrenInfo({ .nodeList = nullptr, .nodeCount = totalSize });
(*handle)->nodeCount = totalSize;
(*handle)->nodeList = new ArkUI_NodeHandle[totalSize] {};
for (uint32_t i = 0; i < totalSize; i++) {
((*handle)->nodeList[i]) = GetArkUINode(innerNodes[i]);
}
delete[] innerNodes;
return 0;
}
ArkUI_NodeHandle OH_ArkUI_NodeUtils_GetParentInPageTree(ArkUI_NodeHandle node)
{
if (node == nullptr) {
return nullptr;
}
const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
auto* attachNode = impl->getNodeModifiers()->getFrameNodeModifier()->getParent(node->uiNodeHandle);
return GetArkUINode(attachNode);
}
ArkUI_NodeHandle OH_ArkUI_NodeUtils_GetCurrentPageRootNode(ArkUI_NodeHandle node)
{
if (node == nullptr) {
return nullptr;
}
const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
auto* attachNode = impl->getNodeModifiers()->getFrameNodeModifier()->getCurrentPageRootNode(node->uiNodeHandle);
return GetArkUINode(attachNode);
}
bool OH_ArkUI_NodeUtils_IsCreatedByNDK(ArkUI_NodeHandle node)
{
if (node == nullptr) {
return 0;
}
const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
return impl->getNodeModifiers()->getFrameNodeModifier()->getNodeTag(node->uiNodeHandle);
}
int32_t OH_ArkUI_NodeUtils_GetNodeType(ArkUI_NodeHandle node)
{
if (node == nullptr) {
return 0;
}
static const std::unordered_map<std::string, ArkUI_NodeType> nodeTypeMap = {
{ OHOS::Ace::V2::TEXT_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_TEXT },
{ OHOS::Ace::V2::SPAN_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_SPAN },
{ OHOS::Ace::V2::IMAGE_SPAN_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_IMAGE_SPAN },
{ OHOS::Ace::V2::IMAGE_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_IMAGE },
{ OHOS::Ace::V2::TOGGLE_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_TOGGLE },
{ OHOS::Ace::V2::LOADING_PROGRESS_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_LOADING_PROGRESS },
{ OHOS::Ace::V2::TEXTINPUT_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_TEXT_INPUT },
{ OHOS::Ace::V2::TEXTAREA_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_TEXT_AREA },
{ OHOS::Ace::V2::BUTTON_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_BUTTON },
{ OHOS::Ace::V2::PROGRESS_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_PROGRESS },
{ OHOS::Ace::V2::CHECK_BOX_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_CHECKBOX },
{ OHOS::Ace::V2::XCOMPONENT_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_XCOMPONENT },
{ OHOS::Ace::V2::DATE_PICKER_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_DATE_PICKER },
{ OHOS::Ace::V2::TIME_PICKER_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_TIME_PICKER },
{ OHOS::Ace::V2::TEXT_PICKER_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_TEXT_PICKER },
{ OHOS::Ace::V2::CALENDAR_PICKER_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_CALENDAR_PICKER },
{ OHOS::Ace::V2::SLIDER_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_SLIDER },
{ OHOS::Ace::V2::RADIO_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_RADIO },
{ OHOS::Ace::V2::IMAGE_ANIMATOR_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_IMAGE_ANIMATOR },
{ OHOS::Ace::V2::STACK_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_STACK },
{ OHOS::Ace::V2::SWIPER_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_SWIPER },
{ OHOS::Ace::V2::SCROLL_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_SCROLL },
{ OHOS::Ace::V2::LIST_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_LIST },
{ OHOS::Ace::V2::LIST_ITEM_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_LIST_ITEM },
{ OHOS::Ace::V2::LIST_ITEM_GROUP_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_LIST_ITEM_GROUP },
{ OHOS::Ace::V2::COLUMN_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_COLUMN },
{ OHOS::Ace::V2::ROW_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_ROW },
{ OHOS::Ace::V2::FLEX_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_FLEX },
{ OHOS::Ace::V2::REFRESH_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_REFRESH },
{ OHOS::Ace::V2::WATERFLOW_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_WATER_FLOW },
{ OHOS::Ace::V2::FLOW_ITEM_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_FLOW_ITEM },
{ OHOS::Ace::V2::RELATIVE_CONTAINER_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_RELATIVE_CONTAINER },
{ OHOS::Ace::V2::GRID_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_GRID },
{ OHOS::Ace::V2::GRID_ITEM_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_GRID_ITEM },
{ OHOS::Ace::V2::CUSTOM_SPAN_NODE_ETS_TAG, ArkUI_NodeType::ARKUI_NODE_CUSTOM_SPAN },
};
const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
auto value = impl->getNodeModifiers()->getFrameNodeModifier()->getNodeType(node->uiNodeHandle);
auto iter = nodeTypeMap.find(value);
if (iter != nodeTypeMap.end()) {
return iter->second;
}
return -1;
}
void OH_ArkUI_CustomProperty_Destroy(ArkUI_CustomProperty* handle)
{
delete[] handle->value;
handle->value = nullptr;
delete handle;
handle = nullptr;
}
const char* OH_ArkUI_CustomProperty_GetStringValue(ArkUI_CustomProperty* handle)
{
CHECK_NULL_RETURN(handle, nullptr);
return handle->value;
}
void OH_ArkUI_ActiveChildrenInfo_Destroy(ArkUI_ActiveChildrenInfo* handle)
{
delete[] handle->nodeList;
handle->nodeList = nullptr;
delete handle;
handle = nullptr;
}
ArkUI_NodeHandle OH_ArkUI_ActiveChildrenInfo_GetNodeByIndex(ArkUI_ActiveChildrenInfo* handle, int32_t index)
{
CHECK_NULL_RETURN(handle, nullptr);
if (index < handle->nodeCount) {
return handle->nodeList[index];
}
return nullptr;
}
int32_t OH_ArkUI_ActiveChildrenInfo_GetCount(ArkUI_ActiveChildrenInfo* handle)
{
CHECK_NULL_RETURN(handle, 0);
return handle->nodeCount;
}
#ifdef __cplusplus
};
#endif

View File

@ -14160,7 +14160,7 @@ int32_t SetNodeAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType type, co
int32_t nodeSubTypeClass =
subTypeClass < MAX_NODE_SCOPE_NUM ? subTypeClass : (subTypeClass - MAX_NODE_SCOPE_NUM + BASIC_COMPONENT_NUM);
if ((static_cast<uint32_t>(nodeSubTypeClass) >= sizeof(setterClasses) / sizeof(AttributeSetterClass*)) ||
!CheckIfAttributeLegal(node, type)) {
!CheckIfAttributeLegal(node, type) || !CheckIsCNode(node)) {
return ERROR_CODE_NATIVE_IMPL_TYPE_NOT_SUPPORTED;
}
if (!setterClasses[nodeSubTypeClass]) {
@ -14217,7 +14217,7 @@ int32_t ResetNodeAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType type)
int32_t nodeSubTypeClass =
subTypeClass < MAX_NODE_SCOPE_NUM ? subTypeClass : (subTypeClass - MAX_NODE_SCOPE_NUM + BASIC_COMPONENT_NUM);
if ((static_cast<uint32_t>(nodeSubTypeClass) >= sizeof(resetterClasses) / sizeof(AttributeResetterClass*)) ||
!CheckIfAttributeLegal(node, type)) {
!CheckIfAttributeLegal(node, type) || !CheckIsCNode(node)) {
TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "node attribute: %{public}d NOT IMPLEMENT", type);
return ERROR_CODE_NATIVE_IMPL_TYPE_NOT_SUPPORTED;
}