1 /*
2  * Copyright (c) 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_PATTERN_WATERFLOW_WATER_FLOW_ITEM_LAYOUT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WATERFLOW_WATER_FLOW_ITEM_LAYOUT_PROPERTY_H
18 
19 #include "core/components/common/layout/constants.h"
20 #include "core/components_ng/layout/layout_property.h"
21 #include "core/components_ng/property/measure_property.h"
22 
23 namespace OHOS::Ace::NG {
24 class ACE_EXPORT WaterFlowItemLayoutProperty : public LayoutProperty {
25     DECLARE_ACE_TYPE(WaterFlowItemLayoutProperty, LayoutProperty);
26 
27 public:
28     WaterFlowItemLayoutProperty() = default;
29     ~WaterFlowItemLayoutProperty() override = default;
30 
Clone()31     RefPtr<LayoutProperty> Clone() const override
32     {
33         auto value = MakeRefPtr<WaterFlowItemLayoutProperty>();
34         value->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this));
35         if (originalConstraint_) {
36             value->originalConstraint_ = std::make_unique<MeasureProperty>(*originalConstraint_);
37         }
38         return value;
39     }
40 
Reset()41     void Reset() override
42     {
43         LayoutProperty::Reset();
44         originalConstraint_.reset();
45     }
46 
UpdateCalcMinSize(const CalcSize & value)47     void UpdateCalcMinSize(const CalcSize& value) override
48     {
49         LayoutProperty::UpdateCalcMinSize(value);
50         if (!originalConstraint_) {
51             originalConstraint_ = std::make_unique<MeasureProperty>();
52         }
53         originalConstraint_->UpdateMinSizeWithCheck(value);
54     }
55 
UpdateCalcMaxSize(const CalcSize & value)56     void UpdateCalcMaxSize(const CalcSize& value) override
57     {
58         LayoutProperty::UpdateCalcMaxSize(value);
59         if (!originalConstraint_) {
60             originalConstraint_ = std::make_unique<MeasureProperty>();
61         }
62         originalConstraint_->UpdateMaxSizeWithCheck(value);
63     }
64 
UpdateItemCalcMinSize(const CalcSize & value)65     void UpdateItemCalcMinSize(const CalcSize& value)
66     {
67         LayoutProperty::UpdateCalcMinSize(value);
68     }
69 
UpdateItemCalcMaxSize(const CalcSize & value)70     void UpdateItemCalcMaxSize(const CalcSize& value)
71     {
72         LayoutProperty::UpdateCalcMaxSize(value);
73     }
74 
GetMinSize()75     std::optional<CalcSize> GetMinSize() const
76     {
77         if (originalConstraint_) {
78             return originalConstraint_->minSize;
79         }
80         return std::optional<CalcSize>();
81     }
82 
GetMaxSize()83     std::optional<CalcSize> GetMaxSize() const
84     {
85         if (originalConstraint_) {
86             return originalConstraint_->maxSize;
87         }
88         return std::optional<CalcSize>();
89     }
90 
HasLayoutConstraint()91     bool HasLayoutConstraint() const
92     {
93         return originalConstraint_ != nullptr;
94     }
95 
96 private:
97     ACE_DISALLOW_COPY_AND_MOVE(WaterFlowItemLayoutProperty);
98     std::unique_ptr<MeasureProperty> originalConstraint_;
99 };
100 } // namespace OHOS::Ace::NG
101 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WATERFLOW_WATER_FLOW_ITEM_LAYOUT_PROPERTY_H
102