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