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     bool cNode = false;
38     bool buildNode = false;
39     void* extraData = nullptr;
40     void* extraCustomData = nullptr;
41     ArkUI_LengthMetricUnit lengthMetricUnit = ARKUI_LENGTH_METRIC_UNIT_DEFAULT;
42     void* eventListeners = nullptr;
43     void* barrierOption = nullptr;
44     void* guidelineOption = nullptr;
45     void* alignRuleOption = nullptr;
46     void* userData = nullptr;
47     void* swiperIndicator = nullptr;
48     int32_t linearGradientDirection = -1;
49     void* customEventListeners = nullptr;
50     void* altDrawableDescriptor = nullptr;
51     void* drawableDescriptor = nullptr;
52     void* imageFrameInfos = nullptr;
53     ArkUI_AttributeItem* areaChangeRadio = nullptr;
54     void* transitionOption = nullptr;
55 };
56 
57 struct ArkUI_Context {
58     int32_t id;
59 };
60 
61 constexpr int BASIC_COMPONENT_NUM = 20;
62 struct ArkUI_GuidelineStyle {
63     std::string id;
64     ArkUI_Axis direction;
65     float start;
66     bool hasStart;
67     float end;
68     bool hasEnd;
69 };
70 
71 struct ArkUI_GuidelineOption {
72     std::vector<ArkUI_GuidelineStyle> styles;
73 };
74 
75 struct ArkUI_BarrierStyle {
76     std::string id;
77     ArkUI_BarrierDirection direction;
78     std::vector<std::string> referencedId;
79 };
80 
81 struct ArkUI_BarrierOption {
82     std::vector<ArkUI_BarrierStyle> styles;
83 };
84 
85 struct ArkUI_HorizontalAlignRule {
86     bool hasValue;
87     std::string anchor;
88     ArkUI_HorizontalAlignment align;
89 };
90 
91 struct ArkUI_VerticalAlignRule {
92     bool hasValue;
93     std::string anchor;
94     ArkUI_VerticalAlignment align;
95 };
96 
97 struct ArkUI_AlignmentRuleOption {
98     ArkUI_HorizontalAlignRule left;
99     ArkUI_HorizontalAlignRule middle;
100     ArkUI_HorizontalAlignRule right;
101     ArkUI_VerticalAlignRule top;
102     ArkUI_VerticalAlignRule center;
103     ArkUI_VerticalAlignRule bottom;
104     float biasHorizontal;
105     float biasVertical;
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 void HandleTouchEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent);
146 void HandleMouseEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent);
147 void HandleKeyEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent);
148 int32_t CheckEvent(ArkUI_NodeEvent* event);
149 void HandleInnerNodeEvent(ArkUINodeEvent* innerEvent);
150 int32_t GetNativeNodeEventType(ArkUINodeEvent* innerEvent);
151 void HandleNodeEvent(ArkUI_NodeEvent* event);
152 void TriggerNodeEvent(ArkUI_NodeEvent* event, std::set<void (*)(ArkUI_NodeEvent*)>* eventListenersSet);
153 void ApplyModifierFinish(ArkUI_NodeHandle nodePtr);
154 void MarkDirty(ArkUI_NodeHandle nodePtr, ArkUI_NodeDirtyFlag dirtyFlag);
155 
156 int32_t SetUserData(ArkUI_NodeHandle node, void* userData);
157 void* GetUserData(ArkUI_NodeHandle node);
158 int32_t SetLengthMetricUnit(ArkUI_NodeHandle nodePtr, ArkUI_LengthMetricUnit unit);
159 int32_t AddNodeEventReceiver(ArkUI_NodeHandle node, void (*eventReceiver)(ArkUI_NodeEvent* event));
160 int32_t RemoveNodeEventReceiver(ArkUI_NodeHandle node, void (*eventReceiver)(ArkUI_NodeEvent* event));
161 void* GetParseJsMedia();
162 bool CheckIsCNode(ArkUI_NodeHandle node);
163 }; // namespace OHOS::Ace::NodeModel
164 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_NODE_MODEL_H
165