• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef _PLUGIN_RENDER_H_
17 #define _PLUGIN_RENDER_H_
18 
19 #include <string>
20 #include <unordered_map>
21 
22 #include <ace/xcomponent/native_interface_xcomponent.h>
23 #include <napi/native_api.h>
24 #include <arkui/native_interface_accessibility.h>
25 
26 #include "egl_core.h"
27 
28 class PluginRender {
29 public:
30     explicit PluginRender(std::string& id);
31     static PluginRender* GetInstance(std::string& id);
32     static OH_NativeXComponent_Callback* GetNXComponentCallback();
33     static OH_NativeXComponent_MouseEvent_Callback* GetNXComponentMouseEventCallback();
34 
35     void SetNativeXComponent(OH_NativeXComponent* component);
36 
37 public:
38     // NAPI interface
39     napi_value Export(napi_env env, napi_value exports);
40 
41     // Exposed to JS developers by NAPI
42     static napi_value NapiChangeShape(napi_env env, napi_callback_info info);
43     static napi_value NapiDrawTriangle(napi_env env, napi_callback_info info);
44     static napi_value NapiChangeColor(napi_env env, napi_callback_info info);
45     static napi_value NapiChangeColorWorker(napi_env env, napi_callback_info info);
46 
47     // xts interfaces
48     static napi_value TestXComponentFindAccessibilityNodeInfosById(napi_env env, napi_callback_info info);
49     static napi_value TestXComponentFindAccessibilityNodeInfosByText(napi_env env, napi_callback_info info);
50     static napi_value TestXComponentFindFocusedAccessibilityNode(napi_env env, napi_callback_info info);
51     static napi_value TestXComponentFindNextFocusAccessibilityNode(napi_env env, napi_callback_info info);
52     static napi_value TestXComponentSendAccessibilityAsyncEvent(napi_env env, napi_callback_info info);
53     static napi_value TestXComponentExecuteAccessibilityAction(napi_env env, napi_callback_info info);
54     static napi_value TestXComponentClearFocusedFocusAccessibilityNode(napi_env env, napi_callback_info info);
55     static napi_value TestXComponentGetAccessibilityNodeCursorPosition(napi_env env, napi_callback_info info);
56 
57     static napi_value TestGetXComponentId(napi_env env, napi_callback_info info);
58     static napi_value TestOnSurfaceCreated(napi_env env, napi_callback_info info);
59     static napi_value TestGetXComponentSize_Height(napi_env env, napi_callback_info info);
60     static napi_value TestGetXComponentSize_Width(napi_env env, napi_callback_info info);
61     static napi_value TestGetXComponentOffset_x(napi_env env, napi_callback_info info);
62     static napi_value TestGetXComponentOffset_y(napi_env env, napi_callback_info info);
63     static napi_value TestGetXComponent_TouchEvent(napi_env env, napi_callback_info info);
64     static napi_value TestGetXComponent_MouseEvent(napi_env env, napi_callback_info info);
65     static napi_value TestGetXComponentpointtool_tiltx(napi_env env, napi_callback_info info);
66     static napi_value TestGetXComponentpointtool_tilty(napi_env env, napi_callback_info info);
67     static napi_value TestGetXComponentpointtool_type(napi_env env, napi_callback_info info);
68     static napi_value TestGetXComponent_RegisterMouseEventCallback(napi_env env, napi_callback_info info);
69     // Callback, called by ACE XComponent
70     void OnSurfaceCreated(OH_NativeXComponent* component, void* window);
71 
72     void OnSurfaceChanged(OH_NativeXComponent* component, void* window);
73 
74     void OnSurfaceDestroyed(OH_NativeXComponent* component, void* window);
75 
76     void DispatchTouchEvent(OH_NativeXComponent* component, void* window);
77 
78     void DispatchMouseEvent(OH_NativeXComponent* component, void* window);
79 
80     void InterfaceDesignTest(OH_NativeXComponent* nativeXComponent);
81 
82     void setElementInfo(ArkUI_AccessibilityElementInfo* elementInfo, int32_t i);
83 
84 public:
85     static std::unordered_map<std::string, PluginRender*> instance_;
86     static OH_NativeXComponent_Callback callback_;
87     static uint32_t isCreated_;
88     static uint32_t xcHeight_;
89     static uint32_t xcWidth_;
90     static uint32_t toolType_;
91     static float tiltX_;
92     static float tiltY_;
93     static uint32_t mousecallback_;
94     static double off_x;
95     static double off_y;
96     static uint32_t touchType;
97     static OH_NativeXComponent_TouchEvent testTouchEvent_;
98     static OH_NativeXComponent_MouseEvent testMouseEvent_;
99     static OH_NativeXComponent_MouseEvent_Callback mouseEventcallback_;
100 
101     OH_NativeXComponent* component_;
102     EGLCore* eglCore_;
103 
104     std::string id_;
105     uint64_t width_;
106     uint64_t height_;
107 
108     double x_;
109     double y_;
110     OH_NativeXComponent_TouchEvent touchEvent_;
111     OH_NativeXComponent_MouseEvent mouseEvent_;
112 
113     ArkUI_AccessibilityProviderCallbacks* accessibilityProviderCallbacks_;
114 };
115 
116 #endif // _PLUGIN_RENDER_H_