1 /*
2 * Copyright (c) 2021 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 <js_native_api.h>
17 #include <js_native_api_types.h>
18 #include <cstdint>
19
20 #include "native_common.h"
21 #include "plugin_common.h"
22 #include "plugin_manager.h"
23 #include "plugin_render.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 std::unordered_map<std::string, PluginRender*> PluginRender::instance_;
30
31 OH_NativeXComponent_Callback PluginRender::callback_;
32
33 uint32_t PluginRender::isCreated_ = 0;
34 uint32_t PluginRender::xcHeight_ = 0;
35 uint32_t PluginRender::xcWidth_ = 0;
36 double PluginRender::off_x = 0;
37 double PluginRender::off_y = 0;
38 uint32_t PluginRender::toolType_ = 5;
39 uint32_t PluginRender::mousecallback_ = 0;
40 float PluginRender::tiltX_ = 0;
41 float PluginRender::tiltY_ = 0;
42 uint32_t PluginRender::touchType = 4;
43 int32_t three = 3;
44 int32_t eight = 8;
45 OH_NativeXComponent_TouchEvent PluginRender::testTouchEvent_;
46 OH_NativeXComponent_MouseEvent PluginRender::testMouseEvent_;
47 OH_NativeXComponent_MouseEvent_Callback PluginRender::mouseEventcallback_;
48
49 ArkUI_AccessibilityProvider* provider_ = nullptr;
50
OnSurfaceCreatedCB(OH_NativeXComponent * component,void * window)51 void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window)
52 {
53 LOGE("OnSurfaceCreatedCB");
54 int32_t ret;
55 char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
56 uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
57 ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
58 if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
59 return;
60 }
61
62 std::string id(idStr);
63 auto render = PluginRender::GetInstance(id);
64 render->OnSurfaceCreated(component, window);
65
66 PluginRender::GetInstance(id)->InterfaceDesignTest(component);
67 }
68
OnSurfaceChangedCB(OH_NativeXComponent * component,void * window)69 void OnSurfaceChangedCB(OH_NativeXComponent* component, void* window)
70 {
71 int32_t ret;
72 char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
73 uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
74 ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
75 if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
76 return;
77 }
78
79 std::string id(idStr);
80 auto render = PluginRender::GetInstance(id);
81 render->OnSurfaceChanged(component, window);
82 }
83
OnSurfaceDestroyedCB(OH_NativeXComponent * component,void * window)84 void OnSurfaceDestroyedCB(OH_NativeXComponent* component, void* window)
85 {
86 int32_t ret;
87 char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
88 uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
89 ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
90 if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
91 return;
92 }
93
94 std::string id(idStr);
95 auto render = PluginRender::GetInstance(id);
96 render->OnSurfaceDestroyed(component, window);
97 }
98
DispatchTouchEventCB(OH_NativeXComponent * component,void * window)99 void DispatchTouchEventCB(OH_NativeXComponent* component, void* window)
100 {
101 LOGE("DispatchTouchEventCB");
102 int32_t ret;
103 char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
104 uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
105 ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
106 if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
107 return;
108 }
109 std::string id(idStr);
110 auto render = PluginRender::GetInstance(id);
111 render->DispatchTouchEvent(component, window);
112 }
113
DispatchMouseEventCB(OH_NativeXComponent * component,void * window)114 void DispatchMouseEventCB(OH_NativeXComponent* component, void* window)
115 {
116 LOGD("DispatchMouseEventCB");
117 int32_t ret;
118 char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
119 uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
120 ret = OH_NativeXComponent_GetXComponentId(component, idStr, &idSize);
121 if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
122 return;
123 }
124 std::string id(idStr);
125 auto render = PluginRender::GetInstance(id);
126 render->DispatchMouseEvent(component, window);
127 }
128
PluginRender(std::string & id)129 PluginRender::PluginRender(std::string& id)
130 {
131 id_ = id;
132 component_ = nullptr;
133 eglCore_ = new EGLCore(id);
134 auto renderCallback = PluginRender::GetNXComponentCallback();
135 renderCallback->OnSurfaceCreated = OnSurfaceCreatedCB;
136 renderCallback->OnSurfaceChanged = OnSurfaceChangedCB;
137 renderCallback->OnSurfaceDestroyed = OnSurfaceDestroyedCB;
138 renderCallback->DispatchTouchEvent = DispatchTouchEventCB;
139 auto renderMouseEventCallback = PluginRender::GetNXComponentMouseEventCallback();
140 renderMouseEventCallback->DispatchMouseEvent = DispatchMouseEventCB;
141 }
142
GetInstance(std::string & id)143 PluginRender* PluginRender::GetInstance(std::string& id)
144 {
145 if (instance_.find(id) == instance_.end()) {
146 PluginRender* instance = new PluginRender(id);
147 instance_[id] = instance;
148 return instance;
149 } else {
150 return instance_[id];
151 }
152 }
153
GetNXComponentCallback()154 OH_NativeXComponent_Callback* PluginRender::GetNXComponentCallback()
155 {
156 return &PluginRender::callback_;
157 }
158
GetNXComponentMouseEventCallback()159 OH_NativeXComponent_MouseEvent_Callback* PluginRender::GetNXComponentMouseEventCallback()
160 {
161 return &PluginRender::mouseEventcallback_;
162 }
163
SetNativeXComponent(OH_NativeXComponent * component)164 void PluginRender::SetNativeXComponent(OH_NativeXComponent* component)
165 {
166 component_ = component;
167 OH_NativeXComponent_RegisterCallback(component_, &PluginRender::callback_);
168 uint32_t mousecallback = OH_NativeXComponent_RegisterMouseEventCallback(component_,
169 &PluginRender::mouseEventcallback_);
170 mousecallback_ = mousecallback;
171 }
172
OnSurfaceCreated(OH_NativeXComponent * component,void * window)173 void PluginRender::OnSurfaceCreated(OH_NativeXComponent* component, void* window)
174 {
175 LOGE("xclog PluginRender::OnSurfaceCreated");
176
177 int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, &width_, &height_);
178
179 LOGE("xclog Offset : x = %{public}f, y = %{public}f ", x_, y_);
180 if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
181 eglCore_->GLContextInit(window, width_, height_);
182 isCreated_++;
183 xcHeight_ = height_;
184 xcWidth_ = width_;
185
186 LOGE("xclog PluginRender::OnSurfaceCreated success ");
187 LOGE("xclog PluginRender::OnSurfaceCreated iscreated %{public}d", isCreated_);
188 } else {
189 LOGE("xclog PluginRender::OnSurfaceCreated failed");
190 }
191 }
192
OnSurfaceChanged(OH_NativeXComponent * component,void * window)193 void PluginRender::OnSurfaceChanged(OH_NativeXComponent* component, void* window)
194 {
195 LOGE("PluginRender::OnSurfaceChanged");
196 int32_t ret = OH_NativeXComponent_GetXComponentSize(component, window, &width_, &height_);
197 int32_t ret1;
198 if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
199 xcHeight_ = height_;
200 xcWidth_ = width_;
201 LOGE("xclog after width = %{public}d, height = %{public}d", xcWidth_, xcHeight_);
202 ret1= OH_NativeXComponent_GetXComponentOffset(component, window, &x_, &y_);
203 off_x = x_;
204 off_y = y_;
205
206 if (ret1 == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
207 LOGE("xclog Offset : x = %{public}lf, y = %{public}lf ", off_x, off_y);
208 } else {
209 LOGE("xclog Offset get failed");
210 }
211
212 LOGE("xclog PluginRender::GetOffset ");
213 LOGE("xclog Offset : x = %{public}lf, y = %{public}lf ", off_x, off_y);
214 }
215 }
216
OnSurfaceDestroyed(OH_NativeXComponent * component,void * window)217 void PluginRender::OnSurfaceDestroyed(OH_NativeXComponent* component, void* window)
218 {
219 LOGE("xclog PluginRender::OnSurfaceDestroyed");
220 isCreated_--;
221 LOGE("xclog PluginRender::OnSurfaceDestroyed iscreated %{public}d", isCreated_);
222 }
223
DispatchTouchEvent(OH_NativeXComponent * component,void * window)224 void PluginRender::DispatchTouchEvent(OH_NativeXComponent* component, void* window)
225 {
226 int32_t ret = OH_NativeXComponent_GetTouchEvent(component, window, &touchEvent_);
227 if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
228 testTouchEvent_ = touchEvent_;
229 LOGE("Touch Info : x = %{public}f, y = %{public}f screenx = %{public}f, screeny = %{public}f",
230 touchEvent_.x, touchEvent_.y, touchEvent_.screenX, touchEvent_.screenY);
231 for (uint32_t i = 0; i < touchEvent_.numPoints; i++) {
232 LOGE("Touch Info : dots[%{public}d] id %{public}d x = %{public}f, y = %{public}f", i,
233 touchEvent_.touchPoints[i].id, touchEvent_.touchPoints[i].x, touchEvent_.touchPoints[i].y);
234 LOGE("Touch Info : screenx = %{public}f, screeny = %{public}f",
235 touchEvent_.touchPoints[i].screenX, touchEvent_.touchPoints[i].screenY);
236 OH_NativeXComponent_TouchPointToolType toolType = OH_NativeXComponent_TouchPointToolType::OH_NATIVEXCOMPONENT_TOOL_TYPE_UNKNOWN;
237 float tiltX = 123.0;
238 float tiltY = 321.0;
239 [[maybe_unused]] int32_t ret1;
240 [[maybe_unused]] int32_t ret2;
241 [[maybe_unused]] int32_t ret3;
242 ret1 = OH_NativeXComponent_GetTouchPointToolType(component, i, &toolType);
243 ret2 = OH_NativeXComponent_GetTouchPointTiltX(component, i, &tiltX);
244 ret3 = OH_NativeXComponent_GetTouchPointTiltY(component, i, &tiltY);
245 toolType_ = toolType;
246 tiltX_ = tiltX;
247 tiltY_ = tiltY;
248 LOGE("Touch Info : DispatchTouchEvent dots[%{public}d] toolType=%{public}u, tiltX=%{public}f, tiltY=%{public}f",
249 i, toolType, tiltX, tiltY);
250 }
251 } else {
252 LOGE("Touch fail");
253 }
254 }
255
FillElementInfo1(ArkUI_AccessibilityElementInfo * elementInfo)256 void FillElementInfo1(ArkUI_AccessibilityElementInfo* elementInfo)
257 {
258 if (elementInfo == nullptr) {
259 LOGI("FillElementInfo1 elementInfo1 is null");
260 return;
261 }
262 //1.
263 ArkUI_AccessibleRect rect = { 0, 0, 1000, 1000 };
264 OH_ArkUI_AccessibilityElementInfoSetScreenRect(elementInfo, &rect);
265 //2.
266 int32_t size = 2;
267 ArkUI_AccessibleAction actions[size];
268 actions[0].actionType =
269 ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLEAR_ACCESSIBILITY_FOCUS;
270 actions[0].description = "nativeAce";
271 actions[1].actionType =
272 ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_GAIN_ACCESSIBILITY_FOCUS;
273 actions[1].description = "nativeAce";
274 OH_ArkUI_AccessibilityElementInfoSetOperationActions(elementInfo, size, actions);
275 //3.
276 OH_ArkUI_AccessibilityElementInfoSetAccessibilityLevel(elementInfo, "yes");
277 //4.
278 OH_ArkUI_AccessibilityElementInfoSetAccessibilityGroup(elementInfo, false);
279 //5.
280 OH_ArkUI_AccessibilityElementInfoSetAccessibilityText(elementInfo, "FillElementInfo1Text");
281 //6.
282 //7.
283 OH_ArkUI_AccessibilityElementInfoSetComponentType(elementInfo, "root");
284 //8.
285 OH_ArkUI_AccessibilityElementInfoSetFocusable(elementInfo, true);
286 //9.
287 const int32_t kInvalidParentId = 2100000;
288 OH_ArkUI_AccessibilityElementInfoSetParentId(elementInfo, -kInvalidParentId);
289 //10.
290 OH_ArkUI_AccessibilityElementInfoSetVisible(elementInfo, true);
291 //11.
292 OH_ArkUI_AccessibilityElementInfoSetElementId(elementInfo, 0);
293
294 // 12.
295 int64_t childNodeIds[3] = {1, 2, 3};
296 const int32_t CHILD_NODE_COUNT = 3;
297 OH_ArkUI_AccessibilityElementInfoSetChildNodeIds(elementInfo, CHILD_NODE_COUNT, childNodeIds);
298
299 //13.
300 OH_ArkUI_AccessibilityElementInfoSetEnabled(elementInfo, true);
301 OH_ArkUI_AccessibilityElementInfoSetClickable(elementInfo, true);
302 OH_ArkUI_AccessibilityElementInfoSetContents(elementInfo, "root_content");
303 OH_ArkUI_AccessibilityElementInfoSetCheckable(elementInfo, true);
304 OH_ArkUI_AccessibilityElementInfoSetChecked(elementInfo, true);
305 }
306
307
setElementInfo(ArkUI_AccessibilityElementInfo * elementInfo,int32_t i)308 void setElementInfo(ArkUI_AccessibilityElementInfo* elementInfo, int32_t i)
309 {
310 int32_t x = 0;
311 int32_t y = (i < 4)?(x + (i -1) * 500) : (x + (i -4) * 100);
312 double min = 0.0;
313 double max = 100.0;
314 double current = 50.0;
315 int32_t rowCount = 10;
316 int32_t columnCount = 10;
317 int32_t selectionMode = 0;
318 int32_t columnIndex = 0;
319 int32_t rowIndex = 0;
320 int32_t columnSpan = 0;
321 int32_t rowSpan = 0;
322 ArkUI_AccessibleRangeInfo rangeInfo = { min, max, current };
323 ArkUI_AccessibleGridInfo gridInfo = { rowCount, columnCount, selectionMode };
324 ArkUI_AccessibleGridItemInfo gridItemInfo = { false, false, columnIndex, rowIndex, columnSpan, rowSpan};
325 OH_ArkUI_AccessibilityElementInfoSetHintText(elementInfo, "hinttext");
326 OH_ArkUI_AccessibilityElementInfoSetAccessibilityDescription(elementInfo, "AccessibilityDescription");
327 OH_ArkUI_AccessibilityElementInfoSetFocused(elementInfo, false);
328 OH_ArkUI_AccessibilityElementInfoSetSelected(elementInfo, false);
329 OH_ArkUI_AccessibilityElementInfoSetLongClickable(elementInfo, false);
330 OH_ArkUI_AccessibilityElementInfoSetIsPassword(elementInfo, false);
331 OH_ArkUI_AccessibilityElementInfoSetScrollable(elementInfo, false);
332 OH_ArkUI_AccessibilityElementInfoSetEditable(elementInfo, false);
333 OH_ArkUI_AccessibilityElementInfoSetIsHint(elementInfo, false);
334 OH_ArkUI_AccessibilityElementInfoSetRangeInfo(elementInfo, &rangeInfo);
335 OH_ArkUI_AccessibilityElementInfoSetGridInfo(elementInfo, &gridInfo);
336 OH_ArkUI_AccessibilityElementInfoSetGridItemInfo(elementInfo, &gridItemInfo);
337 OH_ArkUI_AccessibilityElementInfoSetSelectedTextStart(elementInfo, x);
338 OH_ArkUI_AccessibilityElementInfoSetSelectedTextEnd(elementInfo, y);
339 OH_ArkUI_AccessibilityElementInfoSetCurrentItemIndex(elementInfo, x);
340 OH_ArkUI_AccessibilityElementInfoSetStartItemIndex(elementInfo, x);
341 OH_ArkUI_AccessibilityElementInfoSetEndItemIndex(elementInfo, y);
342 OH_ArkUI_AccessibilityElementInfoSetItemCount(elementInfo, rowCount * columnCount);
343 OH_ArkUI_AccessibilityElementInfoSetAccessibilityOffset(elementInfo, rowCount);
344 OH_ArkUI_AccessibilityElementInfoSetZIndex(elementInfo, x);
345 OH_ArkUI_AccessibilityElementInfoSetAccessibilityOpacity(elementInfo, min);
346 OH_ArkUI_AccessibilityElementInfoSetBackgroundColor(elementInfo, "red");
347 OH_ArkUI_AccessibilityElementInfoSetBackgroundImage(elementInfo, "app.media.icon");
348 OH_ArkUI_AccessibilityElementInfoSetBlur(elementInfo, "blur");
349 OH_ArkUI_AccessibilityElementInfoSetHitTestBehavior(elementInfo, "default");
350 return;
351 }
352
FillElementInfo2(ArkUI_AccessibilityElementInfo * elementInfo,int32_t i)353 void FillElementInfo2(ArkUI_AccessibilityElementInfo* elementInfo, int32_t i)
354 {
355 if (elementInfo == nullptr) {
356 LOGI("FillElementInfo1 elementInfo1 is null");
357 return;
358 }
359 //1.
360 int32_t x = 0;
361 int32_t y = (i < 4)?(x + (i -1) * 500) : (x + (i -4) * 100);
362 int32_t zx = x + ((i < 4)? 500 : 100);
363 int32_t zy = y + ((i < 4)? 500 : 100);
364 ArkUI_AccessibleRect rect = { x, y, zx, zy };
365 OH_ArkUI_AccessibilityElementInfoSetScreenRect(elementInfo, &rect);
366 //2.
367 int32_t size = 3;
368 ArkUI_AccessibleAction actions[size];
369 actions[0].actionType =
370 ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLEAR_ACCESSIBILITY_FOCUS;
371 actions[0].description = "ace";
372 actions[1].actionType =
373 ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_GAIN_ACCESSIBILITY_FOCUS;
374 actions[1].description = "ace";
375 const int32_t second = 2;
376 actions[second].actionType =
377 ArkUI_Accessibility_ActionType::ARKUI_ACCESSIBILITY_NATIVE_ACTION_TYPE_CLICK;
378 actions[second].description = "ace";
379 setElementInfo(elementInfo, i);
380 OH_ArkUI_AccessibilityElementInfoSetOperationActions(elementInfo, size, actions);
381 //3.
382 OH_ArkUI_AccessibilityElementInfoSetAccessibilityLevel(elementInfo, "yes");
383 //4.
384 OH_ArkUI_AccessibilityElementInfoSetAccessibilityGroup(elementInfo, false);
385 //5.
386 std::string text = "FillElementInfo222Text_" + std::to_string(i);
387 OH_ArkUI_AccessibilityElementInfoSetAccessibilityText(elementInfo, text.c_str());
388 //6.
389 //7.
390 const int32_t two = 2;
391 if (i % two == 0) {
392 OH_ArkUI_AccessibilityElementInfoSetComponentType(elementInfo, "button");
393 } else {
394 OH_ArkUI_AccessibilityElementInfoSetComponentType(elementInfo, "text");
395 }
396 }
397
ExtractFunction(ArkUI_AccessibilityElementInfo * elementInfo,int32_t i)398 void ExtractFunction(ArkUI_AccessibilityElementInfo* elementInfo, int32_t i)
399 {
400 //8.
401 OH_ArkUI_AccessibilityElementInfoSetFocusable(elementInfo, true);
402 //9.
403 const int32_t kNoParent = 0;
404 const int32_t kHasParent = 1;
405 const int32_t four = 4;
406 OH_ArkUI_AccessibilityElementInfoSetParentId(elementInfo, i < four? kNoParent : kHasParent);
407 //10.
408 OH_ArkUI_AccessibilityElementInfoSetVisible(elementInfo, true);
409 //11.
410 OH_ArkUI_AccessibilityElementInfoSetElementId(elementInfo, i);
411 //12.
412 OH_ArkUI_AccessibilityElementInfoSetEnabled(elementInfo, true);
413
414 if (i == 1) {
415 int64_t childNodeIds[6] = {4, 5, 6, 7, 8, 9};
416 const int32_t NUMBER_OF_CHILDREN = 6;
417 OH_ArkUI_AccessibilityElementInfoSetChildNodeIds(elementInfo, NUMBER_OF_CHILDREN, childNodeIds);
418 }
419 OH_ArkUI_AccessibilityElementInfoSetClickable(elementInfo, true);
420 std::string ss;
421 ss.append("contenttest_").append(std::to_string(i));
422 OH_ArkUI_AccessibilityElementInfoSetContents(elementInfo, ss.c_str());
423
424 OH_ArkUI_AccessibilityElementInfoSetCheckable(elementInfo, true);
425 OH_ArkUI_AccessibilityElementInfoSetChecked(elementInfo, true);
426 }
427
FindAccessibilityNodeInfosById(int64_t elementId,ArkUI_AccessibilitySearchMode mode,int32_t requestId,ArkUI_AccessibilityElementInfoList * elementList)428 int32_t FindAccessibilityNodeInfosById(int64_t elementId, ArkUI_AccessibilitySearchMode mode,
429 int32_t requestId, ArkUI_AccessibilityElementInfoList* elementList)
430 {
431 if (elementList == nullptr) {
432 LOGI("FindAccessibilityNodeInfosById elementList is null");
433 return OH_NATIVEXCOMPONENT_RESULT_FAILED;
434 }
435
436 // 传第一个info
437 ArkUI_AccessibilityElementInfo* elementInfo = OH_ArkUI_AddAndGetAccessibilityElementInfo(elementList);
438 if (elementInfo == nullptr) {
439 LOGI("FindAccessibilityNodeInfosById elementInfo1 is null");
440 return OH_NATIVEXCOMPONENT_RESULT_FAILED;
441 }
442 if (mode == eight) {
443 FillElementInfo1(elementInfo);
444 const int32_t AccessibilityStartIndex = 1;
445 const int32_t AccessibilityEndIndex = 10;
446 for (int32_t i = AccessibilityStartIndex; i< AccessibilityEndIndex; i++) {
447 ArkUI_AccessibilityElementInfo* elementInfox = OH_ArkUI_AddAndGetAccessibilityElementInfo(elementList);
448 if (elementInfox == nullptr) {
449 LOGI("FindAccessibilityNodeInfosById elementInfox is null");
450 return OH_NATIVEXCOMPONENT_RESULT_FAILED;
451 }
452 FillElementInfo2(elementInfox, i);
453 }
454 } else if (elementId == 0) {
455 FillElementInfo1(elementInfo);
456 } else if (elementId == -1) {
457 FillElementInfo1(elementInfo);
458 } else {
459 FillElementInfo2(elementInfo, static_cast<int32_t>(elementId));
460 }
461
462 LOGI("FindAccessibilityNodeInfosById end");
463 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
464 }
465
FindAccessibilityNodeInfosByText(int64_t elementId,const char * text,int32_t requestId,ArkUI_AccessibilityElementInfoList * elementList)466 int32_t FindAccessibilityNodeInfosByText(int64_t elementId, const char* text, int32_t requestId,
467 ArkUI_AccessibilityElementInfoList* elementList)
468 {
469 LOGI("FindAccessibilityNodeInfosByText start,requestId: %{public}d, text: %{public}s",
470 requestId, text);
471 if (elementList == nullptr) {
472 LOGI("FindAccessibilityNodeInfosByText elementInfo is null");
473 return OH_NATIVEXCOMPONENT_RESULT_FAILED;
474 }
475
476 // 传第一个info
477 ArkUI_AccessibilityElementInfo* elementInfo1 = OH_ArkUI_AddAndGetAccessibilityElementInfo(elementList);
478 if (elementInfo1 == nullptr) {
479 LOGI("FindFocusedAccessibilityNode elementInfo1 is null");
480 return OH_NATIVEXCOMPONENT_RESULT_FAILED;
481 }
482 int32_t two = 2;
483 FillElementInfo2(elementInfo1, two);
484
485 // 传第二个info
486 ArkUI_AccessibilityElementInfo* elementInfo2 = OH_ArkUI_AddAndGetAccessibilityElementInfo(elementList);
487 if (elementInfo2 == nullptr) {
488 LOGI("FindFocusedAccessibilityNode elementInfo2 is null");
489 return OH_NATIVEXCOMPONENT_RESULT_FAILED;
490 }
491 FillElementInfo2(elementInfo2, three);
492
493 LOGI("FindAccessibilityNodeInfosByText end");
494 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
495 }
496
FindFocusedAccessibilityNode(int64_t elementId,ArkUI_AccessibilityFocusType focusType,int32_t requestId,ArkUI_AccessibilityElementInfo * elementInfo)497 int32_t FindFocusedAccessibilityNode(int64_t elementId, ArkUI_AccessibilityFocusType focusType, int32_t requestId,
498 ArkUI_AccessibilityElementInfo* elementInfo)
499 {
500 LOGI("FindFocusedAccessibilityNode start,requestId: %{public}d, focusType: %{public}d",
501 requestId, static_cast<int32_t>(focusType));
502 if (elementInfo == nullptr) {
503 LOGI("FindFocusedAccessibilityNode elementInfo is null");
504 return OH_NATIVEXCOMPONENT_RESULT_FAILED;
505 }
506 const int32_t four = 4;
507 OH_ArkUI_DestoryAccessibilityElementInfo(elementInfo);
508 FillElementInfo2(elementInfo, four);
509
510 LOGI("FindFocusedAccessibilityNode end");
511 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
512 }
513
FindNextFocusAccessibilityNode(int64_t elementId,ArkUI_AccessibilityFocusMoveDirection direction,int32_t requestId,ArkUI_AccessibilityElementInfo * elementInfo)514 int32_t FindNextFocusAccessibilityNode(int64_t elementId, ArkUI_AccessibilityFocusMoveDirection direction,
515 int32_t requestId, ArkUI_AccessibilityElementInfo* elementInfo)
516 {
517 LOGI(
518 "FindNextFocusAccessibilityNode start,requestId: %{public}d, direction: %{public}d",
519 requestId, static_cast<int32_t>(direction));
520 if (elementInfo == nullptr) {
521 LOGI("FindNextFocusAccessibilityNode elementInfo is null");
522 return OH_NATIVEXCOMPONENT_RESULT_FAILED;
523 }
524 const int32_t CHILD_NODE_COUNT = 5;
525 FillElementInfo2(elementInfo, CHILD_NODE_COUNT);
526 LOGI("FindNextFocusAccessibilityNode end");
527 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
528 }
529
FillEvent(ArkUI_AccessibilityEventInfo * eventInfo,ArkUI_AccessibilityElementInfo * elementInfo)530 void FillEvent(ArkUI_AccessibilityEventInfo* eventInfo, ArkUI_AccessibilityElementInfo* elementInfo)
531 {
532 if (eventInfo == nullptr) {
533 LOGI("FillEvent eventInfo is null");
534 return;
535 }
536 int32_t x = 0;
537 OH_ArkUI_AccessibilityEventSetRequestFocusId(eventInfo, x);
538 OH_ArkUI_AccessibilityEventSetTextAnnouncedForAccessibility(eventInfo, "TextAnnounced");
539 OH_ArkUI_AccessibilityEventSetEventType(eventInfo,
540 ArkUI_AccessibilityEventType::ARKUI_ACCESSIBILITY_NATIVE_EVENT_TYPE_ACCESSIBILITY_FOCUSED);
541
542 OH_ArkUI_AccessibilityEventSetElementInfo(eventInfo, elementInfo);
543 }
544
SendAccessibilityAsyncEvent(int64_t elementId,bool accessibilityFocus)545 void SendAccessibilityAsyncEvent(int64_t elementId, bool accessibilityFocus)
546 {
547 if (provider_ == nullptr) {
548 LOGI("OH_ArkUI_SendAccessibilityAsyncEvent provider is null");
549 return;
550 }
551 // 1.调用CreateArkUI_AccessibilityEventInfo创建ArkUI_AccessibilityEventInfo对象
552 ArkUI_AccessibilityEventInfo *eventInfo = OH_ArkUI_CreateAccessibilityEventInfo();
553 if (eventInfo == nullptr) {
554 LOGI("OH_ArkUI_SendAccessibilityAsyncEvent eventInfo is null");
555 return;
556 }
557
558 ArkUI_AccessibilityElementInfo* elementInfo = OH_ArkUI_CreateAccessibilityElementInfo();
559 if (elementInfo == nullptr) {
560 LOGI("OH_ArkUI_SendAccessibilityAsyncEvent elementInfo is null");
561 return;
562 }
563 // 2.为info赋值
564 FillElementInfo2(elementInfo, static_cast<int32_t>(elementId));
565 OH_ArkUI_AccessibilityElementInfoSetAccessibilityFocused(elementInfo, accessibilityFocus);
566 FillEvent(eventInfo, elementInfo);
567 // 3.callack
568 auto callback = [](int32_t errorCode) {
569 LOGI("errorCode: %{public}d", errorCode);
570 };
571 // 4.调用接口发给OH侧
572 LOGI("OH_ArkUI_SendAccessibilityAsyncEvent doing");
573 OH_ArkUI_SendAccessibilityAsyncEvent(provider_, eventInfo, callback);
574 // 销毁info
575 OH_ArkUI_DestoryAccessibilityEventInfo(eventInfo);
576 };
577
ExecuteAccessibilityAction(int64_t elementId,ArkUI_Accessibility_ActionType action,ArkUI_AccessibilityActionArguments * actionArguments,int32_t requestId)578 int32_t ExecuteAccessibilityAction(int64_t elementId, ArkUI_Accessibility_ActionType action,
579 ArkUI_AccessibilityActionArguments *actionArguments, int32_t requestId)
580 {
581 LOGI("ExecuteAccessibilityAction start,requestId: %{public}d, action: %{public}d",
582 requestId, static_cast<int32_t>(action));
583 if (actionArguments == nullptr) {
584 LOGI("ExecuteAccessibilityAction actionArguments is null");
585 return OH_NATIVEXCOMPONENT_RESULT_FAILED;
586 }
587
588 std::string key = "key1";
589 char* value;
590 OH_ArkUI_FindAccessibilityActionArgumentByKey(actionArguments, key.c_str(), &value);
591 if (value == nullptr) {
592 LOGI("ExecuteAccessibilityAction value is null");
593 } else {
594 LOGI("ExecuteAccessibilityAction 11111 value : %{public}s", value);
595 }
596 bool accessibilityFocu = (action == 64);
597 SendAccessibilityAsyncEvent(elementId, accessibilityFocu);
598
599 LOGI("ExecuteAccessibilityAction end");
600 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
601 }
602
ClearFocusedFocusAccessibilityNode()603 int32_t ClearFocusedFocusAccessibilityNode()
604 {
605 LOGI("ClearFocusedFocusAccessibilityNode ");
606 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
607 }
608
GetAccessibilityNodeCursorPosition(int64_t elementId,int32_t requestId,int32_t * index)609 int32_t GetAccessibilityNodeCursorPosition(int64_t elementId, int32_t requestId, int32_t* index)
610 {
611 const int32_t cursorPosition = 17805;
612 *index = cursorPosition;
613 return OH_NATIVEXCOMPONENT_RESULT_SUCCESS;
614 }
615
InterfaceDesignTest(OH_NativeXComponent * nativeXComponent)616 void PluginRender::InterfaceDesignTest(OH_NativeXComponent* nativeXComponent)
617 {
618 LOGI("InterfaceDesignTest start");
619 if (nativeXComponent == nullptr) {
620 LOGI("InterfaceDesignTest nativeXComponent is null");
621 return;
622 }
623
624 //1.获得provider实例
625 int32_t ret = OH_NativeXComponent_GetNativeAccessibilityProvider(nativeXComponent, &provider_);
626 if (provider_ == nullptr) {
627 LOGI("InterfaceDesignTest get provider is null");
628 return;
629 }
630
631 accessibilityProviderCallbacks_ = new ArkUI_AccessibilityProviderCallbacks();
632 accessibilityProviderCallbacks_->findAccessibilityNodeInfosById = FindAccessibilityNodeInfosById;
633 accessibilityProviderCallbacks_->findAccessibilityNodeInfosByText = FindAccessibilityNodeInfosByText;
634 accessibilityProviderCallbacks_->findFocusedAccessibilityNode = FindFocusedAccessibilityNode;
635 accessibilityProviderCallbacks_->findNextFocusAccessibilityNode = FindNextFocusAccessibilityNode;
636 accessibilityProviderCallbacks_->executeAccessibilityAction = ExecuteAccessibilityAction;
637 accessibilityProviderCallbacks_->clearFocusedFocusAccessibilityNode = ClearFocusedFocusAccessibilityNode;
638 accessibilityProviderCallbacks_->getAccessibilityNodeCursorPosition = GetAccessibilityNodeCursorPosition;
639 ret = OH_ArkUI_AccessibilityProviderRegisterCallback(provider_, accessibilityProviderCallbacks_);
640 if (ret != 0) {
641 LOGI("InterfaceDesignTest OH_ArkUI_AccessibilityProviderRegisterCallback failed");
642 return;
643 }
644 }
645
Export(napi_env env,napi_value exports)646 napi_value PluginRender::Export(napi_env env, napi_value exports)
647 {
648 LOGE("PluginRender::Export");
649 // Register JS API
650 napi_property_descriptor desc[] = {
651 DECLARE_NAPI_FUNCTION("changeShape", PluginRender::NapiChangeShape),
652 DECLARE_NAPI_FUNCTION("drawTriangle", PluginRender::NapiDrawTriangle),
653 DECLARE_NAPI_FUNCTION("changeColor", PluginRender::NapiChangeColor),
654 DECLARE_NAPI_FUNCTION("TestGetXComponentId", PluginRender::TestGetXComponentId),
655 DECLARE_NAPI_FUNCTION("TestOnSurfaceCreated", PluginRender::TestOnSurfaceCreated),
656 DECLARE_NAPI_FUNCTION("TestGetXComponentSize_Height", PluginRender::TestGetXComponentSize_Height),
657 DECLARE_NAPI_FUNCTION("TestGetXComponentSize_Width", PluginRender::TestGetXComponentSize_Width),
658 DECLARE_NAPI_FUNCTION("TestGetXComponentOffset_x", PluginRender::TestGetXComponentOffset_x),
659 DECLARE_NAPI_FUNCTION("TestGetXComponentOffset_y", PluginRender::TestGetXComponentOffset_y),
660 DECLARE_NAPI_FUNCTION("TestGetXComponent_TouchEvent", PluginRender::TestGetXComponent_TouchEvent),
661 DECLARE_NAPI_FUNCTION("TestGetXComponent_MouseEvent", PluginRender::TestGetXComponent_MouseEvent),
662 DECLARE_NAPI_FUNCTION("TestGetXComponentpointtool_tilty", PluginRender::TestGetXComponentpointtool_tilty),
663 DECLARE_NAPI_FUNCTION("TestGetXComponentpointtool_type", PluginRender::TestGetXComponentpointtool_type),
664 DECLARE_NAPI_FUNCTION("TestGetXComponentpointtool_tiltx", PluginRender::TestGetXComponentpointtool_tiltx),
665 DECLARE_NAPI_FUNCTION("TestGetXComponent_RegisterMouseEventCallback",
666 PluginRender::TestGetXComponent_RegisterMouseEventCallback),
667
668 DECLARE_NAPI_FUNCTION("TestXComponentFindAccessibilityNodeInfosById",
669 PluginRender::TestXComponentFindAccessibilityNodeInfosById),
670 DECLARE_NAPI_FUNCTION("TestXComponentFindAccessibilityNodeInfosByText",
671 PluginRender::TestXComponentFindAccessibilityNodeInfosByText),
672 DECLARE_NAPI_FUNCTION("TestXComponentFindFocusedAccessibilityNode",
673 PluginRender::TestXComponentFindFocusedAccessibilityNode),
674 DECLARE_NAPI_FUNCTION("TestXComponentFindNextFocusAccessibilityNode",
675 PluginRender::TestXComponentFindNextFocusAccessibilityNode),
676 DECLARE_NAPI_FUNCTION("TestXComponentSendAccessibilityAsyncEvent",
677 PluginRender::TestXComponentSendAccessibilityAsyncEvent),
678 DECLARE_NAPI_FUNCTION("TestXComponentExecuteAccessibilityAction",
679 PluginRender::TestXComponentExecuteAccessibilityAction),
680 DECLARE_NAPI_FUNCTION("TestXComponentClearFocusedFocusAccessibilityNode",
681 PluginRender::TestXComponentClearFocusedFocusAccessibilityNode),
682 DECLARE_NAPI_FUNCTION("TestXComponentGetAccessibilityNodeCursorPosition",
683 PluginRender::TestXComponentGetAccessibilityNodeCursorPosition),
684
685 };
686 NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
687 return exports;
688 }
689
TestXComponentFindAccessibilityNodeInfosById(napi_env env,napi_callback_info info)690 napi_value PluginRender::TestXComponentFindAccessibilityNodeInfosById(napi_env env, napi_callback_info info)
691 {
692 return nullptr;
693 }
694
TestXComponentFindAccessibilityNodeInfosByText(napi_env env,napi_callback_info info)695 napi_value PluginRender::TestXComponentFindAccessibilityNodeInfosByText(napi_env env, napi_callback_info info)
696 {
697 return nullptr;
698 }
699
TestXComponentFindFocusedAccessibilityNode(napi_env env,napi_callback_info info)700 napi_value PluginRender::TestXComponentFindFocusedAccessibilityNode(napi_env env, napi_callback_info info)
701 {
702 return nullptr;
703 }
704
TestXComponentFindNextFocusAccessibilityNode(napi_env env,napi_callback_info info)705 napi_value PluginRender::TestXComponentFindNextFocusAccessibilityNode(napi_env env, napi_callback_info info)
706 {
707 return nullptr;
708 }
709
TestXComponentSendAccessibilityAsyncEvent(napi_env env,napi_callback_info info)710 napi_value PluginRender::TestXComponentSendAccessibilityAsyncEvent(napi_env env, napi_callback_info info)
711 {
712 return nullptr;
713 }
714
TestXComponentExecuteAccessibilityAction(napi_env env,napi_callback_info info)715 napi_value PluginRender::TestXComponentExecuteAccessibilityAction(napi_env env, napi_callback_info info)
716 {
717 return nullptr;
718 }
719
TestXComponentClearFocusedFocusAccessibilityNode(napi_env env,napi_callback_info info)720 napi_value PluginRender::TestXComponentClearFocusedFocusAccessibilityNode(napi_env env, napi_callback_info info)
721 {
722 return nullptr;
723 }
724
TestXComponentGetAccessibilityNodeCursorPosition(napi_env env,napi_callback_info info)725 napi_value PluginRender::TestXComponentGetAccessibilityNodeCursorPosition(napi_env env, napi_callback_info info)
726 {
727 return nullptr;
728 }
729
DispatchMouseEvent(OH_NativeXComponent * component,void * window)730 void PluginRender::DispatchMouseEvent(OH_NativeXComponent* component, void* window)
731 {
732 LOGE("----------TestMouse Mouse Info DispatchMouseEvent 11");
733 int32_t ret = OH_NativeXComponent_GetMouseEvent(component, window, &mouseEvent_);
734 LOGE("----------TestMouse Mouse Info DispatchMouseEvent");
735 if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
736 testMouseEvent_ = mouseEvent_;
737 LOGE("TestMouse Mouse Info : x = %{public}f, y = %{public}f screenx = %{public}f, screeny = %{public}f",
738 mouseEvent_.x, mouseEvent_.y, mouseEvent_.screenX, mouseEvent_.screenY);
739 LOGE("TestMouse Mouse Info : action = %{public}d, button = %{public}d", mouseEvent_.action, mouseEvent_.button);
740 } else {
741 LOGE("Mouse Info fail");
742 }
743 }
744
NapiChangeShape(napi_env env,napi_callback_info info)745 napi_value PluginRender::NapiChangeShape(napi_env env, napi_callback_info info)
746 {
747 LOGE("NapiChangeShape");
748 napi_value exportInstance;
749 napi_value thisArg;
750 [[maybe_unused]] napi_status status;
751 OH_NativeXComponent *nativeXComponent = nullptr;
752
753 int32_t ret;
754 char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
755 uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
756
757 NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &thisArg, NULL));
758
759 status = napi_get_named_property(env, thisArg, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
760 if (status != napi_ok) {
761 return nullptr;
762 };
763
764 status = napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent));
765 if (status != napi_ok) {
766 return nullptr;
767 }
768
769 ret = OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize);
770 if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
771 return nullptr;
772 }
773
774 std::string id(idStr);
775 PluginRender* instance = PluginRender::GetInstance(id);
776 if (instance) {
777 instance->eglCore_->ChangeShape();
778 }
779 return nullptr;
780 }
781
NapiDrawTriangle(napi_env env,napi_callback_info info)782 napi_value PluginRender::NapiDrawTriangle(napi_env env, napi_callback_info info)
783 {
784 LOGE("NapiDrawTriangle");
785 napi_value exportInstance;
786 napi_value thisArg;
787 napi_status status;
788 OH_NativeXComponent *nativeXComponent = nullptr;
789
790 int32_t ret;
791 char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
792 uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
793
794 NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &thisArg, NULL));
795
796 status = napi_get_named_property(env, thisArg, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
797 if (status != napi_ok) {
798 return nullptr;
799 };
800
801 status = napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent));
802 if (status != napi_ok) {
803 return nullptr;
804 }
805
806 ret = OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize);
807 if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
808 return nullptr;
809 }
810
811 std::string id(idStr);
812 PluginRender* instance = PluginRender::GetInstance(id);
813 if (instance) {
814 instance->eglCore_->DrawTriangle();
815 }
816 return nullptr;
817 }
818
NapiChangeColor(napi_env env,napi_callback_info info)819 napi_value PluginRender::NapiChangeColor(napi_env env, napi_callback_info info)
820 {
821 LOGE("NapiChangeColor");
822 napi_value exportInstance;
823 napi_value thisArg;
824 napi_status status;
825 OH_NativeXComponent *nativeXComponent = nullptr;
826
827 int32_t ret;
828 char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
829 uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
830
831 NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &thisArg, NULL));
832
833 status = napi_get_named_property(env, thisArg, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
834 if (status != napi_ok) {
835 return nullptr;
836 }
837
838 status = napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent));
839 if (status != napi_ok) {
840 return nullptr;
841 }
842
843 ret = OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize);
844 if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
845 return nullptr;
846 }
847
848 std::string id(idStr);
849 PluginRender* instance = PluginRender::GetInstance(id);
850 if (instance) {
851 instance->eglCore_->ChangeColor();
852 }
853 return nullptr;
854 }
855
TestGetXComponentId(napi_env env,napi_callback_info info)856 napi_value PluginRender::TestGetXComponentId(napi_env env, napi_callback_info info)
857 {
858 napi_value thisArg;
859 [[maybe_unused]] napi_status status;
860 napi_value exportInstance;
861 OH_NativeXComponent *nativeXComponent = nullptr;
862
863 int32_t ret;
864 char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
865 uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
866
867 NAPI_CALL(env, napi_get_cb_info(env, info, NULL, NULL, &thisArg, NULL));
868 status = napi_get_named_property(env, thisArg, OH_NATIVE_XCOMPONENT_OBJ, &exportInstance);
869 if (status != napi_ok) {
870 return nullptr;
871 };
872
873 status = napi_unwrap(env, exportInstance, reinterpret_cast<void**>(&nativeXComponent));
874 if (status != napi_ok) {
875 return nullptr;
876 };
877
878 ret = OH_NativeXComponent_GetXComponentId(nativeXComponent, idStr, &idSize);
879 if (ret != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
880 return nullptr;
881 }
882
883 std::string id(idStr);
884
885 napi_value output;
886 NAPI_CALL(env, napi_create_string_utf8(env, idStr, id.length(), &output));
887
888 return output;
889 }
890
TestOnSurfaceCreated(napi_env env,napi_callback_info info)891 napi_value PluginRender::TestOnSurfaceCreated(napi_env env, napi_callback_info info)
892 {
893 LOGE("xclog iscreated instance.size ");
894
895 napi_value output;
896 NAPI_CALL(env, napi_get_boolean(env, isCreated_ == instance_.size(), &output));
897 LOGE("xclog iscreated instance.size ");
898
899 return output;
900 }
901
TestGetXComponentSize_Height(napi_env env,napi_callback_info info)902 napi_value PluginRender::TestGetXComponentSize_Height(napi_env env, napi_callback_info info)
903 {
904 LOGE("xclog running PluginRender::TestGetXComponentSize_Height");
905 napi_value output;
906 NAPI_CALL(env, napi_create_uint32(env, xcHeight_, &output));
907 LOGE("xclog TestGetXComponentSize_Height %{public}d ", xcHeight_);
908 return output;
909 }
910
TestGetXComponentSize_Width(napi_env env,napi_callback_info info)911 napi_value PluginRender::TestGetXComponentSize_Width(napi_env env, napi_callback_info info)
912 {
913 LOGE("xclog running PluginRender::TestGetXComponentSize_Width");
914 napi_value output;
915 NAPI_CALL(env, napi_create_uint32(env, xcWidth_, &output));
916 LOGE("xclog TestGetXComponentSize_Width %{public}d ", xcWidth_);
917 return output;
918 }
919
TestGetXComponentOffset_x(napi_env env,napi_callback_info info)920 napi_value PluginRender::TestGetXComponentOffset_x(napi_env env, napi_callback_info info)
921 {
922 LOGE("xclog running PluginRender::TestGetXComponentOffset_x");
923
924 napi_value output;
925 NAPI_CALL(env, napi_create_double(env, off_x, &output));
926 LOGE("xclog TestGetXComponentOffset_x : %{public}f", off_x);
927
928 return output;
929 }
930
TestGetXComponentOffset_y(napi_env env,napi_callback_info info)931 napi_value PluginRender::TestGetXComponentOffset_y(napi_env env, napi_callback_info info)
932 {
933 LOGE("xclog running PluginRender::TestGetXComponentOffset_y");
934
935 napi_value output;
936 NAPI_CALL(env, napi_create_double(env, off_y, &output));
937 LOGE("xclog TestGetXComponentOffset_y : %{public}f", off_y);
938
939 return output;
940 }
941
TestGetXComponentpointtool_tiltx(napi_env env,napi_callback_info info)942 napi_value PluginRender::TestGetXComponentpointtool_tiltx(napi_env env, napi_callback_info info)
943 {
944 LOGE("xclog running PluginRender::TestGetXComponentpointtool_tiltx");
945
946 napi_value output;
947 NAPI_CALL(env, napi_create_double(env, tiltX_, &output));
948 LOGE("xclog TestGetXComponentpointtool_tiltx : %{public}f", tiltX_);
949
950 return output;
951 }
952
TestGetXComponentpointtool_tilty(napi_env env,napi_callback_info info)953 napi_value PluginRender::TestGetXComponentpointtool_tilty(napi_env env, napi_callback_info info)
954 {
955 LOGE("xclog running PluginRender::TestGetXComponentpointtool_tilty");
956
957 napi_value output;
958 NAPI_CALL(env, napi_create_double(env, tiltY_, &output));
959 LOGE("xclog TestGetXComponentpointtool_tilty : %{public}f", tiltY_);
960
961 return output;
962 }
963
TestGetXComponentpointtool_type(napi_env env,napi_callback_info info)964 napi_value PluginRender::TestGetXComponentpointtool_type(napi_env env, napi_callback_info info)
965 {
966 LOGE("xclog running PluginRender::TestGetXComponentpointtool_type");
967
968 napi_value output;
969 NAPI_CALL(env, napi_create_double(env, toolType_, &output));
970 LOGE("xclog TestGetXComponentpointtool_type : %{public}u", toolType_);
971
972 return output;
973 }
974
TestGetXComponent_TouchEvent(napi_env env,napi_callback_info info)975 napi_value PluginRender::TestGetXComponent_TouchEvent(napi_env env, napi_callback_info info)
976 {
977 LOGE("xclog running PluginRender::TestGetXComponent_TouchEvent");
978
979 napi_value surf_x;
980 napi_value surf_y;
981 napi_value t_type;
982
983 NAPI_CALL(env, napi_create_double(env, testTouchEvent_.x, &(surf_x)));
984 NAPI_CALL(env, napi_create_double(env, testTouchEvent_.y, &(surf_y)));
985 NAPI_CALL(env, napi_create_uint32(env, testTouchEvent_.type, &(t_type)));
986
987 napi_value obj;
988 NAPI_CALL(env, napi_create_object(env, &obj));
989 NAPI_CALL(env, napi_set_named_property(env, obj, "surface_X", surf_x)); // float x
990 NAPI_CALL(env, napi_set_named_property(env, obj, "surface_Y", surf_y)); // float y
991 NAPI_CALL(env, napi_set_named_property(env, obj, "touchType", t_type)); // int32_t
992
993 return obj;
994 }
995
TestGetXComponent_MouseEvent(napi_env env,napi_callback_info info)996 napi_value PluginRender::TestGetXComponent_MouseEvent(napi_env env, napi_callback_info info)
997 {
998 LOGE("xclog running PluginRender::TestGetXComponent_MouseEvent");
999
1000 napi_value surf_x;
1001 napi_value surf_y;
1002 napi_value t_button;
1003
1004 NAPI_CALL(env, napi_create_double(env, testMouseEvent_.x, &(surf_x)));
1005 NAPI_CALL(env, napi_create_double(env, testMouseEvent_.y, &(surf_y)));
1006 NAPI_CALL(env, napi_create_uint32(env, testMouseEvent_.button, &(t_button)));
1007
1008 napi_value obj;
1009 NAPI_CALL(env, napi_create_object(env, &obj));
1010 NAPI_CALL(env, napi_set_named_property(env, obj, "surface_X1", surf_x)); // float x
1011 NAPI_CALL(env, napi_set_named_property(env, obj, "surface_Y1", surf_y)); // float y
1012 NAPI_CALL(env, napi_set_named_property(env, obj, "mousebutton", t_button)); // int32_t
1013
1014 return obj;
1015 }
1016
1017
TestGetXComponent_RegisterMouseEventCallback(napi_env env,napi_callback_info info)1018 napi_value PluginRender::TestGetXComponent_RegisterMouseEventCallback(napi_env env, napi_callback_info info)
1019 {
1020 LOGE("xclog running PluginRender::TestGetXComponent_RegisterMouseEventCallback");
1021
1022 napi_value callback_;
1023 NAPI_CALL(env, napi_create_double(env, mousecallback_, &(callback_)));
1024
1025 napi_value obj;
1026 NAPI_CALL(env, napi_create_object(env, &obj));
1027 NAPI_CALL(env, napi_set_named_property(env, obj, "MouseCallback_", callback_)); // float x
1028
1029 return obj;
1030 }
1031
1032 #ifdef __cplusplus
1033 }
1034 #endif