1 /*
2 * Copyright (c) 2021-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 #include "native_interface_xcomponent.h"
17
18 #include "node/node_model.h"
19
20 #include "base/error/error_code.h"
21 #include "frameworks/core/components/xcomponent/native_interface_xcomponent_impl.h"
22 #include "frameworks/core/components_ng/pattern/xcomponent/xcomponent_surface_holder.h"
23 #include "frameworks/core/accessibility/native_interface_accessibility_provider.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
OH_NativeXComponent_GetXComponentId(OH_NativeXComponent * component,char * id,uint64_t * size)29 int32_t OH_NativeXComponent_GetXComponentId(OH_NativeXComponent* component, char* id, uint64_t* size)
30 {
31 if ((component == nullptr) || (id == nullptr) || (size == nullptr)) {
32 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
33 }
34 if (((*size) == 0) || ((*size) > (OH_XCOMPONENT_ID_LEN_MAX + 1))) {
35 LOGE("The referenced value of 'size' should be in the range (0, OH_XCOMPONENT_ID_LEN_MAX + 1]");
36 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
37 }
38 return component->GetXComponentId(id, size);
39 }
40
OH_NativeXComponent_GetXComponentSize(OH_NativeXComponent * component,const void * window,uint64_t * width,uint64_t * height)41 int32_t OH_NativeXComponent_GetXComponentSize(
42 OH_NativeXComponent* component, const void* window, uint64_t* width, uint64_t* height)
43 {
44 if ((component == nullptr) || (window == nullptr) || (width == nullptr) || (height == nullptr)) {
45 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
46 }
47 return component->GetXComponentSize(window, width, height);
48 }
49
OH_NativeXComponent_GetXComponentOffset(OH_NativeXComponent * component,const void * window,double * x,double * y)50 int32_t OH_NativeXComponent_GetXComponentOffset(
51 OH_NativeXComponent* component, const void* window, double* x, double* y)
52 {
53 if ((component == nullptr) || (window == nullptr) || (x == nullptr) || (y == nullptr)) {
54 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
55 }
56 return component->GetXComponentOffset(window, x, y);
57 }
58
OH_NativeXComponent_GetTouchEvent(OH_NativeXComponent * component,const void * window,OH_NativeXComponent_TouchEvent * touchEvent)59 int32_t OH_NativeXComponent_GetTouchEvent(
60 OH_NativeXComponent* component, const void* window, OH_NativeXComponent_TouchEvent* touchEvent)
61 {
62 if ((component == nullptr) || (window == nullptr) || (touchEvent == nullptr)) {
63 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
64 }
65 return component->GetTouchEvent(window, touchEvent);
66 }
67
OH_NativeXComponent_GetTouchPointToolType(OH_NativeXComponent * component,uint32_t pointIndex,OH_NativeXComponent_TouchPointToolType * toolType)68 int32_t OH_NativeXComponent_GetTouchPointToolType(
69 OH_NativeXComponent* component, uint32_t pointIndex, OH_NativeXComponent_TouchPointToolType* toolType)
70 {
71 if ((component == nullptr) || (toolType == nullptr)) {
72 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
73 }
74 return component->GetToolType(pointIndex, toolType);
75 }
76
OH_NativeXComponent_GetTouchPointTiltX(OH_NativeXComponent * component,uint32_t pointIndex,float * tiltX)77 int32_t OH_NativeXComponent_GetTouchPointTiltX(OH_NativeXComponent* component, uint32_t pointIndex, float* tiltX)
78 {
79 if ((component == nullptr) || (tiltX == nullptr)) {
80 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
81 }
82 return component->GetTiltX(pointIndex, tiltX);
83 }
84
OH_NativeXComponent_GetTouchPointTiltY(OH_NativeXComponent * component,uint32_t pointIndex,float * tiltY)85 int32_t OH_NativeXComponent_GetTouchPointTiltY(OH_NativeXComponent* component, uint32_t pointIndex, float* tiltY)
86 {
87 if ((component == nullptr) || (tiltY == nullptr)) {
88 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
89 }
90 return component->GetTiltY(pointIndex, tiltY);
91 }
92
OH_NativeXComponent_GetTouchPointWindowX(OH_NativeXComponent * component,uint32_t pointIndex,float * windowX)93 int32_t OH_NativeXComponent_GetTouchPointWindowX(OH_NativeXComponent* component, uint32_t pointIndex, float* windowX)
94 {
95 if ((component == nullptr) || (windowX == nullptr)) {
96 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
97 }
98 return component->GetWindowX(pointIndex, windowX);
99 }
100
OH_NativeXComponent_GetTouchPointWindowY(OH_NativeXComponent * component,uint32_t pointIndex,float * windowY)101 int32_t OH_NativeXComponent_GetTouchPointWindowY(OH_NativeXComponent* component, uint32_t pointIndex, float* windowY)
102 {
103 if ((component == nullptr) || (windowY == nullptr)) {
104 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
105 }
106 return component->GetWindowY(pointIndex, windowY);
107 }
108
OH_NativeXComponent_GetTouchPointDisplayX(OH_NativeXComponent * component,uint32_t pointIndex,float * displayX)109 int32_t OH_NativeXComponent_GetTouchPointDisplayX(OH_NativeXComponent* component, uint32_t pointIndex, float* displayX)
110 {
111 if ((component == nullptr) || (displayX == nullptr)) {
112 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
113 }
114 return component->GetDisplayX(pointIndex, displayX);
115 }
116
OH_NativeXComponent_GetTouchPointDisplayY(OH_NativeXComponent * component,uint32_t pointIndex,float * displayY)117 int32_t OH_NativeXComponent_GetTouchPointDisplayY(OH_NativeXComponent* component, uint32_t pointIndex, float* displayY)
118 {
119 if ((component == nullptr) || (displayY == nullptr)) {
120 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
121 }
122 return component->GetDisplayY(pointIndex, displayY);
123 }
124
OH_NativeXComponent_GetHistoricalPoints(OH_NativeXComponent * component,const void * window,int32_t * size,OH_NativeXComponent_HistoricalPoint ** historicalPoints)125 int32_t OH_NativeXComponent_GetHistoricalPoints(OH_NativeXComponent* component, const void* window,
126 int32_t* size, OH_NativeXComponent_HistoricalPoint** historicalPoints)
127 {
128 if ((component == nullptr) || (window == nullptr)) {
129 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
130 }
131 return component->GetHistoryPoints(window, size, historicalPoints);
132 }
133
OH_NativeXComponent_GetMouseEvent(OH_NativeXComponent * component,const void * window,OH_NativeXComponent_MouseEvent * mouseEvent)134 int32_t OH_NativeXComponent_GetMouseEvent(
135 OH_NativeXComponent* component, const void* window, OH_NativeXComponent_MouseEvent* mouseEvent)
136 {
137 if ((component == nullptr) || (window == nullptr) || (mouseEvent == nullptr)) {
138 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
139 }
140 return component->GetMouseEvent(window, mouseEvent);
141 }
142
OH_NativeXComponent_RegisterCallback(OH_NativeXComponent * component,OH_NativeXComponent_Callback * callback)143 int32_t OH_NativeXComponent_RegisterCallback(OH_NativeXComponent* component, OH_NativeXComponent_Callback* callback)
144 {
145 if ((component == nullptr) || (callback == nullptr)) {
146 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
147 }
148 return component->RegisterCallback(callback);
149 }
150
OH_NativeXComponent_RegisterMouseEventCallback(OH_NativeXComponent * component,OH_NativeXComponent_MouseEvent_Callback * callback)151 int32_t OH_NativeXComponent_RegisterMouseEventCallback(
152 OH_NativeXComponent* component, OH_NativeXComponent_MouseEvent_Callback* callback)
153 {
154 if ((component == nullptr) || (callback == nullptr)) {
155 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
156 }
157 return component->RegisterMouseEventCallback(callback);
158 }
159
OH_NativeXComponent_RegisterFocusEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))160 int32_t OH_NativeXComponent_RegisterFocusEventCallback(
161 OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
162 {
163 if ((component == nullptr) || (callback == nullptr)) {
164 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
165 }
166 return component->RegisterFocusEventCallback(callback);
167 }
168
OH_NativeXComponent_RegisterKeyEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))169 int32_t OH_NativeXComponent_RegisterKeyEventCallback(
170 OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
171 {
172 if ((component == nullptr) || (callback == nullptr)) {
173 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
174 }
175 return component->RegisterKeyEventCallback(callback);
176 }
177
OH_NativeXComponent_RegisterBlurEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))178 int32_t OH_NativeXComponent_RegisterBlurEventCallback(
179 OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
180 {
181 if ((component == nullptr) || (callback == nullptr)) {
182 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
183 }
184 return component->RegisterBlurEventCallback(callback);
185 }
186
OH_NativeXComponent_GetKeyEvent(OH_NativeXComponent * component,OH_NativeXComponent_KeyEvent ** keyEvent)187 int32_t OH_NativeXComponent_GetKeyEvent(OH_NativeXComponent* component, OH_NativeXComponent_KeyEvent** keyEvent)
188 {
189 if ((component == nullptr) || (keyEvent == nullptr)) {
190 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
191 }
192 return component->GetKeyEvent(keyEvent);
193 }
194
OH_NativeXComponent_GetKeyEventAction(OH_NativeXComponent_KeyEvent * keyEvent,OH_NativeXComponent_KeyAction * action)195 int32_t OH_NativeXComponent_GetKeyEventAction(
196 OH_NativeXComponent_KeyEvent* keyEvent, OH_NativeXComponent_KeyAction* action)
197 {
198 if ((keyEvent == nullptr) || (action == nullptr)) {
199 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
200 }
201 (*action) = keyEvent->action;
202 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
203 }
204
OH_NativeXComponent_GetKeyEventCode(OH_NativeXComponent_KeyEvent * keyEvent,OH_NativeXComponent_KeyCode * code)205 int32_t OH_NativeXComponent_GetKeyEventCode(OH_NativeXComponent_KeyEvent* keyEvent, OH_NativeXComponent_KeyCode* code)
206 {
207 if ((keyEvent == nullptr) || (code == nullptr)) {
208 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
209 }
210 (*code) = keyEvent->code;
211 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
212 }
213
OH_NativeXComponent_GetKeyEventSourceType(OH_NativeXComponent_KeyEvent * keyEvent,OH_NativeXComponent_EventSourceType * sourceType)214 int32_t OH_NativeXComponent_GetKeyEventSourceType(
215 OH_NativeXComponent_KeyEvent* keyEvent, OH_NativeXComponent_EventSourceType* sourceType)
216 {
217 if ((keyEvent == nullptr) || (sourceType == nullptr)) {
218 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
219 }
220 (*sourceType) = keyEvent->sourceType;
221 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
222 }
223
OH_NativeXComponent_GetKeyEventDeviceId(OH_NativeXComponent_KeyEvent * keyEvent,int64_t * deviceId)224 int32_t OH_NativeXComponent_GetKeyEventDeviceId(OH_NativeXComponent_KeyEvent* keyEvent, int64_t* deviceId)
225 {
226 if ((keyEvent == nullptr) || (deviceId == nullptr)) {
227 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
228 }
229 (*deviceId) = keyEvent->deviceId;
230 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
231 }
232
OH_NativeXComponent_GetKeyEventTimestamp(OH_NativeXComponent_KeyEvent * keyEvent,int64_t * timestamp)233 int32_t OH_NativeXComponent_GetKeyEventTimestamp(OH_NativeXComponent_KeyEvent* keyEvent, int64_t* timestamp)
234 {
235 if ((keyEvent == nullptr) || (timestamp == nullptr)) {
236 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
237 }
238 (*timestamp) = keyEvent->timestamp;
239 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
240 }
241
OH_NativeXComponent_SetExpectedFrameRateRange(OH_NativeXComponent * component,OH_NativeXComponent_ExpectedRateRange * range)242 int32_t OH_NativeXComponent_SetExpectedFrameRateRange(
243 OH_NativeXComponent* component, OH_NativeXComponent_ExpectedRateRange* range)
244 {
245 if (component == nullptr || range == nullptr) {
246 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
247 }
248 return component->SetExpectedFrameRateRange(range);
249 }
250
OH_NativeXComponent_RegisterOnFrameCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,uint64_t timestamp,uint64_t targetTimestamp))251 int32_t OH_NativeXComponent_RegisterOnFrameCallback(OH_NativeXComponent* component,
252 void (*callback)(OH_NativeXComponent* component, uint64_t timestamp, uint64_t targetTimestamp))
253 {
254 if (component == nullptr) {
255 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
256 }
257 return component->RegisterOnFrameCallback(callback);
258 }
259
OH_NativeXComponent_UnregisterOnFrameCallback(OH_NativeXComponent * component)260 int32_t OH_NativeXComponent_UnregisterOnFrameCallback(OH_NativeXComponent* component)
261 {
262 if (component == nullptr) {
263 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
264 }
265 return component->UnregisterOnFrameCallback();
266 }
267
OH_NativeXComponent_AttachNativeRootNode(OH_NativeXComponent * component,ArkUI_NodeHandle root)268 int32_t OH_NativeXComponent_AttachNativeRootNode(
269 OH_NativeXComponent* component, ArkUI_NodeHandle root)
270 {
271 if ((component == nullptr) || (root == nullptr) || !OHOS::Ace::NodeModel::CheckIsCNode(root)) {
272 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
273 }
274 return component->AttachNativeRootNode(root->uiNodeHandle);
275 }
276
OH_NativeXComponent_DetachNativeRootNode(OH_NativeXComponent * component,ArkUI_NodeHandle root)277 int32_t OH_NativeXComponent_DetachNativeRootNode(
278 OH_NativeXComponent* component, ArkUI_NodeHandle root)
279 {
280 if ((component == nullptr) || (root == nullptr) || !OHOS::Ace::NodeModel::CheckIsCNode(root)) {
281 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
282 }
283 return component->DetachNativeRootNode(root->uiNodeHandle);
284 }
285
OH_NativeXComponent_RegisterUIInputEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,ArkUI_UIInputEvent * event,ArkUI_UIInputEvent_Type type),ArkUI_UIInputEvent_Type type)286 int32_t OH_NativeXComponent_RegisterUIInputEventCallback(OH_NativeXComponent* component,
287 void (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event, ArkUI_UIInputEvent_Type type),
288 ArkUI_UIInputEvent_Type type)
289 {
290 if ((component == nullptr) || (callback == nullptr)) {
291 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
292 }
293 if (type == ArkUI_UIInputEvent_Type::ARKUI_UIINPUTEVENT_TYPE_AXIS) {
294 return component->RegisterUIAxisEventCallback(callback);
295 }
296 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
297 }
298
OH_NativeXComponent_SetNeedSoftKeyboard(OH_NativeXComponent * component,bool needSoftKeyboard)299 int32_t OH_NativeXComponent_SetNeedSoftKeyboard(OH_NativeXComponent* component, bool needSoftKeyboard)
300 {
301 return component ? component->SetNeedSoftKeyboard(needSoftKeyboard) : OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
302 }
303
OH_NativeXComponent_RegisterSurfaceShowCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))304 int32_t OH_NativeXComponent_RegisterSurfaceShowCallback(
305 OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
306 {
307 return (component && callback) ? component->RegisterSurfaceShowCallback(callback)
308 : OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
309 }
310
OH_NativeXComponent_RegisterSurfaceHideCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))311 int32_t OH_NativeXComponent_RegisterSurfaceHideCallback(
312 OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
313 {
314 return (component && callback) ? component->RegisterSurfaceHideCallback(callback)
315 : OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
316 }
317
OH_NativeXComponent_RegisterOnTouchInterceptCallback(OH_NativeXComponent * component,HitTestMode (* callback)(OH_NativeXComponent * component,ArkUI_UIInputEvent * event))318 int32_t OH_NativeXComponent_RegisterOnTouchInterceptCallback(
319 OH_NativeXComponent* component, HitTestMode (*callback)(OH_NativeXComponent* component, ArkUI_UIInputEvent* event))
320 {
321 if ((component == nullptr) || (callback == nullptr)) {
322 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
323 }
324 return component->RegisterOnTouchInterceptCallback(callback);
325 }
326
OH_NativeXComponent_GetTouchEventSourceType(OH_NativeXComponent * component,int32_t pointId,OH_NativeXComponent_EventSourceType * sourceType)327 int32_t OH_NativeXComponent_GetTouchEventSourceType(
328 OH_NativeXComponent* component, int32_t pointId, OH_NativeXComponent_EventSourceType* sourceType)
329 {
330 return (component && sourceType) ? component->GetSourceType(pointId, sourceType)
331 : OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
332 }
333
OH_NativeXComponent_GetNativeXComponent(ArkUI_NodeHandle node)334 OH_NativeXComponent* OH_NativeXComponent_GetNativeXComponent(ArkUI_NodeHandle node)
335 {
336 if (node == nullptr || (node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE)) {
337 return nullptr;
338 }
339 auto nodeModifiers = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers();
340 return reinterpret_cast<OH_NativeXComponent*>(
341 nodeModifiers->getXComponentModifier()->getNativeXComponent(node->uiNodeHandle));
342 }
343
OH_NativeXComponent_GetNativeAccessibilityProvider(OH_NativeXComponent * component,ArkUI_AccessibilityProvider ** handle)344 int32_t OH_NativeXComponent_GetNativeAccessibilityProvider(
345 OH_NativeXComponent* component, ArkUI_AccessibilityProvider** handle)
346 {
347 if ((component == nullptr) || (handle == nullptr)) {
348 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
349 }
350
351 return component->GetAccessibilityProvider(handle);
352 }
353
OH_NativeXComponent_RegisterKeyEventCallbackWithResult(OH_NativeXComponent * component,bool (* callback)(OH_NativeXComponent * component,void * window))354 int32_t OH_NativeXComponent_RegisterKeyEventCallbackWithResult(
355 OH_NativeXComponent* component, bool (*callback)(OH_NativeXComponent* component, void* window))
356 {
357 if ((component == nullptr) || (callback == nullptr)) {
358 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
359 }
360 return component->RegisterKeyEventCallbackWithResult(callback);
361 }
362
OH_ArkUI_XComponent_StartImageAnalyzer(ArkUI_NodeHandle node,void * userData,void (* callback)(ArkUI_NodeHandle node,ArkUI_XComponent_ImageAnalyzerState statusCode,void * userData))363 int32_t OH_ArkUI_XComponent_StartImageAnalyzer(ArkUI_NodeHandle node, void* userData,
364 void (*callback)(ArkUI_NodeHandle node, ArkUI_XComponent_ImageAnalyzerState statusCode, void* userData))
365 {
366 if ((!OHOS::Ace::NodeModel::IsValidArkUINode(node)) ||
367 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE) ||
368 (callback == nullptr)) {
369 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
370 }
371 auto nodeModifiers = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers();
372 nodeModifiers->getXComponentModifier()->startImageAnalyzer(node->uiNodeHandle, node, userData,
373 reinterpret_cast<XComponentAnalyzerCallback>(callback));
374 return OHOS::Ace::ERROR_CODE_NO_ERROR;
375 }
376
OH_ArkUI_XComponent_StopImageAnalyzer(ArkUI_NodeHandle node)377 int32_t OH_ArkUI_XComponent_StopImageAnalyzer(ArkUI_NodeHandle node)
378 {
379 if ((!OHOS::Ace::NodeModel::IsValidArkUINode(node)) ||
380 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE)) {
381 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
382 }
383 auto nodeModifiers = OHOS::Ace::NodeModel::GetFullImpl()->getNodeModifiers();
384 nodeModifiers->getXComponentModifier()->stopImageAnalyzer(node->uiNodeHandle);
385 return OHOS::Ace::ERROR_CODE_NO_ERROR;
386 }
387
OH_ArkUI_SurfaceHolder_Create(ArkUI_NodeHandle node)388 OH_ArkUI_SurfaceHolder* OH_ArkUI_SurfaceHolder_Create(ArkUI_NodeHandle node)
389 {
390 if (!OHOS::Ace::NodeModel::IsValidArkUINode(node) ||
391 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE)) {
392 return nullptr;
393 }
394 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
395 CHECK_NULL_RETURN(impl, nullptr);
396 auto nodeModifiers = impl->getNodeModifiers();
397 CHECK_NULL_RETURN(nodeModifiers, nullptr);
398 auto xComponentModifier = nodeModifiers->getXComponentModifier();
399 CHECK_NULL_RETURN(xComponentModifier, nullptr);
400 auto* surfaceHolder =
401 reinterpret_cast<OH_ArkUI_SurfaceHolder*>(xComponentModifier->createSurfaceHolder(node->uiNodeHandle));
402 CHECK_NULL_RETURN(surfaceHolder, nullptr);
403 surfaceHolder->node_ = node;
404 return surfaceHolder;
405 }
406
OH_ArkUI_SurfaceHolder_Dispose(OH_ArkUI_SurfaceHolder * surfaceHolder)407 void OH_ArkUI_SurfaceHolder_Dispose(OH_ArkUI_SurfaceHolder* surfaceHolder)
408 {
409 if (surfaceHolder) {
410 auto node = surfaceHolder->node_;
411 if (OHOS::Ace::NodeModel::IsValidArkUINode(node)) {
412 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
413 CHECK_NULL_VOID(impl);
414 auto nodeModifiers = impl->getNodeModifiers();
415 CHECK_NULL_VOID(nodeModifiers);
416 auto xComponentModifier = nodeModifiers->getXComponentModifier();
417 CHECK_NULL_VOID(xComponentModifier);
418 xComponentModifier->dispose(node->uiNodeHandle);
419 }
420 }
421 delete surfaceHolder;
422 }
423
OH_ArkUI_SurfaceHolder_SetUserData(OH_ArkUI_SurfaceHolder * surfaceHolder,void * userData)424 int32_t OH_ArkUI_SurfaceHolder_SetUserData(OH_ArkUI_SurfaceHolder* surfaceHolder, void* userData)
425 {
426 if (surfaceHolder == nullptr) {
427 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
428 }
429 surfaceHolder->userData_ = userData;
430 return OHOS::Ace::ERROR_CODE_NO_ERROR;
431 }
432
OH_ArkUI_SurfaceHolder_GetUserData(OH_ArkUI_SurfaceHolder * surfaceHolder)433 void* OH_ArkUI_SurfaceHolder_GetUserData(OH_ArkUI_SurfaceHolder* surfaceHolder)
434 {
435 if (surfaceHolder == nullptr) {
436 return nullptr;
437 }
438 return surfaceHolder->userData_;
439 }
440
OH_ArkUI_SurfaceCallback_Create(void)441 OH_ArkUI_SurfaceCallback* OH_ArkUI_SurfaceCallback_Create(void)
442 {
443 OH_ArkUI_SurfaceCallback* surfaceCallback = new OH_ArkUI_SurfaceCallback();
444 return surfaceCallback;
445 }
446
OH_ArkUI_SurfaceCallback_Dispose(OH_ArkUI_SurfaceCallback * callback)447 void OH_ArkUI_SurfaceCallback_Dispose(OH_ArkUI_SurfaceCallback* callback)
448 {
449 delete callback;
450 }
451
OH_ArkUI_SurfaceCallback_SetSurfaceCreatedEvent(OH_ArkUI_SurfaceCallback * callback,void (* onSurfaceCreated)(OH_ArkUI_SurfaceHolder * surfaceHolder))452 void OH_ArkUI_SurfaceCallback_SetSurfaceCreatedEvent(
453 OH_ArkUI_SurfaceCallback* callback, void (*onSurfaceCreated)(OH_ArkUI_SurfaceHolder* surfaceHolder))
454 {
455 CHECK_NULL_VOID(callback);
456 callback->OnSurfaceCreated = onSurfaceCreated;
457 }
458
OH_ArkUI_SurfaceCallback_SetSurfaceChangedEvent(OH_ArkUI_SurfaceCallback * callback,void (* onSurfaceChanged)(OH_ArkUI_SurfaceHolder * surfaceHolder,uint64_t width,uint64_t height))459 void OH_ArkUI_SurfaceCallback_SetSurfaceChangedEvent(OH_ArkUI_SurfaceCallback* callback,
460 void (*onSurfaceChanged)(OH_ArkUI_SurfaceHolder* surfaceHolder, uint64_t width, uint64_t height))
461 {
462 CHECK_NULL_VOID(callback);
463 callback->OnSurfaceChanged = onSurfaceChanged;
464 }
465
OH_ArkUI_SurfaceCallback_SetSurfaceDestroyedEvent(OH_ArkUI_SurfaceCallback * callback,void (* onSurfaceDestroyed)(OH_ArkUI_SurfaceHolder * surfaceHolder))466 void OH_ArkUI_SurfaceCallback_SetSurfaceDestroyedEvent(
467 OH_ArkUI_SurfaceCallback* callback,
468 void (*onSurfaceDestroyed)(OH_ArkUI_SurfaceHolder* surfaceHolder))
469 {
470 CHECK_NULL_VOID(callback);
471 callback->OnSurfaceDestroyed = onSurfaceDestroyed;
472 }
473
OH_ArkUI_SurfaceHolder_AddSurfaceCallback(OH_ArkUI_SurfaceHolder * surfaceHolder,OH_ArkUI_SurfaceCallback * callback)474 int32_t OH_ArkUI_SurfaceHolder_AddSurfaceCallback(
475 OH_ArkUI_SurfaceHolder* surfaceHolder, OH_ArkUI_SurfaceCallback* callback)
476 {
477 if ((surfaceHolder == nullptr) || (callback == nullptr)) {
478 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
479 }
480 return surfaceHolder->AddSurfaceCallback(callback);
481 }
482
OH_ArkUI_SurfaceHolder_RemoveSurfaceCallback(OH_ArkUI_SurfaceHolder * surfaceHolder,OH_ArkUI_SurfaceCallback * callback)483 int32_t OH_ArkUI_SurfaceHolder_RemoveSurfaceCallback(
484 OH_ArkUI_SurfaceHolder* surfaceHolder, OH_ArkUI_SurfaceCallback* callback)
485 {
486 if ((surfaceHolder == nullptr) || (callback == nullptr)) {
487 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
488 }
489 return surfaceHolder->RemoveSurfaceCallback(callback);
490 }
491
OH_ArkUI_XComponent_GetNativeWindow(OH_ArkUI_SurfaceHolder * surfaceHolder)492 OHNativeWindow* OH_ArkUI_XComponent_GetNativeWindow(OH_ArkUI_SurfaceHolder* surfaceHolder)
493 {
494 if (surfaceHolder == nullptr) {
495 return nullptr;
496 }
497 return surfaceHolder->nativeWindow_;
498 }
499
OH_ArkUI_XComponent_SetAutoInitialize(ArkUI_NodeHandle node,bool autoInitialize)500 int32_t OH_ArkUI_XComponent_SetAutoInitialize(ArkUI_NodeHandle node, bool autoInitialize)
501 {
502 if (!OHOS::Ace::NodeModel::IsValidArkUINode(node) ||
503 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE)) {
504 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
505 }
506 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
507 CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
508 auto nodeModifiers = impl->getNodeModifiers();
509 CHECK_NULL_RETURN(nodeModifiers, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
510 auto xComponentModifier = nodeModifiers->getXComponentModifier();
511 CHECK_NULL_RETURN(xComponentModifier, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
512 return xComponentModifier->setAutoInitialize(node->uiNodeHandle, autoInitialize);
513 }
514
OH_ArkUI_XComponent_Initialize(ArkUI_NodeHandle node)515 int32_t OH_ArkUI_XComponent_Initialize(ArkUI_NodeHandle node)
516 {
517 if (!OHOS::Ace::NodeModel::IsValidArkUINode(node) ||
518 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE)) {
519 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
520 }
521 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
522 CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
523 auto nodeModifiers = impl->getNodeModifiers();
524 CHECK_NULL_RETURN(nodeModifiers, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
525 auto xComponentModifier = nodeModifiers->getXComponentModifier();
526 CHECK_NULL_RETURN(xComponentModifier, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
527 return xComponentModifier->initialize(node->uiNodeHandle);
528 }
529
OH_ArkUI_XComponent_Finalize(ArkUI_NodeHandle node)530 int32_t OH_ArkUI_XComponent_Finalize(ArkUI_NodeHandle node)
531 {
532 if (!OHOS::Ace::NodeModel::IsValidArkUINode(node) ||
533 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE)) {
534 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
535 }
536 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
537 CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
538 auto nodeModifiers = impl->getNodeModifiers();
539 CHECK_NULL_RETURN(nodeModifiers, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
540 auto xComponentModifier = nodeModifiers->getXComponentModifier();
541 CHECK_NULL_RETURN(xComponentModifier, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
542 return xComponentModifier->finalize(node->uiNodeHandle);
543 }
544
OH_ArkUI_XComponent_IsInitialized(ArkUI_NodeHandle node,bool * isInitialized)545 int32_t OH_ArkUI_XComponent_IsInitialized(ArkUI_NodeHandle node, bool* isInitialized)
546 {
547 if (!OHOS::Ace::NodeModel::IsValidArkUINode(node) ||
548 (!node->isBindNative && node->type != ARKUI_NODE_XCOMPONENT && node->type != ARKUI_NODE_XCOMPONENT_TEXTURE) ||
549 !isInitialized) {
550 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
551 }
552 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
553 CHECK_NULL_RETURN(impl, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
554 auto nodeModifiers = impl->getNodeModifiers();
555 CHECK_NULL_RETURN(nodeModifiers, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
556 auto xComponentModifier = nodeModifiers->getXComponentModifier();
557 CHECK_NULL_RETURN(xComponentModifier, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
558 ArkUI_Bool value = 0;
559 auto res = xComponentModifier->isInitialized(node->uiNodeHandle, &value);
560 *isInitialized = value;
561 return res;
562 }
563
OH_NativeXComponent_GetExtraMouseEventInfo(OH_NativeXComponent * component,OH_NativeXComponent_ExtraMouseEventInfo ** extraMouseEventInfo)564 int32_t OH_NativeXComponent_GetExtraMouseEventInfo(OH_NativeXComponent* component,
565 OH_NativeXComponent_ExtraMouseEventInfo** extraMouseEventInfo)
566 {
567 if ((component == nullptr) || (extraMouseEventInfo == nullptr)) {
568 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
569 }
570 return component->GetExtraMouseEventInfo(extraMouseEventInfo);
571 }
572
OH_NativeXComponent_GetMouseEventModifierKeyStates(OH_NativeXComponent_ExtraMouseEventInfo * ExtraMouseEventInfo,uint64_t * keys)573 int32_t OH_NativeXComponent_GetMouseEventModifierKeyStates(
574 OH_NativeXComponent_ExtraMouseEventInfo* ExtraMouseEventInfo, uint64_t* keys)
575 {
576 if ((ExtraMouseEventInfo == nullptr) || (keys == nullptr)) {
577 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
578 }
579 (*keys) = ExtraMouseEventInfo->modifierKeyStates;
580 return OHOS::Ace::ERROR_CODE_NO_ERROR;
581 }
582
OH_NativeXComponent_GetKeyEventModifierKeyStates(OH_NativeXComponent_KeyEvent * keyEvent,uint64_t * keys)583 int32_t OH_NativeXComponent_GetKeyEventModifierKeyStates(OH_NativeXComponent_KeyEvent* keyEvent, uint64_t* keys)
584 {
585 if ((keyEvent == nullptr) || (keys == nullptr)) {
586 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
587 }
588 (*keys) = keyEvent->modifierKeyStates;
589 return OHOS::Ace::ERROR_CODE_NO_ERROR;
590 }
591
OH_NativeXComponent_GetKeyEventNumLockState(OH_NativeXComponent_KeyEvent * keyEvent,bool * isNumLockOn)592 int32_t OH_NativeXComponent_GetKeyEventNumLockState(OH_NativeXComponent_KeyEvent* keyEvent, bool* isNumLockOn)
593 {
594 if ((keyEvent == nullptr) || (isNumLockOn == nullptr)) {
595 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
596 }
597 (*isNumLockOn) = keyEvent->isNumLockOn;
598 return OHOS::Ace::ERROR_CODE_NO_ERROR;
599 }
600
OH_NativeXComponent_GetKeyEventCapsLockState(OH_NativeXComponent_KeyEvent * keyEvent,bool * isCapsLockOn)601 int32_t OH_NativeXComponent_GetKeyEventCapsLockState(OH_NativeXComponent_KeyEvent* keyEvent, bool* isCapsLockOn)
602 {
603 if ((keyEvent == nullptr) || (isCapsLockOn == nullptr)) {
604 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
605 }
606 (*isCapsLockOn) = keyEvent->isCapsLockOn;
607 return OHOS::Ace::ERROR_CODE_NO_ERROR;
608 }
609
OH_NativeXComponent_GetKeyEventScrollLockState(OH_NativeXComponent_KeyEvent * keyEvent,bool * isScrollLockOn)610 int32_t OH_NativeXComponent_GetKeyEventScrollLockState(OH_NativeXComponent_KeyEvent* keyEvent, bool* isScrollLockOn)
611 {
612 if ((keyEvent == nullptr) || (isScrollLockOn == nullptr)) {
613 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
614 }
615 (*isScrollLockOn) = keyEvent->isScrollLockOn;
616 return OHOS::Ace::ERROR_CODE_NO_ERROR;
617 }
618
GetArkUIXComponentModifier()619 const ArkUIXComponentModifier* GetArkUIXComponentModifier()
620 {
621 const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
622 CHECK_NULL_RETURN(impl, nullptr);
623 auto nodeModifiers = impl->getNodeModifiers();
624 CHECK_NULL_RETURN(nodeModifiers, nullptr);
625 auto xComponentModifier = nodeModifiers->getXComponentModifier();
626 return xComponentModifier;
627 }
628
IsValidXComponentNode(ArkUI_NodeHandle node)629 bool IsValidXComponentNode(ArkUI_NodeHandle node)
630 {
631 return OHOS::Ace::NodeModel::IsValidArkUINode(node) &&
632 (node->isBindNative || node->type == ARKUI_NODE_XCOMPONENT || node->type == ARKUI_NODE_XCOMPONENT_TEXTURE);
633 }
634
OH_ArkUI_XComponent_SetExpectedFrameRateRange(ArkUI_NodeHandle node,OH_NativeXComponent_ExpectedRateRange range)635 int32_t OH_ArkUI_XComponent_SetExpectedFrameRateRange(
636 ArkUI_NodeHandle node, OH_NativeXComponent_ExpectedRateRange range)
637 {
638 if (!IsValidXComponentNode(node)) {
639 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
640 }
641 auto xComponentModifier = GetArkUIXComponentModifier();
642 CHECK_NULL_RETURN(xComponentModifier, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
643 ArkUI_Int32 min = range.min;
644 ArkUI_Int32 max = range.max;
645 ArkUI_Int32 expected = range.expected;
646 auto res = xComponentModifier->setExpectedFrameRateRange(node->uiNodeHandle, min, max, expected);
647 return res;
648 }
649
OH_ArkUI_XComponent_RegisterOnFrameCallback(ArkUI_NodeHandle node,void (* callback)(ArkUI_NodeHandle node,uint64_t timestamp,uint64_t targetTimestamp))650 int32_t OH_ArkUI_XComponent_RegisterOnFrameCallback(ArkUI_NodeHandle node,
651 void (*callback)(ArkUI_NodeHandle node, uint64_t timestamp, uint64_t targetTimestamp))
652 {
653 if (!IsValidXComponentNode(node)) {
654 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
655 }
656 auto xComponentModifier = GetArkUIXComponentModifier();
657 CHECK_NULL_RETURN(xComponentModifier, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
658 auto res = xComponentModifier->registerOnFrameCallback(node->uiNodeHandle,
659 reinterpret_cast<void(*)(void*, uint64_t, uint64_t)>(callback), node);
660 return res;
661 }
662
OH_ArkUI_XComponent_UnregisterOnFrameCallback(ArkUI_NodeHandle node)663 int32_t OH_ArkUI_XComponent_UnregisterOnFrameCallback(ArkUI_NodeHandle node)
664 {
665 if (!IsValidXComponentNode(node)) {
666 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
667 }
668 auto xComponentModifier = GetArkUIXComponentModifier();
669 CHECK_NULL_RETURN(xComponentModifier, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
670 auto res = xComponentModifier->unregisterOnFrameCallback(node->uiNodeHandle);
671 return res;
672 }
673
OH_ArkUI_XComponent_SetNeedSoftKeyboard(ArkUI_NodeHandle node,bool needSoftKeyboard)674 int32_t OH_ArkUI_XComponent_SetNeedSoftKeyboard(ArkUI_NodeHandle node, bool needSoftKeyboard)
675 {
676 if (!IsValidXComponentNode(node)) {
677 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
678 }
679 auto xComponentModifier = GetArkUIXComponentModifier();
680 CHECK_NULL_RETURN(xComponentModifier, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
681 auto res = xComponentModifier->setNeedSoftKeyboard(node->uiNodeHandle, needSoftKeyboard);
682 return res;
683 }
684
OH_ArkUI_AccessibilityProvider_Create(ArkUI_NodeHandle node)685 ArkUI_AccessibilityProvider* OH_ArkUI_AccessibilityProvider_Create(ArkUI_NodeHandle node)
686 {
687 if (!IsValidXComponentNode(node)) {
688 return nullptr;
689 }
690 auto xComponentModifier = GetArkUIXComponentModifier();
691 CHECK_NULL_RETURN(xComponentModifier, nullptr);
692 auto accessibilityProvider = reinterpret_cast<ArkUI_AccessibilityProvider*>(
693 xComponentModifier->createAccessibilityProvider(node->uiNodeHandle));
694 return accessibilityProvider;
695 }
696
OH_ArkUI_AccessibilityProvider_Dispose(ArkUI_AccessibilityProvider * provider)697 void OH_ArkUI_AccessibilityProvider_Dispose(ArkUI_AccessibilityProvider* provider)
698 {
699 if (provider == nullptr) {
700 return;
701 }
702 auto xComponentModifier = GetArkUIXComponentModifier();
703 CHECK_NULL_VOID(xComponentModifier);
704 xComponentModifier->disposeAccessibilityProvider(provider);
705 }
706
OH_ArkUI_SurfaceCallback_SetSurfaceShowEvent(OH_ArkUI_SurfaceCallback * callback,void (* onSurfaceShow)(OH_ArkUI_SurfaceHolder * surfaceHolder))707 void OH_ArkUI_SurfaceCallback_SetSurfaceShowEvent(
708 OH_ArkUI_SurfaceCallback* callback,
709 void (*onSurfaceShow)(OH_ArkUI_SurfaceHolder* surfaceHolder))
710 {
711 CHECK_NULL_VOID(callback);
712 callback->onSurfaceShow = onSurfaceShow;
713 }
714
OH_ArkUI_SurfaceCallback_SetSurfaceHideEvent(OH_ArkUI_SurfaceCallback * callback,void (* onSurfaceHide)(OH_ArkUI_SurfaceHolder * surfaceHolder))715 void OH_ArkUI_SurfaceCallback_SetSurfaceHideEvent(
716 OH_ArkUI_SurfaceCallback* callback,
717 void (*onSurfaceHide)(OH_ArkUI_SurfaceHolder* surfaceHolder))
718 {
719 CHECK_NULL_VOID(callback);
720 callback->onSurfaceHide = onSurfaceHide;
721 }
722
723 #ifdef __cplusplus
724 };
725 #endif
726