• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_NG_PATTERNS_TEXT_FIELD_TEXT_FIELD_CONTENT_MODIFIER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_FIELD_TEXT_FIELD_CONTENT_MODIFIER_H
18 
19 #include "base/memory/ace_type.h"
20 #include "core/components/common/properties/color.h"
21 #include "core/components_ng/base/modifier.h"
22 #include "core/components_ng/pattern/pattern.h"
23 #include "core/components_ng/pattern/text_field/text_field_paint_property.h"
24 #include "core/components_ng/property/property.h"
25 #include "core/components_ng/render/animation_utils.h"
26 #include "core/components_ng/render/drawing.h"
27 
28 namespace OHOS::Ace::NG {
29 class TextFieldContentModifier : public ContentModifier {
30     DECLARE_ACE_TYPE(TextFieldContentModifier, ContentModifier);
31 
32 public:
33     explicit TextFieldContentModifier(const WeakPtr<OHOS::Ace::NG::Pattern>& pattern);
34     ~TextFieldContentModifier() override = default;
35 
36     void onDraw(DrawingContext& context) override;
37     void ModifyTextStyle(TextStyle& textStyle);
38     void SetDefaultAnimatablePropertyValue();
39 
40     void SetFontFamilies(const std::vector<std::string>& value);
41     void SetFontSize(const Dimension& value);
42     void SetFontWeight(const FontWeight& value);
43     void SetTextColor(const Color& value);
44     void SetFontStyle(const OHOS::Ace::FontStyle& value);
45     void SetContentOffset(OffsetF& value);
46     float GetContentOffsetY();
47     void SetContentSize(SizeF& value);
48     void SetTextValue(std::string& value);
49     void SetErrorTextValue(const std::string& value);
50     void SetPlaceholderValue(std::string&& value);
51     void SetTextRectY(const float value);
52     float GetTextRectX();
53     void SetTextObscured(bool value);
54     void ChangeDragStatus();
55     void SetTextRectX(const float value);
56     float GetTextRectY();
57     void SetTextAlign(const TextAlign value);
58     bool NeedMeasureUpdate(PropertyChangeFlag& flag);
59     void SetShowErrorState(bool value);
60     void SetShowUnderlineState(bool value);
61     void SetFontReady(bool value);
62     void SetTextOverflow(const TextOverflow value);
63     void ContentChange();
64 
65 private:
66     void SetDefaultFontSize(const TextStyle& textStyle);
67     void SetDefaultFontWeight(const TextStyle& textStyle);
68     void SetDefaultTextColor(const TextStyle& textStyle);
69     void SetDefaultFontStyle(const TextStyle& textStyle);
70     void SetDefaultTextOverflow(const TextStyle& textStyle);
71     void SetDefaultPropertyValue();
72     void GetFrameRectClip(RSRect& clipRect, std::vector<RSPoint>& clipRadius);
73     void ProcessErrorParagraph(DrawingContext& context, float errorMargin);
74 
75     WeakPtr<Pattern> pattern_;
76     RefPtr<PropertyString> fontFamilyString_;
77 
78     std::optional<Dimension> fontSize_;
79     RefPtr<AnimatablePropertyFloat> fontSizeFloat_;
80 
81     std::optional<FontWeight> fontWeight_;
82     RefPtr<AnimatablePropertyFloat> fontWeightFloat_;
83 
84     std::optional<Color> textColor_;
85     RefPtr<AnimatablePropertyColor> animatableTextColor_;
86 
87     RefPtr<PropertyFloat> textRectX_;
88     RefPtr<PropertyFloat> textRectY_;
89     RefPtr<PropertyOffsetF> contentOffset_;
90     RefPtr<PropertySizeF> contentSize_;
91     RefPtr<PropertyString> textValue_;
92     RefPtr<PropertyString> errorTextValue_;
93     RefPtr<PropertyString> placeholderValue_;
94     RefPtr<PropertyBool> textObscured_;
95     RefPtr<PropertyBool> dragStatus_;
96     RefPtr<PropertyInt> textAlign_;
97     RefPtr<PropertyBool> showErrorState_;
98     RefPtr<PropertyBool> showUnderline_;
99     RefPtr<PropertyBool> contentChange_;
100     RefPtr<PropertyInt> fontStyle_;
101     RefPtr<PropertyBool> fontReady_;
102     RefPtr<PropertyInt> textOverflow_;
103 
104     ACE_DISALLOW_COPY_AND_MOVE(TextFieldContentModifier);
105 };
106 } // namespace OHOS::Ace::NG
107 
108 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_FIELD_TEXT_FIELD_CONTENT_MODIFIER_H
109