1 /*
2 * Copyright (c) 2023-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 #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 void* imageFrameInfos = nullptr;
49 void* drawableDescriptor = nullptr;
50 int32_t linearGradientDirection = -1;
51 void* customEventListeners = nullptr;
52 void* altDrawableDescriptor = nullptr;
53 ArkUI_AttributeItem* areaChangeRadio = nullptr;
54 void* transitionOption = nullptr;
55 void* progressLinearStyle = nullptr;
56 void* visibleAreaEventOptions = nullptr;
57 bool isBindNative = false;
58 };
59
60 struct ArkUI_Context {
61 int32_t id;
62 };
63
64 struct ArkUI_GuidelineStyle {
65 std::string id;
66 ArkUI_Axis direction;
67 float start;
68 bool hasStart;
69 float end;
70 bool hasEnd;
71 };
72
73 struct ArkUI_GuidelineOption {
74 std::vector<ArkUI_GuidelineStyle> styles;
75 };
76
77 struct ArkUI_BarrierStyle {
78 std::string id;
79 ArkUI_BarrierDirection direction;
80 std::vector<std::string> referencedId;
81 };
82
83 struct ArkUI_BarrierOption {
84 std::vector<ArkUI_BarrierStyle> styles;
85 };
86
87 struct ArkUI_HorizontalAlignRule {
88 bool hasValue;
89 std::string anchor;
90 ArkUI_HorizontalAlignment align;
91 };
92
93 struct ArkUI_VerticalAlignRule {
94 bool hasValue;
95 std::string anchor;
96 ArkUI_VerticalAlignment align;
97 };
98
99 struct ArkUI_AlignmentRuleOption {
100 ArkUI_HorizontalAlignRule left;
101 ArkUI_HorizontalAlignRule middle;
102 ArkUI_HorizontalAlignRule right;
103 ArkUI_VerticalAlignRule top;
104 ArkUI_VerticalAlignRule center;
105 ArkUI_VerticalAlignRule bottom;
106 float biasHorizontal;
107 float biasVertical;
108 };
109
110 constexpr int BASIC_COMPONENT_NUM = 22;
111
112 #ifdef __cplusplus
113 };
114 #endif
115
116 struct ArkUIFullNodeAPI;
117
118 namespace OHOS::Ace::NodeModel {
119
UsePXUnit(ArkUI_NodeHandle nodePtr)120 inline bool UsePXUnit(ArkUI_NodeHandle nodePtr)
121 {
122 return nodePtr && (nodePtr->lengthMetricUnit == ARKUI_LENGTH_METRIC_UNIT_PX);
123 }
124
125 bool InitialFullImpl();
126 ArkUIFullNodeAPI* GetFullImpl();
127 ArkUI_NodeHandle CreateNode(ArkUI_NodeType type);
128 void DisposeNode(ArkUI_NodeHandle nativePtr);
129 bool IsValidArkUINode(ArkUI_NodeHandle nodePtr);
130
131 int32_t AddChild(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode);
132 int32_t RemoveChild(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode);
133 int32_t InsertChildAfter(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode, ArkUI_NodeHandle siblingNode);
134 int32_t InsertChildBefore(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode, ArkUI_NodeHandle siblingNode);
135 int32_t InsertChildAt(ArkUI_NodeHandle parentNode, ArkUI_NodeHandle childNode, int32_t position);
136
137 // deprecated.
138 [[deprecated]] void SetAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType attribute, const char* value);
139
140 int32_t SetAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType attribute, const ArkUI_AttributeItem* value);
141 const ArkUI_AttributeItem* GetAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType attribute);
142 int32_t ResetAttribute(ArkUI_NodeHandle node, ArkUI_NodeAttributeType attribute);
143
144 int32_t RegisterNodeEvent(ArkUI_NodeHandle nodePtr, ArkUI_NodeEventType eventType, int32_t targetId);
145 int32_t RegisterNodeEvent(ArkUI_NodeHandle nodePtr, ArkUI_NodeEventType eventType, int32_t targetId, void* userData);
146 void UnregisterNodeEvent(ArkUI_NodeHandle nodePtr, ArkUI_NodeEventType eventType);
147 void RegisterOnEvent(void (*eventReceiver)(ArkUI_NodeEvent* event));
148 void RegisterOnEvent(void (*eventReceiver)(ArkUI_CompatibleNodeEvent* event));
149 void UnregisterOnEvent();
150 void HandleTouchEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent);
151 void HandleMouseEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent);
152 void HandleKeyEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent);
153 void HandleFocusAxisEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent);
154 void HandleHoverEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent);
155 void HandleClickEvent(ArkUI_UIInputEvent& uiEvent, ArkUINodeEvent* innerEvent);
156 int32_t CheckEvent(ArkUI_NodeEvent* event);
157 void HandleInnerNodeEvent(ArkUINodeEvent* innerEvent);
158 int32_t GetNativeNodeEventType(ArkUINodeEvent* innerEvent);
159 void HandleNodeEvent(ArkUI_NodeEvent* event);
160 void TriggerNodeEvent(ArkUI_NodeEvent* event, std::set<void (*)(ArkUI_NodeEvent*)>* eventListenersSet);
161 void ApplyModifierFinish(ArkUI_NodeHandle nodePtr);
162 void MarkDirty(ArkUI_NodeHandle nodePtr, ArkUI_NodeDirtyFlag dirtyFlag);
163
164 int32_t SetUserData(ArkUI_NodeHandle node, void* userData);
165 void* GetUserData(ArkUI_NodeHandle node);
166 int32_t SetLengthMetricUnit(ArkUI_NodeHandle nodePtr, ArkUI_LengthMetricUnit unit);
167 int32_t AddNodeEventReceiver(ArkUI_NodeHandle node, void (*eventReceiver)(ArkUI_NodeEvent* event));
168 int32_t RemoveNodeEventReceiver(ArkUI_NodeHandle node, void (*eventReceiver)(ArkUI_NodeEvent* event));
169 void* GetParseJsMedia();
170 bool CheckIsCNode(ArkUI_NodeHandle node);
171 bool CheckIsCNodeOrCrossLanguage(ArkUI_NodeHandle node);
172 ArkUI_NodeHandle GetArkUINode(ArkUINodeHandle node);
173 int32_t GetNodeTypeByTag(ArkUI_NodeHandle node);
174 void RegisterBindNativeNode(ArkUI_NodeHandle node);
175 }; // namespace OHOS::Ace::NodeModel
176 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_NODE_MODEL_H
177