1 /* 2 * Copyright (c) 2021 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_BOX_BOX_COMPONENT_HELPER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BOX_BOX_COMPONENT_HELPER_H 18 19 #include "core/components/common/properties/color.h" 20 #include "core/components/common/properties/decoration.h" 21 22 // Helper class for updating of the attributes for Box Component 23 // Used by RenderBox and by JSViewAbstract 24 25 namespace OHOS::Ace { 26 class BoxComponentHelper { 27 public: 28 static void SetBorderColor( 29 const RefPtr<Decoration> decoration, const Color& color, 30 const AnimationOption& option = AnimationOption()) 31 { 32 if (!decoration) { 33 return; 34 } 35 Border border = decoration->GetBorder(); 36 BorderEdge edge; 37 edge = border.Left(); 38 edge.SetColor(color, option); 39 40 border.SetLeftEdge(edge); 41 border.SetRightEdge(edge); 42 border.SetTopEdge(edge); 43 border.SetBottomEdge(edge); 44 decoration->SetBorder(border); 45 } 46 GetBorderColor(const RefPtr<Decoration> decoration)47 static Color GetBorderColor(const RefPtr<Decoration> decoration) 48 { 49 if (decoration == nullptr) { 50 return Color(); 51 } 52 return decoration->GetBorder().Left().GetColor(); 53 } 54 55 static void SetBorderRadius(const RefPtr<Decoration> decoration, const Dimension& radius, 56 const AnimationOption& option = AnimationOption()) 57 { 58 if (!decoration) { 59 return; 60 } 61 Border border = decoration->GetBorder(); 62 border.SetBorderRadius(Radius(AnimatableDimension(radius, option))); 63 decoration->SetBorder(border); 64 } 65 GetBorderRadius(const RefPtr<Decoration> decoration)66 static Radius GetBorderRadius(const RefPtr<Decoration> decoration) 67 { 68 if (decoration == nullptr) { 69 return Radius(0.0); 70 } 71 Border border = decoration->GetBorder(); 72 if (!border.HasRadius()) { 73 return Radius(0.0); 74 } 75 return border.TopLeftRadius(); 76 } 77 SetBorderStyle(const RefPtr<Decoration> decoration,const BorderStyle & style)78 static void SetBorderStyle(const RefPtr<Decoration> decoration, const BorderStyle& style) 79 { 80 if (!decoration) { 81 return; 82 } 83 Border border = decoration->GetBorder(); 84 auto edge = border.Left(); 85 86 edge.SetStyle(style); 87 border.SetLeftEdge(edge); 88 border.SetRightEdge(edge); 89 border.SetTopEdge(edge); 90 border.SetBottomEdge(edge); 91 92 decoration->SetBorder(border); 93 } 94 GetBorderStyle(const RefPtr<Decoration> decoration)95 static BorderStyle GetBorderStyle(const RefPtr<Decoration> decoration) 96 { 97 if (decoration == nullptr) { 98 return BorderStyle::NONE; 99 } 100 Border border = decoration->GetBorder(); 101 return border.Left().GetBorderStyle(); 102 } 103 104 static void SetBorderWidth( 105 const RefPtr<Decoration> decoration, const Dimension& width, 106 const AnimationOption& option = AnimationOption()) 107 { 108 if (!decoration) { 109 return; 110 } 111 Border border = decoration->GetBorder(); 112 border.SetWidth(width, option); 113 decoration->SetBorder(border); 114 } 115 GetBorderWidth(const RefPtr<Decoration> decoration)116 static Dimension GetBorderWidth(const RefPtr<Decoration> decoration) 117 { 118 if (decoration == nullptr) { 119 return Dimension(0); 120 } 121 return decoration->GetBorder().Left().GetWidth(); 122 } 123 }; 124 125 } // namespace OHOS::Ace 126 127 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BOX_BOX_COMPONENT_HELPER_H 128