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