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/pattern.h" 23 #include "core/components_ng/pattern/stack/stack_layout_algorithm.h" 24 #include "core/components_ng/pattern/stack/stack_layout_property.h" 25 26 namespace OHOS::Ace::NG { 27 class NodeContainerPattern : virtual public Pattern { 28 DECLARE_ACE_TYPE(NodeContainerPattern, Pattern); 29 30 public: 31 NodeContainerPattern() = default; 32 ~NodeContainerPattern() override = default; 33 CreateLayoutProperty()34 RefPtr<LayoutProperty> CreateLayoutProperty() override 35 { 36 return MakeRefPtr<StackLayoutProperty>(); 37 } 38 CreateLayoutAlgorithm()39 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 40 { 41 return MakeRefPtr<NodeContainerLayoutAlgorithm>(); 42 } 43 44 void RemakeNode(); 45 BindController(std::function<void ()> && resetFunc)46 void BindController(std::function<void()>&& resetFunc) 47 { 48 resetFunc_ = std::move(resetFunc); 49 } 50 ResetController()51 void ResetController() const 52 { 53 CHECK_NULL_VOID(resetFunc_); 54 resetFunc_(); 55 } 56 SetMakeFunction(std::function<RefPtr<UINode> ()> && makeFunc)57 void SetMakeFunction(std::function<RefPtr<UINode>()>&& makeFunc) 58 { 59 makeFunc_ = std::move(makeFunc); 60 } 61 FireMakeFunction()62 RefPtr<UINode> FireMakeFunction() const 63 { 64 CHECK_NULL_RETURN(makeFunc_, nullptr); 65 return makeFunc_(); 66 } 67 SetOnResize(std::function<void (const SizeF & size)> && resizeFunc)68 void SetOnResize(std::function<void(const SizeF& size)>&& resizeFunc) 69 { 70 resizeFunc_ = std::move(resizeFunc); 71 } 72 FireOnResize(const SizeF & size)73 void FireOnResize(const SizeF& size) const 74 { 75 CHECK_NULL_VOID(resizeFunc_); 76 resizeFunc_(size); 77 } 78 GetFocusPattern()79 FocusPattern GetFocusPattern() const override 80 { 81 return { FocusType::SCOPE, true }; 82 } 83 IsAtomicNode()84 bool IsAtomicNode() const override 85 { 86 return true; 87 } 88 89 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 90 91 void OnAddBaseNode(); 92 93 RefPtr<FrameNode> GetExportTextureNode() const; 94 GetSurfaceId()95 uint64_t GetSurfaceId() const 96 { 97 return surfaceId_; 98 } 99 100 void ResetExportTextureInfo(); 101 102 private: 103 void OnDetachFromFrameNode(FrameNode* frameNode) override; 104 void OnMountToParentDone() override; 105 void SetExportTextureInfoIfNeeded(); 106 bool HandleTextureExport(bool isStop); 107 std::function<void()> resetFunc_; 108 std::function<RefPtr<UINode>()> makeFunc_; 109 std::function<void(const SizeF& size)> resizeFunc_; 110 WeakPtr<UINode> exportTextureNode_; 111 uint64_t surfaceId_ = 0U; 112 113 ACE_DISALLOW_COPY_AND_MOVE(NodeContainerPattern); 114 }; 115 } // namespace OHOS::Ace::NG 116 117 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NODE_CONTAINER_NODE_CONTAINER_PATTERN_H 118