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 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NODE_CONTAINER_NODE_CONTAINER_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NODE_CONTAINER_NODE_CONTAINER_PATTERN_H 18 19 #include "base/utils/noncopyable.h" 20 #include "base/utils/utils.h" 21 #include "core/components_ng/pattern/node_container/node_container_layout_algorithm.h" 22 #include "core/components_ng/pattern/node_container/node_container_event_hub.h" 23 #include "core/components_ng/pattern/pattern.h" 24 #include "core/components_ng/pattern/stack/stack_layout_algorithm.h" 25 #include "core/components_ng/pattern/stack/stack_layout_property.h" 26 27 namespace OHOS::Ace::NG { 28 class NodeContainerPattern : virtual public Pattern { 29 DECLARE_ACE_TYPE(NodeContainerPattern, Pattern); 30 31 public: 32 NodeContainerPattern() = default; 33 ~NodeContainerPattern() override = default; 34 CreateLayoutProperty()35 RefPtr<LayoutProperty> CreateLayoutProperty() override 36 { 37 return MakeRefPtr<StackLayoutProperty>(); 38 } 39 CreateLayoutAlgorithm()40 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 41 { 42 return MakeRefPtr<NodeContainerLayoutAlgorithm>(); 43 } 44 CreateEventHub()45 RefPtr<EventHub> CreateEventHub() override 46 { 47 return MakeRefPtr<NodeContainerEventHub>(); 48 } 49 50 void RemakeNode(); 51 52 void CleanChild(); 53 BindController(std::function<void ()> && resetFunc)54 void BindController(std::function<void()>&& resetFunc) 55 { 56 resetFunc_ = std::move(resetFunc); 57 } 58 ResetController()59 void ResetController() const 60 { 61 CHECK_NULL_VOID(resetFunc_); 62 resetFunc_(); 63 } 64 SetMakeFunction(std::function<RefPtr<UINode> ()> && makeFunc)65 void SetMakeFunction(std::function<RefPtr<UINode>()>&& makeFunc) 66 { 67 makeFunc_ = std::move(makeFunc); 68 } 69 FireMakeFunction()70 RefPtr<UINode> FireMakeFunction() const 71 { 72 CHECK_NULL_RETURN(makeFunc_, nullptr); 73 return makeFunc_(); 74 } 75 76 void FireOnWillBind(int32_t containerId); 77 78 void FireOnWillUnbind(int32_t containerId); 79 80 void FireOnBind(int32_t containerId); 81 82 void FireOnUnbind(int32_t containerId); 83 SetOnResize(std::function<void (const SizeF & size)> && resizeFunc)84 void SetOnResize(std::function<void(const SizeF& size)>&& resizeFunc) 85 { 86 resizeFunc_ = std::move(resizeFunc); 87 } 88 FireOnResize(const SizeF & size)89 void FireOnResize(const SizeF& size) const 90 { 91 CHECK_NULL_VOID(resizeFunc_); 92 resizeFunc_(size); 93 } 94 GetFocusPattern()95 FocusPattern GetFocusPattern() const override 96 { 97 return { FocusType::SCOPE, true }; 98 } 99 IsAtomicNode()100 bool IsAtomicNode() const override 101 { 102 return true; 103 } 104 105 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 106 107 void OnAddBaseNode(); 108 109 RefPtr<FrameNode> GetExportTextureNode() const; 110 GetSurfaceId()111 uint64_t GetSurfaceId() const 112 { 113 return surfaceId_; 114 } 115 116 void ResetExportTextureInfo(); 117 IsEnableChildrenMatchParent()118 bool IsEnableChildrenMatchParent() override 119 { 120 return true; 121 } 122 IsEnableMatchParent()123 bool IsEnableMatchParent() override 124 { 125 return true; 126 } 127 IsEnableFix()128 bool IsEnableFix() override 129 { 130 return true; 131 } 132 133 void AddBaseNode(const RefPtr<UINode>& newNode); 134 135 private: 136 void OnDetachFromFrameNode(FrameNode* frameNode) override; 137 void OnMountToParentDone() override; 138 void SetExportTextureInfoIfNeeded(); 139 bool HandleTextureExport(bool isStop, FrameNode* frameNode); 140 std::function<void()> resetFunc_; 141 std::function<RefPtr<UINode>()> makeFunc_; 142 std::function<void(const SizeF& size)> resizeFunc_; 143 WeakPtr<UINode> exportTextureNode_; 144 uint64_t surfaceId_ = 0U; 145 RefPtr<NodeContainerEventHub> GetNodeContainerEventHub(); 146 147 ACE_DISALLOW_COPY_AND_MOVE(NodeContainerPattern); 148 }; 149 } // namespace OHOS::Ace::NG 150 151 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NODE_CONTAINER_NODE_CONTAINER_PATTERN_H 152