• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_MODEL_H
18 
19 #include <mutex>
20 
21 #include "base/memory/ace_type.h"
22 #include "core/common/container.h"
23 #include "core/components/common/layout/constants.h"
24 #include "core/components_ng/pattern/xcomponent/inner_xcomponent_controller.h"
25 
26 namespace OHOS::Ace {
27 using LoadEvent = std::function<void(const std::string&)>;
28 using DestroyEvent = std::function<void()>;
29 using DetachCallback = std::function<void(const std::string&)>;
30 class XComponentModel {
31 public:
32     static XComponentModel* GetInstance();
IsBackGroundColorAvailable(const XComponentType & type)33     static bool IsBackGroundColorAvailable(const XComponentType& type)
34     {
35         return type == XComponentType::TEXTURE || type == XComponentType::NODE ||
36                (type == XComponentType::SURFACE && Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN));
37     }
38     virtual ~XComponentModel() = default;
39 
40     virtual void Create(const std::string& id, XComponentType type, const std::string& libraryname,
41         const std::shared_ptr<InnerXComponentController>& xcomponentController) = 0;
Create(int32_t,float,float,const std::string &,XComponentType,const std::string &,const std::shared_ptr<InnerXComponentController> &)42     virtual 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 */)
45     {
46         return nullptr;
47     };
48     virtual void SetSoPath(const std::string& soPath) = 0;
49     virtual void SetOnLoad(LoadEvent&& onLoad) = 0;
50     virtual void SetOnDestroy(DestroyEvent&& onDestroy) = 0;
RegisterOnCreate(const RefPtr<AceType> & node,LoadEvent && onLoad)51     virtual void RegisterOnCreate(const RefPtr<AceType>& node, LoadEvent&& onLoad) {};
RegisterOnDestroy(const RefPtr<AceType> & node,DestroyEvent && onDestroy)52     virtual void RegisterOnDestroy(const RefPtr<AceType>& node, DestroyEvent&& onDestroy) {};
IsTexture()53     virtual bool IsTexture()
54     {
55         return false;
56     }
SetDetachCallback(DetachCallback && onDetach)57     virtual void SetDetachCallback(DetachCallback&& onDetach) {}
GetType()58     virtual XComponentType GetType()
59     {
60         return XComponentType::UNKNOWN;
61     }
62 
63 private:
64     static std::unique_ptr<XComponentModel> instance_;
65     static std::mutex mutex_;
66 };
67 
68 } // namespace OHOS::Ace
69 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_XCOMPONENT_MODEL_H
70