• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_TEXT_FIELD_MODEL_IMPL_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_TEXT_FIELD_MODEL_IMPL_H
18 
19 #include <optional>
20 #include <string>
21 
22 #include "frameworks/core/components/text_field/text_field_component.h"
23 #include "frameworks/core/components/text_field/textfield_theme.h"
24 #include "frameworks/core/components_ng/pattern/text_field/text_field_model.h"
25 #include "frameworks/core/components_ng/pattern/text_field/text_field_event_hub.h"
26 
27 namespace OHOS::Ace::Framework {
28 
29 class TextFieldModelImpl : public TextFieldModel {
30 public:
31     RefPtr<TextFieldControllerBase> CreateTextInput(
32         const std::optional<std::u16string>& placeholder, const std::optional<std::u16string>& value) override;
33 
34     RefPtr<TextFieldControllerBase> CreateTextArea(
35         const std::optional<std::u16string>& placeholder, const std::optional<std::u16string>& value) override;
RequestKeyboardOnFocus(bool needToRequest)36     void RequestKeyboardOnFocus(bool needToRequest) override {};
SetWidthAuto(bool isAuto)37     void SetWidthAuto(bool isAuto) override {};
38     void SetType(TextInputType value) override;
SetContentType(const NG::TextContentType & value)39     void SetContentType(const NG::TextContentType& value) override {};
40     void SetPlaceholderColor(const Color& value) override;
ResetPlaceholderColor()41     void ResetPlaceholderColor() override {};
42     void SetPlaceholderFont(const Font& value) override;
43     void SetEnterKeyType(TextInputAction value) override;
SetCapitalizationMode(AutoCapitalizationMode value)44     void SetCapitalizationMode(AutoCapitalizationMode value) override {};
45     void SetTextAlign(TextAlign value) override;
SetLineBreakStrategy(LineBreakStrategy value)46     void SetLineBreakStrategy(LineBreakStrategy value) override {};
47     void SetCaretColor(const Color& value) override;
ResetCaretColor()48     void ResetCaretColor() override {};
49     void SetCaretStyle(const CaretStyle& value) override;
50     void SetCaretPosition(const int32_t& value) override;
51     void SetSelectedBackgroundColor(const Color& value) override;
52     void SetMaxLength(uint32_t value) override;
53     void SetMaxLines(uint32_t value) override;
54     void SetFontSize(const Dimension& value) override;
55     void SetFontWeight(FontWeight value) override;
56     void SetMinFontScale(const float value) override;
57     void SetMaxFontScale(const float value) override;
58     void SetTextColor(const Color& value) override;
ResetTextColor()59     void ResetTextColor() override {};
60     void SetFontStyle(FontStyle value) override;
61     void SetFontFamily(const std::vector<std::string>& value) override;
62     void SetInputFilter(const std::string& value, const std::function<void(const std::u16string&)>&& func) override;
63     void SetInputStyle(InputStyle value) override;
64     void SetShowPasswordIcon(bool value) override;
65     void SetOnEditChanged(std::function<void(bool)>&& func) override;
66     void SetOnSubmit(std::function<void(int32_t)>&& func) override;
SetOnSubmit(std::function<void (int32_t,NG::TextFieldCommonEvent &)> && func)67     void SetOnSubmit(std::function<void(int32_t, NG::TextFieldCommonEvent&)>&& func) override {};
68     void SetOnChange(std::function<void(const ChangeValueInfo&)>&& func) override;
SetOnTextSelectionChange(std::function<void (int32_t,int32_t)> && func)69     void SetOnTextSelectionChange(std::function<void(int32_t, int32_t)>&& func) override {};
SetOnSecurityStateChange(std::function<void (bool)> && func)70     void SetOnSecurityStateChange(std::function<void(bool)>&& func) override {};
SetOnContentScroll(std::function<void (float,float)> && func)71     void SetOnContentScroll(std::function<void(float, float)>&& func) override {};
72     void SetOnCopy(std::function<void(const std::u16string&)>&& func) override;
73     void SetOnCut(std::function<void(const std::u16string&)>&& func) override;
74     void SetOnPaste(std::function<void(const std::u16string&)>&& func) override;
SetOnPasteWithEvent(std::function<void (const std::u16string &,NG::TextCommonEvent &)> && func)75     void SetOnPasteWithEvent(std::function<void(const std::u16string&, NG::TextCommonEvent&)>&& func) override {};
76     void SetCopyOption(CopyOptions copyOption) override;
ResetMaxLength()77     void ResetMaxLength() override {};
78     static void InitTextInputDefaultStyle();
SetForegroundColor(const Color & value)79     void SetForegroundColor(const Color& value) override {};
SetShowUnit(std::function<void ()> && unitAction)80     void SetShowUnit(std::function<void()>&& unitAction) override {};
SetOnWillChangeEvent(std::function<bool (const ChangeValueInfo &)> && func)81     void SetOnWillChangeEvent(std::function<bool(const ChangeValueInfo&)>&& func) override {};
SetOnChangeEvent(std::function<void (const std::u16string &)> && func)82     void SetOnChangeEvent(std::function<void(const std::u16string&)>&& func) override {};
83     void SetBackgroundColor(const Color& color, bool tmp) override;
ResetBackgroundColor()84     void ResetBackgroundColor() override {};
85     void SetHeight(const Dimension& value) override;
86     void SetPadding(const NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp, bool hasRegist = false) override;
87     void SetBackBorder() override;
88     void SetHoverEffect(HoverEffectType value) override;
89     void SetOnClick(std::function<void(const ClickInfo&)>&& func) override;
90     void SetFocusableAndFocusNode() override;
SetSelectionMenuHidden(bool contextMenuHidden)91     void SetSelectionMenuHidden(bool contextMenuHidden) override {};
92     void SetCustomKeyboard(const std::function<void()>&& buildFunc, bool supportAvoidance = false) override {};
SetPasswordRules(const std::string & passwordRules)93     void SetPasswordRules(const std::string& passwordRules) override {};
SetEnableAutoFill(bool enableAutoFill)94     void SetEnableAutoFill(bool enableAutoFill) override {};
SetEnableAutoFillAnimation(bool enableAutoFill)95     void SetEnableAutoFillAnimation(bool enableAutoFill) override {};
SetCleanNodeStyle(CleanNodeStyle cleanNodeStyle)96     void SetCleanNodeStyle(CleanNodeStyle cleanNodeStyle) override {};
SetCancelIconSize(const CalcDimension & iconSize)97     void SetCancelIconSize(const CalcDimension& iconSize) override {};
SetCanacelIconSrc(const std::string & iconSrc,const std::string & bundleName,const std::string & moduleName)98     void SetCanacelIconSrc(
99         const std::string& iconSrc, const std::string& bundleName, const std::string& moduleName) override {};
SetCancelIconColor(const Color & iconColor)100     void SetCancelIconColor(const Color& iconColor) override {};
SetCancelButtonSymbol(bool isShowSymbol)101     void SetCancelButtonSymbol(bool isShowSymbol) override {};
SetCancelSymbolIcon(const std::function<void (WeakPtr<NG::FrameNode>)> & iconSymbol)102     void SetCancelSymbolIcon(const std::function<void(WeakPtr<NG::FrameNode>)>& iconSymbol) override{};
SetIsShowCancelButton(bool isShowCancelButton)103     void SetIsShowCancelButton(bool isShowCancelButton) override {};
SetShowPasswordText(bool value)104     void SetShowPasswordText(bool value) override {}
SetSelectAllValue(bool isSetSelectAllValue)105     void SetSelectAllValue(bool isSetSelectAllValue) override {};
SetFontFeature(const std::list<std::pair<std::string,int32_t>> & value)106     void SetFontFeature(const std::list<std::pair<std::string, int32_t>>& value) override {};
SetOnWillInsertValueEvent(std::function<bool (const InsertValueInfo &)> && func)107     void SetOnWillInsertValueEvent(std::function<bool(const InsertValueInfo&)>&& func) override {};
SetOnDidInsertValueEvent(std::function<void (const InsertValueInfo &)> && func)108     void SetOnDidInsertValueEvent(std::function<void(const InsertValueInfo&)>&& func) override {};
SetOnWillDeleteEvent(std::function<bool (const DeleteValueInfo &)> && func)109     void SetOnWillDeleteEvent(std::function<bool(const DeleteValueInfo&)>&& func) override {};
SetOnDidDeleteEvent(std::function<void (const DeleteValueInfo &)> && func)110     void SetOnDidDeleteEvent(std::function<void(const DeleteValueInfo&)>&& func) override {};
SetEnablePreviewText(bool enablePreviewText)111     void SetEnablePreviewText(bool enablePreviewText) override {};
SetEnableHapticFeedback(bool state)112     void SetEnableHapticFeedback(bool state) override {};
SetKeyboardAppearance(KeyboardAppearance value)113     void SetKeyboardAppearance(KeyboardAppearance value) override {};
SetEnableAutoSpacing(bool enabled)114     void SetEnableAutoSpacing(bool enabled) override {};
SetOnWillAttachIME(std::function<void (const IMEClient &)> && func)115     void SetOnWillAttachIME(std::function<void(const IMEClient&)>&& func) override {};
116 
117 private:
118     static void UpdateDecoration(const RefPtr<BoxComponent>& boxComponent, const RefPtr<TextFieldComponent>& component,
119         const Border& boxBorder, const RefPtr<TextFieldTheme>& textFieldTheme);
120 };
121 
122 } // namespace OHOS::Ace::Framework
123 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_TEXT_FIELD_MODEL_IMPL_H
124