1 /*
2 * Copyright (c) 2021-2022 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 "frameworks/core/components/xcomponent/native_interface_xcomponent_impl.h"
19 #include "node/node_model.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
OH_NativeXComponent_GetXComponentId(OH_NativeXComponent * component,char * id,uint64_t * size)25 int32_t OH_NativeXComponent_GetXComponentId(OH_NativeXComponent* component, char* id, uint64_t* size)
26 {
27 if ((component == nullptr) || (id == nullptr) || (size == nullptr)) {
28 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
29 }
30 if (((*size) == 0) || ((*size) > (OH_XCOMPONENT_ID_LEN_MAX + 1))) {
31 LOGE("The referenced value of 'size' should be in the range (0, OH_XCOMPONENT_ID_LEN_MAX + 1]");
32 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
33 }
34 return component->GetXComponentId(id, size);
35 }
36
OH_NativeXComponent_GetXComponentSize(OH_NativeXComponent * component,const void * window,uint64_t * width,uint64_t * height)37 int32_t OH_NativeXComponent_GetXComponentSize(
38 OH_NativeXComponent* component, const void* window, uint64_t* width, uint64_t* height)
39 {
40 if ((component == nullptr) || (window == nullptr) || (width == nullptr) || (height == nullptr)) {
41 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
42 }
43 return component->GetXComponentSize(window, width, height);
44 }
45
OH_NativeXComponent_GetXComponentOffset(OH_NativeXComponent * component,const void * window,double * x,double * y)46 int32_t OH_NativeXComponent_GetXComponentOffset(
47 OH_NativeXComponent* component, const void* window, double* x, double* y)
48 {
49 if ((component == nullptr) || (window == nullptr) || (x == nullptr) || (y == nullptr)) {
50 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
51 }
52 return component->GetXComponentOffset(window, x, y);
53 }
54
OH_NativeXComponent_GetTouchEvent(OH_NativeXComponent * component,const void * window,OH_NativeXComponent_TouchEvent * touchEvent)55 int32_t OH_NativeXComponent_GetTouchEvent(
56 OH_NativeXComponent* component, const void* window, OH_NativeXComponent_TouchEvent* touchEvent)
57 {
58 if ((component == nullptr) || (window == nullptr) || (touchEvent == nullptr)) {
59 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
60 }
61 return component->GetTouchEvent(window, touchEvent);
62 }
63
OH_NativeXComponent_GetTouchPointToolType(OH_NativeXComponent * component,uint32_t pointIndex,OH_NativeXComponent_TouchPointToolType * toolType)64 int32_t OH_NativeXComponent_GetTouchPointToolType(
65 OH_NativeXComponent* component, uint32_t pointIndex, OH_NativeXComponent_TouchPointToolType* toolType)
66 {
67 if ((component == nullptr) || (toolType == nullptr)) {
68 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
69 }
70 return component->GetToolType(pointIndex, toolType);
71 }
72
OH_NativeXComponent_GetTouchPointTiltX(OH_NativeXComponent * component,uint32_t pointIndex,float * tiltX)73 int32_t OH_NativeXComponent_GetTouchPointTiltX(OH_NativeXComponent* component, uint32_t pointIndex, float* tiltX)
74 {
75 if ((component == nullptr) || (tiltX == nullptr)) {
76 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
77 }
78 return component->GetTiltX(pointIndex, tiltX);
79 }
80
OH_NativeXComponent_GetTouchPointTiltY(OH_NativeXComponent * component,uint32_t pointIndex,float * tiltY)81 int32_t OH_NativeXComponent_GetTouchPointTiltY(OH_NativeXComponent* component, uint32_t pointIndex, float* tiltY)
82 {
83 if ((component == nullptr) || (tiltY == nullptr)) {
84 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
85 }
86 return component->GetTiltY(pointIndex, tiltY);
87 }
88
OH_NativeXComponent_GetHistoricalPoints(OH_NativeXComponent * component,const void * window,int32_t * size,OH_NativeXComponent_HistoricalPoint ** historicalPoints)89 int32_t OH_NativeXComponent_GetHistoricalPoints(OH_NativeXComponent* component, const void* window,
90 int32_t* size, OH_NativeXComponent_HistoricalPoint** historicalPoints)
91 {
92 if ((component == nullptr) || (window == nullptr)) {
93 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
94 }
95 return component->GetHistoryPoints(window, size, historicalPoints);
96 }
97
OH_NativeXComponent_GetMouseEvent(OH_NativeXComponent * component,const void * window,OH_NativeXComponent_MouseEvent * mouseEvent)98 int32_t OH_NativeXComponent_GetMouseEvent(
99 OH_NativeXComponent* component, const void* window, OH_NativeXComponent_MouseEvent* mouseEvent)
100 {
101 if ((component == nullptr) || (window == nullptr) || (mouseEvent == nullptr)) {
102 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
103 }
104 return component->GetMouseEvent(window, mouseEvent);
105 }
106
OH_NativeXComponent_RegisterCallback(OH_NativeXComponent * component,OH_NativeXComponent_Callback * callback)107 int32_t OH_NativeXComponent_RegisterCallback(OH_NativeXComponent* component, OH_NativeXComponent_Callback* callback)
108 {
109 if ((component == nullptr) || (callback == nullptr)) {
110 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
111 }
112 return component->RegisterCallback(callback);
113 }
114
OH_NativeXComponent_RegisterMouseEventCallback(OH_NativeXComponent * component,OH_NativeXComponent_MouseEvent_Callback * callback)115 int32_t OH_NativeXComponent_RegisterMouseEventCallback(
116 OH_NativeXComponent* component, OH_NativeXComponent_MouseEvent_Callback* callback)
117 {
118 if ((component == nullptr) || (callback == nullptr)) {
119 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
120 }
121 return component->RegisterMouseEventCallback(callback);
122 }
123
OH_NativeXComponent_RegisterFocusEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))124 int32_t OH_NativeXComponent_RegisterFocusEventCallback(
125 OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
126 {
127 if ((component == nullptr) || (callback == nullptr)) {
128 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
129 }
130 return component->RegisterFocusEventCallback(callback);
131 }
132
OH_NativeXComponent_RegisterKeyEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))133 int32_t OH_NativeXComponent_RegisterKeyEventCallback(
134 OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
135 {
136 if ((component == nullptr) || (callback == nullptr)) {
137 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
138 }
139 return component->RegisterKeyEventCallback(callback);
140 }
141
OH_NativeXComponent_RegisterBlurEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))142 int32_t OH_NativeXComponent_RegisterBlurEventCallback(
143 OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
144 {
145 if ((component == nullptr) || (callback == nullptr)) {
146 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
147 }
148 return component->RegisterBlurEventCallback(callback);
149 }
150
OH_NativeXComponent_GetKeyEvent(OH_NativeXComponent * component,OH_NativeXComponent_KeyEvent ** keyEvent)151 int32_t OH_NativeXComponent_GetKeyEvent(OH_NativeXComponent* component, OH_NativeXComponent_KeyEvent** keyEvent)
152 {
153 if ((component == nullptr) || (keyEvent == nullptr)) {
154 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
155 }
156 return component->GetKeyEvent(keyEvent);
157 }
158
OH_NativeXComponent_GetKeyEventAction(OH_NativeXComponent_KeyEvent * keyEvent,OH_NativeXComponent_KeyAction * action)159 int32_t OH_NativeXComponent_GetKeyEventAction(
160 OH_NativeXComponent_KeyEvent* keyEvent, OH_NativeXComponent_KeyAction* action)
161 {
162 if ((keyEvent == nullptr) || (action == nullptr)) {
163 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
164 }
165 (*action) = keyEvent->action;
166 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
167 }
168
OH_NativeXComponent_GetKeyEventCode(OH_NativeXComponent_KeyEvent * keyEvent,OH_NativeXComponent_KeyCode * code)169 int32_t OH_NativeXComponent_GetKeyEventCode(OH_NativeXComponent_KeyEvent* keyEvent, OH_NativeXComponent_KeyCode* code)
170 {
171 if ((keyEvent == nullptr) || (code == nullptr)) {
172 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
173 }
174 (*code) = keyEvent->code;
175 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
176 }
177
OH_NativeXComponent_GetKeyEventSourceType(OH_NativeXComponent_KeyEvent * keyEvent,OH_NativeXComponent_EventSourceType * sourceType)178 int32_t OH_NativeXComponent_GetKeyEventSourceType(
179 OH_NativeXComponent_KeyEvent* keyEvent, OH_NativeXComponent_EventSourceType* sourceType)
180 {
181 if ((keyEvent == nullptr) || (sourceType == nullptr)) {
182 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
183 }
184 (*sourceType) = keyEvent->sourceType;
185 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
186 }
187
OH_NativeXComponent_GetKeyEventDeviceId(OH_NativeXComponent_KeyEvent * keyEvent,int64_t * deviceId)188 int32_t OH_NativeXComponent_GetKeyEventDeviceId(OH_NativeXComponent_KeyEvent* keyEvent, int64_t* deviceId)
189 {
190 if ((keyEvent == nullptr) || (deviceId == nullptr)) {
191 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
192 }
193 (*deviceId) = keyEvent->deviceId;
194 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
195 }
196
OH_NativeXComponent_GetKeyEventTimestamp(OH_NativeXComponent_KeyEvent * keyEvent,int64_t * timestamp)197 int32_t OH_NativeXComponent_GetKeyEventTimestamp(OH_NativeXComponent_KeyEvent* keyEvent, int64_t* timestamp)
198 {
199 if ((keyEvent == nullptr) || (timestamp == nullptr)) {
200 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
201 }
202 (*timestamp) = keyEvent->timestamp;
203 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
204 }
205
OH_NativeXComponent_SetExpectedFrameRateRange(OH_NativeXComponent * component,OH_NativeXComponent_ExpectedRateRange * range)206 int32_t OH_NativeXComponent_SetExpectedFrameRateRange(
207 OH_NativeXComponent* component, OH_NativeXComponent_ExpectedRateRange* range)
208 {
209 if (component == nullptr || range == nullptr) {
210 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
211 }
212 return component->SetExpectedFrameRateRange(range);
213 }
214
OH_NativeXComponent_RegisterOnFrameCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,uint64_t timestamp,uint64_t targetTimestamp))215 int32_t OH_NativeXComponent_RegisterOnFrameCallback(OH_NativeXComponent* component,
216 void (*callback)(OH_NativeXComponent* component, uint64_t timestamp, uint64_t targetTimestamp))
217 {
218 if (component == nullptr) {
219 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
220 }
221 return component->RegisterOnFrameCallback(callback);
222 }
223
OH_NativeXComponent_UnregisterOnFrameCallback(OH_NativeXComponent * component)224 int32_t OH_NativeXComponent_UnregisterOnFrameCallback(OH_NativeXComponent* component)
225 {
226 if (component == nullptr) {
227 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
228 }
229 return component->UnregisterOnFrameCallback();
230 }
231
OH_NativeXComponent_AttachNativeRootNode(OH_NativeXComponent * component,ArkUI_NodeHandle root)232 int32_t OH_NativeXComponent_AttachNativeRootNode(
233 OH_NativeXComponent* component, ArkUI_NodeHandle root)
234 {
235 if ((component == nullptr) || (root == nullptr)) {
236 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
237 }
238 return component->AttachNativeRootNode(root->uiNodeHandle);
239 }
240
OH_NativeXComponent_DetachNativeRootNode(OH_NativeXComponent * component,ArkUI_NodeHandle root)241 int32_t OH_NativeXComponent_DetachNativeRootNode(
242 OH_NativeXComponent* component, ArkUI_NodeHandle root)
243 {
244 if ((component == nullptr) || (root == nullptr)) {
245 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
246 }
247 return component->DetachNativeRootNode(root->uiNodeHandle);
248 }
249
250 #ifdef __cplusplus
251 };
252 #endif
253