• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 MYAPPLICATION_CONTAINER_H
17 #define MYAPPLICATION_CONTAINER_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 
25 const unsigned int LOG_PRINT_DOMAIN = 0xFF00;
26 
27 namespace NativeXComponentSample {
28 
29 class Container {
30 public:
31     explicit Container(const std::string &id);
32     ~Container() = default;
33     static Container *GetInstance(const std::string &id);
34     static void Release(const std::string &id);
35     void Export(napi_env env, napi_value exports);
36     void OnSurfaceChanged(OH_NativeXComponent *component, void *window);
37     void OnTouchEvent(OH_NativeXComponent *component, void *window);
38     void OnMouseEvent(OH_NativeXComponent *component, void *window);
39     void OnHoverEvent(OH_NativeXComponent *component, bool isHover);
40     void OnKeyEvent(OH_NativeXComponent *component, void *window);
41     void RegisterCallback(OH_NativeXComponent *nativeXComponent);
42 
43 public:
44     static std::unordered_map<std::string, Container *> instance_;
45     std::string id_;
46 
47 private:
48     OH_NativeXComponent_Callback containerCallback_;
49     OH_NativeXComponent_MouseEvent_Callback mouseCallback_;
50 };
51 
52 } // namespace NativeXComponentSample
53 
54 
55 #endif //MYAPPLICATION_CONTAINER_H
56