1 /* 2 * Copyright (c) 2022-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 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_MODEL_NG_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_MODEL_NG_H 18 19 #include <optional> 20 #include "base/memory/referenced.h" 21 #include "core/components_ng/pattern/xcomponent/xcomponent_model.h" 22 #include "core/components_ng/base/frame_node.h" 23 #include "core/interfaces/arkoala/arkoala_api.h" 24 25 namespace OHOS::Ace::NG { 26 class FrameNode; 27 28 class ArkUI_XComponent_Params final : public ArkUI_Params { 29 public: 30 std::string id; 31 XComponentType type = XComponentType::SURFACE; 32 std::optional<std::string> libraryName = std::nullopt; 33 std::shared_ptr<InnerXComponentController> controller = nullptr; 34 void* aiOptions = nullptr; 35 }; 36 37 class ACE_EXPORT XComponentModelNG : public OHOS::Ace::XComponentModel { 38 public: 39 void Create(const std::optional<std::string>& id, XComponentType type, 40 const std::optional<std::string>& libraryname, 41 const std::shared_ptr<InnerXComponentController>& xcomponentController) override; 42 RefPtr<AceType> Create(int32_t nodeId, float width, float height, 43 const std::string& id, XComponentType type, const std::string& libraryname, 44 const std::shared_ptr<InnerXComponentController>& xcomponentController) override; 45 XComponentType GetType() override; 46 std::optional<std::string> GetLibraryName() override; 47 void SetSoPath(const std::string& soPath) override; 48 void SetOnLoad(LoadEvent&& onLoad) override; 49 void SetOnDestroy(DestroyEvent&& onDestroy) override; 50 void RegisterOnCreate(const RefPtr<AceType>& node, LoadEvent&& onLoad) override; 51 void RegisterOnDestroy(const RefPtr<AceType>& node, DestroyEvent&& onDestroy) override; 52 bool IsTexture() override; 53 void SetDetachCallback(DetachCallback&& onDetach) override; 54 void SetControllerOnCreated(SurfaceCreatedEvent&& onCreated) override; 55 void SetControllerOnChanged(SurfaceChangedEvent&& onChanged) override; 56 void SetControllerOnDestroyed(SurfaceDestroyedEvent&& onDestroyed) override; 57 void EnableAnalyzer(bool enable) override; 58 void SetImageAIOptions(void* options) override; 59 void SetRenderFit(RenderFit renderFit) override; 60 void EnableSecure(bool isSecure) override; 61 62 static bool IsTexture(FrameNode* frameNode); 63 static XComponentType GetType(FrameNode* frameNode); 64 static RefPtr<FrameNode> CreateFrameNode( 65 int32_t nodeId, const std::string& id, XComponentType type, const std::optional<std::string>& libraryname); 66 static RefPtr<FrameNode> CreateTypeNode(int32_t nodeId, ArkUI_XComponent_Params* params); 67 static void InitXComponent(FrameNode* frameNode); 68 static void SetXComponentId(FrameNode* frameNode, const std::string& id); 69 static void SetXComponentType(FrameNode* frameNode, XComponentType type); 70 static void SetXComponentSurfaceSize(FrameNode* frameNode, uint32_t width, uint32_t height); 71 static std::string GetXComponentId(FrameNode* frameNode); 72 static XComponentType GetXComponentType(FrameNode* frameNode); 73 static uint32_t GetXComponentSurfaceWidth(FrameNode* frameNode); 74 static uint32_t GetXComponentSurfaceHeight(FrameNode* frameNode); 75 static void SetXComponentLibraryname(FrameNode* frameNode, const std::string& libraryname); 76 static void SetControllerOnCreated(FrameNode* frameNode, SurfaceCreatedEvent&& onCreated); 77 static void SetControllerOnChanged(FrameNode* frameNode, SurfaceChangedEvent&& onChanged); 78 static void SetControllerOnDestroyed(FrameNode* frameNode, SurfaceDestroyedEvent&& onDestroyed); 79 static void SetDetachCallback(FrameNode* frameNode, DetachCallback&& onDetach); 80 static void SetImageAIOptions(FrameNode* frameNode, void* options); 81 static void SetOnLoad(FrameNode* frameNode, LoadEvent&& onLoad); 82 static void SetOnDestroy(FrameNode* frameNode, DestroyEvent&& onDestroy); 83 static void EnableAnalyzer(FrameNode* frameNode, bool enable); 84 static void EnableSecure(FrameNode* frameNode, bool enable); 85 static void SetRenderFit(FrameNode* frameNode, RenderFit renderFit); 86 87 private: 88 static XComponentType GetTypeImpl(const RefPtr<FrameNode>& frameNode); 89 }; 90 91 } // namespace OHOS::Ace::NG 92 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_MODEL_NG_H 93