• 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/button/button_layout_property.h"
21 #include "core/components_ng/pattern/security_component/security_component_common.h"
22 #include "core/components_ng/pattern/security_component/security_component_layout_element.h"
23 #include "core/components_ng/pattern/security_component/security_component_layout_property.h"
24 #include "core/components_ng/pattern/security_component/security_component_theme.h"
25 
26 namespace OHOS::Ace::NG {
27 class ACE_EXPORT SecurityComponentLayoutAlgorithm : public BoxLayoutAlgorithm {
28     DECLARE_ACE_TYPE(SecurityComponentLayoutAlgorithm, BoxLayoutAlgorithm);
29 
30 public:
31     SecurityComponentLayoutAlgorithm() = default;
32     ~SecurityComponentLayoutAlgorithm() override = default;
33 
34     void Measure(LayoutWrapper* layoutWrapper) override;
35     void Layout(LayoutWrapper* layoutWrapper) override;
36 
37 private:
38     RefPtr<LayoutWrapper> GetChildWrapper(LayoutWrapper* layoutWrapper, const std::string& tag);
39     void UpdateChildPosition(LayoutWrapper* layoutWrapper, const std::string& tag,
40         OffsetF& offset);
41     void MeasureButton(LayoutWrapper* layoutWrapper,
42         RefPtr<SecurityComponentLayoutProperty>& securityComponentProperty);
43     void UpdateHorizontalOffset(LayoutWrapper* layoutWrapper, OffsetF& offsetIcon, OffsetF& offsetText,
44         SizeF& childSize);
45     void UpdateVerticalOffset(OffsetF& offsetIcon, OffsetF& offsetText, SizeF& childSize);
46     void InitPadding(RefPtr<SecurityComponentLayoutProperty>& property);
47     double ShrinkWidth(double diff);
48     double EnlargeWidth(double diff);
49     double ShrinkHeight(double diff);
50     double EnlargeHeight(double diff);
51     void AdaptWidth();
52     void AdaptHeight();
53     void MeasureIntegralSize();
54     void UpdateCircleButtonConstraint();
55     void FillBlank();
56     TextDirection GetTextDirection(LayoutWrapper* layoutWrapper);
57     RefPtr<FrameNode> GetSecCompChildNode(RefPtr<FrameNode>& parent, const std::string& tag);
58     bool IsTextAdaptOutOfRange(SizeF& leftPoint, SizeF& rightPoint, SizeF& circlePoint, float maxDistance);
59     void UpdateTextRectPoint();
60     bool IsTextOutOfRangeInCircle();
61     bool IsTextOutOfRangeInCapsule();
62     bool IsOutOfRangeInHoriCapsule(SizeF& leftCirclePoint, SizeF& rightCirclePoint, float maxDistance);
63     bool IsOutOfRangeInVertiCapsule(SizeF& topCirclePoint, SizeF& bottomCirclePoint, float maxDistance);
64     bool IsTextOutOfRangeInNormal();
65     void UpdateTextFlags(LayoutWrapper* layoutWrapper);
66     bool GetMaxLineLimitExceededFlag(std::optional<SizeF>& currentTextSize);
67     bool GetTextLimitExceededFlag(RefPtr<SecurityComponentLayoutProperty>& property, RefPtr<FrameNode>& frameNode,
68         std::optional<SizeF>& currentTextSize);
69     bool GetIconExceededFlag(RefPtr<SecurityComponentLayoutProperty>& property, RefPtr<FrameNode>& frameNode);
70     bool IsIconOutOfRange(SizeF& iconPoint, SizeF& point, double maxDistance);
71     bool IsIconOutOfBackground(const NG::BorderRadiusProperty& radius);
72     bool CompareDistance(SizeF& point, SizeF& circlePoint, float maxDistance);
73     bool TopLeftCompDistance(float obtainedRadius, float maxRadius, float threshold);
74     bool TopRightCompDistance(float obtainedRadius, float maxRadius, float threshold);
75     bool BottomLeftCompDistance(float obtainedRadius, float maxRadius, float threshold);
76     bool BottomRightCompDistance(float obtainedRadius, float maxRadius, float threshold);
77     bool IsTextOutOfOneColumn(RefPtr<FrameNode>& frameNode, float threshold);
78     Alignment ParseAlignmentRTL(LayoutWrapper* layoutWrapper, Alignment align);
79     void InitLayoutWrapper(LayoutWrapper* layoutWrapper,
80         const RefPtr<SecurityComponentLayoutProperty>& securityComponentLayoutProperty);
81 
82     void UpdateTextSize();
83 
pow(float value)84     float pow(float value)
85     {
86         return value * value;
87     }
88 
89     double componentWidth_ = 0.0;
90     double componentHeight_ = 0.0;
91     IconLayoutElement icon_;
92     TextLayoutElement text_;
93     PaddingLayoutElement left_;
94     PaddingLayoutElement top_;
95     PaddingLayoutElement right_;
96     PaddingLayoutElement bottom_;
97     PaddingLayoutElement middle_;
98     SizeF textLeftTopPoint_;
99     SizeF textRightTopPoint_;
100     SizeF textLeftBottomPoint_;
101     SizeF textRightBottomPoint_;
102     Dimension currentFontSize_;
103 
104     double idealWidth_ = 0.0;
105     double idealHeight_ = 0.0;
106     double minWidth_ = 0.0;
107     double minHeight_ = 0.0;
108     double maxWidth_ = 1000000.0; // Infinity
109     double maxHeight_ = 1000000.0; // Infinity
110 
111     std::optional<LayoutConstraintF> constraint_;
112     bool isNeedReadaptWidth_ = false;
113     bool isVertical_ = false;
114     bool isNobg_ = false;
115     ACE_DISALLOW_COPY_AND_MOVE(SecurityComponentLayoutAlgorithm);
116     RefPtr<ButtonLayoutProperty> buttonLayoutProperty_;
117 };
118 } // namespace OHOS::Ace::NG
119 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_LAYOUT_ALGORITHM_H
120