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 void UpdateVerticalOffset(OffsetF& offsetIcon, OffsetF& offsetText); 45 void InitPadding(RefPtr<SecurityComponentLayoutProperty>& property); 46 double ShrinkWidth(double diff); 47 double EnlargeWidth(double diff); 48 double ShrinkHeight(double diff); 49 double EnlargeHeight(double diff); 50 void AdaptWidth(); 51 void AdaptHeight(); 52 void MeasureIntegralSize(); 53 void UpdateCircleButtonConstraint(); 54 void FillBlank(); 55 TextDirection GetTextDirection(LayoutWrapper* layoutWrapper); 56 RefPtr<FrameNode> GetSecCompChildNode(RefPtr<FrameNode>& parent, const std::string& tag); 57 bool IsTextAdaptOutOfRange(SizeF& leftPoint, SizeF& rightPoint, SizeF& circlePoint, float maxDistance); 58 void UpdateTextRectPoint(); 59 bool IsTextOutOfRangeInCircle(); 60 bool IsTextOutOfRangeInCapsule(); 61 bool IsOutOfRangeInHoriCapsule(SizeF& leftCirclePoint, SizeF& rightCirclePoint, float maxDistance); 62 bool IsOutOfRangeInVertiCapsule(SizeF& topCirclePoint, SizeF& bottomCirclePoint, float maxDistance); 63 bool IsTextOutOfRangeInNormal(); 64 bool GetTextLimitExceededFlag(RefPtr<SecurityComponentLayoutProperty>& property, LayoutWrapper* layoutWrapper); 65 bool CompareDistance(SizeF& point, SizeF& circlePoint, float maxDistance); 66 bool TopLeftCompDistance(float obtainedRadius, float maxRadius, float threshold); 67 bool TopRightCompDistance(float obtainedRadius, float maxRadius, float threshold); 68 bool BottomLeftCompDistance(float obtainedRadius, float maxRadius, float threshold); 69 bool BottomRightCompDistance(float obtainedRadius, float maxRadius, float threshold); 70 bool IsTextOutOfOneColumn(RefPtr<FrameNode>& frameNode, float threshold); 71 72 void UpdateTextSize(); 73 pow(float value)74 float pow(float value) 75 { 76 return value * value; 77 } 78 79 double componentWidth_ = 0.0; 80 double componentHeight_ = 0.0; 81 IconLayoutElement icon_; 82 TextLayoutElement text_; 83 PaddingLayoutElement left_; 84 PaddingLayoutElement top_; 85 PaddingLayoutElement right_; 86 PaddingLayoutElement bottom_; 87 PaddingLayoutElement middle_; 88 SizeF textLeftTopPoint_; 89 SizeF textRightTopPoint_; 90 SizeF textLeftBottomPoint_; 91 SizeF textRightBottomPoint_; 92 Dimension currentFontSize_; 93 94 double idealWidth_ = 0.0; 95 double idealHeight_ = 0.0; 96 double minWidth_ = 0.0; 97 double minHeight_ = 0.0; 98 double maxWidth_ = 1000000.0; // Infinity 99 double maxHeight_ = 1000000.0; // Infinity 100 101 std::optional<LayoutConstraintF> constraint_; 102 bool isNeedReadaptWidth_ = false; 103 bool isVertical_ = false; 104 bool isNobg_ = false; 105 ACE_DISALLOW_COPY_AND_MOVE(SecurityComponentLayoutAlgorithm); 106 RefPtr<ButtonLayoutProperty> buttonLayoutProperty_; 107 }; 108 } // namespace OHOS::Ace::NG 109 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_LAYOUT_ALGORITHM_H 110