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 } // namespace 61 class SheetTheme : public virtual Theme { 62 DECLARE_ACE_TYPE(SheetTheme, Theme); 63 64 public: 65 class Builder { 66 public: 67 Builder() = default; 68 ~Builder() = default; 69 Build(const RefPtr<ThemeConstants> & themeConstants)70 RefPtr<SheetTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 71 { 72 RefPtr<SheetTheme> theme = AceType::Claim(new SheetTheme()); 73 if (!themeConstants) { 74 return theme; 75 } 76 77 ParsePattern(themeConstants, theme); 78 return theme; 79 } 80 81 private: ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<SheetTheme> & theme)82 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<SheetTheme>& theme) const 83 { 84 RefPtr<ThemeStyle> sheetPattern = themeConstants->GetPatternByName(THEME_PATTERN_SHEET); 85 if (!sheetPattern) { 86 TAG_LOGE(AceLogTag::ACE_SHEET, "sheetPattern is null"); 87 return; 88 } 89 90 theme->sheetRadius_ = sheetPattern->GetAttr<Dimension>("sheet_radius", 32.0_vp); 91 theme->titleTextFontSize_ = sheetPattern->GetAttr<Dimension>("title_text_font_size", 20.0_vp); 92 theme->titleTextMargin_ = sheetPattern->GetAttr<Dimension>("title_text_margin", 16.0_vp); 93 theme->subtitleTextFontSize_ = sheetPattern->GetAttr<Dimension>("subtitle_text_font_size", 14.0_fp); 94 theme->subtitleTextMargin_ = sheetPattern->GetAttr<Dimension>("subtitle_text_margin", 2.0_fp); 95 theme->titleTextFontColor_ = sheetPattern->GetAttr<Color>("title_text_font_color", Color(0xff182431)); 96 theme->subtitleTextFontColor_ = sheetPattern->GetAttr<Color>("subtitle_text_font_color", Color(0x99182431)); 97 theme->sheetBackgoundColor_ = sheetPattern->GetAttr<Color>("sheet_background_color", Color(0xfff1f3f5)); 98 theme->dragBarColor_ = sheetPattern->GetAttr<Color>("drag_bar_color", Color(0x33182431)); 99 theme->sheetType_ = sheetPattern->GetAttr<std::string>("sheet_type", "auto"); 100 theme->sheetBottom_ = sheetPattern->GetAttr<std::string>("sheet_bottom", "auto"); 101 theme->maskColor_ = sheetPattern->GetAttr<Color>("mask_color", Color(0x33182431)); 102 theme->closeIconColor_ = sheetPattern->GetAttr<Color>("close_icon_color", Color(0x0c182431)); 103 theme->closeIconImageColor_ = sheetPattern->GetAttr<Color>("close_icon_image_color", Color(0xff182431)); 104 theme->sheetBackgroundBlurStyle_ = sheetPattern->GetAttr<int>("sheet_background_blur_style", 0); 105 theme->sheetNormalScale_ = sheetPattern->GetAttr<double>("sheet_normal_aging_scale", 1.0f); 106 theme->sheetMaxAgingScale_ = sheetPattern->GetAttr<double>("sheet_max_aging_scale", 1.75f); 107 theme->closeIconSource_ = themeConstants->GetSymbolByName("sys.symbol.xmark"); 108 theme->closeIconSymbolColor_ = sheetPattern->GetAttr<Color>("close_icon_symbol_color", Color(0xff182431)); 109 theme->sheetShadowConfig_ = sheetPattern->GetAttr<int32_t>("sheet_shadow_config", SHEET_SHADOW_NONE); 110 theme->sheetShadowConfigS_ = sheetPattern->GetAttr<int32_t>("sheet_shadow_config_s", SHEET_SHADOW_NONE); 111 theme->sheetOuterBorderWidth_ = sheetPattern->GetAttr<Dimension>("sheet_outline_border_width", 0.0_vp); 112 // If the outline border width is valid, outline border, shadow and border are default enable. 113 theme->isOuterBorderEnable_ = theme->sheetOuterBorderWidth_.IsValid(); 114 theme->sheetInnerBorderWidth_ = sheetPattern->GetAttr<Dimension>("sheet_inner_border_width", 0.0_vp); 115 theme->sheetOuterBorderColor_ = 116 sheetPattern->GetAttr<Color>("sheet_outline_border_color", Color::TRANSPARENT); 117 theme->sheetInnerBorderColor_ = 118 sheetPattern->GetAttr<Color>("sheet_inner_border_color", Color::TRANSPARENT); 119 theme->closeIconWidth_ = 120 sheetPattern->GetAttr<Dimension>("close_icon_width", SHEET_CLOSE_ICON_IMAGE_HEIGHT); 121 theme->titleTextHorizMargin_ = 122 sheetPattern->GetAttr<Dimension>("title_text_horizontal_margin", SHEET_TITLE_TEXT_HORIZONTAL_MARGIN); 123 theme->closeIconRadius_ = sheetPattern->GetAttr<Dimension>("close_icon_radius", SHEET_CLOSE_ICON_RADIUS); 124 ParseAdditionalStylePattern(sheetPattern, theme); 125 } 126 ParseAdditionalStylePattern(const RefPtr<ThemeStyle> & sheetPattern,const RefPtr<SheetTheme> & theme)127 void ParseAdditionalStylePattern( 128 const RefPtr<ThemeStyle>& sheetPattern, const RefPtr<SheetTheme>& theme) const 129 { 130 theme->largePercent_ = sheetPattern->GetAttr<double>("sheet_height_percent_large", 1.0f); 131 theme->mediumPercent_ = sheetPattern->GetAttr<double>("sheet_height_percent_medium", 0.6f); 132 theme->operationAreaHeight_ = sheetPattern->GetAttr<Dimension>("sheet_operation_height", 56.0_vp); 133 theme->heightApplyFullScreen_ = 134 static_cast<bool>(sheetPattern->GetAttr<int>("sheet_height_apply_full_screen", 0)); 135 theme->showCloseIcon_ = static_cast<bool>(sheetPattern->GetAttr<int>("sheet_show_close_icon", 1)); 136 theme->sheetTitleFontWeight_ = FontWeight(static_cast<int32_t>( 137 sheetPattern->GetAttr<double>("sheet_title_font_weight", SHEET_TITLE_FONT_WEIGHT))); 138 theme->sheetDragBarHeight_ = sheetPattern->GetAttr<Dimension>("sheet_drag_bar_height", 139 SHEET_DRAG_BAR_HEIGHT); 140 theme->titleTopPadding_ = sheetPattern->GetAttr<Dimension>("sheet_double_title_top_padding", 141 SHEET_DOUBLE_TITLE_TOP_PADDING); 142 theme->sheetTitleAreaMargin_ = sheetPattern->GetAttr<Dimension>("sheet_title_area_margin", 143 SHEET_TITLE_AREA_MARGIN); 144 } 145 }; 146 ~SheetTheme() override = default; 147 GetSheetRadius()148 const Dimension& GetSheetRadius() const 149 { 150 return sheetRadius_; 151 } 152 GetTitleTextFontSize()153 const Dimension& GetTitleTextFontSize() const 154 { 155 return titleTextFontSize_; 156 } 157 GetTitleTextMargin()158 const Dimension& GetTitleTextMargin() const 159 { 160 return titleTextMargin_; 161 } 162 GetTitleTextHorizMargin()163 const Dimension& GetTitleTextHorizMargin() const 164 { 165 return titleTextHorizMargin_; 166 } 167 GetSubtitleTextFontSize()168 const Dimension& GetSubtitleTextFontSize() const 169 { 170 return subtitleTextFontSize_; 171 } 172 GetSubtitleTextMargin()173 const Dimension& GetSubtitleTextMargin() const 174 { 175 return subtitleTextMargin_; 176 } 177 GetTitleTextFontColor()178 const Color& GetTitleTextFontColor() const 179 { 180 return titleTextFontColor_; 181 } 182 GetSubtitleTextFontColor()183 const Color& GetSubtitleTextFontColor() const 184 { 185 return subtitleTextFontColor_; 186 } 187 GetSheetBackgoundColor()188 const Color& GetSheetBackgoundColor() const 189 { 190 return sheetBackgoundColor_; 191 } 192 GetDragBarColor()193 const Color& GetDragBarColor() const 194 { 195 return dragBarColor_; 196 } 197 GetMaskColor()198 const Color& GetMaskColor() const 199 { 200 return maskColor_; 201 } 202 GetCloseIconColor()203 const Color& GetCloseIconColor() const 204 { 205 return closeIconColor_; 206 } 207 GetCloseIconImageColor()208 const Color& GetCloseIconImageColor() const 209 { 210 return closeIconImageColor_; 211 } 212 IsOnlyBottom()213 bool IsOnlyBottom() const 214 { 215 return sheetBottom_ == "bottom"; 216 } 217 GetSheetType()218 const std::string& GetSheetType() const 219 { 220 return sheetType_; 221 } 222 GetSheetBackgroundBlurStyle()223 const int& GetSheetBackgroundBlurStyle() const 224 { 225 return sheetBackgroundBlurStyle_; 226 } 227 GetSheetNormalScale()228 const double& GetSheetNormalScale() const 229 { 230 return sheetNormalScale_; 231 } 232 GetSheetMaxAgingScale()233 const double& GetSheetMaxAgingScale() const 234 { 235 return sheetMaxAgingScale_; 236 } 237 GetCloseIconSymbolColor()238 const Color& GetCloseIconSymbolColor() const 239 { 240 return closeIconSymbolColor_; 241 } 242 GetCloseIconSource()243 const uint32_t& GetCloseIconSource() const 244 { 245 return closeIconSource_; 246 } 247 GetSheetShadowConfig()248 int32_t GetSheetShadowConfig() const 249 { 250 return sheetShadowConfig_; 251 } 252 GetSheetShadowConfigS()253 int32_t GetSheetShadowConfigS() const 254 { 255 return sheetShadowConfigS_; 256 } 257 GetSheetOuterBorderWidth()258 const Dimension& GetSheetOuterBorderWidth() const 259 { 260 return sheetOuterBorderWidth_; 261 } 262 GetSheetInnerBorderWidth()263 const Dimension& GetSheetInnerBorderWidth() const 264 { 265 return sheetInnerBorderWidth_; 266 } 267 GetSheetOuterBorderColor()268 const Color& GetSheetOuterBorderColor() const 269 { 270 return sheetOuterBorderColor_; 271 } 272 GetSheetInnerBorderColor()273 const Color& GetSheetInnerBorderColor() const 274 { 275 return sheetInnerBorderColor_; 276 } 277 IsOuterBorderEnable()278 bool IsOuterBorderEnable() const 279 { 280 return isOuterBorderEnable_; 281 } 282 GetCloseIconWidth()283 const Dimension& GetCloseIconWidth() const 284 { 285 return closeIconWidth_; 286 } 287 GetCloseIconRadius()288 const Dimension& GetCloseIconRadius() const 289 { 290 return closeIconRadius_; 291 } 292 GetOperationAreaHeight()293 const Dimension& GetOperationAreaHeight() const 294 { 295 return operationAreaHeight_; 296 } 297 GetLargePercent()298 double GetLargePercent() const 299 { 300 return largePercent_; 301 } 302 GetMediumPercent()303 double GetMediumPercent() const 304 { 305 return mediumPercent_; 306 } 307 GetHeightApplyFullScreen()308 bool GetHeightApplyFullScreen() const 309 { 310 return heightApplyFullScreen_; 311 } 312 GetShowCloseIcon()313 bool GetShowCloseIcon() const 314 { 315 return showCloseIcon_; 316 } GetSheetTitleFontWeight()317 const FontWeight& GetSheetTitleFontWeight() const 318 { 319 return sheetTitleFontWeight_; 320 } 321 GetSheetDragBarHeight()322 const Dimension& GetSheetDragBarHeight() const 323 { 324 return sheetDragBarHeight_; 325 } 326 GetTitleTopPadding()327 const Dimension& GetTitleTopPadding() const 328 { 329 return titleTopPadding_; 330 } 331 GetSheetTitleAreaMargin()332 const Dimension& GetSheetTitleAreaMargin() const 333 { 334 return sheetTitleAreaMargin_; 335 } 336 protected: 337 SheetTheme() = default; 338 339 private: 340 Dimension sheetRadius_; 341 Dimension titleTextFontSize_; 342 Dimension titleTextMargin_; 343 Dimension subtitleTextFontSize_; 344 Dimension subtitleTextMargin_; 345 Dimension sheetDragBarHeight_; 346 Dimension titleTopPadding_; 347 Dimension sheetTitleAreaMargin_; 348 FontWeight sheetTitleFontWeight_ = FontWeight::BOLD; 349 Color titleTextFontColor_; 350 Color subtitleTextFontColor_; 351 Color sheetBackgoundColor_; 352 Color dragBarColor_; 353 Color maskColor_; 354 Color closeIconColor_; 355 Color closeIconImageColor_; 356 Color closeIconSymbolColor_; 357 std::string sheetType_; 358 std::string sheetBottom_; 359 int sheetBackgroundBlurStyle_; 360 double sheetNormalScale_; 361 double sheetMaxAgingScale_; 362 uint32_t closeIconSource_ = 0; 363 int32_t sheetShadowConfig_; 364 int32_t sheetShadowConfigS_; 365 Dimension sheetOuterBorderWidth_; 366 Dimension sheetInnerBorderWidth_; 367 bool isOuterBorderEnable_; 368 Color sheetOuterBorderColor_; 369 Color sheetInnerBorderColor_; 370 Dimension closeIconWidth_; 371 Dimension titleTextHorizMargin_; 372 Dimension closeIconRadius_; 373 Dimension operationAreaHeight_; 374 double largePercent_ = 1.0; // 1.0 is default value 375 double mediumPercent_ = 0.6; // 0.6 is default value 376 bool heightApplyFullScreen_ = false; 377 bool showCloseIcon_ = true; 378 }; 379 } // namespace OHOS::Ace::NG 380 381 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SHEET_SHEET_THEME_H 382