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