1 /* 2 * Copyright (c) 2021 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_VIDEO_VIDEO_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_VIDEO_VIDEO_THEME_H 18 19 #include "base/geometry/size.h" 20 #include "core/components/common/properties/color.h" 21 #include "core/components/common/properties/edge.h" 22 #include "core/components/common/properties/text_style.h" 23 #include "core/components/theme/theme.h" 24 #include "core/components/theme/theme_constants.h" 25 #include "core/components/theme/theme_constants_defines.h" 26 27 namespace OHOS::Ace { 28 29 /** 30 * VideoTheme defines color and styles of VideoComponent. VideoTheme should be built 31 * using VideoTheme::Builder. 32 */ 33 class VideoTheme : public virtual Theme { 34 DECLARE_ACE_TYPE(VideoTheme, Theme); 35 36 public: 37 class Builder { 38 public: 39 Builder() = default; 40 ~Builder() = default; 41 Build(const RefPtr<ThemeConstants> & themeConstants)42 RefPtr<VideoTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 43 { 44 RefPtr<VideoTheme> theme = AceType::Claim(new VideoTheme()); 45 if (!themeConstants) { 46 return theme; 47 } 48 ParsePattern(themeConstants, theme); 49 return theme; 50 } 51 ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<VideoTheme> & theme)52 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<VideoTheme>& theme) const 53 { 54 RefPtr<ThemeStyle> videoPattern = themeConstants->GetPatternByName(THEME_PATTERN_VIDEO); 55 if (!videoPattern) { 56 LOGW("find pattern of video fail"); 57 return; 58 } 59 theme->btnSize_ = Size(videoPattern->GetAttr<double>("control_bar_play_width", 40.0f), 60 videoPattern->GetAttr<double>("control_bar_play_height", 40.0f)); 61 theme->btnEdge_ = Edge( 62 videoPattern->GetAttr<Dimension>("control_bar_play_padding_left", 10.0_vp).Value(), 63 videoPattern->GetAttr<Dimension>("control_bar_play_padding_top", 5.0_vp).Value(), 64 videoPattern->GetAttr<Dimension>("control_bar_play_padding_right", 10.0_vp).Value(), 65 videoPattern->GetAttr<Dimension>("control_bar_play_padding_bottom", 5.0_vp).Value()); 66 theme->textEdge_ = Edge( 67 videoPattern->GetAttr<Dimension>("control_bar_current_time_padding_left", 5.0_vp).Value(), 68 videoPattern->GetAttr<Dimension>("control_bar_current_time_padding_top", 5.0_vp).Value(), 69 videoPattern->GetAttr<Dimension>("control_bar_current_time_padding_right", 5.0_vp).Value(), 70 videoPattern->GetAttr<Dimension>("control_bar_current_time_padding_bottom", 5.0_vp).Value()); 71 theme->sliderEdge_ = Edge( 72 videoPattern->GetAttr<Dimension>("control_bar_progress_padding_left", 0.0_vp).Value(), 73 videoPattern->GetAttr<Dimension>("control_bar_progress_padding_top", 0.0_vp).Value(), 74 videoPattern->GetAttr<Dimension>("control_bar_progress_padding_right", 0.0_vp).Value(), 75 videoPattern->GetAttr<Dimension>("control_bar_progress_padding_bottom", 0.0_vp).Value()); 76 theme->timeTextStyle_.SetFontSize(videoPattern->GetAttr<Dimension>("control_bar_text_font_size", 15.0_vp)); 77 Color timeText = themeConstants->GetColorByName("sys.color.ohos_id_color_foreground_contrary"). 78 BlendOpacity(themeConstants->GetDoubleByName("sys.color.ohos_id_alpha_content_secondary")); 79 theme->timeTextStyle_.SetTextColor(timeText); 80 theme->errorTextStyle_.SetFontSize(videoPattern->GetAttr<Dimension>("control_bar_text_font_size", 15.0_vp)); 81 theme->errorTextStyle_.SetTextColor(videoPattern->GetAttr<Color>("control_bar_error_text_color", 82 Color::GRAY)); 83 theme->selectColor_ = themeConstants->GetColorByName("sys.color.ohos_id_color_foreground_contrary"); 84 theme->trackBgColor_ = themeConstants->GetColorByName("sys.color.ohos_id_color_foreground_contrary"). 85 BlendOpacity(themeConstants->GetDoubleByName("sys.color.ohos_id_alpha_normal_bg")); 86 theme->btnIconColor_ = themeConstants->GetColorByName("sys.color.ohos_id_color_foreground_contrary"); 87 theme->bkgColor_ = Color(0x00ffffff); 88 } 89 }; 90 91 ~VideoTheme() override = default; 92 GetBtnSize()93 const Size& GetBtnSize() const 94 { 95 return btnSize_; 96 } 97 GetBtnEdge()98 const Edge& GetBtnEdge() const 99 { 100 return btnEdge_; 101 } 102 GetTextEdge()103 const Edge& GetTextEdge() const 104 { 105 return textEdge_; 106 } 107 GetSliderEdge()108 const Edge& GetSliderEdge() const 109 { 110 return sliderEdge_; 111 } 112 GetTimeTextStyle()113 const TextStyle& GetTimeTextStyle() const 114 { 115 return timeTextStyle_; 116 } 117 GetErrorTextStyle()118 const TextStyle& GetErrorTextStyle() const 119 { 120 return errorTextStyle_; 121 } 122 GetBkgColor()123 const Color& GetBkgColor() const 124 { 125 return bkgColor_; 126 } 127 GetSelectColor()128 const Color& GetSelectColor() const 129 { 130 return selectColor_; 131 } 132 GetTrackBgColor()133 const Color& GetTrackBgColor() const 134 { 135 return trackBgColor_; 136 } 137 GetIconColor()138 const Color& GetIconColor() const 139 { 140 return btnIconColor_; 141 } 142 143 protected: 144 VideoTheme() = default; 145 146 private: 147 Size btnSize_; 148 Edge btnEdge_; 149 Edge textEdge_; 150 Edge sliderEdge_; 151 TextStyle timeTextStyle_; 152 TextStyle errorTextStyle_; 153 Color bkgColor_; 154 Color selectColor_; 155 Color trackBgColor_; 156 Color btnIconColor_; 157 }; 158 159 } // namespace OHOS::Ace 160 161 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_VIDEO_VIDEO_THEME_H 162