1 /* 2 * Copyright (c) 2024 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_SYNTAX_NODE_CONTENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_NODE_CONTENT_H 18 19 #include <functional> 20 #include <list> 21 22 #include "base/memory/ace_type.h" 23 #include "core/components_ng/base/ui_node.h" 24 25 namespace OHOS::Ace::NG { 26 27 class NodeContent : public AceType { 28 DECLARE_ACE_TYPE(NodeContent, AceType) 29 public: 30 NodeContent() = default; 31 ~NodeContent() override = default; 32 33 void AttachToNode(UINode* node); 34 void DetachFromNode(); 35 36 void AddNode(UINode* node, int32_t position = -1); 37 void RemoveNode(UINode* node); 38 39 void OnAttachToMainTree(); 40 41 void OnDetachFromMainTree(); 42 SetAttachToMainTreeCallback(std::function<void ()> && callback)43 void SetAttachToMainTreeCallback(std::function<void()>&& callback) 44 { 45 onAttachCallback_ = std::move(callback); 46 } 47 SetDetachFromMainTreeCallback(std::function<void ()> && callback)48 void SetDetachFromMainTreeCallback(std::function<void()>&& callback) 49 { 50 onDetachCallback_ = std::move(callback); 51 } 52 GetUserData()53 void* GetUserData() const 54 { 55 return userData_; 56 } 57 SetUserData(void * userData)58 void SetUserData(void* userData) 59 { 60 userData_ = userData; 61 } 62 GetContentSlot()63 WeakPtr<UINode> GetContentSlot() 64 { 65 return nodeSlot_; 66 } 67 68 private: 69 WeakPtr<UINode> nodeSlot_; 70 std::list<RefPtr<UINode>> children_; 71 std::function<void()> onAttachCallback_; 72 std::function<void()> onDetachCallback_; 73 void* userData_ = nullptr; 74 75 bool onMainTree_ = false; 76 }; 77 78 } // namespace OHOS::Ace::NG 79 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_NODE_CONTENT_H 80