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