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 theme->moreSymbolId_ = themeConstants->GetSymbolByName("sys.symbol.chevron_down"); 54 theme->backSymbolId_ = themeConstants->GetSymbolByName("sys.symbol.chevron_up"); 55 theme->cutSymbolId_ = themeConstants->GetSymbolByName("sys.symbol.cut"); 56 theme->copySymbolId_ = themeConstants->GetSymbolByName("sys.symbol.plus_square_on_square"); 57 theme->copyAllSymbolId_ = themeConstants->GetSymbolByName("sys.symbol.checkmark_square_on_square"); 58 theme->pasteSymbolId_ = themeConstants->GetSymbolByName("sys.symbol.plus_square_dashed_on_square"); 59 theme->cameraInputSymbolId_ = themeConstants->GetSymbolByName("sys.symbol.auto_camera"); 60 theme->aiWriteSymbolId_ = themeConstants->GetSymbolByName("sys.symbol.edit_badge_star"); 61 theme->searchSymbolId_ = themeConstants->GetSymbolByName("sys.symbol.magnifyingglass"); 62 theme->translateSymbolId_ = themeConstants->GetSymbolByName("sys.symbol.translate_c2e"); 63 ParsePattern(themeConstants->GetThemeStyle(), theme); 64 ParseMenuPattern(themeConstants->GetThemeStyle(), theme); 65 return theme; 66 } 67 68 private: ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<TextOverlayTheme> & theme)69 void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<TextOverlayTheme>& theme) const 70 { 71 if (!themeStyle || !theme) { 72 return; 73 } 74 auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>("text_overlay_pattern", nullptr); 75 if (pattern) { 76 const double defaultTertiaryColorAlpha = 0.4; 77 78 theme->menuBorder_ = Border(BorderEdge( 79 pattern->GetAttr<Color>("text_overlay_menu_border_color", Color()), 80 pattern->GetAttr<Dimension>("text_overlay_menu_border_width", 0.0_vp), 81 BorderStyle( 82 static_cast<int32_t>(pattern->GetAttr<double>("text_overlay_menu_border_style", 0.0))))); 83 theme->menuPadding_ = Edge(pattern->GetAttr<Dimension>("text_overlay_menu_padding_left", 0.0_vp), 84 pattern->GetAttr<Dimension>("text_overlay_menu_padding_top", 0.0_vp), 85 pattern->GetAttr<Dimension>("text_overlay_menu_padding_right", 0.0_vp), 86 pattern->GetAttr<Dimension>("text_overlay_menu_padding_bottom", 0.0_vp)); 87 theme->menuSpacingWithText_ = 88 pattern->GetAttr<Dimension>("text_overlay_menu_spacing_with_text", 0.0_vp); 89 theme->menuSafeSpacing_ = pattern->GetAttr<Dimension>("text_overlay_menu_safe_spacing", 16.0_vp); 90 theme->menuButtonWidth_ = pattern->GetAttr<Dimension>("text_overlay_menu_button_width", 0.0_vp); 91 theme->menuButtonHeight_ = pattern->GetAttr<Dimension>("text_overlay_menu_button_height", 0.0_vp); 92 theme->menuButtonTextStyle_.SetFontWeight(FontWeight( 93 static_cast<int32_t>(pattern->GetAttr<double>("text_overlay_button_text_font_weight", 0.0)))); 94 theme->menuButtonPadding_ = 95 Edge(pattern->GetAttr<Dimension>("text_overlay_menu_button_padding_left", 0.0_vp).Value(), 96 pattern->GetAttr<Dimension>("text_overlay_menu_button_padding_top", 0.0_vp).Value(), 97 pattern->GetAttr<Dimension>("text_overlay_menu_button_padding_right", 0.0_vp).Value(), 98 pattern->GetAttr<Dimension>("text_overlay_menu_button_padding_bottom", 0.0_vp).Value(), 99 pattern->GetAttr<Dimension>("text_overlay_menu_padding_left", 0.0_vp).Unit()); 100 theme->iconColor_ = pattern->GetAttr<Color>("icon_color", Color()); 101 theme->menuIconColor_ = pattern->GetAttr<Color>("memu_icon_color", Color()); 102 theme->handleColor_ = pattern->GetAttr<Color>("handle_outer_color", Color()); 103 theme->handleColorInner_ = pattern->GetAttr<Color>("handle_inner_color", Color()); 104 theme->menuBackgroundColor_ = pattern->GetAttr<Color>("menu_bg_color", Color()); 105 theme->buttonHoverColor_ = pattern->GetAttr<Color>("button_bg_color_hovered", Color()); 106 theme->buttonClickedColor_ = pattern->GetAttr<Color>("button_bg_color_clicked", Color()); 107 theme->moreOrBackIconColor_ = pattern->GetAttr<Color>("more_or_back_icon_color", Color()); 108 theme->menuButtonTextStyle_.SetTextColor(pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color())); 109 theme->menuButtonTextStyle_.SetFontSize(pattern->GetAttr<Dimension>(PATTERN_TEXT_SIZE, 0.0_fp)); 110 theme->handleDiameter_ = pattern->GetAttr<Dimension>("handle_outer_diameter", 14.0_vp); 111 theme->handleDiameterInner_ = pattern->GetAttr<Dimension>("handle_inner_diameter", 12.0_vp); 112 theme->alphaDisabled_ = 113 pattern->GetAttr<double>(PATTERN_BG_COLOR_DISABLED_ALPHA, defaultTertiaryColorAlpha); 114 theme->cameraInput_ = pattern->GetAttr<std::string>("camera_input", "Camera input"); 115 theme->aiWrite_ = pattern->GetAttr<std::string>("ai_write_menu_name", "Celia writer"); 116 theme->symbolSize_ = pattern->GetAttr<Dimension>("more_or_back_symbol_size", 24.0_vp); 117 theme->symbolColor_ = pattern->GetAttr<Color>("more_or_back_symbol_color", Color()); 118 } else { 119 LOGW("find pattern of textoverlay fail"); 120 } 121 } ParseMenuPattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<TextOverlayTheme> & theme)122 void ParseMenuPattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<TextOverlayTheme>& theme) const 123 { 124 CHECK_NULL_VOID(themeStyle && theme); 125 auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>("text_overlay_pattern", nullptr); 126 CHECK_NULL_VOID(pattern); 127 theme->copyLabelInfo_ = pattern->GetAttr<std::string>("text_overlay_menu_copy", "Ctrl+C"); 128 theme->pasteLabelInfo_ = pattern->GetAttr<std::string>("text_overlay_menu_paste", "Ctrl+V"); 129 theme->selectAllLabelInfo_ = pattern->GetAttr<std::string>("text_overlay_menu_select_all", "Ctrl+A"); 130 theme->cutLabelInfo_ = pattern->GetAttr<std::string>("text_overlay_menu_cut", "Ctrl+X"); 131 theme->showShortcut_ = static_cast<bool>(pattern->GetAttr<double>("text_overlay_menu_show_shortcut", 0.0)); 132 theme->enableSelectionMenu_ = static_cast<bool>(pattern->GetAttr<double>("text_overlay_menu_enable", 1.0)); 133 } 134 }; 135 136 ~TextOverlayTheme() override = default; 137 GetMenuBorder()138 const Border& GetMenuBorder() const 139 { 140 return menuBorder_; 141 } 142 GetMenuBackgroundColor()143 const Color& GetMenuBackgroundColor() const 144 { 145 return menuBackgroundColor_; 146 } 147 GetHandleColor()148 const Color& GetHandleColor() const 149 { 150 return handleColor_; 151 } 152 GetHandleColorInner()153 const Color& GetHandleColorInner() const 154 { 155 return handleColorInner_; 156 } 157 GetButtonClickedColor()158 const Color& GetButtonClickedColor() const 159 { 160 return buttonClickedColor_; 161 } 162 GetButtonHoverColor()163 const Color& GetButtonHoverColor() const 164 { 165 return buttonHoverColor_; 166 } 167 GetIconColor()168 const Color& GetIconColor() const 169 { 170 return iconColor_; 171 } 172 GetMenuIconColor()173 const Color& GetMenuIconColor() const 174 { 175 return menuIconColor_; 176 } 177 GetMoreOrBackIconColor()178 const Color& GetMoreOrBackIconColor() const 179 { 180 return moreOrBackIconColor_; 181 } 182 GetMenuPadding()183 const Edge& GetMenuPadding() const 184 { 185 return menuPadding_; 186 } 187 GetMenuButtonPadding()188 const Edge& GetMenuButtonPadding() const 189 { 190 return menuButtonPadding_; 191 } 192 GetHandleDiameter()193 const Dimension& GetHandleDiameter() const 194 { 195 return handleDiameter_; 196 } 197 GetHandleDiameterStrokeWidth()198 const Dimension GetHandleDiameterStrokeWidth() const 199 { 200 return 2.0_vp; 201 } 202 GetHandleDiameterInner()203 const Dimension& GetHandleDiameterInner() const 204 { 205 return handleDiameterInner_; 206 } 207 GetMenuSpacingWithText()208 const Dimension& GetMenuSpacingWithText() const 209 { 210 return menuSpacingWithText_; 211 } 212 GetMenuSafeSpacing()213 const Dimension& GetMenuSafeSpacing() const 214 { 215 return menuSafeSpacing_; 216 } 217 GetMenuButtonWidth()218 const Dimension& GetMenuButtonWidth() const 219 { 220 return menuButtonWidth_; 221 } 222 GetMenuButtonHeight()223 const Dimension& GetMenuButtonHeight() const 224 { 225 return menuButtonHeight_; 226 } 227 GetMenuButtonTextStyle()228 const TextStyle& GetMenuButtonTextStyle() const 229 { 230 return menuButtonTextStyle_; 231 } 232 GetMenuToolbarHeight()233 Dimension GetMenuToolbarHeight() const 234 { 235 return 40.0_vp; 236 } 237 GetDefaultMenuPositionX()238 float GetDefaultMenuPositionX() 239 { 240 return Dimension(16.0_vp).ConvertToPx(); 241 } 242 GetHandleLineWidth()243 Dimension GetHandleLineWidth() const 244 { 245 return 2.0_vp; 246 } 247 GetHandleHotZoneRadius()248 Dimension GetHandleHotZoneRadius() const 249 { 250 return handleDiameter_; 251 } 252 GetBackResourceId()253 InternalResource::ResourceId GetBackResourceId() const 254 { 255 return backResourceId_; 256 } 257 GetMoreResourceId()258 InternalResource::ResourceId GetMoreResourceId() const 259 { 260 return moreResourceId_; 261 } 262 GetAlphaDisabled()263 double GetAlphaDisabled() const 264 { 265 return alphaDisabled_; 266 } 267 GetCameraInput()268 const std::string& GetCameraInput() const 269 { 270 return cameraInput_; 271 } 272 GetAIWrite()273 const std::string& GetAIWrite() const 274 { 275 return aiWrite_; 276 } 277 GetCopyLabelInfo()278 const std::string& GetCopyLabelInfo() const 279 { 280 return copyLabelInfo_; 281 } 282 GetPasteLabelInfo()283 const std::string& GetPasteLabelInfo() const 284 { 285 return pasteLabelInfo_; 286 } 287 GetSelectAllLabelInfo()288 const std::string& GetSelectAllLabelInfo() const 289 { 290 return selectAllLabelInfo_; 291 } 292 GetCutLabelInfo()293 const std::string& GetCutLabelInfo() const 294 { 295 return cutLabelInfo_; 296 } 297 GetShowShortcut()298 bool GetShowShortcut() const 299 { 300 return showShortcut_; 301 } 302 GetMoreSymbolId()303 const uint32_t& GetMoreSymbolId() const 304 { 305 return moreSymbolId_; 306 } 307 GetBackSymbolId()308 const uint32_t& GetBackSymbolId() const 309 { 310 return backSymbolId_; 311 } 312 GetCutSymbolId()313 const uint32_t& GetCutSymbolId() const 314 { 315 return cutSymbolId_; 316 } 317 GetCopySymbolId()318 const uint32_t& GetCopySymbolId() const 319 { 320 return copySymbolId_; 321 } 322 GetCopyAllSymbolId()323 const uint32_t& GetCopyAllSymbolId() const 324 { 325 return copyAllSymbolId_; 326 } 327 GetPasteSymbolId()328 const uint32_t& GetPasteSymbolId() const 329 { 330 return pasteSymbolId_; 331 } 332 GetCameraInputSymbolId()333 const uint32_t& GetCameraInputSymbolId() const 334 { 335 return cameraInputSymbolId_; 336 } 337 GetAIWriteSymbolId()338 const uint32_t& GetAIWriteSymbolId() const 339 { 340 return aiWriteSymbolId_; 341 } 342 GetSearchSymbolId()343 const uint32_t& GetSearchSymbolId() const 344 { 345 return searchSymbolId_; 346 } 347 GetTranslateSymbolId()348 const uint32_t& GetTranslateSymbolId() const 349 { 350 return translateSymbolId_; 351 } 352 GetSymbolSize()353 const Dimension& GetSymbolSize() const 354 { 355 return symbolSize_; 356 } 357 GetSymbolColor()358 const Color& GetSymbolColor() const 359 { 360 return symbolColor_; 361 } 362 GetEnableSelectionMenu()363 bool GetEnableSelectionMenu() const 364 { 365 return enableSelectionMenu_; 366 } 367 368 protected: 369 TextOverlayTheme() = default; 370 371 private: 372 Border menuBorder_; 373 Color iconColor_; 374 Color menuIconColor_; 375 Color menuBackgroundColor_; 376 Color handleColor_; 377 Color handleColorInner_; 378 Color buttonClickedColor_; 379 Color buttonHoverColor_; 380 Color moreOrBackIconColor_; 381 Edge menuPadding_; 382 Edge menuButtonPadding_; 383 Dimension handleDiameter_; 384 Dimension handleDiameterInner_; 385 Dimension menuSpacingWithText_; 386 Dimension menuSafeSpacing_; 387 Dimension menuButtonWidth_; 388 Dimension menuButtonHeight_; 389 TextStyle menuButtonTextStyle_; 390 double alphaDisabled_ = 0.0; 391 std::string cameraInput_; 392 std::string aiWrite_; 393 std::string copyLabelInfo_; 394 std::string pasteLabelInfo_; 395 std::string selectAllLabelInfo_; 396 std::string cutLabelInfo_; 397 bool showShortcut_ = false; 398 bool enableSelectionMenu_ = true; 399 400 InternalResource::ResourceId backResourceId_ = InternalResource::ResourceId::NO_ID; 401 InternalResource::ResourceId moreResourceId_ = InternalResource::ResourceId::NO_ID; 402 403 Dimension symbolSize_; 404 Color symbolColor_; 405 uint32_t moreSymbolId_ = 0; 406 uint32_t backSymbolId_ = 0; 407 uint32_t cutSymbolId_ = 0; 408 uint32_t copySymbolId_ = 0; 409 uint32_t copyAllSymbolId_ = 0; 410 uint32_t pasteSymbolId_ = 0; 411 uint32_t cameraInputSymbolId_ = 0; 412 uint32_t aiWriteSymbolId_ = 0; 413 uint32_t searchSymbolId_ = 0; 414 uint32_t translateSymbolId_ = 0; 415 }; 416 417 } // namespace OHOS::Ace 418 419 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_OVERLAY_TEXT_OVERLAY_THEME_H 420