• 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     bool GetTextLimitExceededFlag(RefPtr<SecurityComponentLayoutProperty>& property, LayoutWrapper* layoutWrapper);
66     bool CompareDistance(SizeF& point, SizeF& circlePoint, float maxDistance);
67     bool TopLeftCompDistance(float obtainedRadius, float maxRadius, float threshold);
68     bool TopRightCompDistance(float obtainedRadius, float maxRadius, float threshold);
69     bool BottomLeftCompDistance(float obtainedRadius, float maxRadius, float threshold);
70     bool BottomRightCompDistance(float obtainedRadius, float maxRadius, float threshold);
71     bool IsTextOutOfOneColumn(RefPtr<FrameNode>& frameNode, float threshold);
72     Alignment ParseAlignmentRTL(LayoutWrapper* layoutWrapper, Alignment align);
73 
74     void UpdateTextSize();
75 
pow(float value)76     float pow(float value)
77     {
78         return value * value;
79     }
80 
81     double componentWidth_ = 0.0;
82     double componentHeight_ = 0.0;
83     IconLayoutElement icon_;
84     TextLayoutElement text_;
85     PaddingLayoutElement left_;
86     PaddingLayoutElement top_;
87     PaddingLayoutElement right_;
88     PaddingLayoutElement bottom_;
89     PaddingLayoutElement middle_;
90     SizeF textLeftTopPoint_;
91     SizeF textRightTopPoint_;
92     SizeF textLeftBottomPoint_;
93     SizeF textRightBottomPoint_;
94     Dimension currentFontSize_;
95 
96     double idealWidth_ = 0.0;
97     double idealHeight_ = 0.0;
98     double minWidth_ = 0.0;
99     double minHeight_ = 0.0;
100     double maxWidth_ = 1000000.0; // Infinity
101     double maxHeight_ = 1000000.0; // Infinity
102 
103     std::optional<LayoutConstraintF> constraint_;
104     bool isNeedReadaptWidth_ = false;
105     bool isVertical_ = false;
106     bool isNobg_ = false;
107     ACE_DISALLOW_COPY_AND_MOVE(SecurityComponentLayoutAlgorithm);
108     RefPtr<ButtonLayoutProperty> buttonLayoutProperty_;
109 };
110 } // namespace OHOS::Ace::NG
111 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_LAYOUT_ALGORITHM_H
112