1 /*
2  * Copyright (c) 2022 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_paint_property.h"
29 #include "core/components_ng/pattern/shape/shape_view_box.h"
30 
31 namespace OHOS::Ace::NG {
32 class ShapeContainerPattern : public Pattern {
33     DECLARE_ACE_TYPE(ShapeContainerPattern, Pattern);
34 
35 public:
36     ShapeContainerPattern() = default;
37     ~ShapeContainerPattern() override = default;
38 
CreateLayoutAlgorithm()39     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
40     {
41         return MakeRefPtr<ShapeContainerLayoutAlgorithm>();
42     }
43 
CreatePaintProperty()44     RefPtr<PaintProperty> CreatePaintProperty() override
45     {
46         return MakeRefPtr<ShapeContainerPaintProperty>();
47     }
48 
49     void OnModifyDone() override;
50 
IsAtomicNode()51     bool IsAtomicNode() const override
52     {
53         return false;
54     }
55 
AddChildShapeNode(WeakPtr<FrameNode> childNode)56     void AddChildShapeNode(WeakPtr<FrameNode> childNode)
57     {
58         ChildNodes_.push_back(std::move(childNode));
59     }
60 
61 private:
62     void ViewPortTransform();
63     void OnAttachToFrameNode() override;
64     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, bool skipMeasure, bool skipLayout) override;
65     bool isShapeContainerInit_ = false;
66     std::vector<WeakPtr<FrameNode>> ChildNodes_;
67 
68     ACE_DISALLOW_COPY_AND_MOVE(ShapeContainerPattern);
69 };
70 } // namespace OHOS::Ace::NG
71 
72 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SHAPE_CONTAINER_PATTERN_H
73