• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_LAYOUT_ALGORITHM_H
16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_LAYOUT_ALGORITHM_H
17 
18 #include "base/geometry/ng/offset_t.h"
19 #include "core/components_ng/layout/box_layout_algorithm.h"
20 #include "core/components_ng/pattern/security_component/security_component_common.h"
21 #include "core/components_ng/pattern/security_component/security_component_layout_element.h"
22 #include "core/components_ng/pattern/security_component/security_component_layout_property.h"
23 #include "core/components_ng/pattern/security_component/security_component_theme.h"
24 
25 namespace OHOS::Ace::NG {
26 class ACE_EXPORT SecurityComponentLayoutAlgorithm : public BoxLayoutAlgorithm {
27     DECLARE_ACE_TYPE(SecurityComponentLayoutAlgorithm, BoxLayoutAlgorithm);
28 
29 public:
30     SecurityComponentLayoutAlgorithm() = default;
31     ~SecurityComponentLayoutAlgorithm() override = default;
32 
33     void Measure(LayoutWrapper* layoutWrapper) override;
34     void Layout(LayoutWrapper* layoutWrapper) override;
35 
36 private:
37     RefPtr<LayoutWrapper> GetChildWrapper(LayoutWrapper* layoutWrapper, const std::string& tag);
38     void UpdateChildPosition(LayoutWrapper* layoutWrapper, const std::string& tag,
39         OffsetF& offset);
40     void MeasureButton(LayoutWrapper* layoutWrapper,
41         RefPtr<SecurityComponentLayoutProperty>& securityComponentProperty);
42     void UpdateHorizontalOffset(OffsetF& offsetIcon, OffsetF& offsetText);
43     void UpdateVerticalOffset(OffsetF& offsetIcon, OffsetF& offsetText);
44     void InitPadding(RefPtr<SecurityComponentLayoutProperty>& property);
45     double ShrinkWidth(double diff);
46     double EnlargeWidth(double diff);
47     double ShrinkHeight(double diff);
48     double EnlargeHeight(double diff);
49     void AdaptWidth();
50     void AdaptHeight();
51     void MeasureIntegralSize();
52     void UpdateCircleButtonConstraint();
53     void FillBlank();
54 
55     double componentWidth_ = 0.0;
56     double componentHeight_ = 0.0;
57     IconLayoutElement icon_;
58     TextLayoutElement text_;
59     PaddingLayoutElement left_;
60     PaddingLayoutElement top_;
61     PaddingLayoutElement right_;
62     PaddingLayoutElement bottom_;
63     PaddingLayoutElement middle_;
64 
65     double idealWidth_ = 0.0;
66     double idealHeight_ = 0.0;
67     double minWidth_ = 0.0;
68     double minHeight_ = 0.0;
69     double maxWidth_ = 1000000.0; // Infinity
70     double maxHeight_ = 1000000.0; // Infinity
71 
72     std::optional<LayoutConstraintF> constraint_;
73     bool isNeedReadaptWidth_ = false;
74     bool isVertical_ = false;
75     bool isNobg_ = false;
76     ACE_DISALLOW_COPY_AND_MOVE(SecurityComponentLayoutAlgorithm);
77 };
78 } // namespace OHOS::Ace::NG
79 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_LAYOUT_ALGORITHM_H
80