• 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_SHEET_SHEET_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SHEET_SHEET_THEME_H
18 
19 #include "core/components/common/properties/color.h"
20 #include "core/components/theme/theme.h"
21 #include "core/components/theme/theme_constants.h"
22 
23 namespace OHOS::Ace::NG {
24 namespace {
25 constexpr Dimension SHEET_BLANK_MINI_HEIGHT = 8.0_vp;
26 constexpr Dimension SHEET_HOVERMODE_UP_HEIGHT = 40.0_vp;
27 constexpr Dimension SHEET_HOVERMODE_DOWN_HEIGHT = 28.0_vp;
28 constexpr Dimension SHEET_BLANK_FLOATING_STATUS_BAR = 32.0_vp;
29 constexpr Dimension SHEET_SPLIT_AI_BAR = 24.0_vp;
30 constexpr Dimension SHEET_SPLIT_STATUS_BAR = 24.0_vp;
31 constexpr Dimension SHEET_OPERATION_AREA_PADDING = 8.0_vp;
32 constexpr Dimension SHEET_OPERATION_AREA_HEIGHT = 56.0_vp;
33 constexpr Dimension SHEET_OPERATION_AREA_HEIGHT_DOUBLE = 72.0_vp;
34 constexpr Dimension SHEET_CLOSE_ICON_WIDTH = 40.0_vp;
35 constexpr Dimension SHEET_CLOSE_ICON_HEIGHT = 40.0_vp;
36 constexpr Dimension SHEET_CLOSE_ICON_IMAGE_HEIGHT = 18.0_vp;
37 constexpr Dimension SHEET_CLOSE_ICON_IMAGE_WIDTH = 18.0_vp;
38 constexpr Dimension SHEET_CLOSE_ICON_TITLE_SPACE = 32.0_vp;
39 constexpr Dimension SHEET_CLOSE_ICON_TITLE_SPACE_NEW = 8.0_vp;
40 constexpr Dimension SHEET_CLOSE_ICON_RADIUS = 20.0_vp;
41 constexpr Dimension SHEET_DRAG_BAR_WIDTH = 64.0_vp;
42 constexpr Dimension SHEET_DRAG_BAR_HEIGHT = 16.0_vp;
43 constexpr Dimension SHEET_LANDSCAPE_WIDTH = 480.0_vp;
44 constexpr Dimension SHEET_POPUP_WIDTH = 360.0_vp;
45 constexpr Dimension SHEET_BIG_WINDOW_WIDTH = 480.0_vp;
46 constexpr Dimension SHEET_BIG_WINDOW_HEIGHT = 560.0_vp;
47 constexpr Dimension SHEET_BIG_WINDOW_MIN_HEIGHT = 320.0_vp;
48 constexpr Dimension SHEET_ARROW_WIDTH = 16.0_vp;
49 constexpr Dimension SHEET_ARROW_HEIGHT = 8.0_vp;
50 constexpr Dimension SHEET_TARGET_SPACE = 8.0_vp;
51 constexpr Dimension SHEET_DEVICE_WIDTH_BREAKPOINT = 600.0_vp;
52 constexpr Dimension SHEET_PC_DEVICE_WIDTH_BREAKPOINT = 840.0_vp;
53 constexpr Dimension SHEET_DOUBLE_TITLE_TOP_PADDING = 16.0_vp;
54 constexpr Dimension SHEET_DOUBLE_TITLE_BOTTON_MARGIN = 4.0_vp;
55 constexpr Dimension SHEET_TITLE_AREA_MARGIN = -8.0_vp;
56 constexpr int32_t SHEET_TITLE_MAX_LINES = 1;
57 constexpr int32_t SHEET_SHADOW_NONE = 6;
58 constexpr Dimension SHEET_TITLE_TEXT_HORIZONTAL_MARGIN = 16.0_vp;
59 constexpr double SHEET_TITLE_FONT_WEIGHT = 9.0;
60 // button style : NORMAL(0) EMPHASIZE(1)
61 constexpr int SHEET_CLOSE_ICON_BUTTON_STYLE = 1;
62 // sheet height mode : LARGE(1) AUTO(2)
63 constexpr int SHEET_HEIGHT_DEFAULT_MODE = 1;
64 } // namespace
65 class SheetTheme : public virtual Theme {
66     DECLARE_ACE_TYPE(SheetTheme, Theme);
67 
68 public:
69     class Builder {
70     public:
71         Builder() = default;
72         ~Builder() = default;
73 
Build(const RefPtr<ThemeConstants> & themeConstants)74         RefPtr<SheetTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
75         {
76             RefPtr<SheetTheme> theme = AceType::MakeRefPtr<SheetTheme>();
77             if (!themeConstants) {
78                 return theme;
79             }
80 
81             ParsePattern(themeConstants, theme);
82             return theme;
83         }
84 
85     private:
ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<SheetTheme> & theme)86         void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<SheetTheme>& theme) const
87         {
88             RefPtr<ThemeStyle> sheetPattern = themeConstants->GetPatternByName(THEME_PATTERN_SHEET);
89             if (!sheetPattern) {
90                 TAG_LOGE(AceLogTag::ACE_SHEET, "sheetPattern is null");
91                 return;
92             }
93 
94             theme->sheetRadius_ = sheetPattern->GetAttr<Dimension>("sheet_radius", 32.0_vp);
95             theme->sheetSideRadius_ = sheetPattern->GetAttr<Dimension>("corner_radius_none", 0.0_vp);
96             theme->titleTextFontSize_ = sheetPattern->GetAttr<Dimension>("title_text_font_size", 20.0_vp);
97             theme->titleTextMargin_ = sheetPattern->GetAttr<Dimension>("title_text_margin", 16.0_vp);
98             theme->subtitleTextFontSize_ = sheetPattern->GetAttr<Dimension>("subtitle_text_font_size", 14.0_fp);
99             theme->subtitleTextMargin_ = sheetPattern->GetAttr<Dimension>("subtitle_text_margin", 2.0_fp);
100             theme->titleTextFontColor_ = sheetPattern->GetAttr<Color>("title_text_font_color", Color(0xff182431));
101             theme->subtitleTextFontColor_ = sheetPattern->GetAttr<Color>("subtitle_text_font_color", Color(0x99182431));
102             theme->sheetBackgoundColor_ = sheetPattern->GetAttr<Color>("sheet_background_color", Color(0xfff1f3f5));
103             theme->dragBarColor_ = sheetPattern->GetAttr<Color>("drag_bar_color", Color(0x33182431));
104             theme->sheetType_ = sheetPattern->GetAttr<std::string>("sheet_type", "auto");
105             theme->sheetBottom_ = sheetPattern->GetAttr<std::string>("sheet_bottom", "auto");
106             theme->maskColor_ = sheetPattern->GetAttr<Color>("mask_color", Color(0x33182431));
107             theme->closeIconColor_ = sheetPattern->GetAttr<Color>("close_icon_color", Color(0x0c182431));
108             theme->closeIconImageColor_ = sheetPattern->GetAttr<Color>("close_icon_image_color", Color(0xff182431));
109             theme->sheetBackgroundBlurStyle_ = sheetPattern->GetAttr<int>("sheet_background_blur_style", 0);
110             theme->sheetNormalScale_ = sheetPattern->GetAttr<double>("sheet_normal_aging_scale", 1.0f);
111             theme->sheetMaxAgingScale_ = sheetPattern->GetAttr<double>("sheet_max_aging_scale", 1.75f);
112             theme->closeIconSource_ = themeConstants->GetSymbolByName("sys.symbol.xmark");
113             theme->closeIconSymbolColor_ = sheetPattern->GetAttr<Color>("close_icon_symbol_color", Color(0xff182431));
114             theme->sheetShadowConfig_ = sheetPattern->GetAttr<int32_t>("sheet_shadow_config", SHEET_SHADOW_NONE);
115             theme->sheetShadowConfigS_ = sheetPattern->GetAttr<int32_t>("sheet_shadow_config_s", SHEET_SHADOW_NONE);
116             theme->sheetOuterBorderWidth_ = sheetPattern->GetAttr<Dimension>("sheet_outline_border_width", 0.0_vp);
117             // If the outline border width is valid, outline border, shadow and border are default enable.
118             theme->isOuterBorderEnable_ = theme->sheetOuterBorderWidth_.IsValid();
119             theme->sheetInnerBorderWidth_ = sheetPattern->GetAttr<Dimension>("sheet_inner_border_width", 0.0_vp);
120             theme->sheetOuterBorderColor_ =
121                 sheetPattern->GetAttr<Color>("sheet_outline_border_color", Color::TRANSPARENT);
122             theme->sheetInnerBorderColor_ =
123                 sheetPattern->GetAttr<Color>("sheet_inner_border_color", Color::TRANSPARENT);
124             theme->closeIconWidth_ =
125                 sheetPattern->GetAttr<Dimension>("close_icon_width", SHEET_CLOSE_ICON_IMAGE_HEIGHT);
126             theme->titleTextHorizMargin_ =
127                 sheetPattern->GetAttr<Dimension>("title_text_horizontal_margin", SHEET_TITLE_TEXT_HORIZONTAL_MARGIN);
128             theme->closeIconRadius_ = sheetPattern->GetAttr<Dimension>("close_icon_radius", SHEET_CLOSE_ICON_RADIUS);
129             ParseAdditionalStylePattern(sheetPattern, theme);
130         }
131 
ParseAdditionalStylePattern(const RefPtr<ThemeStyle> & sheetPattern,const RefPtr<SheetTheme> & theme)132         void ParseAdditionalStylePattern(
133             const RefPtr<ThemeStyle>& sheetPattern, const RefPtr<SheetTheme>& theme) const
134         {
135             theme->largePercent_ = sheetPattern->GetAttr<double>("sheet_height_percent_large", 1.0f);
136             theme->mediumPercent_ = sheetPattern->GetAttr<double>("sheet_height_percent_medium", 0.6f);
137             theme->operationAreaHeight_ = sheetPattern->GetAttr<Dimension>("sheet_operation_height", 56.0_vp);
138             theme->heightApplyFullScreen_ =
139                 static_cast<bool>(sheetPattern->GetAttr<int>("sheet_height_apply_full_screen", 0));
140             theme->showCloseIcon_ = static_cast<bool>(sheetPattern->GetAttr<int>("sheet_show_close_icon", 1));
141             theme->sheetTitleFontWeight_ = FontWeight(static_cast<int32_t>(
142                 sheetPattern->GetAttr<double>("sheet_title_font_weight", SHEET_TITLE_FONT_WEIGHT)));
143             theme->sheetDragBarHeight_ = sheetPattern->GetAttr<Dimension>("sheet_drag_bar_height",
144                 SHEET_DRAG_BAR_HEIGHT);
145             theme->titleTopPadding_ = sheetPattern->GetAttr<Dimension>("sheet_double_title_top_padding",
146                 SHEET_DOUBLE_TITLE_TOP_PADDING);
147             theme->sheetTitleAreaMargin_ = sheetPattern->GetAttr<Dimension>("sheet_title_area_margin",
148                 SHEET_TITLE_AREA_MARGIN);
149             theme->closeIconButtonWidth_ =
150                 sheetPattern->GetAttr<Dimension>("sheet_close_icon_button_width", SHEET_CLOSE_ICON_WIDTH);
151             theme->centerDefaultWidth_ =
152                 sheetPattern->GetAttr<Dimension>("sheet_center_default_width", SHEET_LANDSCAPE_WIDTH);
153             theme->sheetCloseIconTitleSpaceNew_ =
154                 sheetPattern->GetAttr<Dimension>("sheet_close_icon_title_space", SHEET_CLOSE_ICON_TITLE_SPACE_NEW);
155             theme->sheetHeightDefaultMode_ =
156                 sheetPattern->GetAttr<int>("sheet_height_default_mode", SHEET_HEIGHT_DEFAULT_MODE);
157             theme->closeIconButtonStyle_ =
158                 sheetPattern->GetAttr<int>("sheet_close_icon_button_style", SHEET_CLOSE_ICON_BUTTON_STYLE);
159             theme->sheetClose_ = sheetPattern->GetAttr<std::string>("sheet_close", "");
160             theme->operationAreaHeightDouble_ =
161                 sheetPattern->GetAttr<Dimension>("operation_area_height_double", SHEET_OPERATION_AREA_HEIGHT_DOUBLE);
162             theme->bigWindowMinHeight_ =
163                 sheetPattern->GetAttr<Dimension>("big_window_min_height", SHEET_BIG_WINDOW_MIN_HEIGHT);
164         }
165     };
166     ~SheetTheme() override = default;
167 
GetSheetRadius()168     const Dimension& GetSheetRadius() const
169     {
170         return sheetRadius_;
171     }
172 
GetSheetSideRadius()173     const Dimension& GetSheetSideRadius() const
174     {
175         return sheetSideRadius_;
176     }
177 
GetTitleTextFontSize()178     const Dimension& GetTitleTextFontSize() const
179     {
180         return titleTextFontSize_;
181     }
182 
GetTitleTextMargin()183     const Dimension& GetTitleTextMargin() const
184     {
185         return titleTextMargin_;
186     }
187 
GetTitleTextHorizMargin()188     const Dimension& GetTitleTextHorizMargin() const
189     {
190         return titleTextHorizMargin_;
191     }
192 
GetSubtitleTextFontSize()193     const Dimension& GetSubtitleTextFontSize() const
194     {
195         return subtitleTextFontSize_;
196     }
197 
GetSubtitleTextMargin()198     const Dimension& GetSubtitleTextMargin() const
199     {
200         return subtitleTextMargin_;
201     }
202 
GetTitleTextFontColor()203     const Color& GetTitleTextFontColor() const
204     {
205         return titleTextFontColor_;
206     }
207 
GetSubtitleTextFontColor()208     const Color& GetSubtitleTextFontColor() const
209     {
210         return subtitleTextFontColor_;
211     }
212 
GetSheetBackgoundColor()213     const Color& GetSheetBackgoundColor() const
214     {
215         return sheetBackgoundColor_;
216     }
217 
GetDragBarColor()218     const Color& GetDragBarColor() const
219     {
220         return dragBarColor_;
221     }
222 
GetMaskColor()223     const Color& GetMaskColor() const
224     {
225         return maskColor_;
226     }
227 
GetCloseIconColor()228     const Color& GetCloseIconColor() const
229     {
230         return closeIconColor_;
231     }
232 
GetCloseIconImageColor()233     const Color& GetCloseIconImageColor() const
234     {
235         return closeIconImageColor_;
236     }
237 
IsOnlyBottom()238     bool IsOnlyBottom() const
239     {
240         return sheetBottom_ == "bottom";
241     }
242 
GetSheetType()243     const std::string& GetSheetType() const
244     {
245         return sheetType_;
246     }
247 
GetSheetBottomType()248     const std::string& GetSheetBottomType() const
249     {
250         return sheetBottom_;
251     }
252 
GetSheetBackgroundBlurStyle()253     const int& GetSheetBackgroundBlurStyle() const
254     {
255         return sheetBackgroundBlurStyle_;
256     }
257 
GetSheetNormalScale()258     const double& GetSheetNormalScale() const
259     {
260         return sheetNormalScale_;
261     }
262 
GetSheetMaxAgingScale()263     const double& GetSheetMaxAgingScale() const
264     {
265         return sheetMaxAgingScale_;
266     }
267 
GetCloseIconSymbolColor()268     const Color& GetCloseIconSymbolColor() const
269     {
270         return closeIconSymbolColor_;
271     }
272 
GetCloseIconSource()273     const uint32_t& GetCloseIconSource() const
274     {
275         return closeIconSource_;
276     }
277 
GetSheetShadowConfig()278     int32_t GetSheetShadowConfig() const
279     {
280         return sheetShadowConfig_;
281     }
282 
GetSheetShadowConfigS()283     int32_t GetSheetShadowConfigS() const
284     {
285         return sheetShadowConfigS_;
286     }
287 
GetSheetOuterBorderWidth()288     const Dimension& GetSheetOuterBorderWidth() const
289     {
290         return sheetOuterBorderWidth_;
291     }
292 
GetSheetInnerBorderWidth()293     const Dimension& GetSheetInnerBorderWidth() const
294     {
295         return sheetInnerBorderWidth_;
296     }
297 
GetSheetOuterBorderColor()298     const Color& GetSheetOuterBorderColor() const
299     {
300         return sheetOuterBorderColor_;
301     }
302 
GetSheetInnerBorderColor()303     const Color& GetSheetInnerBorderColor() const
304     {
305         return sheetInnerBorderColor_;
306     }
307 
308     /**
309      * Now the switch is enabled on 2in1 and tv devices.
310      * When this switch is on, it affects
311      * the shadow config、
312      * outer border、
313      * inner border、
314      * enableHoverMode.
315      */
IsOuterBorderEnable()316     bool IsOuterBorderEnable() const
317     {
318         return isOuterBorderEnable_;
319     }
320 
GetCloseIconWidth()321     const Dimension& GetCloseIconWidth() const
322     {
323         return closeIconWidth_;
324     }
325 
GetCloseIconRadius()326     const Dimension& GetCloseIconRadius() const
327     {
328         return closeIconRadius_;
329     }
330 
GetOperationAreaHeight()331     const Dimension& GetOperationAreaHeight() const
332     {
333         return operationAreaHeight_;
334     }
335 
GetCloseIconButtonWidth()336     const Dimension& GetCloseIconButtonWidth() const
337     {
338         return closeIconButtonWidth_;
339     }
340 
GetCenterDefaultWidth()341     const Dimension& GetCenterDefaultWidth() const
342     {
343         return centerDefaultWidth_;
344     }
345 
GetSheetCloseIconTitleSpaceNew()346     const Dimension& GetSheetCloseIconTitleSpaceNew() const
347     {
348         return sheetCloseIconTitleSpaceNew_;
349     }
350 
GetCloseIconButtonStyle()351     const int& GetCloseIconButtonStyle() const
352     {
353         return closeIconButtonStyle_;
354     }
355 
GetSheetHeightDefaultMode()356     const int& GetSheetHeightDefaultMode() const
357     {
358         return sheetHeightDefaultMode_;
359     }
360 
GetLargePercent()361     double GetLargePercent() const
362     {
363         return largePercent_;
364     }
365 
GetMediumPercent()366     double GetMediumPercent() const
367     {
368         return mediumPercent_;
369     }
370 
GetHeightApplyFullScreen()371     bool GetHeightApplyFullScreen() const
372     {
373         return heightApplyFullScreen_;
374     }
375 
GetShowCloseIcon()376     bool GetShowCloseIcon() const
377     {
378         return showCloseIcon_;
379     }
GetSheetTitleFontWeight()380     const FontWeight& GetSheetTitleFontWeight() const
381     {
382         return sheetTitleFontWeight_;
383     }
384 
GetSheetDragBarHeight()385     const Dimension& GetSheetDragBarHeight() const
386     {
387         return sheetDragBarHeight_;
388     }
389 
GetTitleTopPadding()390     const Dimension& GetTitleTopPadding() const
391     {
392         return titleTopPadding_;
393     }
394 
GetSheetTitleAreaMargin()395     const Dimension& GetSheetTitleAreaMargin() const
396     {
397         return sheetTitleAreaMargin_;
398     }
399 
GetSheetClose()400     const std::string& GetSheetClose() const
401     {
402         return sheetClose_;
403     }
404 
GetOperationAreaHeightDouble()405     const Dimension& GetOperationAreaHeightDouble() const
406     {
407         return operationAreaHeightDouble_;
408     }
409 
GetBigWindowMinHeight()410     const Dimension& GetBigWindowMinHeight() const
411     {
412         return bigWindowMinHeight_;
413     }
414 protected:
415     SheetTheme() = default;
416 
417 private:
418     Dimension sheetRadius_;
419     Dimension sheetSideRadius_;
420     Dimension titleTextFontSize_;
421     Dimension titleTextMargin_;
422     Dimension subtitleTextFontSize_;
423     Dimension subtitleTextMargin_;
424     Dimension sheetDragBarHeight_;
425     Dimension titleTopPadding_;
426     Dimension sheetTitleAreaMargin_;
427     FontWeight sheetTitleFontWeight_ = FontWeight::BOLD;
428     Color titleTextFontColor_;
429     Color subtitleTextFontColor_;
430     Color sheetBackgoundColor_;
431     Color dragBarColor_;
432     Color maskColor_;
433     Color closeIconColor_;
434     Color closeIconImageColor_;
435     Color closeIconSymbolColor_;
436     std::string sheetType_;
437     std::string sheetBottom_;
438     std::string sheetClose_;
439     int sheetBackgroundBlurStyle_;
440     double sheetNormalScale_;
441     double sheetMaxAgingScale_;
442     uint32_t closeIconSource_ = 0;
443     int32_t sheetShadowConfig_;
444     int32_t sheetShadowConfigS_;
445     Dimension sheetOuterBorderWidth_;
446     Dimension sheetInnerBorderWidth_;
447     bool isOuterBorderEnable_;
448     Color sheetOuterBorderColor_;
449     Color sheetInnerBorderColor_;
450     Dimension closeIconWidth_;
451     Dimension titleTextHorizMargin_;
452     Dimension closeIconRadius_;
453     Dimension operationAreaHeight_;
454     Dimension closeIconButtonWidth_;
455     Dimension centerDefaultWidth_;
456     Dimension sheetCloseIconTitleSpaceNew_;
457     int closeIconButtonStyle_;
458     int sheetHeightDefaultMode_;
459     double largePercent_ = 1.0; // 1.0 is default value
460     double mediumPercent_ = 0.6; // 0.6 is default value
461     bool heightApplyFullScreen_ = false;
462     bool showCloseIcon_ = true;
463 
464     Dimension operationAreaHeightDouble_ = SHEET_OPERATION_AREA_HEIGHT_DOUBLE;
465     Dimension bigWindowMinHeight_ = SHEET_BIG_WINDOW_MIN_HEIGHT;
466 };
467 } // namespace OHOS::Ace::NG
468 
469 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SHEET_SHEET_THEME_H
470