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_COUNTER_COUNTER_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_COUNTER_COUNTER_PATTERN_H
18 
19 #include <optional>
20 
21 #include "core/components_ng/pattern/counter/counter_layout_algorithm.h"
22 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
23 #include "core/components_ng/pattern/pattern.h"
24 
25 namespace OHOS::Ace::NG {
26 
27 class CounterPattern : public LinearLayoutPattern {
28     DECLARE_ACE_TYPE(CounterPattern, LinearLayoutPattern);
29 
30 public:
CounterPattern()31     CounterPattern() : LinearLayoutPattern(false) {};
32     ~CounterPattern() override = default;
33 
HasSubNode()34     bool HasSubNode() const
35     {
36         return subId_.has_value();
37     }
GetSubId()38     int32_t GetSubId()
39     {
40         if (!subId_.has_value()) {
41             subId_ = ElementRegister::GetInstance()->MakeUniqueId();
42         }
43         return subId_.value();
44     }
45 
HasContentNode()46     bool HasContentNode() const
47     {
48         return contentId_.has_value();
49     }
GetContentId()50     int32_t GetContentId()
51     {
52         if (!contentId_.has_value()) {
53             contentId_ = ElementRegister::GetInstance()->MakeUniqueId();
54         }
55         return contentId_.value();
56     }
57 
HasAddNode()58     bool HasAddNode() const
59     {
60         return addId_.has_value();
61     }
GetAddId()62     int32_t GetAddId()
63     {
64         if (!addId_.has_value()) {
65             addId_ = ElementRegister::GetInstance()->MakeUniqueId();
66         }
67         return addId_.value();
68     }
69 
CreateLayoutAlgorithm()70     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
71     {
72         return MakeRefPtr<CounterLayoutAlgorithm>();
73     }
74 
GetFocusPattern()75     FocusPattern GetFocusPattern() const override
76     {
77         return { FocusType::NODE, false, FocusStyleType::OUTER_BORDER };
78     }
79 
80 private:
81     std::optional<int32_t> subId_;
82     std::optional<int32_t> contentId_;
83     std::optional<int32_t> addId_;
84     ACE_DISALLOW_COPY_AND_MOVE(CounterPattern);
85 };
86 
87 } // namespace OHOS::Ace::NG
88 
89 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_COUNTER_COUNTER_PATTERN_H
90