1 /*
2  * Copyright (c) 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 OHOS_ACE_FRAMEWORK_CJ_VIEW_ABSTRACT_FFI_H
17 #define OHOS_ACE_FRAMEWORK_CJ_VIEW_ABSTRACT_FFI_H
18 
19 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_common_ffi.h"
20 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_macro.h"
21 #include "bridge/cj_frontend/interfaces/cj_ffi/utils.h"
22 #include "core/components/common/properties/color.h"
23 #include "core/common/container.h"
24 #include "cj_transitioneffect.h"
25 
26 using VectorMenuValuePtr = void*;
27 using VectorStringPtr = void*;
28 using VectorNativeRectangleHandle = void*;
29 
30 namespace OHOS::Ace::Framework {
31 
GetPipelineContext()32 static RefPtr<PipelineBase> GetPipelineContext()
33 {
34     auto currentObj = Container::Current();
35     CHECK_NULL_RETURN(currentObj, nullptr);
36     return currentObj->GetPipelineContext();
37 }
38 
39 template<typename T>
GetTheme()40 static RefPtr<T> GetTheme()
41 {
42     auto pipelineContext = GetPipelineContext();
43     CHECK_NULL_RETURN(pipelineContext, nullptr);
44     auto themeManager = pipelineContext->GetThemeManager();
45     CHECK_NULL_RETURN(themeManager, nullptr);
46     return themeManager->GetTheme<T>();
47 }
48 }
49 
50 extern "C" {
51 struct NativeRectangle {
52     double x;
53     int32_t xUnit;
54     double y;
55     int32_t yUnit;
56     double width;
57     int32_t widthUnit;
58     double height;
59     int32_t heightUnit;
60 };
61 
62 struct CJBindPopupParams {
63     char* message;
64     bool placementOnTop;
65     char* primaryValue;
66     void (*primaryAction)();
67     char* secondaryValue;
68     void (*secondaryAction)();
69     void (*onStateChange)(bool);
70 };
71 
72 struct CJSheetOptions {
73     NativeOptionUInt32 backgroundColor;
74     NativeOptionCallBack onAppear;
75     NativeOptionCallBack onDisappear;
76     NativeOptionCallBack onWillAppear;
77     NativeOptionCallBack onWillDisappear;
78     NativeOptionInt32 height;
79     NativeOptionCArrInt32 detents;
80     NativeOptionInt32 preferType;
81     NativeOptionBool showClose;
82     NativeOptionBool dragBarl;
83     NativeOptionInt32 blurStyle;
84     NativeOptionUInt32 maskColor;
85     NativeOptionCallBack title;
86     NativeOptionBool enableOutsideInteractive;
87     NativeOptionCallBack shouldDismiss;
88 };
89 
90 struct CJBorder {
91     double width;
92     int32_t widthUnit;
93     uint32_t color;
94     double radius;
95     int32_t radiusUnit;
96     int32_t style;
97 };
98 
99 struct CJBorderWithId {
100     double width;
101     int32_t widthUnit;
102     int64_t colorId;
103     double radius;
104     int32_t radiusUnit;
105     int32_t style;
106 };
107 
108 struct CJEdge {
109     double top;
110     int32_t topUnit;
111     double right;
112     int32_t rightUnit;
113     double bottom;
114     int32_t bottomUnit;
115     double left;
116     int32_t leftUnit;
117 };
118 
119 struct RetDimension {
120     double value;
121     int32_t unit;
122 };
123 
124 struct CJBorderRadius {
125     double topLeft;
126     int32_t topLeftUnit;
127     double topRight;
128     int32_t topRightUnit;
129     double bottomLeft;
130     int32_t bottomLeftUnit;
131     double bottomRight;
132     int32_t bottomRightUnit;
133 };
134 
135 struct CJTranslate {
136     double x;
137     int32_t xUnit;
138     double y;
139     int32_t yUnit;
140     double z;
141     int32_t zUnit;
142 };
143 
144 struct CJResponseRegion {
145     double x;
146     int32_t xUnit;
147     double y;
148     int32_t yUnit;
149     double width;
150     int32_t widthUnit;
151     double height;
152     int32_t heightUnit;
153 };
154 
155 struct CJConstraintSize {
156     double minWidth;
157     int32_t minWidthUnit;
158     double maxWidth;
159     int32_t maxWidthUnit;
160     double minHeight;
161     int32_t minHeightUnit;
162     double maxHeight;
163     int32_t maxHeightUnit;
164 };
165 
166 struct CJSetScale {
167     float scaleX;
168     float scaleY;
169     float scaleZ;
170     double centerX;
171     int32_t centerXUnit;
172     double centerY;
173     int32_t centerYUnit;
174 };
175 
176 struct CJBlurOptions {
177     float grayscale[2];
178 };
179 
180 struct CJForegroundBlurStyle {
181     int32_t colorMode;
182     int32_t adaptiveColor;
183     CJBlurOptions blurOptions;
184 };
185 
186 struct CJAlignRuleOption {
187     char* leftAnchor;
188     int32_t leftHorizontalAlign;
189     char* rightAnchor;
190     int32_t rightHorizontalAlign;
191     char* middleAnchor;
192     int32_t middleHorizontalAlign;
193     char* topAnchor;
194     int32_t topVerticalAlign;
195     char* bottomAnchor;
196     int32_t bottomVerticalAlign;
197     char* centerAnchor;
198     int32_t centerVerticalAlign;
199     float* horizontalBias;
200     float* verticalBias;
201 };
202 
203 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetWidth(double width, int32_t unit);
204 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetHeight(double height, int32_t unit);
205 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetSize(
206     double width, int32_t widthUnit, double height, int32_t heightUnit);
207 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetResponseRegion(CJResponseRegion value);
208 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetResponseRegionArray(VectorStringPtr vecContent);
209 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetConstraintSize(CJConstraintSize value);
210 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetLayoutPriority(int32_t value);
211 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetLayoutWeight(int32_t value);
212 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBorder(CJBorder params);
213 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBorderWidth(double width, int32_t unit);
214 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBorderWidthWithCJEdge(CJEdge params);
215 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBorderColor(uint32_t color);
216 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBorderRadius(double radius, int32_t unit);
217 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetAllBorderRadius(CJBorderRadius value);
218 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBorderStyle(int32_t style);
219 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetMargin(double margin, int32_t unit);
220 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetMargins(CJEdge params);
221 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetPadding(double padding, int32_t unit);
222 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetPaddings(CJEdge params);
223 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetForegroundBlurStyle(int32_t blurStyle);
224 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetForegroundBlurStyleOption(int32_t blurStyle,
225                                                                            CJForegroundBlurStyle options);
226 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetForegroundColor(char* strategy);
227 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetForegroundResourceColor(uint32_t color);
228 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBackgroundColor(uint32_t color);
229 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBackgroundImage(const char* src, int32_t repeat);
230 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBackgroundImageSizeType(int32_t imageSize);
231 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBackgroundImageSize(
232     double width, int32_t widthUnit, double height, int32_t heightUnit);
233 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBackgroundImagePositionAlign(int32_t align);
234 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBackgroundImagePositionXY(
235     double x, int32_t xUnit, double y, int32_t yUnit);
236 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetScale(CJSetScale value);
237 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetScaleSingle(float scale);
238 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetScaleX(float scaleVal);
239 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetScaleY(float scaleVal);
240 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetOpacity(double opacity);
241 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractbindSheetParam(bool isShow, void (*builder)(), CJSheetOptions option);
242 
243 struct CJSetRotate {
244     float dx;
245     float dy;
246     float dz;
247     float angle;
248     double centerX;
249     int32_t centerXUnit;
250     double centerY;
251     int32_t centerYUnit;
252 };
253 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetRotate(CJSetRotate value);
254 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetRotateSingle(float rotateZ);
255 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetRotateX(float rotateVal);
256 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetRotateY(float rotateVal);
257 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetTranslate(CJTranslate value);
258 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetTranslateSingle(double translateValue, int32_t translateUnit);
259 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetTranslateX(double translateValue, int32_t translateUnit);
260 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetTranslateY(double translateValue, int32_t translateUnit);
261 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetTransition();
262 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractTransition(int64_t id);
263 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetTransform(int64_t id);
264 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetAlign(int32_t value);
265 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetDirection(int32_t dirValue);
266 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetPosition(double x, int32_t xUnit, double y, int32_t yUnit);
267 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetMarkAnchor(double x, int32_t xUnit, double y, int32_t yUnit);
268 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetOffset(double x, int32_t xUnit, double y, int32_t yUnit);
269 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetAlignRules(CJAlignRuleOption option);
270 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetEnabled(bool value);
271 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetAspectRatio(double value);
272 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetDisplayPriority(int32_t value);
273 
274 struct CJMotionPathOptions {
275     char* path;
276     double from;
277     double to;
278     bool rotatable;
279 };
280 struct CJSharedTransitionOptions {
281     int32_t duration;
282     int32_t delay;
283     int32_t zIndex;
284     char* curve;
285     CJMotionPathOptions motionPathOption;
286     int32_t type;
287 };
288 struct CJGeometryTransitionOptions {
289     bool follow = false;
290     int32_t hierarchyStrategy;
291 };
292 
293 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetSharedTransition(char* shareId, CJSharedTransitionOptions option);
294 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetGeometryTransition(char* id, CJGeometryTransitionOptions option);
295 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBlur(double value);
296 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetColorBlend(uint32_t color);
297 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBackdropBlur(double value);
298 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetWindowBlur(float progress, int32_t styleValue);
299 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetShadow(double radius, uint32_t color, double offsetX, double offsetY);
300 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetGrayScale(double value);
301 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetBrightness(double value);
302 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetSaturate(double value);
303 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetContrast(double value);
304 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetInvert(double value);
305 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetSepia(double value);
306 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetHueRotate(float deg);
307 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetFlexBasis(double value, int32_t unit);
308 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetFlexGrow(double value);
309 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetFlexShrink(double value);
310 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetAlignSelf(int32_t alignValue);
311 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetZIndex(int32_t zIndex);
312 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetVisibility(int32_t visibility);
313 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetClip(bool isClip);
314 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetClipByShape(int64_t shapeId);
315 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetMaskByShape(int64_t shapeId);
316 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractPop();
317 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetOverlay(const char* title, int32_t align, double x, double y);
318 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractBindPopup(bool isShow, CJBindPopupParams bindPopupParams);
319 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractKeyShortcutByFuncKey(
320     int32_t value, int32_t *keysArray, int64_t size, void (*callback)(void));
321 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractKeyShortcutByChar(
322     const char* value, int32_t *keysArray, int64_t size, void (*callback)(void));
323 
324 struct CJBindCustomPopup {
325     bool isShow;
326     void (*builder)();
327     int32_t placement;
328     uint32_t maskColor;
329     uint32_t backgroundColor;
330     bool enableArrow;
331     bool autoCancel;
332     void (*onStateChange)(bool);
333 };
334 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractBindCustomPopup(CJBindCustomPopup value);
335 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractBindMenu(
336     VectorMenuValuePtr vectorMenuValue, void (*menuActionCallback)(const char*));
337 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractBindCustomMenu(void (*builder)());
338 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractBindContextMenu(void (*builder)(), int32_t responseType);
339 struct CColors {
340     uint32_t color;
341     double location;
342 };
343 
344 struct CArrCColors {
345     CColors* header;
346     int64_t size;
347 };
348 
349 struct LinearGradientParam {
350     double* angle;
351     int32_t direction;
352     CArrCColors colors;
353     bool repeating;
354 };
355 
356 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractLinearGradient(LinearGradientParam linearGradientParam);
357 struct CTupleLength {
358     double rowValue;
359     int32_t rowUnitType;
360     double columnValue;
361     int32_t columnUnitType;
362 };
363 
364 struct SweepGradientParam {
365     CTupleLength center;
366     double start;
367     double end;
368     double rotation;
369     CArrCColors colors;
370     bool repeating;
371 };
372 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSweepGradient(SweepGradientParam sweepGradientParam);
373 
374 struct RadialGradientParam {
375     CTupleLength center;
376     double radius;
377     int32_t radiusUnit;
378     CArrCColors colors;
379     bool repeating;
380 };
381 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractRadialGradient(RadialGradientParam radialGradientParam);
382 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractRenderFit(int32_t fitMode);
383 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetInspectorKey(const char* key);
384 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractSetId(const char* id);
385 CJ_EXPORT VectorNativeRectangleHandle FFICJCreateVectorNativeRectangle(int64_t size);
386 CJ_EXPORT void FFICJVectorNativeRectangleSetElement(
387     VectorNativeRectangleHandle vec, int64_t index, NativeRectangle rect);
388 CJ_EXPORT void FFICJVectorNativeRectangleDelete(VectorNativeRectangleHandle vec);
389 CJ_EXPORT ExternalString FFIOHOSAceFrameworkGetResourceStr(int64_t id, uint32_t type, const char* param);
390 CJ_EXPORT ExternalString FFIOHOSAceFrameworkGetResourcePluralStr(
391     int64_t id, uint32_t type, int64_t count, const char* plural);
392 CJ_EXPORT RetDimension FFIOHOSAceFrameworkGetResourceDimension(int64_t id);
393 CJ_EXPORT uint32_t FFIOHOSAceFrameworkGetResourceColor(int64_t id);
394 CJ_EXPORT ExternalString FFIOHOSAceFrameworkGetResourceMedia(int64_t id, uint32_t type, const char* param);
395 CJ_EXPORT void FfiOHOSAceFrameworkViewAbstractExpandSafeArea(uint32_t types, uint32_t edges);
396 CJ_EXPORT void FFIOHOSAceFrameworkFocusable(bool isFocusable);
397 CJ_EXPORT void FFIOHOSAceFrameworkTabIndex(int32_t index);
398 CJ_EXPORT void FFIOHOSAceFrameworkDefaultFocus(bool isDefaultFocus);
399 CJ_EXPORT void FFIOHOSAceFrameworkGroupDefaultFocus(bool isGroupDefaultFocus);
400 CJ_EXPORT void FFIOHOSAceFrameworkFocusOnTouch(bool isFocusOnTouch);
401 CJ_EXPORT bool FFIOHOSAceFrameworkRequestFocus(const char* inspectorKey);
402 
403 CJ_EXPORT void FFISetWidthWithEmpty();
404 CJ_EXPORT void FFISetHeightWithEmpty();
405 
406 struct CJContentCoverOptions {
407     uint32_t modalTransition;
408     NativeOptionUInt32 backgroundColor;
409     NativeOptionCallBack onAppear;
410     NativeOptionCallBack onDisappear;
411     NativeOptionCallBack onWillAppear;
412     NativeOptionCallBack onWillDisappear;
413 };
414 CJ_EXPORT void FFIOHOSAceFrameworkBindContentCover(bool isShow, void (*builder)(), CJContentCoverOptions options);
415 }
416 
417 namespace OHOS::Ace {
418 enum class ResourceType : uint32_t {
419     COLOR = 10001,
420     FLOAT,
421     STRING,
422     PLURAL,
423     BOOLEAN,
424     INTARRAY,
425     INTEGER,
426     PATTERN,
427     STRARRAY,
428     MEDIA = 20000,
429     RAWFILE = 30000
430 };
431 bool ParseCjMedia(int64_t id, ResourceType type, const std::string& params, std::string& result);
432 bool ParseCjString(int64_t id, ResourceType type, const std::string& params, std::string& result);
433 bool ParseCjString(
434     int64_t id, ResourceType type, int64_t count, const std::string& plural, std::string& result);
435 bool ParseCjDimension(int64_t id, Dimension& result);
436 bool ParseColorById(int64_t id, Color& color);
437 void ParseCJResponseRegion(CJResponseRegion value, std::vector<DimensionRect>& result);
438 void ParseVectorStringPtr(VectorStringPtr value, std::vector<DimensionRect>& result);
439 } // namespace OHOS::Ace
440 
441 #endif // OHOS_ACE_FRAMEWORK_CJ_VIEW_ABSTRACT_FFI_H
442