• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
OH_NativeXComponent_GetXComponentId(OH_NativeXComponent * component,char * id,uint64_t * size)24 int32_t OH_NativeXComponent_GetXComponentId(OH_NativeXComponent* component, char* id, uint64_t* size)
25 {
26     if ((component == nullptr) || (id == nullptr) || (size == nullptr)) {
27         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
28     }
29     if (((*size) == 0) || ((*size) > (OH_XCOMPONENT_ID_LEN_MAX + 1))) {
30         LOGE("The referenced value of 'size' should be in the range (0, OH_XCOMPONENT_ID_LEN_MAX + 1]");
31         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
32     }
33     return component->GetXComponentId(id, size);
34 }
35 
OH_NativeXComponent_GetXComponentSize(OH_NativeXComponent * component,const void * window,uint64_t * width,uint64_t * height)36 int32_t OH_NativeXComponent_GetXComponentSize(
37     OH_NativeXComponent* component, const void* window, uint64_t* width, uint64_t* height)
38 {
39     if ((component == nullptr) || (window == nullptr) || (width == nullptr) || (height == nullptr)) {
40         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
41     }
42     return component->GetXComponentSize(window, width, height);
43 }
44 
OH_NativeXComponent_GetXComponentOffset(OH_NativeXComponent * component,const void * window,double * x,double * y)45 int32_t OH_NativeXComponent_GetXComponentOffset(
46     OH_NativeXComponent* component, const void* window, double* x, double* y)
47 {
48     if ((component == nullptr) || (window == nullptr) || (x == nullptr) || (y == nullptr)) {
49         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
50     }
51     return component->GetXComponentOffset(window, x, y);
52 }
53 
OH_NativeXComponent_GetTouchEvent(OH_NativeXComponent * component,const void * window,OH_NativeXComponent_TouchEvent * touchEvent)54 int32_t OH_NativeXComponent_GetTouchEvent(
55     OH_NativeXComponent* component, const void* window, OH_NativeXComponent_TouchEvent* touchEvent)
56 {
57     if ((component == nullptr) || (window == nullptr) || (touchEvent == nullptr)) {
58         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
59     }
60     return component->GetTouchEvent(window, touchEvent);
61 }
62 
OH_NativeXComponent_GetTouchPointToolType(OH_NativeXComponent * component,uint32_t pointIndex,OH_NativeXComponent_TouchPointToolType * toolType)63 int32_t OH_NativeXComponent_GetTouchPointToolType(
64     OH_NativeXComponent* component, uint32_t pointIndex, OH_NativeXComponent_TouchPointToolType* toolType)
65 {
66     if ((component == nullptr) || (toolType == nullptr)) {
67         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
68     }
69     return component->GetToolType(pointIndex, toolType);
70 }
71 
OH_NativeXComponent_GetTouchPointTiltX(OH_NativeXComponent * component,uint32_t pointIndex,float * tiltX)72 int32_t OH_NativeXComponent_GetTouchPointTiltX(OH_NativeXComponent* component, uint32_t pointIndex, float* tiltX)
73 {
74     if ((component == nullptr) || (tiltX == nullptr)) {
75         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
76     }
77     return component->GetTiltX(pointIndex, tiltX);
78 }
79 
OH_NativeXComponent_GetTouchPointTiltY(OH_NativeXComponent * component,uint32_t pointIndex,float * tiltY)80 int32_t OH_NativeXComponent_GetTouchPointTiltY(OH_NativeXComponent* component, uint32_t pointIndex, float* tiltY)
81 {
82     if ((component == nullptr) || (tiltY == nullptr)) {
83         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
84     }
85     return component->GetTiltY(pointIndex, tiltY);
86 }
87 
OH_NativeXComponent_GetHistoricalPoints(OH_NativeXComponent * component,const void * window,int32_t * size,OH_NativeXComponent_HistoricalPoint ** historicalPoints)88 int32_t OH_NativeXComponent_GetHistoricalPoints(OH_NativeXComponent* component, const void* window,
89     int32_t* size, OH_NativeXComponent_HistoricalPoint** historicalPoints)
90 {
91     if ((component == nullptr) || (window == nullptr)) {
92         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
93     }
94     return component->GetHistoryPoints(window, size, historicalPoints);
95 }
96 
OH_NativeXComponent_GetMouseEvent(OH_NativeXComponent * component,const void * window,OH_NativeXComponent_MouseEvent * mouseEvent)97 int32_t OH_NativeXComponent_GetMouseEvent(
98     OH_NativeXComponent* component, const void* window, OH_NativeXComponent_MouseEvent* mouseEvent)
99 {
100     if ((component == nullptr) || (window == nullptr) || (mouseEvent == nullptr)) {
101         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
102     }
103     return component->GetMouseEvent(window, mouseEvent);
104 }
105 
OH_NativeXComponent_RegisterCallback(OH_NativeXComponent * component,OH_NativeXComponent_Callback * callback)106 int32_t OH_NativeXComponent_RegisterCallback(OH_NativeXComponent* component, OH_NativeXComponent_Callback* callback)
107 {
108     if ((component == nullptr) || (callback == nullptr)) {
109         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
110     }
111     return component->RegisterCallback(callback);
112 }
113 
OH_NativeXComponent_RegisterMouseEventCallback(OH_NativeXComponent * component,OH_NativeXComponent_MouseEvent_Callback * callback)114 int32_t OH_NativeXComponent_RegisterMouseEventCallback(
115     OH_NativeXComponent* component, OH_NativeXComponent_MouseEvent_Callback* callback)
116 {
117     if ((component == nullptr) || (callback == nullptr)) {
118         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
119     }
120     return component->RegisterMouseEventCallback(callback);
121 }
122 
OH_NativeXComponent_RegisterFocusEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))123 int32_t OH_NativeXComponent_RegisterFocusEventCallback(
124     OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
125 {
126     if ((component == nullptr) || (callback == nullptr)) {
127         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
128     }
129     return component->RegisterFocusEventCallback(callback);
130 }
131 
OH_NativeXComponent_RegisterKeyEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))132 int32_t OH_NativeXComponent_RegisterKeyEventCallback(
133     OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
134 {
135     if ((component == nullptr) || (callback == nullptr)) {
136         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
137     }
138     return component->RegisterKeyEventCallback(callback);
139 }
140 
OH_NativeXComponent_RegisterBlurEventCallback(OH_NativeXComponent * component,void (* callback)(OH_NativeXComponent * component,void * window))141 int32_t OH_NativeXComponent_RegisterBlurEventCallback(
142     OH_NativeXComponent* component, void (*callback)(OH_NativeXComponent* component, void* window))
143 {
144     if ((component == nullptr) || (callback == nullptr)) {
145         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
146     }
147     return component->RegisterBlurEventCallback(callback);
148 }
149 
OH_NativeXComponent_GetKeyEvent(OH_NativeXComponent * component,OH_NativeXComponent_KeyEvent ** keyEvent)150 int32_t OH_NativeXComponent_GetKeyEvent(OH_NativeXComponent* component, OH_NativeXComponent_KeyEvent** keyEvent)
151 {
152     if ((component == nullptr) || (keyEvent == nullptr)) {
153         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
154     }
155     return component->GetKeyEvent(keyEvent);
156 }
157 
OH_NativeXComponent_GetKeyEventAction(OH_NativeXComponent_KeyEvent * keyEvent,OH_NativeXComponent_KeyAction * action)158 int32_t OH_NativeXComponent_GetKeyEventAction(
159     OH_NativeXComponent_KeyEvent* keyEvent, OH_NativeXComponent_KeyAction* action)
160 {
161     if ((keyEvent == nullptr) || (action == nullptr)) {
162         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
163     }
164     (*action) = keyEvent->action;
165     return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
166 }
167 
OH_NativeXComponent_GetKeyEventCode(OH_NativeXComponent_KeyEvent * keyEvent,OH_NativeXComponent_KeyCode * code)168 int32_t OH_NativeXComponent_GetKeyEventCode(OH_NativeXComponent_KeyEvent* keyEvent, OH_NativeXComponent_KeyCode* code)
169 {
170     if ((keyEvent == nullptr) || (code == nullptr)) {
171         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
172     }
173     (*code) = keyEvent->code;
174     return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
175 }
176 
OH_NativeXComponent_GetKeyEventSourceType(OH_NativeXComponent_KeyEvent * keyEvent,OH_NativeXComponent_EventSourceType * sourceType)177 int32_t OH_NativeXComponent_GetKeyEventSourceType(
178     OH_NativeXComponent_KeyEvent* keyEvent, OH_NativeXComponent_EventSourceType* sourceType)
179 {
180     if ((keyEvent == nullptr) || (sourceType == nullptr)) {
181         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
182     }
183     (*sourceType) = keyEvent->sourceType;
184     return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
185 }
186 
OH_NativeXComponent_GetKeyEventDeviceId(OH_NativeXComponent_KeyEvent * keyEvent,int64_t * deviceId)187 int32_t OH_NativeXComponent_GetKeyEventDeviceId(OH_NativeXComponent_KeyEvent* keyEvent, int64_t* deviceId)
188 {
189     if ((keyEvent == nullptr) || (deviceId == nullptr)) {
190         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
191     }
192     (*deviceId) = keyEvent->deviceId;
193     return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
194 }
195 
OH_NativeXComponent_GetKeyEventTimestamp(OH_NativeXComponent_KeyEvent * keyEvent,int64_t * timestamp)196 int32_t OH_NativeXComponent_GetKeyEventTimestamp(OH_NativeXComponent_KeyEvent* keyEvent, int64_t* timestamp)
197 {
198     if ((keyEvent == nullptr) || (timestamp == nullptr)) {
199         return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
200     }
201     (*timestamp) = keyEvent->timestamp;
202     return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
203 }
204 #ifdef __cplusplus
205 };
206 #endif
207