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 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SECURITY_COMPONENT_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SECURITY_COMPONENT_THEME_H 18 19 #include "base/geometry/dimension.h" 20 #include "base/log/ace_scoring_log.h" 21 #include "base/memory/ace_type.h" 22 #include "base/memory/referenced.h" 23 #include "core/components/common/properties/color.h" 24 #include "core/components/theme/theme.h" 25 #include "core/components/theme/theme_attributes.h" 26 #include "core/components/theme/theme_constants.h" 27 #include "core/components/theme/theme_style.h" 28 #include "core/components_ng/pattern/security_component/security_component_log.h" 29 30 namespace OHOS::Ace::NG { 31 class SecurityComponentTheme : public virtual Theme { 32 DECLARE_ACE_TYPE(SecurityComponentTheme, Theme); 33 34 public: 35 ~SecurityComponentTheme() = default; 36 37 class Builder { 38 public: 39 Builder() = default; 40 ~Builder() = default; Build(const RefPtr<ThemeConstants> & themeConstants)41 RefPtr<SecurityComponentTheme> Build(const RefPtr<ThemeConstants>& themeConstants) 42 { 43 RefPtr<SecurityComponentTheme> theme = AceType::Claim(new SecurityComponentTheme()); 44 if (!themeConstants) { 45 SC_LOG_ERROR("Build SecurityComponentTheme error, themeConstants is null!"); 46 return theme; 47 } 48 ParsePattern(themeConstants, theme); 49 return theme; 50 } 51 }; 52 GetIconSize()53 const Dimension& GetIconSize() const 54 { 55 return iconSize_; 56 } 57 GetFontSize()58 const Dimension& GetFontSize() const 59 { 60 return fontSize_; 61 } 62 GetMinIconSize()63 const Dimension& GetMinIconSize() const 64 { 65 return minIconSize_; 66 } 67 GetMinFontSize()68 const Dimension& GetMinFontSize() const 69 { 70 return minFontSize_; 71 } 72 GetBackgroundTopPadding()73 const Dimension& GetBackgroundTopPadding() const 74 { 75 return backgroundTopPadding_; 76 } 77 GetBackgroundRightPadding()78 const Dimension& GetBackgroundRightPadding() const 79 { 80 return backgroundRightPadding_; 81 } 82 GetBackgroundBottomPadding()83 const Dimension& GetBackgroundBottomPadding() const 84 { 85 return backgroundBottomPadding_; 86 } 87 GetBackgroundLeftPadding()88 const Dimension& GetBackgroundLeftPadding() const 89 { 90 return backgroundLeftPadding_; 91 } 92 GetTextIconSpace()93 const Dimension& GetTextIconSpace() const 94 { 95 return textIconSpace_; 96 } 97 GetPaddingWithoutBg()98 const Dimension& GetPaddingWithoutBg() const 99 { 100 return paddingWithoutBg_; 101 } 102 GetBorderRadius()103 const Dimension& GetBorderRadius() const 104 { 105 return borderRadius_; 106 } 107 GetBorderWidth()108 const Dimension& GetBorderWidth() const 109 { 110 return borderWidth_; 111 } 112 GetIconColor()113 const Color& GetIconColor() const 114 { 115 return iconColor_; 116 } 117 GetFontColor()118 const Color& GetFontColor() const 119 { 120 return fontColor_; 121 } 122 GetIconColorNoBg()123 const Color& GetIconColorNoBg() const 124 { 125 return iconColorNoBg_; 126 } 127 GetFontColorNoBg()128 const Color& GetFontColorNoBg() const 129 { 130 return fontColorNoBg_; 131 } 132 GetBackgroundColor()133 const Color& GetBackgroundColor() const 134 { 135 return backgroundColor_; 136 } 137 GetBorderColor()138 const Color& GetBorderColor() const 139 { 140 return borderColor_; 141 } 142 GetLocationDescriptions(int32_t index)143 const std::string& GetLocationDescriptions(int32_t index) 144 { 145 if (index < 0 || index >= static_cast<int32_t>(locationDescriptions_.size())) { 146 return emptyString_; 147 } 148 return locationDescriptions_[index]; 149 } 150 GetPasteDescriptions(int32_t index)151 const std::string& GetPasteDescriptions(int32_t index) 152 { 153 if (index < 0 || index >= static_cast<int32_t>(pasteDescriptions_.size())) { 154 return emptyString_; 155 } 156 return pasteDescriptions_[index]; 157 } 158 GetSaveDescriptions(int32_t index)159 const std::string& GetSaveDescriptions(int32_t index) 160 { 161 if (index < 0 || index >= static_cast<int32_t>(saveDescriptions_.size())) { 162 return emptyString_; 163 } 164 return saveDescriptions_[index]; 165 } 166 GetDefaultTextMaxLines()167 uint32_t GetDefaultTextMaxLines() const 168 { 169 return defaultTextMaxLines_; 170 } 171 172 private: 173 SecurityComponentTheme() = default; ParseLocationDescriptions(RefPtr<ThemeStyle> securityComponentPattern,const RefPtr<SecurityComponentTheme> & theme)174 static void ParseLocationDescriptions(RefPtr<ThemeStyle> securityComponentPattern, 175 const RefPtr<SecurityComponentTheme>& theme) 176 { 177 theme->locationDescriptions_.emplace_back( 178 securityComponentPattern->GetAttr<std::string>("description_current_location", "")); 179 theme->locationDescriptions_.emplace_back( 180 securityComponentPattern->GetAttr<std::string>("description_add_location", "")); 181 theme->locationDescriptions_.emplace_back( 182 securityComponentPattern->GetAttr<std::string>("description_select_location", "")); 183 theme->locationDescriptions_.emplace_back( 184 securityComponentPattern->GetAttr<std::string>("description_share_location", "")); 185 theme->locationDescriptions_.emplace_back( 186 securityComponentPattern->GetAttr<std::string>("description_send_location", "")); 187 theme->locationDescriptions_.emplace_back( 188 securityComponentPattern->GetAttr<std::string>("description_locating", "")); 189 theme->locationDescriptions_.emplace_back( 190 securityComponentPattern->GetAttr<std::string>("description_location", "")); 191 theme->locationDescriptions_.emplace_back( 192 securityComponentPattern->GetAttr<std::string>("description_send_current_location", "")); 193 theme->locationDescriptions_.emplace_back( 194 securityComponentPattern->GetAttr<std::string>("description_relocation", "")); 195 theme->locationDescriptions_.emplace_back( 196 securityComponentPattern->GetAttr<std::string>("description_punch_in", "")); 197 theme->locationDescriptions_.emplace_back( 198 securityComponentPattern->GetAttr<std::string>("description_current_position", "")); 199 } 200 ParsePasteDescriptions(RefPtr<ThemeStyle> securityComponentPattern,const RefPtr<SecurityComponentTheme> & theme)201 static void ParsePasteDescriptions(RefPtr<ThemeStyle> securityComponentPattern, 202 const RefPtr<SecurityComponentTheme>& theme) 203 { 204 theme->pasteDescriptions_.emplace_back( 205 securityComponentPattern->GetAttr<std::string>("description_paste", "")); 206 } 207 ParseSaveDescriptions(RefPtr<ThemeStyle> securityComponentPattern,const RefPtr<SecurityComponentTheme> & theme)208 static void ParseSaveDescriptions(RefPtr<ThemeStyle> securityComponentPattern, 209 const RefPtr<SecurityComponentTheme>& theme) 210 { 211 theme->saveDescriptions_.emplace_back( 212 securityComponentPattern->GetAttr<std::string>("description_download", "")); 213 theme->saveDescriptions_.emplace_back( 214 securityComponentPattern->GetAttr<std::string>("description_download_file", "")); 215 theme->saveDescriptions_.emplace_back( 216 securityComponentPattern->GetAttr<std::string>("description_save", "")); 217 theme->saveDescriptions_.emplace_back( 218 securityComponentPattern->GetAttr<std::string>("description_save_image", "")); 219 theme->saveDescriptions_.emplace_back( 220 securityComponentPattern->GetAttr<std::string>("description_save_file", "")); 221 theme->saveDescriptions_.emplace_back( 222 securityComponentPattern->GetAttr<std::string>("description_download_and_share", "")); 223 theme->saveDescriptions_.emplace_back( 224 securityComponentPattern->GetAttr<std::string>("description_receive", "")); 225 theme->saveDescriptions_.emplace_back( 226 securityComponentPattern->GetAttr<std::string>("description_continue_to_receive", "")); 227 theme->saveDescriptions_.emplace_back( 228 securityComponentPattern->GetAttr<std::string>("description_save_to_gallery", "")); 229 theme->saveDescriptions_.emplace_back( 230 securityComponentPattern->GetAttr<std::string>("description_export_to_gallery", "")); 231 theme->saveDescriptions_.emplace_back( 232 securityComponentPattern->GetAttr<std::string>("description_quick_save_to_gallery", "")); 233 theme->saveDescriptions_.emplace_back( 234 securityComponentPattern->GetAttr<std::string>("description_quick_resave_to_gallery", "")); 235 } 236 ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<SecurityComponentTheme> & theme)237 static void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<SecurityComponentTheme>& theme) 238 { 239 RefPtr<ThemeStyle> securityComponentPattern = 240 themeConstants->GetPatternByName(THEME_PATTERN_SECURITY_COMPONENT); 241 if (!securityComponentPattern) { 242 return; 243 } 244 theme->iconSize_ = securityComponentPattern->GetAttr<Dimension>("icon_size", 0.0_vp); 245 theme->fontSize_ = securityComponentPattern->GetAttr<Dimension>("font_size", 0.0_vp); 246 theme->minIconSize_ = securityComponentPattern->GetAttr<Dimension>("min_icon_size", 0.0_vp); 247 theme->minFontSize_ = securityComponentPattern->GetAttr<Dimension>("min_font_size", 0.0_vp); 248 theme->backgroundTopPadding_ = 249 securityComponentPattern->GetAttr<Dimension>("background_top_padding", 0.0_vp); 250 theme->backgroundRightPadding_ = 251 securityComponentPattern->GetAttr<Dimension>("background_right_padding", 0.0_vp); 252 theme->backgroundBottomPadding_ = 253 securityComponentPattern->GetAttr<Dimension>("background_bottom_padding", 0.0_vp); 254 theme->backgroundLeftPadding_ = 255 securityComponentPattern->GetAttr<Dimension>("background_left_padding", 0.0_vp); 256 theme->textIconSpace_ = securityComponentPattern->GetAttr<Dimension>("text_icon_padding", 0.0_vp); 257 theme->paddingWithoutBg_ = securityComponentPattern->GetAttr<Dimension>("padding_without_background", 0.0_vp); 258 theme->borderRadius_ = securityComponentPattern->GetAttr<Dimension>("border_radius", 0.0_vp); 259 theme->borderWidth_ = securityComponentPattern->GetAttr<Dimension>("border_width", 0.0_vp); 260 theme->iconColor_ = securityComponentPattern->GetAttr<Color>("icon_color", Color()); 261 theme->fontColor_ = securityComponentPattern->GetAttr<Color>("font_color", Color()); 262 theme->iconColorNoBg_ = securityComponentPattern->GetAttr<Color>("icon_color_no_bg", Color()); 263 theme->fontColorNoBg_ = securityComponentPattern->GetAttr<Color>("font_color_no_bg", Color()); 264 theme->backgroundColor_ = securityComponentPattern->GetAttr<Color>("background_color", Color()); 265 theme->borderColor_ = securityComponentPattern->GetAttr<Color>("border_color", Color()); 266 ParseLocationDescriptions(securityComponentPattern, theme); 267 ParsePasteDescriptions(securityComponentPattern, theme); 268 ParseSaveDescriptions(securityComponentPattern, theme); 269 } 270 271 Dimension iconSize_; 272 Dimension fontSize_; 273 Dimension minIconSize_; 274 Dimension minFontSize_; 275 Dimension backgroundTopPadding_; 276 Dimension backgroundRightPadding_; 277 Dimension backgroundBottomPadding_; 278 Dimension backgroundLeftPadding_; 279 Dimension textIconSpace_; 280 Dimension borderRadius_; 281 Dimension borderWidth_; 282 Dimension paddingWithoutBg_; 283 284 Color iconColor_; 285 Color fontColor_; 286 Color iconColorNoBg_; 287 Color fontColorNoBg_; 288 Color backgroundColor_; 289 Color borderColor_; 290 291 uint32_t defaultTextMaxLines_ = 1000000; // Infinity 292 293 std::vector<std::string> locationDescriptions_; 294 std::vector<std::string> pasteDescriptions_; 295 std::vector<std::string> saveDescriptions_; 296 std::string emptyString_; 297 }; 298 } // namespace OHOS::Ace::NG 299 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_APP_BAR_THEME_H 300