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_FIELD_TEXTFIELD_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_FIELD_TEXTFIELD_THEME_H 18 19 #include "base/geometry/dimension.h" 20 #include "core/components/common/properties/border.h" 21 #include "core/components/common/properties/color.h" 22 #include "core/components/common/properties/edge.h" 23 #include "core/components/common/properties/radius.h" 24 #include "core/components/swiper/render_swiper.h" 25 #include "core/components/theme/theme.h" 26 #include "core/components/theme/theme_constants.h" 27 #include "core/components/theme/theme_constants_defines.h" 28 #include "core/components_ng/pattern/text_field/text_field_model.h" 29 30 namespace OHOS::Ace { 31 32 /** 33 * TextFieldTheme defines color and styles of SliderComponent. TextFieldTheme should be built 34 * using TextFieldTheme::Builder. 35 */ 36 class TextFieldTheme : public virtual Theme { 37 DECLARE_ACE_TYPE(TextFieldTheme, Theme); 38 39 public: 40 class Builder { 41 public: 42 Builder() = default; 43 ~Builder() = default; 44 Build(const RefPtr<ThemeConstants> & themeConstants)45 RefPtr<TextFieldTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 46 { 47 RefPtr<TextFieldTheme> theme = AceType::Claim(new TextFieldTheme()); 48 if (!themeConstants) { 49 return theme; 50 } 51 ParsePattern(themeConstants, theme); 52 return theme; 53 } 54 55 protected: ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<TextFieldTheme> & theme)56 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<TextFieldTheme>& theme) const 57 { 58 theme->height_ = themeConstants->GetDimension(THEME_TEXTFIELD_HEIGHT); 59 theme->showSymbolId_ = themeConstants->GetSymbolByName("sys.symbol.eye"); 60 theme->hideSymbolId_ = themeConstants->GetSymbolByName("sys.symbol.eye_slash"); 61 theme->cancelSymbolId_ = themeConstants->GetSymbolByName("sys.symbol.xmark"); 62 auto themeStyle = themeConstants->GetThemeStyle(); 63 if (!themeStyle || !theme) { 64 return; 65 } 66 auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>("textfield_pattern", nullptr); 67 if (!pattern) { 68 LOGW("find pattern of textfield fail"); 69 return; 70 } 71 ParsePatternSubFirstPart(pattern, theme); 72 ParsePatternSubSecondPart(pattern, theme); 73 ParsePatternSubThirdPart(pattern, theme); 74 ParsePatternSubFourthPart(pattern, theme); 75 } 76 private: ParsePatternSubFirstPart(const RefPtr<ThemeStyle> & pattern,const RefPtr<TextFieldTheme> & theme)77 void ParsePatternSubFirstPart(const RefPtr<ThemeStyle>& pattern, const RefPtr<TextFieldTheme>& theme) const 78 { 79 theme->padding_ = Edge(pattern->GetAttr<Dimension>("textfield_padding_horizontal", 0.0_vp), 80 pattern->GetAttr<Dimension>("textfield_padding_vertical", 0.0_vp), 81 pattern->GetAttr<Dimension>("textfield_padding_horizontal", 0.0_vp), 82 pattern->GetAttr<Dimension>("textfield_padding_vertical", 0.0_vp)); 83 theme->underlinePadding_ = 84 Edge(pattern->GetAttr<Dimension>("textfield_underline_padding_horizontal", 0.0_vp), 85 pattern->GetAttr<Dimension>("textfield_underline_padding_vertical", 12.0_vp), 86 pattern->GetAttr<Dimension>("textfield_underline_padding_horizontal", 0.0_vp), 87 pattern->GetAttr<Dimension>("textfield_underline_padding_vertical", 12.0_vp)); 88 theme->fontWeight_ = 89 FontWeight(static_cast<int32_t>(pattern->GetAttr<double>("textfield_font_weight", 0.0))); 90 theme->borderRadius_ = Radius(pattern->GetAttr<Dimension>("textfield_border_radius", 0.0_vp)); 91 theme->disableOpacityRatio_ = pattern->GetAttr<double>("textfield_disable_opacity_ratio", 0.0); 92 theme->overHideLength_ = pattern->GetAttr<Dimension>("textfield_over_hide_length", 0.0_vp); 93 theme->cursorRadius_ = pattern->GetAttr<Dimension>("textfield_cursor_radius", 0.0_vp); 94 theme->needFade_ = static_cast<bool>(pattern->GetAttr<double>("textfield_need_fade", 0.0)); 95 theme->iconSize_ = pattern->GetAttr<Dimension>("textfield_icon_size", 0.0_vp); 96 theme->iconHotZoneSize_ = pattern->GetAttr<Dimension>("textfield_icon_hot_zone_size", 0.0_vp); 97 theme->symbolSize_ = pattern->GetAttr<Dimension>("textfield_icon_size", 0.0_vp); 98 theme->symbolColor_ = pattern->GetAttr<Color>("textfield_symbol_color", Color()); 99 theme->showEllipsis_ = static_cast<bool>(pattern->GetAttr<double>("textfield_show_ellipsis", 0.0)); 100 theme->errorSpacing_ = pattern->GetAttr<Dimension>("textfield_error_spacing", 0.0_vp); 101 theme->errorIsInner_ = static_cast<bool>(pattern->GetAttr<double>("textfield_error_is_inner", 0.0)); 102 theme->errorBorderWidth_ = pattern->GetAttr<Dimension>("textfield_error_border_width", 0.0_vp); 103 theme->errorTextStyle_.SetFontWeight( 104 FontWeight(static_cast<int32_t>(pattern->GetAttr<double>("textfield_error_font_weight", 0.0)))); 105 theme->countTextStyle_.SetFontWeight( 106 FontWeight(static_cast<int32_t>(pattern->GetAttr<double>("textfield_count_font_weight", 0.0)))); 107 theme->overCountStyle_.SetFontWeight( 108 FontWeight(static_cast<int32_t>(pattern->GetAttr<double>("textfield_over_count_font_weight", 0.0)))); 109 theme->countTextStyleOuter_.SetFontWeight( 110 FontWeight(static_cast<int32_t>(pattern->GetAttr<double>("textfield_count_font_weight", 0.0)))); 111 theme->overCountStyleOuter_.SetFontWeight( 112 FontWeight(static_cast<int32_t>(pattern->GetAttr<double>("textfield_over_count_font_weight", 0.0)))); 113 theme->fontSize_ = pattern->GetAttr<Dimension>(PATTERN_TEXT_SIZE, 0.0_fp); 114 theme->textColor_ = pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color()); 115 theme->focusTextColor_ = pattern->GetAttr<Color>(PATTERN_TEXT_COLOR_FOCUSED, Color()); 116 theme->placeholderColor_ = pattern->GetAttr<Color>("tips_text_color", Color()); 117 theme->focusPlaceholderColor_ = pattern->GetAttr<Color>("tips_text_color_focused", Color()); 118 theme->bgColor_ = pattern->GetAttr<Color>(PATTERN_BG_COLOR, Color()); 119 theme->focusBgColor_ = pattern->GetAttr<Color>(PATTERN_BG_COLOR_FOCUSED, Color()); 120 theme->glassOutlinePrimaryColor_ = 121 pattern->GetAttr<Color>("glass_material_outline_primary", Color(0xffffff)); 122 theme->glassOutlineSecondaryColor_ = 123 pattern->GetAttr<Color>("glass_material_outline_secondary", Color(0xf0f0f0)); 124 theme->glassMaskPrimaryColor_ = pattern->GetAttr<Color>("glass_material_mask_primary", Color(0x00808080)); 125 theme->glassMaskSecondaryColor_ = 126 pattern->GetAttr<Color>("glass_material_mask_secondary", Color(0x26808080)); 127 } 128 ParsePatternSubSecondPart(const RefPtr<ThemeStyle> & pattern,const RefPtr<TextFieldTheme> & theme)129 void ParsePatternSubSecondPart(const RefPtr<ThemeStyle>& pattern, const RefPtr<TextFieldTheme>& theme) const 130 { 131 const double defaultErrorAlpha = 0.6; 132 const double defaultUnderlineAlpha = 0.6; 133 const double defaultDisableUnderlineAlpha = 0.4; 134 const Color defaultUnderlineColor = Color(0x33182431); 135 const Color defaultUnderlineTextColor = Color(0x99182431); 136 const Color defaultCounterColor = Color(0x66182431); 137 const Color overCounterColor = Color(0x99FA2A2D); 138 // color of error border blend 60% opacity 139 theme->errorBorderColor_ = 140 pattern->GetAttr<Color>("error_text_border_color", Color()) 141 .BlendOpacity(pattern->GetAttr<double>("error_text_border_color_alpha", defaultErrorAlpha)); 142 theme->errorUnderlineColor_ = pattern->GetAttr<Color>(ERROR_UNDERLINE_COLOR, Color()); 143 theme->underlineColor_ = pattern->GetAttr<Color>(UNDERLINE_COLOR, defaultUnderlineColor); 144 theme->disableUnderlineColor_ = 145 pattern->GetAttr<Color>(UNDERLINE_COLOR, defaultUnderlineColor) 146 .BlendOpacity(pattern->GetAttr<double>(DISABLE_UNDERLINE_ALPHA, defaultDisableUnderlineAlpha)); 147 theme->underlineTextColor_ = pattern->GetAttr<Color>(UNDERLINE_TEXT_COLOR, defaultUnderlineTextColor); 148 theme->defaultCounterColor_ = pattern->GetAttr<Color>(DEFAULT_COUNTER_COLOR, defaultCounterColor); 149 theme->overCounterColor_ = pattern->GetAttr<Color>(OVER_COUNTER_COLOR, overCounterColor); 150 theme->underlineFontSize_ = pattern->GetAttr<Dimension>(UNDERLINE_FONT_SIZE, 0.0_fp); 151 theme->errorTextStyle_.SetTextColor(pattern->GetAttr<Color>(ERROR_UNDERLINE_TEXT_COLOR, Color())); 152 theme->errorTextStyle_.SetFontSize(pattern->GetAttr<Dimension>(ERROR_UNDERLINE_TEXT_SIZE, 0.0_fp)); 153 theme->errorTextAlign_ = 154 static_cast<bool>(pattern->GetAttr<double>("textfield_error_text_align", 0.0)); 155 156 theme->countTextStyle_.SetTextColor(pattern->GetAttr<Color>("count_text_color", Color())); 157 theme->countTextStyle_.SetFontSize(pattern->GetAttr<Dimension>("count_text_font_size", 0.0_fp)); 158 theme->overCountStyle_.SetTextColor(pattern->GetAttr<Color>("over_text_color", Color())); 159 theme->overCountStyle_.SetFontSize(pattern->GetAttr<Dimension>("over_text_font_size", 0.0_fp)); 160 161 theme->countTextStyleOuter_.SetTextColor(pattern->GetAttr<Color>("count_outer_text_color", Color())); 162 theme->countTextStyleOuter_.SetFontSize(pattern->GetAttr<Dimension>("count_outer_text_font_size", 0.0_fp)); 163 theme->overCountStyleOuter_.SetTextColor(pattern->GetAttr<Color>("over_outer_text_color", Color())); 164 theme->overCountStyleOuter_.SetFontSize(pattern->GetAttr<Dimension>("over_outer_text_font_size", 0.0_fp)); 165 theme->overCountTextStyle_.SetTextColor(pattern->GetAttr<Color>(OVER_COUNT_TEXT_COLOR, Color())); 166 theme->overCountTextStyle_.SetFontSize(pattern->GetAttr<Dimension>(OVER_COUNT_TEXT_FONT_SIZE, 0.0_fp)); 167 theme->selectedColor_ = pattern->GetAttr<Color>(PATTERN_BG_COLOR_SELECTED, Color()); 168 theme->disableTextColor_ = pattern->GetAttr<Color>(PATTERN_TEXT_COLOR_DISABLED, Color()); 169 theme->underlineActivedColor_ = 170 pattern->GetAttr<Color>(PATTERN_UNDERLINE_ACTIVED_COLOR, Color()) 171 .BlendOpacity(pattern->GetAttr<double>(UNDERLINE_COLOR_ALPHA, defaultUnderlineAlpha)); 172 theme->underlineTypingColor_ = 173 pattern->GetAttr<Color>(PATTERN_UNDERLINE_TYPING_COLOR, Color()) 174 .BlendOpacity(pattern->GetAttr<double>(UNDERLINE_COLOR_ALPHA, defaultUnderlineAlpha)); 175 } 176 ParsePatternSubThirdPart(const RefPtr<ThemeStyle> & pattern,const RefPtr<TextFieldTheme> & theme)177 void ParsePatternSubThirdPart(const RefPtr<ThemeStyle>& pattern, const RefPtr<TextFieldTheme>& theme) const 178 { 179 const double defaultErrorAlpha = 0.6; 180 theme->textColorDisable_ = pattern->GetAttr<Color>(PATTERN_DISABLED_TEXT_COLOR, Color()); 181 theme->cursorColor_ = pattern->GetAttr<Color>("cursor_color", Color()); 182 theme->cursorWidth_ = pattern->GetAttr<Dimension>("cursor_width", 2.0_vp); 183 theme->hoverColor_ = pattern->GetAttr<Color>(PATTERN_BG_COLOR_HOVERED, Color()); 184 theme->pressColor_ = pattern->GetAttr<Color>(PATTERN_BG_COLOR_PRESSED, Color()); 185 theme->borderRadiusSize_ = Radius(pattern->GetAttr<Dimension>(BORDER_RADIUS_SIZE, 20.0_vp)); 186 theme->disabledIconFillColor_ = theme->bgColor_.BlendOpacity(theme->disableOpacityRatio_); 187 theme->passwordErrorTextColor_ = pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color()); 188 theme->passwordErrorInputColor_ = pattern->GetAttr<Color>(ERROR_PASSWORD_INPUT_COLOR, Color()); 189 theme->passwordErrorBorderColor_ = 190 pattern->GetAttr<Color>(ERROR_PASSWORD_BORDER_COLOR, Color()) 191 .BlendOpacity(pattern->GetAttr<double>(ERROR_PASSWORD_BORDER_ALPHA, defaultErrorAlpha)); 192 theme->passwordErrorLableColor_ = pattern->GetAttr<Color>(ERROR_PASSWORD_TEXT_COLOR, Color()); 193 theme->overCountBorderColor_ = 194 pattern->GetAttr<Color>(OVER_COUNT_BORDER_COLOR, Color()) 195 .BlendOpacity(pattern->GetAttr<double>(OVER_COUNT_BORDER_COLOR_ALPHA, defaultErrorAlpha)); 196 theme->inlineTextColor_ = pattern->GetAttr<Color>(INLINE_TEXT_COLOR, Color()); 197 theme->inlineRadiusSize_ = Radius(pattern->GetAttr<Dimension>(INLINE_RADIUS_SIZE, 4.0_vp)); 198 theme->inlineBgColor_ = pattern->GetAttr<Color>(INLINE_BG_COLOR, Color()); 199 theme->inlineBorderColor_ = pattern->GetAttr<Color>(INLINE_BORDER_COLOR, Color()); 200 auto draggable = pattern->GetAttr<std::string>("draggable", "0"); 201 theme->draggable_ = StringUtils::StringToInt(draggable); 202 theme->height_ = pattern->GetAttr<Dimension>("textinput_default_height", 24.0_vp); 203 theme->contentHeight_ = pattern->GetAttr<Dimension>("textfield_content_height", 0.0_vp); 204 auto showPasswordDirectly = pattern->GetAttr<std::string>("show_password_directly", "0"); 205 theme->showPasswordDirectly_ = StringUtils::StringToInt(showPasswordDirectly); 206 auto textfieldShowHandle = pattern->GetAttr<std::string>("textfield_show_handle", "0"); 207 theme->textfieldShowHandle_ = StringUtils::StringToInt(textfieldShowHandle); 208 209 theme->cancelButtonIconColor_ = pattern->GetAttr<Color>("textfield_symbol_color", Color()); 210 theme->previewUnderlineColor_ = pattern->GetAttr<Color>(PREVIEW_UNDERLINE_COLOR, Color()); 211 theme->previewBoardColor_ = pattern->GetAttr<Color>(PREVIEW_BOARD_COLOR, Color()); 212 213 theme->placeholderLineSpacing_ = pattern->GetAttr<Dimension>("text_field_placeholder_linespacing", 0.0_vp); 214 215 theme->cancelButton_ = pattern->GetAttr<std::string>("textfield_accessibility_clear", ""); 216 theme->cancelImageText_ = pattern->GetAttr<std::string>("textfield_accessibility_property_clear", ""); 217 theme->showPassword_ = pattern->GetAttr<std::string>("textfield_show_password_button", ""); 218 theme->hidePassword_ = pattern->GetAttr<std::string>("textfield_hide_password_button", ""); 219 theme->hasShowedPassword_ = pattern->GetAttr<std::string>("textfield_has_showed_password", ""); 220 theme->hasHiddenPassword_ = pattern->GetAttr<std::string>("textfield_has_hidden_password", ""); 221 theme->aiWriteBundleName_ = pattern->GetAttr<std::string>("textfield_writting_bundle_name", ""); 222 theme->aiWriteAbilityName_ = pattern->GetAttr<std::string>("textfield_writting_ability_name", ""); 223 theme->aiWriteIsSupport_ = pattern->GetAttr<std::string>("textfield_writting_is_support", ""); 224 225 theme->inlinePaddingLeft_ = pattern->GetAttr<Dimension>("inline_padding_left", 2.0_vp); 226 theme->inlinePaddingRight_ = pattern->GetAttr<Dimension>("inline_padding_right", 12.0_vp); 227 auto supportTranslate = pattern->GetAttr<std::string>("menu_translate_is_support", "0"); 228 theme->translateIsSupport_ = StringUtils::StringToInt(supportTranslate); 229 auto supportSearch = pattern->GetAttr<std::string>("textfield_menu_search_is_support", "0"); 230 theme->supportSearch_ = StringUtils::StringToInt(supportSearch); 231 } 232 ParsePatternSubFourthPart(const RefPtr<ThemeStyle> & pattern,const RefPtr<TextFieldTheme> & theme)233 void ParsePatternSubFourthPart(const RefPtr<ThemeStyle>& pattern, const RefPtr<TextFieldTheme>& theme) const 234 { 235 std::string isTextFadeout = pattern->GetAttr<std::string>("text_fadeout_enable", ""); 236 theme->textFadeoutEnabled_ = isTextFadeout == "true"; 237 theme->textInputBorderColor_ = pattern->GetAttr<Color>("text_input_border_color", Color()); 238 theme->textInputBorderWidth_ = pattern->GetAttr<Dimension>("text_input_border_width", 0.0_vp); 239 theme->errorTextInputBorderWidth_ = pattern->GetAttr<Dimension>("error_text_input_border_width", 1.0_vp); 240 theme->showPasswordIcon_ = static_cast<bool>(pattern->GetAttr<double>("show_icon_text_input", 1.0)); 241 theme->hoverAndPressBgColorEnabled_ = 242 static_cast<uint32_t>(pattern->GetAttr<int>("textfield_hover_press_bg_color_enabled", 0)); 243 theme->needFocusBox_ = static_cast<bool>(pattern->GetAttr<double>("text_input_need_focus_box", 0.0)); 244 theme->focusPadding_ = pattern->GetAttr<Dimension>("text_input_focus_padding", 0.0_vp); 245 theme->independentControlKeyboard_ = 246 static_cast<bool>(pattern->GetAttr<double>("independent_control_keyboard", 0.0)); 247 theme->directionKeysMoveFocusOut_ = 248 static_cast<bool>(pattern->GetAttr<double>("direction_keys_move_focus_out", 0.0)); 249 theme->cancelIconSize_ = pattern->GetAttr<Dimension>("textfield_icon_size", 0.0_vp); 250 if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) { 251 theme->cancelIconSize_ = pattern->GetAttr<Dimension>("textfield_cancel_icon_size", 16.0_vp); 252 } 253 } 254 }; 255 256 ~TextFieldTheme() override = default; 257 GetPadding()258 const Edge& GetPadding() const 259 { 260 return padding_; 261 } 262 GetUnderlinePadding()263 const Edge& GetUnderlinePadding() const 264 { 265 return underlinePadding_; 266 } 267 GetHeight()268 const Dimension& GetHeight() const 269 { 270 return height_; 271 } 272 GetContentHeight()273 const Dimension& GetContentHeight() const 274 { 275 return contentHeight_; 276 } 277 GetFontSize()278 const Dimension& GetFontSize() const 279 { 280 return fontSize_; 281 } 282 GetUnderlineFontSize()283 const Dimension& GetUnderlineFontSize() const 284 { 285 return underlineFontSize_; 286 } 287 GetFontWeight()288 const FontWeight& GetFontWeight() const 289 { 290 return fontWeight_; 291 } 292 GetBorderRadius()293 const Radius& GetBorderRadius() const 294 { 295 return borderRadius_; 296 } 297 GetBgColor()298 const Color& GetBgColor() const 299 { 300 return bgColor_; 301 } 302 GetPlaceholderColor()303 const Color& GetPlaceholderColor() const 304 { 305 return placeholderColor_; 306 } 307 GetFocusBgColor()308 const Color& GetFocusBgColor() const 309 { 310 return focusBgColor_; 311 } 312 GetFocusPlaceholderColor()313 const Color& GetFocusPlaceholderColor() const 314 { 315 return focusPlaceholderColor_; 316 } 317 GetFocusTextColor()318 const Color& GetFocusTextColor() const 319 { 320 return focusTextColor_; 321 } 322 GetTextColor()323 const Color& GetTextColor() const 324 { 325 return textColor_; 326 } 327 GetDisableTextColor()328 const Color& GetDisableTextColor() const 329 { 330 return disableTextColor_; 331 } 332 GetTextColorDisable()333 const Color& GetTextColorDisable() const 334 { 335 return textColorDisable_; 336 } 337 GetUnderlineActivedColor()338 const Color& GetUnderlineActivedColor() const 339 { 340 return underlineActivedColor_; 341 } 342 GetUnderlineTypingColor()343 const Color& GetUnderlineTypingColor() const 344 { 345 return underlineTypingColor_; 346 } 347 GetSelectedColor()348 const Color& GetSelectedColor() const 349 { 350 return selectedColor_; 351 } 352 GetHoverColor()353 const Color& GetHoverColor() const 354 { 355 return hoverColor_; 356 } 357 GetPressColor()358 const Color& GetPressColor() const 359 { 360 return pressColor_; 361 } 362 GetBorderRadiusSize()363 const Radius& GetBorderRadiusSize() const 364 { 365 return borderRadiusSize_; 366 } 367 GetDisableOpacityRatio()368 double GetDisableOpacityRatio() const 369 { 370 return disableOpacityRatio_; 371 } 372 GetDisabledIconFillColor()373 const Color& GetDisabledIconFillColor() const 374 { 375 return disabledIconFillColor_; 376 } 377 GetOverHideLength()378 const Dimension& GetOverHideLength() const 379 { 380 return overHideLength_; 381 } 382 GetCursorColor()383 const Color& GetCursorColor() const 384 { 385 return cursorColor_; 386 } 387 GetCursorRadius()388 const Dimension& GetCursorRadius() const 389 { 390 return cursorRadius_; 391 } 392 GetCursorWidth()393 const Dimension& GetCursorWidth() const 394 { 395 return cursorWidth_; 396 } 397 NeedFade()398 bool NeedFade() const 399 { 400 return needFade_; 401 } 402 GetIconSize()403 const Dimension& GetIconSize() const 404 { 405 return iconSize_; 406 } 407 GetCancelIconSize()408 const Dimension& GetCancelIconSize() const 409 { 410 return cancelIconSize_; 411 } 412 GetPasswordIconSize()413 const Dimension& GetPasswordIconSize() const 414 { 415 return passwordIconSize_; 416 } 417 GetCancelIconPadding()418 const Dimension& GetCancelIconPadding() const 419 { 420 return cancelIconPadding_; 421 } 422 GetPasswordIconPadding()423 const Dimension& GetPasswordIconPadding() const 424 { 425 return passwordIconPadding_; 426 } 427 GetIconHotZoneSize()428 const Dimension& GetIconHotZoneSize() const 429 { 430 return iconHotZoneSize_; 431 } 432 GetSymbolSize()433 const Dimension& GetSymbolSize() const 434 { 435 return symbolSize_; 436 } 437 GetSymbolColor()438 const Color& GetSymbolColor() const 439 { 440 return symbolColor_; 441 } 442 GetShowSymbolId()443 uint32_t GetShowSymbolId() const 444 { 445 return showSymbolId_; 446 } 447 GetHideSymbolId()448 uint32_t GetHideSymbolId() const 449 { 450 return hideSymbolId_; 451 } 452 GetCancelSymbolId()453 uint32_t GetCancelSymbolId() const 454 { 455 return cancelSymbolId_; 456 } 457 ShowEllipsis()458 bool ShowEllipsis() const 459 { 460 return showEllipsis_; 461 } 462 GetErrorSpacing()463 const Dimension& GetErrorSpacing() const 464 { 465 return errorSpacing_; 466 } 467 GetErrorIsInner()468 bool GetErrorIsInner() const 469 { 470 return errorIsInner_; 471 } 472 GetIndependentControlKeyboard()473 bool GetIndependentControlKeyboard() const 474 { 475 return independentControlKeyboard_; 476 } 477 GetDirectionKeysMoveFocusOut()478 bool GetDirectionKeysMoveFocusOut() const 479 { 480 return directionKeysMoveFocusOut_; 481 } 482 GetErrorBorderWidth()483 const Dimension& GetErrorBorderWidth() const 484 { 485 return errorBorderWidth_; 486 } 487 GetErrorBorderColor()488 const Color& GetErrorBorderColor() const 489 { 490 return errorBorderColor_; 491 } 492 GetErrorUnderlineColor()493 const Color& GetErrorUnderlineColor() const 494 { 495 return errorUnderlineColor_; 496 } 497 GetUnderlineColor()498 const Color& GetUnderlineColor() const 499 { 500 return underlineColor_; 501 } 502 GetDisableUnderlineColor()503 const Color& GetDisableUnderlineColor() const 504 { 505 return disableUnderlineColor_; 506 } 507 GetUnderlineTextColor()508 const Color& GetUnderlineTextColor() const 509 { 510 return underlineTextColor_; 511 } 512 GetOverCountBorderColor()513 const Color& GetOverCountBorderColor() const 514 { 515 return overCountBorderColor_; 516 } 517 GetTextStyle()518 TextStyle GetTextStyle() const 519 { 520 return textStyle_; 521 } 522 GetErrorTextStyle()523 const TextStyle& GetErrorTextStyle() const 524 { 525 return errorTextStyle_; 526 } 527 GetCountTextStyle()528 const TextStyle& GetCountTextStyle() const 529 { 530 return countTextStyle_; 531 } 532 GetOverCountStyle()533 const TextStyle& GetOverCountStyle() const 534 { 535 return overCountStyle_; 536 } 537 GetCountTextStyleOuter()538 const TextStyle& GetCountTextStyleOuter() const 539 { 540 return countTextStyleOuter_; 541 } 542 GetOverCountStyleOuter()543 const TextStyle& GetOverCountStyleOuter() const 544 { 545 return overCountStyleOuter_; 546 } 547 GetPasswordErrorTextColor()548 const Color& GetPasswordErrorTextColor() const 549 { 550 return passwordErrorTextColor_; 551 } 552 GetPasswordErrorInputColor()553 const Color& GetPasswordErrorInputColor() const 554 { 555 return passwordErrorInputColor_; 556 } 557 GetPasswordErrorBorderColor()558 const Color& GetPasswordErrorBorderColor() const 559 { 560 return passwordErrorBorderColor_; 561 } 562 GetPasswordErrorLableColor()563 const Color& GetPasswordErrorLableColor() const 564 { 565 return passwordErrorLableColor_; 566 } 567 GetOverCountTextStyle()568 const TextStyle& GetOverCountTextStyle() const 569 { 570 return overCountTextStyle_; 571 } 572 GetInlineTextColor()573 const Color& GetInlineTextColor() const 574 { 575 return inlineTextColor_; 576 } 577 GetInlineRadiusSize()578 const Radius& GetInlineRadiusSize() const 579 { 580 return inlineRadiusSize_; 581 } 582 GetInlineBgColor()583 const Color& GetInlineBgColor() const 584 { 585 return inlineBgColor_; 586 } 587 GetInlineBorderColor()588 const Color& GetInlineBorderColor() const 589 { 590 return inlineBorderColor_; 591 } 592 GetInlineBorderWidth()593 const Dimension& GetInlineBorderWidth() const 594 { 595 return inlineBorderWidth_; 596 } 597 GetDraggable()598 bool GetDraggable() const 599 { 600 return draggable_; 601 } 602 GetDefaultCounterColor()603 const Color& GetDefaultCounterColor() const 604 { 605 return defaultCounterColor_; 606 } 607 GetOverCounterColor()608 const Color& GetOverCounterColor() const 609 { 610 return overCounterColor_; 611 } 612 GetGlassOutlinePrimaryColor()613 const Color& GetGlassOutlinePrimaryColor() const 614 { 615 return glassOutlinePrimaryColor_; 616 } 617 GetGlassOutlineSecondaryColor()618 const Color& GetGlassOutlineSecondaryColor() const 619 { 620 return glassOutlineSecondaryColor_; 621 } 622 GetGlassMaskPrimaryColor()623 const Color& GetGlassMaskPrimaryColor() const 624 { 625 return glassMaskPrimaryColor_; 626 } 627 GetGlassMaskSecondaryColor()628 const Color& GetGlassMaskSecondaryColor() const 629 { 630 return glassMaskSecondaryColor_; 631 } 632 GetInsertCursorOffset()633 const Dimension& GetInsertCursorOffset() const 634 { 635 return insertCursorOffset_; 636 } 637 GetPasswordTypeHeight()638 const Dimension& GetPasswordTypeHeight() const 639 { 640 return passwordTypeHeight_; 641 } 642 IsShowPasswordDirectly()643 bool IsShowPasswordDirectly() const 644 { 645 return showPasswordDirectly_; 646 } 647 IsTextFieldShowHandle()648 bool IsTextFieldShowHandle() const 649 { 650 return textfieldShowHandle_; 651 } 652 GetAvoidKeyboardOffset()653 const Dimension& GetAvoidKeyboardOffset() const 654 { 655 return avoidKeyboardOffset_; 656 } 657 GetCancelButtonStyle()658 const CancelButtonStyle& GetCancelButtonStyle() const 659 { 660 return cancelButtonStyle_; 661 } 662 GetCancelButtonIconColor()663 const Color& GetCancelButtonIconColor() const 664 { 665 return cancelButtonIconColor_; 666 } 667 GetPreviewUnderlineColor()668 const Color& GetPreviewUnderlineColor() const 669 { 670 return previewUnderlineColor_; 671 } 672 GetPreviewBoardColor()673 const Color& GetPreviewBoardColor() const 674 { 675 return previewBoardColor_; 676 } 677 GetCancelButton()678 const std::string& GetCancelButton() const 679 { 680 return cancelButton_; 681 } 682 GetCancelImageText()683 const std::string& GetCancelImageText() const 684 { 685 return cancelImageText_; 686 } 687 getInlinePaddingLeft()688 const Dimension& getInlinePaddingLeft() const 689 { 690 return inlinePaddingLeft_; 691 } 692 getInlinePaddingRight()693 const Dimension& getInlinePaddingRight() const 694 { 695 return inlinePaddingRight_; 696 } 697 GetPlaceholderLineSpacing()698 const Dimension& GetPlaceholderLineSpacing() const 699 { 700 return placeholderLineSpacing_; 701 } 702 GetShowPasswordPromptInformation()703 const std::string& GetShowPasswordPromptInformation() const 704 { 705 return showPassword_; 706 } 707 GetHiddenPasswordPromptInformation()708 const std::string& GetHiddenPasswordPromptInformation() const 709 { 710 return hidePassword_; 711 } 712 GetHasShowedPassword()713 const std::string& GetHasShowedPassword() const 714 { 715 return hasShowedPassword_; 716 } 717 GetHasHiddenPassword()718 const std::string& GetHasHiddenPassword() const 719 { 720 return hasHiddenPassword_; 721 } 722 GetAIWriteBundleName()723 const std::string& GetAIWriteBundleName() const 724 { 725 return aiWriteBundleName_; 726 } 727 GetAIWriteAbilityName()728 const std::string& GetAIWriteAbilityName() const 729 { 730 return aiWriteAbilityName_; 731 } 732 GetTranslateIsSupport()733 bool GetTranslateIsSupport() const 734 { 735 return translateIsSupport_; 736 } 737 GetIsSupportSearch()738 bool GetIsSupportSearch() const 739 { 740 return supportSearch_; 741 } 742 GetAIWriteIsSupport()743 const std::string& GetAIWriteIsSupport() const 744 { 745 return aiWriteIsSupport_; 746 } 747 GetCounterTextTopMargin()748 const Dimension& GetCounterTextTopMargin() const 749 { 750 return counterTextTopMargin_; 751 } 752 GetCounterTextBottomMargin()753 const Dimension& GetCounterTextBottomMargin() const 754 { 755 return counterTextBottomMargin_; 756 } 757 GetStandardCounterTextMargin()758 const Dimension& GetStandardCounterTextMargin() const 759 { 760 return standardCounterTextMargin_; 761 } 762 GetErrorTextTopMargin()763 const Dimension& GetErrorTextTopMargin() const 764 { 765 return errorTextTopMargin_; 766 } 767 GetErrorTextBottomMargin()768 const Dimension& GetErrorTextBottomMargin() const 769 { 770 return errorTextBottomMargin_; 771 } 772 GetCounterTextMarginOffset()773 const Dimension& GetCounterTextMarginOffset() const 774 { 775 return counterTextMarginOffset_; 776 } 777 GetErrorTextUnderlineMargin()778 const Dimension& GetErrorTextUnderlineMargin() const 779 { 780 return errorTextUnderlineMargin_; 781 } 782 GetErrorTextCapsuleMargin()783 const Dimension& GetErrorTextCapsuleMargin() const 784 { 785 return errorTextCapsuleMargin_; 786 } 787 GetErrorTextMaxFontScale()788 float GetErrorTextMaxFontScale() const 789 { 790 return errorTextMaxFontScale_; 791 } 792 GetCounterTextMaxline()793 uint32_t GetCounterTextMaxline() const 794 { 795 return counterTextMaxline_; 796 } 797 GetErrorTextMaxLine()798 uint32_t GetErrorTextMaxLine() const 799 { 800 return errorTextMaxLine_; 801 } 802 TextFadeoutEnabled()803 bool TextFadeoutEnabled() const 804 { 805 return textFadeoutEnabled_; 806 } 807 GetTextInputWidth()808 const Dimension& GetTextInputWidth() const 809 { 810 return textInputBorderWidth_; 811 } 812 GetTextInputColor()813 const Color& GetTextInputColor() const 814 { 815 return textInputBorderColor_; 816 } 817 IsShowPasswordIcon()818 bool IsShowPasswordIcon() const 819 { 820 return showPasswordIcon_; 821 } 822 GetHoverAndPressBgColorEnabled()823 bool GetHoverAndPressBgColorEnabled() const 824 { 825 return hoverAndPressBgColorEnabled_; 826 } 827 GetErrorTextInputBorderWidth()828 const Dimension& GetErrorTextInputBorderWidth() const 829 { 830 return errorTextInputBorderWidth_; 831 } 832 NeedFocusBox()833 bool NeedFocusBox() const 834 { 835 return needFocusBox_; 836 } 837 GetFocusPadding()838 const Dimension& GetFocusPadding() const 839 { 840 return focusPadding_; 841 } 842 GetErrorTextCenter()843 bool GetErrorTextCenter() const 844 { 845 return errorTextAlign_; 846 } 847 848 protected: 849 TextFieldTheme() = default; 850 TextStyle textStyle_; 851 Color textColor_; 852 Color placeholderColor_; 853 Color bgColor_; 854 Color focusBgColor_; 855 Color inlineBgColor_; 856 Color cursorColor_; 857 Color symbolColor_; 858 Color textColorDisable_; 859 860 private: 861 Edge padding_; 862 Edge underlinePadding_; 863 Dimension height_; 864 Dimension contentHeight_; 865 Dimension fontSize_; 866 Dimension underlineFontSize_; 867 FontWeight fontWeight_ = FontWeight::NORMAL; 868 Radius borderRadius_; 869 870 Radius borderRadiusSize_; 871 Color focusPlaceholderColor_; 872 Color focusTextColor_; 873 Color disableTextColor_; 874 Color underlineActivedColor_; 875 Color underlineTypingColor_; 876 Color selectedColor_; 877 Color hoverColor_; 878 Color pressColor_; 879 Color disabledIconFillColor_; 880 Dimension errorSpacing_; 881 bool errorIsInner_ = false; 882 Dimension errorBorderWidth_; 883 Color errorBorderColor_; 884 Color overCountBorderColor_; 885 Color errorUnderlineColor_; 886 Color underlineColor_; 887 Color disableUnderlineColor_; 888 Color underlineTextColor_; 889 Color passwordErrorTextColor_; 890 Color passwordErrorInputColor_; 891 Color passwordErrorBorderColor_; 892 Color passwordErrorLableColor_; 893 TextStyle errorTextStyle_; 894 TextStyle countTextStyle_; 895 TextStyle overCountStyle_; 896 TextStyle countTextStyleOuter_; 897 TextStyle overCountStyleOuter_; 898 TextStyle overCountTextStyle_; 899 Color inlineTextColor_; 900 Radius inlineRadiusSize_; 901 Color inlineBorderColor_; 902 Color defaultCounterColor_; 903 Color overCounterColor_; 904 Color glassOutlinePrimaryColor_; 905 Color glassOutlineSecondaryColor_; 906 Color glassMaskPrimaryColor_; 907 Color glassMaskSecondaryColor_; 908 909 // UX::disable state: opacity is set to 38% of the default 910 double disableOpacityRatio_ = 1.0; 911 912 // UX::over length state 913 Dimension overHideLength_; 914 915 // UX::cursor state cursor-color=#000000, cursor blur-radius=0.9, cursor-width=2, cursor-height=24, cursor-radius=1 916 Dimension cursorRadius_; 917 Dimension cursorWidth_; 918 bool needFade_ = false; 919 920 // UX::icon size = 24, hotZoneSize = 36 921 Dimension iconSize_; 922 Dimension iconHotZoneSize_; 923 Dimension inlineBorderWidth_ = 2.0_vp; 924 Dimension cancelIconSize_; 925 Dimension passwordIconSize_ = 20.0_vp; 926 Dimension cancelIconPadding_ = 14.0_vp; 927 Dimension passwordIconPadding_ = 10.0_vp; 928 929 // Replace image(icon) with symbol 930 Dimension symbolSize_; 931 uint32_t showSymbolId_ = 0; 932 uint32_t hideSymbolId_ = 0; 933 uint32_t cancelSymbolId_ = 0; 934 935 // UX::insert cursor offset up by 24vp 936 Dimension insertCursorOffset_ = 24.0_vp; 937 938 Dimension avoidKeyboardOffset_ = 24.0_vp; 939 940 bool showEllipsis_ = true; 941 bool draggable_ = false; 942 bool showPasswordDirectly_ = false; 943 bool textfieldShowHandle_ = false; 944 bool translateIsSupport_ = false; 945 bool supportSearch_ = false; 946 Dimension passwordTypeHeight_ = 40.0_vp; 947 948 // cancelButton 949 Color cancelButtonIconColor_; 950 CancelButtonStyle cancelButtonStyle_ = CancelButtonStyle::INPUT; 951 Color previewUnderlineColor_; 952 Color previewBoardColor_; 953 954 bool textFadeoutEnabled_ = false; 955 Dimension textInputBorderWidth_ = 0.0_vp; 956 Dimension errorTextInputBorderWidth_ = 1.0_vp; 957 Color textInputBorderColor_; 958 bool showPasswordIcon_ = true; 959 bool hoverAndPressBgColorEnabled_ = false; 960 bool independentControlKeyboard_ = false; 961 bool directionKeysMoveFocusOut_ = false; 962 963 std::string cancelButton_; 964 965 Dimension inlinePaddingLeft_ = 0.0_vp; 966 Dimension inlinePaddingRight_ = 0.0_vp; 967 Dimension placeholderLineSpacing_ = 0.0_vp; 968 969 Dimension counterTextTopMargin_ = 8.0_vp; 970 Dimension counterTextBottomMargin_ = 8.0_vp; 971 Dimension standardCounterTextMargin_ = 22.0_vp; 972 Dimension errorTextTopMargin_ = 8.0_vp; 973 Dimension errorTextBottomMargin_ = 8.0_vp; 974 Dimension counterTextMarginOffset_ = 8._vp; 975 Dimension errorTextUnderlineMargin_ = 8.0_vp; 976 Dimension errorTextCapsuleMargin_ = 8.0_vp; 977 978 float errorTextMaxFontScale_ = 2.0f; 979 uint32_t counterTextMaxline_ = 1; 980 uint32_t errorTextMaxLine_ = 1; 981 982 bool errorTextAlign_ = false; 983 984 std::string hasShowedPassword_; 985 std::string hasHiddenPassword_; 986 std::string showPassword_; 987 std::string hidePassword_; 988 std::string aiWriteBundleName_; 989 std::string aiWriteAbilityName_; 990 std::string aiWriteIsSupport_; 991 std::string cancelImageText_; 992 bool needFocusBox_ = false; 993 Dimension focusPadding_; 994 }; 995 996 } // namespace OHOS::Ace 997 998 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEXT_FIELD_TEXTFIELD_THEME_H 999