• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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_PATTERN_TEXT_FIELD_TEXT_FIELD_MODEL_NG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_MODEL_NG_H
18 
19 #include "core/components_ng/pattern/text_field/text_content_type.h"
20 #include "core/components_ng/pattern/text_field/text_field_model.h"
21 
22 namespace OHOS::Ace::NG {
23 class ACE_EXPORT TextFieldModelNG : public TextFieldModel {
24 public:
25     TextFieldModelNG() = default;
26     ~TextFieldModelNG() override = default;
27     void CreateNode(
28         const std::optional<std::string>& placeholder, const std::optional<std::string>& value, bool isTextArea);
29     RefPtr<TextFieldControllerBase> CreateTextInput(
30         const std::optional<std::string>& placeholder, const std::optional<std::string>& value) override;
31 
32     RefPtr<TextFieldControllerBase> CreateTextArea(
33         const std::optional<std::string>& placeholder, const std::optional<std::string>& value) override;
34 
35     void RequestKeyboardOnFocus(bool needToRequest) override;
36     void SetWidthAuto(bool isAuto) override;
37     void SetType(TextInputType value) override;
38     void SetContentType(const TextContentType& value) override;
39     void SetPlaceholderColor(const Color& value) override;
40     void SetPlaceholderFont(const Font& value) override;
41     void SetEnterKeyType(TextInputAction value) override;
42     void SetTextAlign(TextAlign value) override;
43     void SetLineBreakStrategy(LineBreakStrategy value) override;
44     void SetCaretColor(const Color& value) override;
45     void SetCaretStyle(const CaretStyle& value) override;
46     void SetCaretPosition(const int32_t& value) override;
47     void SetSelectedBackgroundColor(const Color& value) override;
48     void SetMaxLength(uint32_t value) override;
49     void SetMaxLines(uint32_t value) override;
50     void SetFontSize(const Dimension& value) override;
51     void SetFontWeight(FontWeight value) override;
52     void SetTextColor(const Color& value) override;
53     void SetWordBreak(Ace::WordBreak value) override;
54     void SetFontStyle(Ace::FontStyle value) override;
55     void SetFontFamily(const std::vector<std::string>& value) override;
56     void SetInputFilter(const std::string& value, const std::function<void(const std::string&)>& onError) override;
57     void SetInputStyle(InputStyle value) override;
58     void SetShowPasswordIcon(bool value) override;
59     void SetShowPasswordText(bool value) override;
60     void SetOnEditChanged(std::function<void(bool)>&& func) override;
SetOnSubmit(std::function<void (int32_t)> && func)61     void SetOnSubmit(std::function<void(int32_t)>&& func) override {};
62     void SetOnSubmit(std::function<void(int32_t, NG::TextFieldCommonEvent&)>&& func) override;
63     void SetOnWillChangeEvent(std::function<bool(const ChangeValueInfo&)>&& func) override;
64     void SetOnChange(std::function<void(const ChangeValueInfo&)>&& func) override;
65     void SetOnTextSelectionChange(std::function<void(int32_t, int32_t)>&& func) override;
66     void SetOnSecurityStateChange(std::function<void(bool)>&& func) override;
67     void SetOnContentScroll(std::function<void(float, float)>&& func) override;
68     void SetOnCopy(std::function<void(const std::string&)>&& func) override;
69     void SetOnCut(std::function<void(const std::string&)>&& func) override;
70     void SetOnPaste(std::function<void(const std::string&)>&& func) override;
71     void SetOnPasteWithEvent(std::function<void(const std::string&, NG::TextCommonEvent&)>&& func) override;
72     void SetCopyOption(CopyOptions copyOption) override;
73     static void ProcessDefaultStyleAndBehaviors(const RefPtr<FrameNode>& frameNode);
74     void ResetMaxLength() override;
75     void SetForegroundColor(const Color& value) override;
76     void SetPasswordIcon(const PasswordIcon& passwordIcon) override;
77     void SetShowUnit(std::function<void()>&& unitFunction) override;
78     void SetShowError(const std::string& errorText, bool visible) override;
79     void SetBarState(OHOS::Ace::DisplayMode value) override;
80     void SetMaxViewLines(uint32_t value) override;
81     void SetNormalMaxViewLines(uint32_t value) override;
82 
83     void SetShowUnderline(bool showUnderLine) override;
84     void SetNormalUnderlineColor(const Color& normalColor) override;
85     void SetUserUnderlineColor(UserUnderlineColor userColor) override;
86     void SetShowCounter(bool value) override;
87     void SetCounterType(int32_t value) override;
88     void SetShowCounterBorder(bool value) override;
89     void SetOnChangeEvent(std::function<void(const std::string&)>&& func) override;
90     void SetBackgroundColor(const Color& color, bool tmp) override;
91     void SetHeight(const Dimension& value) override;
92     void SetPadding(const NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp) override;
93     void SetMargin() override;
94     void SetHoverEffect(HoverEffectType hoverEffect) override;
95     void SetSelectionMenuHidden(bool contextMenuHidden) override;
96     void SetCustomKeyboard(const std::function<void()>&& buildFunc, bool supportAvoidance = false) override;
97     void SetPasswordRules(const std::string& passwordRules) override;
98     void SetEnableAutoFill(bool enableAutoFill) override;
99     void SetCleanNodeStyle(CleanNodeStyle cleanNodeStyle) override;
100     void SetCancelIconSize(const CalcDimension& iconSize) override;
101     void SetCanacelIconSrc(
102         const std::string& iconSrc, const std::string& bundleName, const std::string& moduleName) override;
103     void SetCancelIconColor(const Color& iconColor) override;
104     void SetIsShowCancelButton(bool isShowCancelButton) override;
105     void SetSelectAllValue(bool isSetSelectAllValue) override;
106     void SetFontFeature(const FONT_FEATURES_LIST& value) override;
107     void SetLetterSpacing(const Dimension& value) override;
108     void SetLineHeight(const Dimension& value) override;
109     void SetLineSpacing(const Dimension& value) override;
110     void SetAdaptMinFontSize(const Dimension& value) override;
111     void SetAdaptMaxFontSize(const Dimension& value) override;
112     void SetHeightAdaptivePolicy(TextHeightAdaptivePolicy value) override;
113     void SetTextDecoration(Ace::TextDecoration value) override;
114     void SetTextDecorationColor(const Color& value) override;
115     void SetTextDecorationStyle(Ace::TextDecorationStyle value) override;
116     void SetBackBorder() override;
117     void SetOnWillInsertValueEvent(std::function<bool(const InsertValueInfo&)>&& func) override;
118     void SetOnDidInsertValueEvent(std::function<void(const InsertValueInfo&)>&& func) override;
119     void SetOnWillDeleteEvent(std::function<bool(const DeleteValueInfo&)>&& func) override;
120     void SetOnDidDeleteEvent(std::function<void(const DeleteValueInfo&)>&& func) override;
121     void SetSelectionMenuOptions(const NG::OnCreateMenuCallback&& onCreateMenuCallback,
122         const NG::OnMenuItemClickCallback&& onMenuItemClick) override;
123     void SetEnablePreviewText(bool enablePreviewText) override;
124     void SetEnableHapticFeedback(bool state) override;
125     void SetStopBackPress(bool isStopBackPress) override;
126     void SetKeyboardAppearance(KeyboardAppearance value) override;
127 
128     static void SetTextDecoration(FrameNode* frameNode, TextDecoration value);
129     static void SetTextDecorationColor(FrameNode* frameNode, const Color& value);
130     static void SetTextDecorationStyle(FrameNode* frameNode, TextDecorationStyle value);
131     static void SetLetterSpacing(FrameNode* frameNode, const Dimension& value);
132     static void SetLineHeight(FrameNode* frameNode, const Dimension& value);
133     static void SetLineSpacing(FrameNode* frameNode, const Dimension& value);
134     void SetTextOverflow(Ace::TextOverflow value) override;
135     void SetTextIndent(const Dimension& value) override;
136     static void SetTextOverflow(FrameNode* frameNode, Ace::TextOverflow value);
137     static void SetTextIndent(FrameNode* frameNode, const Dimension& value);
138     static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId, const std::optional<std::string>& placeholder,
139         const std::optional<std::string>& value, bool isTextArea);
140     static void SetAdaptMinFontSize(FrameNode* frameNode, const Dimension& value);
141     static void SetAdaptMaxFontSize(FrameNode* frameNode, const Dimension& value);
142     static void SetHeightAdaptivePolicy(FrameNode* frameNode, TextHeightAdaptivePolicy value);
143     static void SetInputStyle(FrameNode* frameNode, InputStyle value);
144     static void SetSelectionMenuHidden(FrameNode* frameNode, bool contextMenuHidden);
145     static bool GetSelectionMenuHidden(FrameNode* frameNode);
146     static void SetPasswordRules(FrameNode* frameNode, const std::string& passwordRules);
147     static void SetEnableAutoFill(FrameNode* frameNode, bool enableAutoFill);
148     static void RequestKeyboardOnFocus(FrameNode* frameNode, bool needToRequest);
149     static void SetBarState(FrameNode* frameNode, OHOS::Ace::DisplayMode value);
150     static void SetPasswordIcon(FrameNode* frameNode, const PasswordIcon& passwordIcon);
151     static void SetSelectedBackgroundColor(FrameNode* frameNode, const Color& value);
152     static void SetMaxViewLines(FrameNode* frameNode, uint32_t value);
153     static void SetNormalMaxViewLines(FrameNode* frameNode, uint32_t value);
154     static void SetType(FrameNode* frameNode, TextInputType value);
155     static void SetContentType(const FrameNode* frameNode, const TextContentType& value);
156     static void SetCopyOption(FrameNode* frameNode, CopyOptions copyOption);
157     static void SetShowPasswordIcon(FrameNode* frameNode, bool value);
158     static void SetShowPassword(FrameNode* frameNode, bool value);
159     static void SetTextAlign(FrameNode* frameNode, TextAlign value);
160     static void SetTextColor(FrameNode* frameNode, const Color& value);
161     static void SetCaretPosition(FrameNode* frameNode, const int32_t& value);
162     static void SetFontStyle(FrameNode* frameNode, Ace::FontStyle value);
163     static void SetMaxLength(FrameNode* frameNode, uint32_t value);
164     static void ResetMaxLength(FrameNode* frameNode);
165     static void SetCaretStyle(FrameNode* frameNode, const CaretStyle& value);
166     static void SetPlaceholderColor(FrameNode* frameNode, const Color& value);
167     static void SetFontWeight(FrameNode* frameNode, FontWeight value);
168     static void SetEnterKeyType(FrameNode* frameNode, TextInputAction value);
169     static void SetShowUnderline(FrameNode* frameNode, bool showUnderLine);
170     static void SetNormalUnderlineColor(FrameNode* frameNode, const Color& normalColor);
171     static void SetUserUnderlineColor(FrameNode* frameNode, UserUnderlineColor userColor);
172     static void SetFontFamily(FrameNode* frameNode, const std::vector<std::string>& value);
173     static void SetMaxLines(FrameNode* frameNode, uint32_t value);
174     static void SetPlaceholderFont(FrameNode* frameNode, const Font& value);
175     static void SetFontSize(FrameNode* frameNode, const Dimension& value);
176     static void SetCaretColor(FrameNode* frameNode, const Color& value);
177     static void SetShowCounter(FrameNode* frameNode, bool value);
178     static void SetCounterType(FrameNode* frameNode, int32_t value);
179     static void SetShowError(FrameNode* frameNode, const std::string& errorText, bool visible);
180     static void SetOnWillChangeEvent(FrameNode* frameNode, std::function<bool(const ChangeValueInfo&)>&& func);
181     static void SetOnChange(FrameNode* frameNode, std::function<void(const ChangeValueInfo&)>&& func);
182     static void SetOnContentSizeChange(FrameNode* frameNode, std::function<void(float, float)>&& func);
183     static void SetOnTextSelectionChange(FrameNode* frameNode, std::function<void(int32_t, int32_t)>&& func);
184     static void SetTextFieldText(FrameNode* frameNode, const std::string& value);
185     static void SetTextFieldPlaceHolder(FrameNode* frameNode, const std::string& placeholder);
186     static void StopTextFieldEditing(FrameNode* frameNode);
187     static void SetOnSubmit(FrameNode* frameNode, std::function<void(int32_t, NG::TextFieldCommonEvent&)>&& func);
188     static void SetOnCut(FrameNode* frameNode, std::function<void(const std::string&)>&& func);
189     static void SetOnPasteWithEvent(FrameNode* frameNode,
190         std::function<void(const std::string&, NG::TextCommonEvent&)>&& func);
191     static void SetCleanNodeStyle(FrameNode* frameNode, CleanNodeStyle cleanNodeStyle);
192     static void SetIsShowCancelButton(FrameNode* frameNode, bool isShowCancelButton);
193     static void SetCancelIconSize(FrameNode* frameNode, const CalcDimension& iconSize);
194     static void SetCanacelIconSrc(FrameNode* frameNode, const std::string& iconSrc);
195     static void SetCancelIconColor(FrameNode* frameNode, const Color& iconColor);
196     static void SetBackgroundColor(FrameNode* frameNode, const Color& color);
197     static std::string GetPlaceholderText(FrameNode* frameNode);
198     static std::string GetTextFieldText(FrameNode* frameNode);
199     static Color GetCaretColor(FrameNode* frameNode);
200     static Dimension GetCaretStyle(FrameNode* frameNode);
201     static bool GetShowUnderline(FrameNode* frameNode);
202     static uint32_t GetMaxLength(FrameNode* frameNode);
203     static TextInputAction GetEnterKeyType(FrameNode* frameNode);
204     static Color GetPlaceholderColor(FrameNode* frameNode);
205     static Font GetPlaceholderFont(FrameNode* frameNode);
206     static bool GetRequestKeyboardOnFocus(FrameNode* frameNode);
207     static TextInputType GetType(FrameNode* frameNode);
208     static Color GetSelectedBackgroundColor(FrameNode* frameNode);
209     static bool GetShowPasswordIcon(FrameNode* frameNode);
210     static bool GetShowPassword(FrameNode* frameNode);
211     static bool GetTextFieldEditing(FrameNode* frameNode);
212     static bool GetShowCancelButton(FrameNode* frameNode);
213     static CalcDimension GetCancelIconSize(FrameNode* frameNode);
214     static std::string GetCanacelIconSrc(FrameNode* frameNode);
215     static Color GetCancelIconColor(FrameNode* frameNode);
216     static TextAlign GetTextAlign(FrameNode* frameNode);
217     static Color GetTextColor(FrameNode* frameNode);
218     static Ace::FontStyle GetFontStyle(FrameNode* frameNode);
219     static FontWeight GetFontWeight(FrameNode* frameNode);
220     static Dimension GetFontSize(FrameNode* frameNode);
221     static CleanNodeStyle GetCleanNodeStyle(FrameNode* frameNode);
222     static void SetShowCounterBorder(FrameNode* frameNode, bool value);
223     static bool GetShowCounter(FrameNode* frameNode);
224     static int GetCounterType(FrameNode* frameNode);
225     static bool GetShowCounterBorder(FrameNode* frameNode);
226     static void SetTextSelection(FrameNode* frameNode, int32_t start, int32_t end);
227     static int32_t GetTextSelectionIndex(FrameNode* frameNode, bool isEnd);
228     static void ResetTextInputPadding(FrameNode* frameNode);
229     static void SetFontFeature(FrameNode* frameNode, const FONT_FEATURES_LIST& value);
230     static void SetAutoWidth(FrameNode* frameNode);
231     static void SetWidth(FrameNode* frameNode, const std::string& value);
232     static void ClearWidth(FrameNode* frameNode);
233     static void SetWordBreak(FrameNode* frameNode, Ace::WordBreak value);
234     static void SetLineBreakStrategy(FrameNode* frameNode, LineBreakStrategy value);
235     static void SetSelectAllValue(FrameNode* frameNode, bool isSelectAllValue);
236     static void SetBlurOnSubmit(FrameNode* frameNode, bool blurOnSubmit);
237     static bool GetBlurOnSubmit(FrameNode* frameNode);
238     static void SetOnEditChange(FrameNode* frameNode, std::function<void(bool)>&& func);
239     static void SetInputFilter(FrameNode* frameNode, const std::string& value,
240         const std::function<void(const std::string&)>& onError);
241     static void SetOnContentScroll(FrameNode* frameNode, std::function<void(float, float)>&& func);
242     static void SetOnCopy(FrameNode* frameNode, std::function<void(const std::string&)>&& func);
243     static void SetOnEditChanged(FrameNode* frameNode, std::function<void(bool)>&& func);
244     static void SetCustomKeyboard(FrameNode* frameNode, FrameNode* customKeyboard, bool supportAvoidance = false);
245     static void SetInputFilter(FrameNode* frameNode, const std::string& value);
246     static void SetInputFilterError(FrameNode* frameNode, const std::function<void(const std::string&)>& onError);
247     static Ace::WordBreak GetWordBreak(FrameNode* frameNode);
248     static bool GetEnableAutoFill(FrameNode* frameNode);
249     static TextContentType GetContentType(FrameNode* frameNode);
250     static UserUnderlineColor GetUnderLineColor(FrameNode* frameNode);
251     static std::string GetPasswordRules(FrameNode* frameNode);
252     static bool GetSelectAllValue(FrameNode* frameNode);
253     static std::string GetInputFilter(FrameNode* frameNode);
254     static InputStyle GetInputStyle(FrameNode* frameNode);
255     static RefPtr<TextFieldControllerBase> GetOrCreateController(FrameNode* frameNode);
256     static FONT_FEATURES_LIST GetFontFeature(FrameNode* frameNode);
257     static Dimension GetAdaptMinFontSize(FrameNode* frameNode);
258     static Dimension GetAdaptMaxFontSize(FrameNode* frameNode);
259     static Dimension GetLineHeight(FrameNode* frameNode);
260     static uint32_t GetMaxLines(FrameNode* frameNode);
261     static void SetPadding(FrameNode* frameNode, NG::PaddingProperty& newPadding);
262     static RefPtr<UINode> GetCustomKeyboard(FrameNode* frameNode);
263     static bool GetCustomKeyboardOption(FrameNode* frameNode);
264     static void SetShowKeyBoardOnFocus(FrameNode* frameNode, bool value);
265     static bool GetShowKeyBoardOnFocus(FrameNode* frameNode);
266     static void SetNumberOfLines(FrameNode* frameNode, int32_t value);
267     static int32_t GetNumberOfLines(FrameNode* frameNode);
268     static void ResetNumberOfLines(FrameNode* frameNode);
269     static void SetBorderWidth(FrameNode* frameNode, NG::BorderWidthProperty borderWidth);
270     static void SetBorderRadius(FrameNode* frameNode, NG::BorderRadiusProperty borderRadius);
271     static void SetBorderColor(FrameNode* frameNode, NG::BorderColorProperty borderColors);
272     static void SetBorderStyle(FrameNode* frameNode, NG::BorderStyleProperty borderStyles);
273     static void SetMargin(FrameNode* frameNode, NG::PaddingProperty& margin);
274     static PaddingProperty GetMargin(FrameNode* frameNode);
275     static void SetOnWillInsertValueEvent(FrameNode* frameNode, std::function<bool(const InsertValueInfo&)>&& func);
276     static void SetOnDidInsertValueEvent(FrameNode* frameNode, std::function<void(const InsertValueInfo&)>&& func);
277     static void SetOnWillDeleteEvent(FrameNode* frameNode, std::function<bool(const DeleteValueInfo&)>&& func);
278     static void SetOnDidDeleteEvent(FrameNode* frameNode, std::function<void(const DeleteValueInfo&)>&& func);
279     static void SetEnablePreviewText(FrameNode* frameNode, bool enablePreviewText);
280     static PaddingProperty GetPadding(FrameNode* frameNode);
281     static void SetSelectionMenuOptions(FrameNode* frameNode, const NG::OnCreateMenuCallback&& onCreateMenuCallback,
282         const NG::OnMenuItemClickCallback&& onMenuItemClick);
283     static void SetEnableHapticFeedback(FrameNode* frameNode, bool state);
284     static void SetJSTextEditableController(FrameNode* frameNode, const RefPtr<Referenced>& controller);
285     static RefPtr<Referenced> GetJSTextEditableController(FrameNode* frameNode);
286     static void SetStopBackPress(FrameNode* frameNode, bool isStopBackPress);
287     static void SetKeyboardAppearance(FrameNode* frameNode, KeyboardAppearance value);
288     static int32_t GetKeyboardAppearance(FrameNode* frameNode);
289     static Dimension GetLetterSpacing(FrameNode* frameNode);
290     static bool GetEnablePreviewText(FrameNode* frameNode);
291 
292 private:
293     void AddDragFrameNodeToManager() const;
294     void SetDraggable(bool draggable);
295     void SetTextRectWillChange();
296     void SetDefaultPadding();
297 };
298 
299 } // namespace OHOS::Ace::NG
300 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_MODEL_NG_H
301