• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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             theme->timeTextStyle_.SetTextColor(videoPattern->GetAttr<Color>("control_bar_text_color", Color::BLACK));
78             theme->errorTextStyle_.SetFontSize(videoPattern->GetAttr<Dimension>("control_bar_text_font_size", 15.0_vp));
79             theme->errorTextStyle_.SetTextColor(videoPattern->GetAttr<Color>("control_bar_error_text_color",
80                 Color::GRAY));
81             theme->bkgColor_ = videoPattern->GetAttr<Color>("control_bar_background_color", Color(0x64c8c8c8));
82         }
83     };
84 
85     ~VideoTheme() override = default;
86 
GetBtnSize()87     const Size& GetBtnSize() const
88     {
89         return btnSize_;
90     }
91 
GetBtnEdge()92     const Edge& GetBtnEdge() const
93     {
94         return btnEdge_;
95     }
96 
GetTextEdge()97     const Edge& GetTextEdge() const
98     {
99         return textEdge_;
100     }
101 
GetSliderEdge()102     const Edge& GetSliderEdge() const
103     {
104         return sliderEdge_;
105     }
106 
GetTimeTextStyle()107     const TextStyle& GetTimeTextStyle() const
108     {
109         return timeTextStyle_;
110     }
111 
GetErrorTextStyle()112     const TextStyle& GetErrorTextStyle() const
113     {
114         return errorTextStyle_;
115     }
116 
GetBkgColor()117     const Color& GetBkgColor() const
118     {
119         return bkgColor_;
120     }
121 
122 protected:
123     VideoTheme() = default;
124 
125 private:
126     Size btnSize_;
127     Edge btnEdge_;
128     Edge textEdge_;
129     Edge sliderEdge_;
130     TextStyle timeTextStyle_;
131     TextStyle errorTextStyle_;
132     Color bkgColor_;
133 };
134 
135 } // namespace OHOS::Ace
136 
137 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_VIDEO_VIDEO_THEME_H
138