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_EXTENED_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_NODE_EXTENED_H
18 
19 #include "drawable_descriptor.h"
20 #include "native_node.h"
21 #include "native_type.h"
22 #include "resource.h"
23 
24 #include "core/components_v2/inspector/inspector_constants.h"
25 #include "frameworks/core/interfaces/arkoala/arkoala_api.h"
26 #include "interfaces/inner_api/drawable_descriptor/drawable_descriptor.h"
27 #include "pixelmap_native_impl.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 struct ArkUI_LayoutConstraint {
33     /** 元素最小宽度。 */
34     int32_t minWidth;
35     /** 元素最小高度。 */
36     int32_t minHeight;
37     /** 元素最大宽度。 */
38     int32_t maxWidth;
39     /** 元素最小宽度。 */
40     int32_t maxHeight;
41     /** 元素宽度百分比基准。 */
42     int32_t percentReferWidth;
43     /** 元素高度百分比基准。*/
44     int32_t percentReferHeight;
45 };
46 
47 /**
48  * @brief 定义自定义组件回调事件的参数类型。
49  *
50  * @since 12
51  */
52 struct ArkUI_CustomNodeAsyncEvent {
53     /** 数据数组对象。*/
54     ArkUI_NumberValue data[MAX_COMPONENT_EVENT_ARG_NUM];
55 };
56 
57 /**
58  * 定义组件绘制上下文类型结构。
59  *
60  * @since 12
61  */
62 struct ArkUI_DrawContext {
63     /** 画布宽度。*/
64     int32_t width;
65     /** 画布高度。*/
66     int32_t height;
67     /** 绘制的画布。*/
68     void* canvas;
69 };
70 
71 /**
72  * @brief 定义自定义组件事件的通用结构类型。
73  *
74  * @since 12
75  */
76 struct ArkUI_NodeCustomEvent {
77     int32_t targetId;
78     ArkUI_NodeHandle node;
79     ArkUICustomNodeEvent* event;
80     ArkUI_LayoutConstraint constraint;
81     void* userData;
82 };
83 
84 struct ArkUI_OptionalFloat {
85     int32_t isSet;
86     float value;
87 };
88 
89 struct ArkUI_OptionalInt {
90     int32_t isSet;
91     int32_t value;
92 };
93 
94 struct ArkUI_OptionalUint {
95     int32_t isSet;
96     uint32_t value;
97 };
98 
99 struct ArkUI_OptionalCharPtr {
100     int32_t isSet;
101     const char* value;
102 };
103 
104 struct ArkUI_SwiperIndicator {
105     ArkUI_SwiperIndicatorType type;
106     ArkUI_OptionalFloat dimLeft;
107     ArkUI_OptionalFloat dimTop;
108     ArkUI_OptionalFloat dimRight;
109     ArkUI_OptionalFloat dimBottom;
110     ArkUI_OptionalFloat itemWidth;
111     ArkUI_OptionalFloat itemHeight;
112     ArkUI_OptionalFloat selectedItemWidth;
113     ArkUI_OptionalFloat selectedItemHeight;
114     ArkUI_OptionalInt maskValue;
115     ArkUI_OptionalUint colorValue;
116     ArkUI_OptionalUint selectedColorValue;
117     ArkUI_OptionalInt maxDisplayCount;
118 };
119 
120 struct ArkUI_DrawableDescriptor {
121     OH_PixelmapNativeHandle pixelMap;
122     OH_PixelmapNativeHandle* pixelMapArray;
123     ArkUI_Int32 size;
124     std::shared_ptr<OHOS::Ace::Napi::DrawableDescriptor> drawableDescriptor;
125     std::shared_ptr<OHOS::Ace::Napi::AnimatedDrawableDescriptor> animatedDrawableDescriptor;
126     std::shared_ptr<OHOS::Ace::Napi::LayeredDrawableDescriptor> layeredDrawableDescriptor;
127     std::shared_ptr<ArkUI_Resource> resource;
128 };
129 
130 struct ArkUI_AccessibilityState {
131     ArkUI_OptionalInt isDisabled;
132     ArkUI_OptionalInt isSelected;
133     ArkUI_OptionalInt checkedType;
134 };
135 
136 struct ArkUI_AccessibilityValue {
137     ArkUI_OptionalInt min;
138     ArkUI_OptionalInt max;
139     ArkUI_OptionalInt current;
140     ArkUI_OptionalCharPtr text;
141 };
142 
143 struct ArkUI_CustomSpanMeasureInfo {
144     float fontSize;
145 };
146 
147 struct ArkUI_CustomSpanMetrics {
148     float width;
149     float height;
150 };
151 
152 struct ArkUI_CustomSpanDrawInfo {
153     float optionsX;
154     float optionsLineTop;
155     float optionsLineBottom;
156     float optionsBaseLine;
157 };
158 
159 struct ArkUI_CustomProperty {
160     char* value;
161 };
162 
163 struct ArkUI_ActiveChildrenInfo {
164     ArkUI_NodeHandle* nodeList;
165     int32_t nodeCount;
166 };
167 
168 #ifdef __cplusplus
169 };
170 #endif
171 
172 namespace OHOS::Ace::NodeModel {
173 
174 void NodeAddExtraData(ArkUI_NodeHandle node, ArkUI_NodeCustomEventType eventType, int32_t targetId, void* userData);
175 int32_t RegisterNodeCustomEvent(
176     ArkUI_NodeHandle node, ArkUI_NodeCustomEventType eventType, int32_t targetId, void* userData);
177 void NodeRemoveExtraData(ArkUI_NodeHandle node, ArkUI_NodeCustomEventType eventType);
178 void UnregisterNodeCustomEvent(ArkUI_NodeHandle node, ArkUI_NodeCustomEventType eventType);
179 void RegisterNodeCustomReceiver(void (*eventReceiver)(ArkUI_NodeCustomEvent* event));
180 void UnregisterNodeCustomEventReceiver();
181 void HandleInnerCustomEvent(ArkUICustomNodeEvent* origin);
182 void HandleCustomEvent(ArkUI_NodeCustomEvent* event);
183 int32_t AddNodeCustomEventReceiver(ArkUI_NodeHandle nodePtr, void (*eventReceiver)(ArkUI_NodeCustomEvent* event));
184 int32_t RemoveNodeCustomEventReceiver(ArkUI_NodeHandle nodePtr,
185     void (*eventReceiver)(ArkUI_NodeCustomEvent* event));
186 int32_t SetMeasuredSize(ArkUI_NodeHandle node, int32_t width, int32_t height);
187 int32_t SetLayoutPosition(ArkUI_NodeHandle node, int32_t positionX, int32_t positionY);
188 int32_t GetLayoutConstraint(ArkUI_NodeHandle node, ArkUI_LayoutConstraint* layoutConstraint);
189 ArkUI_IntSize GetMeasuredSize(ArkUI_NodeHandle node);
190 ArkUI_IntOffset GetLayoutPosition(ArkUI_NodeHandle node);
191 int32_t MeasureNode(ArkUI_NodeHandle node, ArkUI_LayoutConstraint* constraint);
192 int32_t LayoutNode(ArkUI_NodeHandle node, int32_t positionX, int32_t positionY);
193 
194 uint32_t GetTotalChildCount(ArkUI_NodeHandle node);
195 ArkUI_NodeHandle GetChildAt(ArkUI_NodeHandle node, int32_t position);
196 ArkUI_NodeHandle GetFirstChild(ArkUI_NodeHandle node);
197 ArkUI_NodeHandle GetLastChild(ArkUI_NodeHandle node);
198 ArkUI_NodeHandle GetPreviousSibling(ArkUI_NodeHandle node);
199 ArkUI_NodeHandle GetNextSibling(ArkUI_NodeHandle node);
200 ArkUI_NodeHandle GetParent(ArkUI_NodeHandle node);
201 int32_t RemoveAllChildren(ArkUI_NodeHandle parentNode);
202 } // namespace OHOS::Ace::NodeModel
203 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_INTERFACES_NATIVE_NODE_NODE_EXTENED_H