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 SetOnResize(std::function<void (const SizeF & size)> && resizeFunc)76 void SetOnResize(std::function<void(const SizeF& size)>&& resizeFunc) 77 { 78 resizeFunc_ = std::move(resizeFunc); 79 } 80 FireOnResize(const SizeF & size)81 void FireOnResize(const SizeF& size) const 82 { 83 CHECK_NULL_VOID(resizeFunc_); 84 resizeFunc_(size); 85 } 86 GetFocusPattern()87 FocusPattern GetFocusPattern() const override 88 { 89 return { FocusType::SCOPE, true }; 90 } 91 IsAtomicNode()92 bool IsAtomicNode() const override 93 { 94 return true; 95 } 96 97 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 98 99 void OnAddBaseNode(); 100 101 RefPtr<FrameNode> GetExportTextureNode() const; 102 GetSurfaceId()103 uint64_t GetSurfaceId() const 104 { 105 return surfaceId_; 106 } 107 108 void ResetExportTextureInfo(); 109 110 private: 111 void OnDetachFromFrameNode(FrameNode* frameNode) override; 112 void OnMountToParentDone() override; 113 void SetExportTextureInfoIfNeeded(); 114 bool HandleTextureExport(bool isStop); 115 std::function<void()> resetFunc_; 116 std::function<RefPtr<UINode>()> makeFunc_; 117 std::function<void(const SizeF& size)> resizeFunc_; 118 WeakPtr<UINode> exportTextureNode_; 119 uint64_t surfaceId_ = 0U; 120 121 ACE_DISALLOW_COPY_AND_MOVE(NodeContainerPattern); 122 }; 123 } // namespace OHOS::Ace::NG 124 125 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NODE_CONTAINER_NODE_CONTAINER_PATTERN_H 126