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_RECT_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SHAPE_RECT_PATTERN_H
18 
19 #include "base/memory/referenced.h"
20 #include "base/utils/noncopyable.h"
21 #include "core/components_ng/pattern/pattern.h"
22 #include "core/components_ng/pattern/shape/rect_paint_method.h"
23 #include "core/components_ng/pattern/shape/rect_paint_property.h"
24 #include "core/components_ng/pattern/shape/shape_pattern.h"
25 
26 namespace OHOS::Ace::NG {
27 
28 class RectPattern : public ShapePattern {
29     DECLARE_ACE_TYPE(RectPattern, ShapePattern);
30 
31 public:
32     RectPattern() = default;
33     ~RectPattern() override = default;
CreateNodePaintMethod()34     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
35     {
36         if (!shapeOverlayModifier_) {
37             shapeOverlayModifier_ = MakeRefPtr<ShapeOverlayModifier>();
38         }
39         return MakeRefPtr<RectPaintMethod>(GetAncestorPaintProperty(), shapeOverlayModifier_);
40     }
CreatePaintProperty()41     RefPtr<PaintProperty> CreatePaintProperty() override
42     {
43         return MakeRefPtr<RectPaintProperty>();
44     }
45 
OnPixelRoundFinish(const SizeF & pixelGridRoundSize)46     void OnPixelRoundFinish(const SizeF& pixelGridRoundSize) override
47     {
48         auto host = GetHost();
49         CHECK_NULL_VOID(host);
50         auto geometryNode = host->GetGeometryNode();
51         CHECK_NULL_VOID(geometryNode);
52         auto pixelRoundContentOffset = geometryNode->GetPixelRoundContentOffset();
53         auto pixelRoundContentSize = geometryNode->GetPixelRoundContentSize();
54         auto rectPaintProperty = host->GetPaintProperty<RectPaintProperty>();
55         CHECK_NULL_VOID(rectPaintProperty);
56         rectPaintProperty->SetContentOffset(pixelRoundContentOffset);
57         rectPaintProperty->SetContentSize(pixelRoundContentSize);
58     }
59 
60 private:
61     ACE_DISALLOW_COPY_AND_MOVE(RectPattern);
62 };
63 
64 } // namespace OHOS::Ace::NG
65 
66 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SHAPE_RECT_PATTERN_H