1 /*
2  * Copyright (c) 2023 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_NODE_MODEL_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_NODE_MODEL_H
18 
19 #include <cstdint>
20 #include <set>
21 #include <vector>
22 #include <string>
23 
24 #include "native_compatible.h"
25 #include "native_node.h"
26 #include "native_type.h"
27 
28 #include "frameworks/core/interfaces/arkoala/arkoala_api.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 struct ArkUI_Node {
35     int32_t type;
36     ArkUINodeHandle uiNodeHandle = nullptr;
37     void* extraData = nullptr;
38     void* extraCustomData = nullptr;
39     ArkUI_LengthMetricUnit lengthMetricUnit = ARKUI_LENGTH_METRIC_UNIT_DEFAULT;
40     void* eventListeners = nullptr;
41     void* barrierOption = nullptr;
42     void* guidelineOption = nullptr;
43     void* alignRuleOption = nullptr;
44     void* userData = nullptr;
45     void* swiperIndicator = nullptr;
46     void* imageFrameInfos = nullptr;
47     void* drawableDescriptor = nullptr;
48     int32_t linearGradientDirection = -1;
49     void* customEventListeners = nullptr;
50     void* altDrawableDescriptor = nullptr;
51     ArkUI_AttributeItem* areaChangeRadio = nullptr;
52     void* transitionOption = nullptr;
53 };
54 
55 struct ArkUI_Context {
56     int32_t id;
57 };
58 
59 struct ArkUI_GuidelineStyle {
60     std::string id;
61     ArkUI_Axis direction;
62     float start;
63     bool hasStart;
64     float end;
65     bool hasEnd;
66 };
67 
68 struct ArkUI_GuidelineOption {
69     std::vector<ArkUI_GuidelineStyle> styles;
70 };
71 
72 struct ArkUI_BarrierStyle {
73     std::string id;
74     ArkUI_BarrierDirection direction;
75     std::vector<std::string> referencedId;
76 };
77 
78 struct ArkUI_BarrierOption {
79     std::vector<ArkUI_BarrierStyle> styles;
80 };
81 
82 struct ArkUI_HorizontalAlignRule {
83     bool hasValue;
84     std::string anchor;
85     ArkUI_HorizontalAlignment align;
86 };
87 
88 struct ArkUI_VerticalAlignRule {
89     bool hasValue;
90     std::string anchor;
91     ArkUI_VerticalAlignment align;
92 };
93 
94 struct ArkUI_AlignmentRuleOption {
95     ArkUI_HorizontalAlignRule left;
96     ArkUI_HorizontalAlignRule middle;
97     ArkUI_HorizontalAlignRule right;
98     ArkUI_VerticalAlignRule top;
99     ArkUI_VerticalAlignRule center;
100     ArkUI_VerticalAlignRule bottom;
101     float biasHorizontal;
102     float biasVertical;
103 };
104 
105 constexpr int BASIC_COMPONENT_NUM = 20;
106 
107 #ifdef __cplusplus
108 };
109 #endif
110 
111 struct ArkUIFullNodeAPI;
112 
113 namespace OHOS::Ace::NodeModel {
114 
UsePXUnit(ArkUI_NodeHandle nodePtr)115 inline bool UsePXUnit(ArkUI_NodeHandle nodePtr)
116 {
117     return nodePtr && (nodePtr->lengthMetricUnit == ARKUI_LENGTH_METRIC_UNIT_PX);
118 }
119 
120 bool InitialFullImpl();
121 ArkUIFullNodeAPI* GetFullImpl();
122 ArkUI_NodeHandle CreateNode(ArkUI_NodeType type);
123 void DisposeNode(ArkUI_NodeHandle nativePtr);
124 bool IsValidArkUINode(ArkUI_NodeHandle nodePtr);
125 
126 int32_t AddChild(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode);
127 int32_t RemoveChild(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode);
128 int32_t InsertChildAfter(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode, ArkUI_NodeHandle siblingNode);
129 int32_t InsertChildBefore(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode, ArkUI_NodeHandle siblingNode);
130 int32_t InsertChildAt(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode, int32_t position);
131 
132 // deprecated.
133 [[deprecated]] void SetAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType attribute, const char* value);
134 
135 int32_t SetAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType attribute, const ArkUI_AttributeItem* value);
136 const ArkUI_AttributeItem* GetAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType attribute);
137 int32_t ResetAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType attribute);
138 
139 int32_t RegisterNodeEvent(ArkUI_NodeHandle nodePtr, ArkUI_NodeEventType eventType, int32_t targetId);
140 int32_t RegisterNodeEvent(ArkUI_NodeHandle nodePtr, ArkUI_NodeEventType eventType, int32_t targetId, void* userData);
141 void UnregisterNodeEvent(ArkUI_NodeHandle nodePtr, ArkUI_NodeEventType eventType);
142 void RegisterOnEvent(void (*eventReceiver)(ArkUI_NodeEvent* event));
143 void RegisterOnEvent(void (*eventReceiver)(ArkUI_CompatibleNodeEvent* event));
144 void UnregisterOnEvent();
145 int32_t CheckEvent(ArkUI_NodeEvent* event);
146 void HandleInnerNodeEvent(ArkUINodeEvent* innerEvent);
147 int32_t GetNativeNodeEventType(ArkUINodeEvent* innerEvent);
148 void HandleNodeEvent(ArkUI_NodeEvent* event);
149 void TriggerNodeEvent(ArkUI_NodeEvent* event, std::set<void (*)(ArkUI_NodeEvent*)>* eventListenersSet);
150 void ApplyModifierFinish(ArkUI_NodeHandle nodePtr);
151 void MarkDirty(ArkUI_NodeHandle nodePtr, ArkUI_NodeDirtyFlag dirtyFlag);
152 
153 int32_t SetUserData(ArkUI_NodeHandle node, void* userData);
154 void* GetUserData(ArkUI_NodeHandle node);
155 int32_t SetLengthMetricUnit(ArkUI_NodeHandle nodePtr, ArkUI_LengthMetricUnit unit);
156 int32_t AddNodeEventReceiver(ArkUI_NodeHandle node, void (*eventReceiver)(ArkUI_NodeEvent* event));
157 int32_t RemoveNodeEventReceiver(ArkUI_NodeHandle node, void (*eventReceiver)(ArkUI_NodeEvent* event));
158 void* GetParseJsMedia();
159 }; // namespace OHOS::Ace::NodeModel
160 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_NODE_MODEL_H
161