• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMMON_FFI_H
17 #define OHOS_ACE_FRAMEWORK_CJ_COMMON_FFI_H
18 
19 #include <cstdint>
20 #include <string>
21 
22 #include "bridge/cj_frontend/interfaces/cj_ffi/cj_macro.h"
23 #include "bridge/cj_frontend/interfaces/cj_ffi/utils.h"
24 #include "core/event/touch_event.h"
25 #include "core/gestures/gesture_info.h"
26 
27 extern "C" {
28 struct NativeFontInfo {
29     const char* path = "";
30     const char* postScriptName = "";
31     const char* fullName = "";
32     const char* family = "";
33     const char* subfamily = "";
34     uint32_t weight = 0;
35     uint32_t width = 0;
36     bool italic = false;
37     bool monoSpace = false;
38     bool symbolic = false;
39 };
40 
41 struct NativeOptionFontInfo {
42     bool hasValue;
43     NativeFontInfo* info;
44 };
45 
46 struct NativeLength {
47     double value;
48     int32_t unitType;
49 };
50 
51 struct NativeOffset {
52     NativeLength dx;
53     NativeLength dy;
54 };
55 
56 struct NativeOptionLength {
57     bool hasValue;
58     NativeLength value;
59 };
60 
61 struct NativeOptionInt32 {
62     bool hasValue;
63     int32_t value;
64 };
65 
66 struct NativeOptionInt64 {
67     bool hasValue;
68     int64_t value;
69 };
70 
71 struct NativeOptionUInt32 {
72     bool hasValue;
73     uint32_t value;
74 };
75 
76 struct NativeOptionFloat32 {
77     bool hasValue;
78     float value;
79 };
80 
81 struct NativeOptionFloat64 {
82     bool hasValue;
83     double value;
84 };
85 
86 struct NativeOptionCallBack {
87     bool hasValue;
88     void (*value)();
89 };
90 
91 struct NativeOptionCallback1Param {
92     bool hasValue;
93     void (*value)(int32_t reason);
94 };
95 
96 struct NativeOptionCallback1FloatParam {
97     bool hasValue;
98     void (*value)(float reason);
99 };
100 
101 struct NativeOptionBool {
102     bool hasValue;
103     bool value;
104 };
105 
106 struct CArrInt32 {
107     int32_t* head;
108     int64_t size;
109 };
110 
111 struct NativeOptionCArrInt32 {
112     bool hasValue;
113     CArrInt32 value;
114 };
115 
116 struct NativeOptionCString {
117     bool hasValue;
118     const char* value;
119 };
120 
121 struct CJOffset {
122     double xOffset;
123     double yOffset;
124 };
125 
126 struct CJRectResult {
127     double x;
128     double y;
129     double width;
130     double height;
131 };
132 
133 struct CJTouchTestInfo {
134     float windowX;
135     float windowY;
136     float parentX;
137     float parentY;
138     float x;
139     float y;
140     CJRectResult rect;
141     ExternalString id;
142 };
143 
144 struct CJTouchResult {
145     int32_t strategy;
146     ExternalString id;
147 };
148 
149 struct CJTouchInfo {
150     uint8_t type;
151     int32_t fingerId;
152     double globalX;
153     double globalY;
154     double localX;
155     double localY;
156 };
157 
158 struct CJTextPickerResult {
159     const char* value;
160     uint32_t index;
161 };
162 
163 struct CJDatePickerResult {
164     const char* value;
165     uint32_t index;
166 };
167 
168 struct CJImageCompleteV2 {
169     double width;
170     double height;
171     double componentWidth;
172     double componentHeight;
173     int32_t loadingStatus;
174     double contentWidth;
175     double contentHeight;
176     double contentOffsetX;
177     double contentOffsetY;
178 };
179 
180 struct CJImageComplete {
181     double width;
182     double height;
183     double componentWidth;
184     double componentHeight;
185     int32_t loadingStatus;
186 };
187 
188 struct CJImageErrorV2 {
189     double componentWidth;
190     double componentHeight;
191     const char* message;
192 };
193 
194 struct CJImageError {
195     double componentWidth;
196     double componentHeight;
197 };
198 
199 struct CJPosition {
200     double x;
201     double y;
202 };
203 
204 struct CJArea {
205     double width;
206     double height;
207     CJPosition* position;
208     CJPosition* globalPosition;
209 };
210 
211 struct CJSizeOptions {
212     double width;
213     double height;
214 };
215 
216 struct CJEventTarget {
217     CJArea* area;
218 };
219 
220 struct CJTouchEvent {
221     uint8_t eventType;
222     CJTouchInfo* touches;
223     int32_t touchesSize;
224     CJTouchInfo* changedTouches;
225     int32_t changedTouchesSize;
226     int64_t timestamp;
227     CJEventTarget* target;
228     int32_t sourceType;
229     std::string ToString() const;
230 };
231 
232 struct CJMouseEvent {
233     int64_t timestamp;
234     double screenX;
235     double screenY;
236     double x;
237     double y;
238     int32_t button;
239     int32_t action;
240 };
241 
242 struct CJClickInfo {
243     double x;
244     double y;
245     int64_t timestamp;
246     int32_t source;
247     CJEventTarget* target;
248     double windowX;
249     double windowY;
250     double displayX;
251     double displayY;
252     double globalDisplayX;
253     double globalDisplayY;
254     std::string ToString() const;
255 };
256 
257 struct CJKeyEvent {
258     const char* keyText;
259     int32_t type;
260     int32_t keyCode;
261     int32_t keySource;
262     int32_t metaKey;
263     int64_t deviceId;
264     int64_t timestamp;
265 };
266 
267 struct CJFingerInfo {
268     int32_t id;
269     double globalX;
270     double globalY;
271     double localX;
272     double localY;
273 };
274 
275 struct CJGestureEventV2 {
276     int64_t timestamp;
277     CJEventTarget* target;
278     bool repeat;
279     CJFingerInfo* fingerList;
280     int32_t fingerListSize;
281     int32_t source;
282     double offsetX;
283     double offsetY;
284     double scale;
285     double pinchCenterX;
286     double pinchCenterY;
287     double angle;
288     double speed;
289     int64_t tiltX;
290     int64_t tiltY;
291     int32_t sourceTool;
292     double velocityX;
293     double velocityY;
294     double velocity;
295     double pressure;
296     float axisHorizontal;
297     float axisVertical;
298     int64_t deviceId;
299     const OHOS::Ace::BaseEventInfo* baseEventInfoPtr;
300 };
301 
302 struct CJGestureEvent {
303     int64_t timestamp;
304     CJEventTarget* target;
305     bool repeat;
306     CJFingerInfo* fingerList;
307     int32_t fingerListSize;
308     int32_t source;
309     double offsetX;
310     double offsetY;
311     double scale;
312     double pinchCenterX;
313     double pinchCenterY;
314     double angle;
315     double speed;
316 };
317 
318 struct CJDragInfo {
319     const char* extraParams;
320     CJPosition* position;
321 };
322 
323 struct CJDragEvent {
324     void* evtPtr;
325     bool useCustomDropAnimation;
326     int32_t dragBehavior;
327 };
328 
329 struct CJDragItemInfo {
330     int64_t pixelMapId;
331     void (*builder)();
332     char* extraInfo;
333 };
334 
335 struct CJBaseEvent {
336     CJEventTarget* target;
337     int64_t timestamp;
338     int32_t source;
339     double pressure;
340     int64_t tiltX;
341     int64_t tiltY;
342     int32_t sourceTool;
343     float* axisHorizontal;
344     float* axisVertical;
345     int64_t deviceId;
346 };
347 
348 struct NativeFont {
349     double size;
350     int32_t sizeUnit;
351     const char* weight;
352     const char* family;
353     uint32_t style;
354 };
355 
356 struct AtCPackage;
357 
358 struct AtCOHOSAceFrameworkCJInstanceLoadEntryParams {
359     const char* name;
360     bool* result;
361 
AtCOHOSAceFrameworkCJInstanceLoadEntryParamsAtCOHOSAceFrameworkCJInstanceLoadEntryParams362     AtCOHOSAceFrameworkCJInstanceLoadEntryParams(const char* name, bool* result) : name(name), result(result) {}
363 };
364 
365 struct AtCOHOSAceFrameworkCJInstanceInitializeParams {
366     int16_t runtimeId;
367     int64_t version;
368     AtCPackage* package;
369     bool* result;
370 
AtCOHOSAceFrameworkCJInstanceInitializeParamsAtCOHOSAceFrameworkCJInstanceInitializeParams371     AtCOHOSAceFrameworkCJInstanceInitializeParams(int16_t runtimeId, int64_t version, AtCPackage* package, bool* result)
372         : runtimeId(runtimeId), version(version), package(package), result(result)
373     {}
374 };
375 
376 struct AtCPackage {
377     bool (*atCOHOSAceFrameworkCJInstanceInitialize)(AtCOHOSAceFrameworkCJInstanceInitializeParams* params) = nullptr;
378     bool (*atCOHOSAceFrameworkCJInstanceLoadEntry)(AtCOHOSAceFrameworkCJInstanceLoadEntryParams*) = nullptr;
379     void (*atCOHOSAceFrameworkRemoteViewRender)(int64_t self) = nullptr;
380     void (*atCOHOSAceFrameworkRemoteViewRerender)(int64_t self) = nullptr;
381     void (*atCOHOSAceFrameworkRemoteViewRelease)(int64_t self) = nullptr;
382     void (*atCOHOSAceFrameworkRemoteViewOnAppear)(int64_t self) = nullptr;
383     void (*atCOHOSAceFrameworkRemoteViewOnShow)(int64_t self) = nullptr;
384     void (*atCOHOSAceFrameworkRemoteViewOnHide)(int64_t self) = nullptr;
385     bool (*atCOHOSAceFrameworkRemoteViewOnBackPress)(int64_t self) = nullptr;
386     void (*atCOHOSAceFrameworkRemoteViewUpdateWithJson)(int64_t self, const char* json) = nullptr;
387     void (*atCOHOSAceFrameworkRemoteViewOnTransition)(int64_t self) = nullptr;
388     void (*atCOHOSAceFrameworkRemoteViewOnAboutToRender)(int64_t self) = nullptr;
389     void (*atCOHOSAceFrameworkRemoteViewOnAfterRender)(int64_t self) = nullptr;
390     void (*atCOHOSAceFrameworkRemoteViewOnDisappear)(int64_t self) = nullptr;
391     void (*atCOHOSAceFrameworkRemoteViewOnAboutToBeDeleted)(int64_t self) = nullptr;
392     void (*atCOHOSAceFrameworkRemoteViewForceCompleteRerender)(int64_t self, bool deep) = nullptr;
393     ExternalString (*atCOHOSAceFrameworkLazyForEachFuncsGenerateKey)(int64_t self, int64_t idx) = nullptr;
394     void (*atCOHOSAceFrameworkLazyForEachFuncsGenerateItem)(int64_t self, int64_t idx) = nullptr;
395     int64_t (*atCOHOSAceFrameworkLazyForEachFuncsGetTotalCount)(int64_t self) = nullptr;
396     void (*atCOHOSAceFrameworkLazyForEachFuncsMarkLazy)(int64_t self, const char* key) = nullptr;
397     void (*atCOHOSAceFrameworkLazyForEachFuncsResetLazy)(int64_t self) = nullptr;
398     void (*atCOHOSAceFrameworkLazyForEachFuncsRemoveChildGroup)(int64_t self, const char* composedId) = nullptr;
399     void (*atCOHOSAceFrameworkLazyForEachFuncsDataChangeListenerRegister)(int64_t self, int64_t idx) = nullptr;
400     void (*atCOHOSAceFrameworkLazyForEachFuncsDataChangeListenerUnregister)(int64_t self, int64_t idx) = nullptr;
401 };
402 
403 struct AtCXComponentCallback {
404     void (*atCXComponentControllerOnSurfaceCreated)(int64_t self, int64_t idx) = nullptr;
405     void (*atCXComponentControllerOnSurfaceChanged)(int64_t self, int64_t idx, CJRectResult rect) = nullptr;
406     void (*atCXComponentControllerOnSurfaceDestroyed)(int64_t self, int64_t idx) = nullptr;
407 };
408 
409 struct AtCPackageV2 {
410     void (*atCOHOSAceFrameworkRemoteViewOnDidBuild)(int64_t self) = nullptr;
411     void (*atCOHOSAceFrameworkRemoteViewAboutToReuse)(int64_t self, const char* params) = nullptr;
412     void (*atCOHOSAceFrameworkRemoteViewAboutToRecycle)(int64_t self) = nullptr;
413     void (*atCOHOSAceFrameworkRemoteViewRecycleSelf)(int64_t self, const char* params) = nullptr;
414 };
415 
416 CJ_EXPORT void FfiOHOSAceFrameworkRegisterCJFuncs(AtCPackage cjFuncs);
417 CJ_EXPORT void FfiOHOSAceFrameworkRegisterCJFuncsV2(void (*callback)(AtCPackageV2* cjFuncs));
418 
419 CJ_EXPORT void FfiOHOSAceFrameworkRegisterCJXComponentCtrFuncs(AtCXComponentCallback cjCtrFuncs);
420 
421 CJ_EXPORT int64_t FfiGeneralSizeOfPointer();
422 
423 CJ_EXPORT bool FfiOHOSAceFrameworkCanIUse(char* syscapString);
424 
425 struct CJIndicator {
426     double left;
427     int32_t leftUnit;
428     double top;
429     int32_t topUnit;
430     double right;
431     int32_t rightUnit;
432     double bottom;
433     int32_t bottomUnit;
434     double start;
435     int32_t startUnit;
436     double end;
437     int32_t endUnit;
438 };
439 }
440 
441 namespace OHOS::Ace {
442 void TransformNativeTouchLocationInfo(
443     CJTouchInfo* sources, const std::list<OHOS::Ace::TouchLocationInfo>& touchLocationInfoList);
444 
445 void TransformNativeCJFingerInfo(CJFingerInfo* sources, const std::list<OHOS::Ace::FingerInfo>& fingerInfoList);
446 
447 void AssambleCJEventTarget(
448     const OHOS::Ace::EventTarget& eventTarget, CJArea& area, CJPosition& position, CJPosition& globalPosition);
449 
450 void AssambleCJClickInfo(const OHOS::Ace::GestureEvent& event, CJClickInfo& clickInfo, CJEventTarget& eventTarget,
451     CJArea& area, CJPosition& position, CJPosition& globalPosition);
452 
453 void ReleaseCJDragItemInfo(CJDragItemInfo& info);
454 } // namespace OHOS::Ace
455 #endif // OHOS_ACE_FRAMEWORK_CJ_COMMON_FFI_H
456