1 /* 2 * Copyright (c) 2022-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_PATTERNS_SHAPE_CONTAINER_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SHAPE_CONTAINER_PATTERN_H 18 19 #include <cstddef> 20 #include <optional> 21 22 #include "base/geometry/ng/rect_t.h" 23 #include "base/log/log_wrapper.h" 24 #include "base/memory/referenced.h" 25 #include "base/utils/noncopyable.h" 26 #include "core/components_ng/pattern/pattern.h" 27 #include "core/components_ng/pattern/shape/shape_container_layout_algorithm.h" 28 #include "core/components_ng/pattern/shape/shape_container_modifier.h" 29 #include "core/components_ng/pattern/shape/shape_container_paint_property.h" 30 #include "core/components_ng/pattern/shape/shape_view_box.h" 31 32 namespace OHOS::Ace::NG { 33 class ShapeContainerPattern : public Pattern { 34 DECLARE_ACE_TYPE(ShapeContainerPattern, Pattern); 35 36 public: 37 ShapeContainerPattern() = default; 38 ~ShapeContainerPattern() override = default; 39 40 void UpdatePropertyImpl(const std::string& key, RefPtr<PropertyValueBase> value) override; 41 IsEnableMatchParent()42 bool IsEnableMatchParent() override 43 { 44 return true; 45 } 46 IsEnableChildrenMatchParent()47 bool IsEnableChildrenMatchParent() override 48 { 49 return true; 50 } 51 IsEnableFix()52 bool IsEnableFix() override 53 { 54 return true; 55 } 56 CreateLayoutAlgorithm()57 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 58 { 59 return MakeRefPtr<ShapeContainerLayoutAlgorithm>(); 60 } 61 CreatePaintProperty()62 RefPtr<PaintProperty> CreatePaintProperty() override 63 { 64 return MakeRefPtr<ShapeContainerPaintProperty>(); 65 } 66 67 RefPtr<NodePaintMethod> CreateNodePaintMethod() override; 68 69 void OnModifyDone() override; 70 IsAtomicNode()71 bool IsAtomicNode() const override 72 { 73 return false; 74 } 75 AddChildShapeNode(WeakPtr<FrameNode> childNode)76 void AddChildShapeNode(WeakPtr<FrameNode> childNode) 77 { 78 ChildNodes_.push_back(std::move(childNode)); 79 } 80 81 private: 82 void ViewPortTransform(); 83 void OnAttachToFrameNode() override; 84 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, bool skipMeasure, bool skipLayout) override; 85 bool isShapeContainerInit_ = false; 86 std::vector<WeakPtr<FrameNode>> ChildNodes_; 87 RefPtr<ShapeContainerModifier> shapeContainerModifier_; 88 89 ACE_DISALLOW_COPY_AND_MOVE(ShapeContainerPattern); 90 }; 91 } // namespace OHOS::Ace::NG 92 93 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SHAPE_CONTAINER_PATTERN_H 94