1 /*
2  * Copyright (c) 2022-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_DIVIDER_DIVIDER_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DIVIDER_DIVIDER_PATTERN_H
18 
19 #include "core/components_ng/pattern/divider/divider_layout_algorithm.h"
20 #include "core/components_ng/pattern/divider/divider_layout_property.h"
21 #include "core/components_ng/pattern/divider/divider_modifier.h"
22 #include "core/components_ng/pattern/divider/divider_paint_method.h"
23 #include "core/components_ng/pattern/divider/divider_render_property.h"
24 #include "core/components_ng/pattern/pattern.h"
25 
26 namespace OHOS::Ace::NG {
27 class DividerPattern : public Pattern {
28     DECLARE_ACE_TYPE(DividerPattern, Pattern);
29 
30 public:
31     DividerPattern() = default;
32     ~DividerPattern() override = default;
33 
CreateNodePaintMethod()34     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
35     {
36         if (!dividerModifier_) {
37             dividerModifier_ = AceType::MakeRefPtr<DividerModifier>();
38         }
39         return MakeRefPtr<DividerPaintMethod>(
40             constrainStrokeWidth_, dividerLength_, vertical_, strokeWidthLimitation_, dividerModifier_);
41     }
42 
CreateLayoutProperty()43     RefPtr<LayoutProperty> CreateLayoutProperty() override
44     {
45         return MakeRefPtr<DividerLayoutProperty>();
46     }
47 
CreateLayoutAlgorithm()48     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
49     {
50         return MakeRefPtr<DividerLayoutAlgorithm>();
51     }
52 
CreatePaintProperty()53     RefPtr<PaintProperty> CreatePaintProperty() override
54     {
55         return MakeRefPtr<DividerRenderProperty>();
56     }
57 
GetFocusPattern()58     FocusPattern GetFocusPattern() const override
59     {
60         return { FocusType::NODE, false, FocusStyleType::OUTER_BORDER };
61     }
62 
63 private:
64     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
65     float constrainStrokeWidth_ = 0;
66     float dividerLength_ = 0;
67     bool vertical_ = false;
68     bool strokeWidthLimitation_ = true;
69     RefPtr<DividerModifier> dividerModifier_;
70     ACE_DISALLOW_COPY_AND_MOVE(DividerPattern);
71 };
72 } // namespace OHOS::Ace::NG
73 
74 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DIVIDER_DIVIDER_PATTERN_H
75