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::string>& placeholder, const std::optional<std::string>& value) override;
33 
34     RefPtr<TextFieldControllerBase> CreateTextArea(
35         const std::optional<std::string>& placeholder, const std::optional<std::string>& 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;
41     void SetPlaceholderFont(const Font& value) override;
42     void SetEnterKeyType(TextInputAction value) override;
43     void SetTextAlign(TextAlign value) override;
SetLineBreakStrategy(LineBreakStrategy value)44     void SetLineBreakStrategy(LineBreakStrategy value) override {};
45     void SetCaretColor(const Color& value) override;
46     void SetCaretStyle(const CaretStyle& value) override;
47     void SetCaretPosition(const int32_t& value) override;
48     void SetSelectedBackgroundColor(const Color& value) override;
49     void SetMaxLength(uint32_t value) override;
50     void SetMaxLines(uint32_t value) override;
51     void SetFontSize(const Dimension& value) override;
52     void SetFontWeight(FontWeight value) override;
53     void SetTextColor(const Color& value) override;
54     void SetFontStyle(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 SetOnEditChanged(std::function<void(bool)>&& func) override;
60     void SetOnSubmit(std::function<void(int32_t)>&& func) override;
SetOnSubmit(std::function<void (int32_t,NG::TextFieldCommonEvent &)> && func)61     void SetOnSubmit(std::function<void(int32_t, NG::TextFieldCommonEvent&)>&& func) override {};
62     void SetOnChange(std::function<void(const std::string&, PreviewText&)>&& func) override;
SetOnTextSelectionChange(std::function<void (int32_t,int32_t)> && func)63     void SetOnTextSelectionChange(std::function<void(int32_t, int32_t)>&& func) override {};
SetOnSecurityStateChange(std::function<void (bool)> && func)64     void SetOnSecurityStateChange(std::function<void(bool)>&& func) override {};
SetOnContentScroll(std::function<void (float,float)> && func)65     void SetOnContentScroll(std::function<void(float, float)>&& func) override {};
66     void SetOnCopy(std::function<void(const std::string&)>&& func) override;
67     void SetOnCut(std::function<void(const std::string&)>&& func) override;
68     void SetOnPaste(std::function<void(const std::string&)>&& func) override;
SetOnPasteWithEvent(std::function<void (const std::string &,NG::TextCommonEvent &)> && func)69     void SetOnPasteWithEvent(std::function<void(const std::string&, NG::TextCommonEvent&)>&& func) override {};
70     void SetCopyOption(CopyOptions copyOption) override;
ResetMaxLength()71     void ResetMaxLength() override {};
72     static void InitTextInputDefaultStyle();
SetForegroundColor(const Color & value)73     void SetForegroundColor(const Color& value) override {};
SetShowUnit(std::function<void ()> && unitAction)74     void SetShowUnit(std::function<void()>&& unitAction) override {};
SetOnChangeEvent(std::function<void (const std::string &)> && func)75     void SetOnChangeEvent(std::function<void(const std::string&)>&& func) override {};
76     void SetBackgroundColor(const Color& color, bool tmp) override;
77     void SetHeight(const Dimension& value) override;
78     void SetPadding(const NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp) override;
79     void SetBackBorder() override;
80     void SetHoverEffect(HoverEffectType value) override;
81     void SetOnClick(std::function<void(const ClickInfo&)>&& func) override;
82     void SetFocusableAndFocusNode() override;
SetSelectionMenuHidden(bool contextMenuHidden)83     void SetSelectionMenuHidden(bool contextMenuHidden) override {};
84     void SetCustomKeyboard(const std::function<void()>&& buildFunc, bool supportAvoidance = false) override {};
SetPasswordRules(const std::string & passwordRules)85     void SetPasswordRules(const std::string& passwordRules) override {};
SetEnableAutoFill(bool enableAutoFill)86     void SetEnableAutoFill(bool enableAutoFill) override {};
SetCleanNodeStyle(CleanNodeStyle cleanNodeStyle)87     void SetCleanNodeStyle(CleanNodeStyle cleanNodeStyle) override {};
SetCancelIconSize(const CalcDimension & iconSize)88     void SetCancelIconSize(const CalcDimension& iconSize) override {};
SetCanacelIconSrc(const std::string & iconSrc,const std::string & bundleName,const std::string & moduleName)89     void SetCanacelIconSrc(
90         const std::string& iconSrc, const std::string& bundleName, const std::string& moduleName) override {};
SetCancelIconColor(const Color & iconColor)91     void SetCancelIconColor(const Color& iconColor) override {};
SetIsShowCancelButton(bool isShowCancelButton)92     void SetIsShowCancelButton(bool isShowCancelButton) override {};
SetShowPasswordText(bool value)93     void SetShowPasswordText(bool value) override {}
SetSelectAllValue(bool isSetSelectAllValue)94     void SetSelectAllValue(bool isSetSelectAllValue) override {};
SetFontFeature(const std::list<std::pair<std::string,int32_t>> & value)95     void SetFontFeature(const std::list<std::pair<std::string, int32_t>>& value) override {};
SetOnWillInsertValueEvent(std::function<bool (const InsertValueInfo &)> && func)96     void SetOnWillInsertValueEvent(std::function<bool(const InsertValueInfo&)>&& func) override {};
SetOnDidInsertValueEvent(std::function<void (const InsertValueInfo &)> && func)97     void SetOnDidInsertValueEvent(std::function<void(const InsertValueInfo&)>&& func) override {};
SetOnWillDeleteEvent(std::function<bool (const DeleteValueInfo &)> && func)98     void SetOnWillDeleteEvent(std::function<bool(const DeleteValueInfo&)>&& func) override {};
SetOnDidDeleteEvent(std::function<void (const DeleteValueInfo &)> && func)99     void SetOnDidDeleteEvent(std::function<void(const DeleteValueInfo&)>&& func) override {};
SetEnablePreviewText(bool enablePreviewText)100     void SetEnablePreviewText(bool enablePreviewText) override {};
SetEnableHapticFeedback(bool state)101     void SetEnableHapticFeedback(bool state) override {};
102 
103 private:
104     static void UpdateDecoration(const RefPtr<BoxComponent>& boxComponent, const RefPtr<TextFieldComponent>& component,
105         const Border& boxBorder, const RefPtr<TextFieldTheme>& textFieldTheme);
106 };
107 
108 } // namespace OHOS::Ace::Framework
109 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_TEXT_FIELD_MODEL_IMPL_H
110