1 /* 2 * Copyright (c) 2023 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 #ifndef NATIVE_XCOMPONENT_XCOMPONENT_MANAGER_H 16 #define NATIVE_XCOMPONENT_XCOMPONENT_MANAGER_H 17 18 #include <ace/xcomponent/native_interface_xcomponent.h> 19 #include <native_window/external_window.h> 20 #include <napi/native_api.h> 21 #include <string> 22 #include <unordered_map> 23 24 namespace NativeXComponentSample { 25 26 class AccessibilityManager; 27 class XComponentManager { 28 public: 29 XComponentManager(); 30 ~XComponentManager(); 31 32 void RegisterCallback(OH_NativeXComponent *nativeXComponent); 33 34 struct XSurface { 35 OH_NativeXComponent *xcomponent; 36 OHNativeWindow *window; 37 }; 38 39 public: 40 41 // manager xcomponent 42 void SetNativeXComponent(const std::string &id, OH_NativeXComponent *nativeXComponent, OHNativeWindow *window); 43 GetXSurface(const std::string & id)44 XSurface GetXSurface(const std::string &id) const 45 { 46 auto it = nativeXComponentMap_.find(id); 47 return it != nativeXComponentMap_.end() ? it->second : XSurface{}; 48 } 49 50 private: 51 std::unordered_map<std::string, XSurface> nativeXComponentMap_; 52 53 OH_NativeXComponent_Callback renderCallback_; 54 OH_NativeXComponent_MouseEvent_Callback mouseCallback_; 55 AccessibilityManager *accessibilityManager; 56 }; 57 } // namespace NativeXComponentSample 58 59 #endif // NATIVE_XCOMPONENT_XCOMPONENT_MANAGER_H