• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_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_field_model.h"
20 
21 namespace OHOS::Ace::NG {
22 class ACE_EXPORT TextFieldModelNG : public TextFieldModel {
23 public:
24     TextFieldModelNG() = default;
25     ~TextFieldModelNG() override = default;
26     void CreateNode(
27         const std::optional<std::string>& placeholder, const std::optional<std::string>& value, bool isTextArea);
28     RefPtr<TextFieldControllerBase> CreateTextInput(
29         const std::optional<std::string>& placeholder, const std::optional<std::string>& value) override;
30 
31     RefPtr<TextFieldControllerBase> CreateTextArea(
32         const std::optional<std::string>& placeholder, const std::optional<std::string>& value) override;
33 
34     void RequestKeyboardOnFocus(bool needToRequest) override;
35     void SetWidthAuto(bool isAuto) override;
36     void SetType(TextInputType value) override;
37     void SetPlaceholderColor(const Color& value) override;
38     void SetPlaceholderFont(const Font& value) override;
39     void SetEnterKeyType(TextInputAction value) override;
40     void SetTextAlign(TextAlign value) override;
41     void SetCaretColor(const Color& value) override;
42     void SetCaretStyle(const CaretStyle& value) override;
43     void SetCaretPosition(const int32_t& value) override;
44     void SetSelectedBackgroundColor(const Color& value) override;
45     void SetMaxLength(uint32_t value) override;
46     void SetMaxLines(uint32_t value) override;
47     void SetFontSize(const Dimension& value) override;
48     void SetFontWeight(FontWeight value) override;
49     void SetTextColor(const Color& value) override;
50     void SetFontStyle(Ace::FontStyle value) override;
51     void SetFontFamily(const std::vector<std::string>& value) override;
52     void SetInputFilter(const std::string& value, const std::function<void(const std::string&)>& onError) override;
53     void SetInputStyle(InputStyle value) override;
54     void SetShowPasswordIcon(bool value) override;
55     void SetOnEditChanged(std::function<void(bool)>&& func) override;
SetOnSubmit(std::function<void (int32_t)> && func)56     void SetOnSubmit(std::function<void(int32_t)>&& func) override {};
57     void SetOnSubmit(std::function<void(int32_t, NG::TextFieldCommonEvent&)>&& func) override;
58     void SetOnChange(std::function<void(const std::string&)>&& func) override;
59     void SetOnTextSelectionChange(std::function<void(int32_t, int32_t)>&& func) override;
60     void SetOnContentScroll(std::function<void(float, float)>&& func) override;
61     void SetOnCopy(std::function<void(const std::string&)>&& func) override;
62     void SetOnCut(std::function<void(const std::string&)>&& func) override;
63     void SetOnPaste(std::function<void(const std::string&)>&& func) override;
64     void SetOnPasteWithEvent(std::function<void(const std::string&, NG::TextCommonEvent&)>&& func) override;
65     void SetCopyOption(CopyOptions copyOption) override;
66     void SetMenuOptionItems(std::vector<MenuOptionsParam>&& menuOptionsItems) override;
67     void ProcessDefaultPadding(PaddingProperty& paddings);
68     static void ProcessDefaultStyleAndBehaviors(const RefPtr<FrameNode>& frameNode);
69     void ResetMaxLength() override;
70     void SetForegroundColor(const Color& value) override;
71     void SetPasswordIcon(const PasswordIcon& passwordIcon) override;
72     void SetShowUnit(std::function<void()>&& unitFunction) override;
73     void SetShowError(const std::string& errorText, bool visible) override;
74     void SetBarState(OHOS::Ace::DisplayMode value) override;
75     void SetMaxViewLines(uint32_t value) override;
76 
77     void SetShowUnderline(bool showUnderLine) override;
78     void SetShowCounter(bool value) override;
79     void SetCounterType(int32_t value) override;
80     void SetShowCounterBorder(bool value) override;
81     void SetOnChangeEvent(std::function<void(const std::string&)>&& func) override;
82     void SetBackgroundColor(const Color& color, bool tmp) override;
83     void SetHeight(const Dimension& value) override;
84     void SetPadding(NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp) override;
85     void SetHoverEffect(HoverEffectType hoverEffect) override;
86     void SetSelectionMenuHidden(bool contextMenuHidden) override;
87     void SetCustomKeyboard(const std::function<void()>&& buildFunc) override;
88     void SetPasswordRules(const std::string& passwordRules) override;
89     void SetEnableAutoFill(bool enableAutoFill) override;
90     void SetCleanNodeStyle(CleanNodeStyle cleanNodeStyle) override;
91     void SetCancelIconSize(const CalcDimension& iconSize) override;
92     void SetCanacelIconSrc(const std::string& iconSrc) override;
93     void SetCancelIconColor(const Color& iconColor) override;
94     void SetIsShowCancelButton(bool isShowCancelButton) override;
95     void SetSelectAllValue(bool isSetSelectAllValue) override;
96     static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId, const std::optional<std::string>& placeholder,
97         const std::optional<std::string>& value, bool isTextArea);
98     static void SetInputStyle(FrameNode* frameNode, InputStyle value);
99     static void SetSelectionMenuHidden(FrameNode* frameNode, bool contextMenuHidden);
100     static void RequestKeyboardOnFocus(FrameNode* frameNode, bool needToRequest);
101     static void SetBarState(FrameNode* frameNode, OHOS::Ace::DisplayMode value);
102     static void SetPasswordIcon(FrameNode* frameNode, const PasswordIcon& passwordIcon);
103     static void SetSelectedBackgroundColor(FrameNode* frameNode, const Color& value);
104     static void SetMaxViewLines(FrameNode* frameNode, uint32_t value);
105     static void SetType(FrameNode* frameNode, TextInputType value);
106     static void SetCopyOption(FrameNode* frameNode, CopyOptions copyOption);
107     static void SetShowPasswordIcon(FrameNode* frameNode, bool value);
108     static void SetTextAlign(FrameNode* frameNode, TextAlign value);
109     static void SetTextColor(FrameNode* frameNode, const Color& value);
110     static void SetCaretPosition(FrameNode* frameNode, const int32_t& value);
111     static void SetFontStyle(FrameNode* frameNode, Ace::FontStyle value);
112     static void SetMaxLength(FrameNode* frameNode, uint32_t value);
113     static void ResetMaxLength(FrameNode* frameNode);
114     static void SetCaretStyle(FrameNode* frameNode, const CaretStyle& value);
115     static void SetPlaceholderColor(FrameNode* frameNode, const Color& value);
116     static void SetFontWeight(FrameNode* frameNode, FontWeight value);
117     static void SetEnterKeyType(FrameNode* frameNode, TextInputAction value);
118     static void SetShowUnderline(FrameNode* frameNode, bool showUnderLine);
119     static void SetFontFamily(FrameNode* frameNode, const std::vector<std::string>& value);
120     static void SetMaxLines(FrameNode* frameNode, uint32_t value);
121     static void SetPlaceholderFont(FrameNode* frameNode, const Font& value);
122     static void SetFontSize(FrameNode* frameNode, const Dimension& value);
123     static void SetCaretColor(FrameNode* frameNode, const Color& value);
124     static void SetShowCounter(FrameNode* frameNode, bool value);
125     static void SetShowError(FrameNode* frameNode, const std::string& errorText, bool visible);
126     static void SetCounterType(FrameNode* frameNode, int32_t value);
127     static void SetOnChange(FrameNode* frameNode, std::function<void(const std::string&)>&& func);
128     static void SetTextFieldText(FrameNode* frameNode, const std::string& value);
129     static void SetTextFieldPlaceHolder(FrameNode* frameNode, const std::string& placeholder);
130     static void StopTextFieldEditing(FrameNode* frameNode);
131     static void SetOnSubmit(FrameNode* frameNode, std::function<void(int32_t, NG::TextFieldCommonEvent&)>&& func);
132 private:
133     void AddDragFrameNodeToManager() const;
134     void SetDraggable(bool draggable);
135     void SetTextRectWillChange();
136 };
137 
138 } // namespace OHOS::Ace::NG
139 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_MODEL_NG_H
140