• 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_TEXT_OVERLAY_TEXT_OVERLAY_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_OVERLAY_TEXT_OVERLAY_THEME_H
18 
19 #include "base/geometry/dimension.h"
20 #include "core/components/common/properties/border.h"
21 #include "core/components/common/properties/border_edge.h"
22 #include "core/components/common/properties/color.h"
23 #include "core/components/common/properties/edge.h"
24 #include "core/components/common/properties/radius.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 
30 namespace OHOS::Ace {
31 
32 /**
33  * DialogTheme defines color and styles of PopupComponent. PopupTheme should be built
34  * using DialogTheme::Builder.
35  */
36 class TextOverlayTheme : public virtual Theme {
37     DECLARE_ACE_TYPE(TextOverlayTheme, Theme);
38 
39 public:
40     class Builder {
41     public:
42         Builder() = default;
43         ~Builder() = default;
44 
Build(const RefPtr<ThemeConstants> & themeConstants)45         RefPtr<TextOverlayTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
46         {
47             RefPtr<TextOverlayTheme> theme = AceType::Claim(new TextOverlayTheme());
48             if (!themeConstants) {
49                 return theme;
50             }
51             theme->backResourceId_ = themeConstants->GetResourceId(THEME_NAVIGATION_BAR_RESOURCE_ID_BACK);
52             theme->moreResourceId_ = themeConstants->GetResourceId(THEME_NAVIGATION_BAR_RESOURCE_ID_MORE);
53             ParsePattern(themeConstants->GetThemeStyle(), theme);
54             ParseMenuPattern(themeConstants->GetThemeStyle(), theme);
55             return theme;
56         }
57 
58     private:
ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<TextOverlayTheme> & theme)59         void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<TextOverlayTheme>& theme) const
60         {
61             if (!themeStyle || !theme) {
62                 return;
63             }
64             auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>("text_overlay_pattern", nullptr);
65             if (pattern) {
66                 const double defaultTertiaryColorAlpha = 0.4;
67 
68                 theme->menuBorder_ = Border(BorderEdge(
69                     pattern->GetAttr<Color>("text_overlay_menu_border_color", Color()),
70                     pattern->GetAttr<Dimension>("text_overlay_menu_border_width", 0.0_vp),
71                     BorderStyle(
72                         static_cast<int32_t>(pattern->GetAttr<double>("text_overlay_menu_border_style", 0.0)))));
73                 theme->menuPadding_ = Edge(pattern->GetAttr<Dimension>("text_overlay_menu_padding_left", 0.0_vp),
74                     pattern->GetAttr<Dimension>("text_overlay_menu_padding_top", 0.0_vp),
75                     pattern->GetAttr<Dimension>("text_overlay_menu_padding_right", 0.0_vp),
76                     pattern->GetAttr<Dimension>("text_overlay_menu_padding_bottom", 0.0_vp));
77                 theme->menuSpacingWithText_ =
78                     pattern->GetAttr<Dimension>("text_overlay_menu_spacing_with_text", 0.0_vp);
79                 theme->menuSafeSpacing_ = pattern->GetAttr<Dimension>("text_overlay_menu_safe_spacing", 16.0_vp);
80                 theme->menuButtonWidth_ = pattern->GetAttr<Dimension>("text_overlay_menu_button_width", 0.0_vp);
81                 theme->menuButtonHeight_ = pattern->GetAttr<Dimension>("text_overlay_menu_button_height", 0.0_vp);
82                 theme->menuButtonTextStyle_.SetFontWeight(FontWeight(
83                     static_cast<int32_t>(pattern->GetAttr<double>("text_overlay_button_text_font_weight", 0.0))));
84                 theme->menuButtonPadding_ =
85                     Edge(pattern->GetAttr<Dimension>("text_overlay_menu_button_padding_left", 0.0_vp).Value(),
86                         pattern->GetAttr<Dimension>("text_overlay_menu_button_padding_top", 0.0_vp).Value(),
87                         pattern->GetAttr<Dimension>("text_overlay_menu_button_padding_right", 0.0_vp).Value(),
88                         pattern->GetAttr<Dimension>("text_overlay_menu_button_padding_bottom", 0.0_vp).Value(),
89                         pattern->GetAttr<Dimension>("text_overlay_menu_padding_left", 0.0_vp).Unit());
90                 theme->iconColor_ = pattern->GetAttr<Color>("icon_color", Color());
91                 theme->menuIconColor_ = pattern->GetAttr<Color>("memu_icon_color", Color());
92                 theme->handleColor_ = pattern->GetAttr<Color>("handle_outer_color", Color());
93                 theme->handleColorInner_ = pattern->GetAttr<Color>("handle_inner_color", Color());
94                 theme->menuBackgroundColor_ = pattern->GetAttr<Color>("menu_bg_color", Color());
95                 theme->buttonHoverColor_ = pattern->GetAttr<Color>("button_bg_color_hovered", Color());
96                 theme->buttonClickedColor_ = pattern->GetAttr<Color>("button_bg_color_clicked", Color());
97                 theme->moreOrBackIconColor_ = pattern->GetAttr<Color>("more_or_back_icon_color", Color());
98                 theme->menuButtonTextStyle_.SetTextColor(pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color()));
99                 theme->menuButtonTextStyle_.SetFontSize(pattern->GetAttr<Dimension>(PATTERN_TEXT_SIZE, 0.0_fp));
100                 theme->handleDiameter_ = pattern->GetAttr<Dimension>("handle_outer_diameter", 14.0_vp);
101                 theme->handleDiameterInner_ = pattern->GetAttr<Dimension>("handle_inner_diameter", 12.0_vp);
102                 theme->alphaDisabled_ =
103                     pattern->GetAttr<double>(PATTERN_BG_COLOR_DISABLED_ALPHA, defaultTertiaryColorAlpha);
104                 theme->cameraInput_ = pattern->GetAttr<std::string>("camera_input", "Camera input");
105                 theme->aiWrite_ = pattern->GetAttr<std::string>("ai_write_menu_name", "Celia writer");
106             } else {
107                 LOGW("find pattern of textoverlay fail");
108             }
109         }
ParseMenuPattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<TextOverlayTheme> & theme)110         void ParseMenuPattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<TextOverlayTheme>& theme) const
111         {
112             CHECK_NULL_VOID(themeStyle && theme);
113             auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>("text_overlay_pattern", nullptr);
114             CHECK_NULL_VOID(pattern);
115             theme->copyLabelInfo_ = pattern->GetAttr<std::string>("text_overlay_menu_copy", "Ctrl+C");
116             theme->pasteLabelInfo_ = pattern->GetAttr<std::string>("text_overlay_menu_paste", "Ctrl+V");
117             theme->selectAllLabelInfo_ = pattern->GetAttr<std::string>("text_overlay_menu_select_all", "Ctrl+A");
118             theme->cutLabelInfo_ = pattern->GetAttr<std::string>("text_overlay_menu_cut", "Ctrl+X");
119             theme->showShortcut_ = static_cast<bool>(pattern->GetAttr<double>("text_overlay_menu_show_shortcut", 0.0));
120         }
121     };
122 
123     ~TextOverlayTheme() override = default;
124 
GetMenuBorder()125     const Border& GetMenuBorder() const
126     {
127         return menuBorder_;
128     }
129 
GetMenuBackgroundColor()130     const Color& GetMenuBackgroundColor() const
131     {
132         return menuBackgroundColor_;
133     }
134 
GetHandleColor()135     const Color& GetHandleColor() const
136     {
137         return handleColor_;
138     }
139 
GetHandleColorInner()140     const Color& GetHandleColorInner() const
141     {
142         return handleColorInner_;
143     }
144 
GetButtonClickedColor()145     const Color& GetButtonClickedColor() const
146     {
147         return buttonClickedColor_;
148     }
149 
GetButtonHoverColor()150     const Color& GetButtonHoverColor() const
151     {
152         return buttonHoverColor_;
153     }
154 
GetIconColor()155     const Color& GetIconColor() const
156     {
157         return iconColor_;
158     }
159 
GetMenuIconColor()160     const Color& GetMenuIconColor() const
161     {
162         return menuIconColor_;
163     }
164 
GetMoreOrBackIconColor()165     const Color& GetMoreOrBackIconColor() const
166     {
167         return moreOrBackIconColor_;
168     }
169 
GetMenuPadding()170     const Edge& GetMenuPadding() const
171     {
172         return menuPadding_;
173     }
174 
GetMenuButtonPadding()175     const Edge& GetMenuButtonPadding() const
176     {
177         return menuButtonPadding_;
178     }
179 
GetHandleDiameter()180     const Dimension& GetHandleDiameter() const
181     {
182         return handleDiameter_;
183     }
184 
GetHandleDiameterStrokeWidth()185     const Dimension GetHandleDiameterStrokeWidth() const
186     {
187         return 2.0_vp;
188     }
189 
GetHandleDiameterInner()190     const Dimension& GetHandleDiameterInner() const
191     {
192         return handleDiameterInner_;
193     }
194 
GetMenuSpacingWithText()195     const Dimension& GetMenuSpacingWithText() const
196     {
197         return menuSpacingWithText_;
198     }
199 
GetMenuSafeSpacing()200     const Dimension& GetMenuSafeSpacing() const
201     {
202         return menuSafeSpacing_;
203     }
204 
GetMenuButtonWidth()205     const Dimension& GetMenuButtonWidth() const
206     {
207         return menuButtonWidth_;
208     }
209 
GetMenuButtonHeight()210     const Dimension& GetMenuButtonHeight() const
211     {
212         return menuButtonHeight_;
213     }
214 
GetMenuButtonTextStyle()215     const TextStyle& GetMenuButtonTextStyle() const
216     {
217         return menuButtonTextStyle_;
218     }
219 
GetMenuToolbarHeight()220     Dimension GetMenuToolbarHeight() const
221     {
222         return 40.0_vp;
223     }
224 
GetDefaultMenuPositionX()225     float GetDefaultMenuPositionX()
226     {
227         return Dimension(16.0_vp).ConvertToPx();
228     }
229 
GetHandleLineWidth()230     Dimension GetHandleLineWidth() const
231     {
232         return 2.0_vp;
233     }
234 
GetHandleHotZoneRadius()235     Dimension GetHandleHotZoneRadius() const
236     {
237         return handleDiameter_;
238     }
239 
GetBackResourceId()240     InternalResource::ResourceId GetBackResourceId() const
241     {
242         return backResourceId_;
243     }
244 
GetMoreResourceId()245     InternalResource::ResourceId GetMoreResourceId() const
246     {
247         return moreResourceId_;
248     }
249 
GetAlphaDisabled()250     double GetAlphaDisabled() const
251     {
252         return alphaDisabled_;
253     }
254 
GetCameraInput()255     const std::string& GetCameraInput() const
256     {
257         return cameraInput_;
258     }
259 
GetAIWrite()260     const std::string& GetAIWrite() const
261     {
262         return aiWrite_;
263     }
264 
GetCopyLabelInfo()265     const std::string& GetCopyLabelInfo() const
266     {
267         return copyLabelInfo_;
268     }
269 
GetPasteLabelInfo()270     const std::string& GetPasteLabelInfo() const
271     {
272         return pasteLabelInfo_;
273     }
274 
GetSelectAllLabelInfo()275     const std::string& GetSelectAllLabelInfo() const
276     {
277         return selectAllLabelInfo_;
278     }
279 
GetCutLabelInfo()280     const std::string& GetCutLabelInfo() const
281     {
282         return cutLabelInfo_;
283     }
284 
GetShowShortcut()285     bool GetShowShortcut() const
286     {
287         return showShortcut_;
288     }
289 protected:
290     TextOverlayTheme() = default;
291 
292 private:
293     Border menuBorder_;
294     Color iconColor_;
295     Color menuIconColor_;
296     Color menuBackgroundColor_;
297     Color handleColor_;
298     Color handleColorInner_;
299     Color buttonClickedColor_;
300     Color buttonHoverColor_;
301     Color moreOrBackIconColor_;
302     Edge menuPadding_;
303     Edge menuButtonPadding_;
304     Dimension handleDiameter_;
305     Dimension handleDiameterInner_;
306     Dimension menuSpacingWithText_;
307     Dimension menuSafeSpacing_;
308     Dimension menuButtonWidth_;
309     Dimension menuButtonHeight_;
310     TextStyle menuButtonTextStyle_;
311     double alphaDisabled_ = 0.0;
312     std::string cameraInput_;
313     std::string aiWrite_;
314     std::string copyLabelInfo_;
315     std::string pasteLabelInfo_;
316     std::string selectAllLabelInfo_;
317     std::string cutLabelInfo_;
318     bool showShortcut_ = false;
319 
320     InternalResource::ResourceId backResourceId_ = InternalResource::ResourceId::NO_ID;
321     InternalResource::ResourceId moreResourceId_ = InternalResource::ResourceId::NO_ID;
322 };
323 
324 } // namespace OHOS::Ace
325 
326 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_OVERLAY_TEXT_OVERLAY_THEME_H
327