• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_CONTAINER_MODAL_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CONTAINER_MODAL_THEME_H
18 
19 #include <cstdint>
20 #include "base/utils/device_config.h"
21 #include "base/utils/system_properties.h"
22 #include "base/utils/utils.h"
23 #include "core/components/common/layout/constants.h"
24 #include "core/components/common/properties/color.h"
25 #include "core/components/common/properties/text_style.h"
26 #include "core/components/theme/theme.h"
27 #include "core/components/theme/theme_constants.h"
28 #include "core/components/theme/theme_constants_defines.h"
29 #include "core/components_ng/pattern/container_modal/container_modal_view.h"
30 
31 namespace OHOS::Ace::NG {
32 
33 constexpr uint32_t DARK_MODE_NORMAL_CLOSE_BTN_COLOR = 0xff3d2e2d;
34 constexpr uint32_t HOVER_CLOSE_BTN_COLOR_DARK = 0xff414141;
35 constexpr uint32_t HOVER_CLOSE_BTN_COLOR_LIGHT = 0xffdcdcdc;
36 constexpr uint32_t HOVER_FILL_CLOSE_BTN_COLOR_DARK = 0xffe5e5e5;
37 constexpr uint32_t HOVER_FILL_CLOSE_BTN_COLOR_LIGHT = 0xffffffff;
38 constexpr uint32_t HOVER_FILL_NORMA_BTN_COLOR_LIGHT = 0xff000000;
39 constexpr uint32_t PRESS_CLOSE_BTN_COLOR_DARK = 0xffde6355;
40 constexpr uint32_t PRESS_CLOSE_BTN_COLOR_LIGHT = 0xffd03922;
41 constexpr uint32_t PRESS_NORMAL_BTN_COLOR_DARK = 0xff4b4b4b;
42 constexpr uint32_t PRESS_NORMAL_BTN_COLOR_LIGHT = 0xffd0d0d0;
43 constexpr uint32_t UNFOCUS_CLOSE_BTN_COLOR_DARK = 0xff191312;
44 constexpr uint32_t UNFOCUS_CLOSE_BTN_COLOR_LIGHT = 0xfffef7f6;
45 constexpr uint32_t UNFOCUS_BTN_COLOR_DARK = 0xff121212;
46 constexpr uint32_t UNFOCUS_BTN_COLOR_LIGHT = 0xfff5f5f5;
47 
48 constexpr uint32_t ICON_PRIMARY_LIGHT = 0xE5000000;
49 constexpr uint32_t ICON_PRIMARY_DARK = 0xDBFFFFFF;
50 constexpr uint32_t ICON_ON_PRIMARY_LIGHT = 0xFFFFFF;
51 constexpr uint32_t ICON_ON_PRIMARY_DARK = 0xE5E5E5;
52 constexpr uint32_t INTERACTIVE_HOVER_LIGHT = 0x0C000000;
53 constexpr uint32_t INTERACTIVE_HOVER_DARK = 0x19FFFFFF;
54 constexpr uint32_t INTERACTIVE_CLICK_LIGHT = 0x19000000;
55 constexpr uint32_t INTERACTIVE_CLICK_DARK = 0x26FFFFFF;
56 constexpr uint32_t WARNING_LIGHT = 0xE84026;
57 constexpr uint32_t WARNING_DARK = 0xD94838;
58 constexpr uint32_t CLOSE_BTN_DARK = 0xE6A5A5;
59 
60 enum ControlBtnColorType {
61     NORMAL,
62     NORMAL_FILL,
63     HOVER,
64     HOVER_FILL,
65     PRESS,
66     PRESS_FILL,
67     FOCUS,
68     FOCUS_FILL,
69     UNFOCUS,
70     UNFOCUS_FILL,
71 };
72 class ContainerModalTheme : public virtual Theme {
73     DECLARE_ACE_TYPE(ContainerModalTheme, Theme);
74 
75 public:
76     class Builder {
77     public:
78         Builder() = default;
79         ~Builder() = default;
80 
Build(const RefPtr<ThemeConstants> & themeConstants)81         RefPtr<ContainerModalTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
82         {
83             RefPtr<ContainerModalTheme> theme = AceType::MakeRefPtr<ContainerModalTheme>();
84             if (!themeConstants) {
85                 return theme;
86             }
87             theme->themeConstants_ = themeConstants;
88             ParsePattern(themeConstants, theme);
89             return theme;
90         }
91 
92     private:
ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<ContainerModalTheme> & theme)93         void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<ContainerModalTheme>& theme) const
94         {
95             auto themeStyle = themeConstants->GetThemeStyle();
96             if (!themeStyle) {
97                 return;
98             }
99             auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_CONTAINER_MODAL, nullptr);
100             if (!pattern) {
101                 return;
102             }
103             theme->backgroundColor_ = pattern->GetAttr<Color>("container_modal_background", Color());
104             theme->backgroundUnfocusColor_ = pattern->GetAttr<Color>("container_modal_unfocus_background", Color());
105             theme->titleTextColor_ = pattern->GetAttr<Color>("ohos_id_color_primary", Color());
106             theme->windowJaggedEdgeRenderColor_ =
107                 pattern->GetAttr<Color>("container_modal_special_background", Color());
108 
109             auto resAdapter = themeConstants->GetResourceAdapter();
110             CHECK_NULL_VOID(resAdapter);
111             auto isLightMode = resAdapter->GetResourceColorMode() == ColorMode::LIGHT;
112 
113             theme->iconPrimaryColor_ = pattern->GetAttr<Color>(
114                 "icon_primary",
115                 isLightMode ? Color(ICON_PRIMARY_LIGHT) : Color(ICON_PRIMARY_DARK)
116             );
117             theme->iconOnPrimaryColor_ = pattern->GetAttr<Color>(
118                 "icon_on_primary",
119                 isLightMode ? Color(ICON_ON_PRIMARY_LIGHT) : Color(ICON_ON_PRIMARY_DARK)
120             );
121             theme->interactiveHoverColor_ = pattern->GetAttr<Color>(
122                 "interactive_hover",
123                 isLightMode ? Color(INTERACTIVE_HOVER_LIGHT) : Color(INTERACTIVE_HOVER_DARK)
124             );
125             theme->interactiveClickColor_ = pattern->GetAttr<Color>(
126                 "interactive_click",
127                 isLightMode ? Color(INTERACTIVE_CLICK_LIGHT) : Color(INTERACTIVE_CLICK_DARK)
128             );
129             theme->warningColor_ = pattern->GetAttr<Color>(
130                 "warning",
131                 isLightMode ? Color(WARNING_LIGHT) : Color(WARNING_DARK)
132             );
133 
134             theme->windowScreenLeft_ = pattern->GetAttr<std::string>("window_left_screen", "");
135             theme->windowScreenRight_ = pattern->GetAttr<std::string>("window_right_screen", "");
136         }
137     };
138     ContainerModalTheme() = default;
139     ~ContainerModalTheme() override = default;
140 
GetBackGroundColor(bool isFocus)141     Color GetBackGroundColor(bool isFocus)
142     {
143         Color backGroundColor = isFocus ? backgroundColor_ : backgroundUnfocusColor_;
144         return backGroundColor;
145     }
146 
147     //The color of the immersive mode settings for windows during edge anti-aliasing.
GetWindowJaggedEdgeRenderColor()148     Color GetWindowJaggedEdgeRenderColor()
149     {
150         return windowJaggedEdgeRenderColor_;
151     }
152 
GetControlBtnColor(bool isCloseBtn,ControlBtnColorType type)153     Color GetControlBtnColor(bool isCloseBtn, ControlBtnColorType type)
154     {
155         auto isLightMode = IsLightMode();
156         auto normalBtnOpacity = isLightMode ? 0.1f : 0.2f;
157         auto normalBtnColor = iconPrimaryColor_;
158         auto closeBtnOpacity = isLightMode ? 0.1f : 0.3f;
159         auto closeBtnColor = isLightMode ? warningColor_ : Color(CLOSE_BTN_DARK);
160         Color btnColor;
161         switch (type) {
162             case ControlBtnColorType::NORMAL:
163                 btnColor = !isCloseBtn
164                     ? normalBtnColor.ChangeOpacity(normalBtnOpacity)
165                     : closeBtnColor.ChangeOpacity(closeBtnOpacity);
166                 break;
167             case ControlBtnColorType::NORMAL_FILL:
168                 btnColor = !isCloseBtn
169                     ? iconPrimaryColor_.ChangeOpacity(1.0f) : warningColor_.ChangeOpacity(1.0f);
170                 break;
171             case ControlBtnColorType::HOVER:
172                 btnColor = !isCloseBtn
173                     ? normalBtnColor.ChangeOpacity(normalBtnOpacity).BlendColor(interactiveHoverColor_)
174                     : warningColor_.ChangeOpacity(1.0f);
175                 break;
176             case ControlBtnColorType::HOVER_FILL:
177                 btnColor = !isCloseBtn
178                     ? iconPrimaryColor_.ChangeOpacity(1.0f) : iconOnPrimaryColor_.ChangeOpacity(1.0f);
179                 break;
180             case ControlBtnColorType::PRESS:
181                 btnColor = !isCloseBtn
182                     ? normalBtnColor.ChangeOpacity(normalBtnOpacity).BlendColor(interactiveClickColor_)
183                     : warningColor_.ChangeOpacity(1.0f).BlendColor(interactiveClickColor_);
184                 break;
185             case ControlBtnColorType::PRESS_FILL:
186                 btnColor = !isCloseBtn
187                     ? iconPrimaryColor_.ChangeOpacity(1.0f) : iconOnPrimaryColor_.ChangeOpacity(1.0f);
188                 break;
189             case ControlBtnColorType::UNFOCUS:
190                 btnColor = !isCloseBtn
191                     ? normalBtnColor.ChangeOpacity(normalBtnOpacity * 0.4f)
192                     : closeBtnColor.ChangeOpacity(closeBtnOpacity * 0.4f);
193                 break;
194             case ControlBtnColorType::UNFOCUS_FILL:
195                 btnColor = !isCloseBtn
196                     ? iconPrimaryColor_.ChangeOpacity(0.4f) : warningColor_.ChangeOpacity(0.4f);
197                 break;
198             default:
199                 break;
200         }
201         return btnColor;
202     }
203 
IsLightMode()204     bool IsLightMode()
205     {
206         CHECK_NULL_RETURN(themeConstants_, true);
207         auto resAdapter = themeConstants_->GetResourceAdapter();
208         CHECK_NULL_RETURN(resAdapter, true);
209         return resAdapter->GetResourceColorMode() == ColorMode::LIGHT;
210     }
211 
GetWindowScreen(bool isLeftSplit)212     std::string GetWindowScreen(bool isLeftSplit)
213     {
214         return isLeftSplit ? windowScreenLeft_ : windowScreenRight_;
215     }
216 
217 private:
218     Color backgroundColor_;
219     Color windowJaggedEdgeRenderColor_;
220     Color backgroundUnfocusColor_;
221     Color titleTextColor_;
222 
223     Color iconPrimaryColor_;
224     Color iconOnPrimaryColor_;
225     Color interactiveHoverColor_;
226     Color interactiveClickColor_;
227     Color warningColor_;
228     RefPtr<ThemeConstants> themeConstants_ = nullptr;
229 
230     std::string windowScreenLeft_;
231     std::string windowScreenRight_;
232 };
233 
234 } // namespace OHOS::Ace
235 
236 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BUTTON_BUTTON_THEME_H