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; 44 void SetTextAlign(TextAlign value) override; SetLineBreakStrategy(LineBreakStrategy value)45 void SetLineBreakStrategy(LineBreakStrategy value) override {}; 46 void SetCaretColor(const Color& value) override; ResetCaretColor()47 void ResetCaretColor() override {}; 48 void SetCaretStyle(const CaretStyle& value) override; 49 void SetCaretPosition(const int32_t& value) override; 50 void SetSelectedBackgroundColor(const Color& value) override; 51 void SetMaxLength(uint32_t value) override; 52 void SetMaxLines(uint32_t value) override; 53 void SetFontSize(const Dimension& value) override; 54 void SetFontWeight(FontWeight value) override; 55 void SetMinFontScale(const float value) override; 56 void SetMaxFontScale(const float value) override; 57 void SetTextColor(const Color& value) override; ResetTextColor()58 void ResetTextColor() override {}; 59 void SetFontStyle(FontStyle value) override; 60 void SetFontFamily(const std::vector<std::string>& value) override; 61 void SetInputFilter(const std::string& value, const std::function<void(const std::u16string&)>&& func) override; 62 void SetInputStyle(InputStyle value) override; 63 void SetShowPasswordIcon(bool value) override; 64 void SetOnEditChanged(std::function<void(bool)>&& func) override; 65 void SetOnSubmit(std::function<void(int32_t)>&& func) override; SetOnSubmit(std::function<void (int32_t,NG::TextFieldCommonEvent &)> && func)66 void SetOnSubmit(std::function<void(int32_t, NG::TextFieldCommonEvent&)>&& func) override {}; 67 void SetOnChange(std::function<void(const ChangeValueInfo&)>&& func) override; SetOnTextSelectionChange(std::function<void (int32_t,int32_t)> && func)68 void SetOnTextSelectionChange(std::function<void(int32_t, int32_t)>&& func) override {}; SetOnSecurityStateChange(std::function<void (bool)> && func)69 void SetOnSecurityStateChange(std::function<void(bool)>&& func) override {}; SetOnContentScroll(std::function<void (float,float)> && func)70 void SetOnContentScroll(std::function<void(float, float)>&& func) override {}; 71 void SetOnCopy(std::function<void(const std::u16string&)>&& func) override; 72 void SetOnCut(std::function<void(const std::u16string&)>&& func) override; 73 void SetOnPaste(std::function<void(const std::u16string&)>&& func) override; SetOnPasteWithEvent(std::function<void (const std::u16string &,NG::TextCommonEvent &)> && func)74 void SetOnPasteWithEvent(std::function<void(const std::u16string&, NG::TextCommonEvent&)>&& func) override {}; 75 void SetCopyOption(CopyOptions copyOption) override; ResetMaxLength()76 void ResetMaxLength() override {}; 77 static void InitTextInputDefaultStyle(); SetForegroundColor(const Color & value)78 void SetForegroundColor(const Color& value) override {}; SetShowUnit(std::function<void ()> && unitAction)79 void SetShowUnit(std::function<void()>&& unitAction) override {}; SetOnWillChangeEvent(std::function<bool (const ChangeValueInfo &)> && func)80 void SetOnWillChangeEvent(std::function<bool(const ChangeValueInfo&)>&& func) override {}; SetOnChangeEvent(std::function<void (const std::u16string &)> && func)81 void SetOnChangeEvent(std::function<void(const std::u16string&)>&& func) override {}; 82 void SetBackgroundColor(const Color& color, bool tmp) override; ResetBackgroundColor()83 void ResetBackgroundColor() override {}; 84 void SetHeight(const Dimension& value) override; 85 void SetPadding(const NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp) override; 86 void SetBackBorder() override; 87 void SetHoverEffect(HoverEffectType value) override; 88 void SetOnClick(std::function<void(const ClickInfo&)>&& func) override; 89 void SetFocusableAndFocusNode() override; SetSelectionMenuHidden(bool contextMenuHidden)90 void SetSelectionMenuHidden(bool contextMenuHidden) override {}; 91 void SetCustomKeyboard(const std::function<void()>&& buildFunc, bool supportAvoidance = false) override {}; SetPasswordRules(const std::string & passwordRules)92 void SetPasswordRules(const std::string& passwordRules) override {}; SetEnableAutoFill(bool enableAutoFill)93 void SetEnableAutoFill(bool enableAutoFill) override {}; SetCleanNodeStyle(CleanNodeStyle cleanNodeStyle)94 void SetCleanNodeStyle(CleanNodeStyle cleanNodeStyle) override {}; SetCancelIconSize(const CalcDimension & iconSize)95 void SetCancelIconSize(const CalcDimension& iconSize) override {}; SetCanacelIconSrc(const std::string & iconSrc,const std::string & bundleName,const std::string & moduleName)96 void SetCanacelIconSrc( 97 const std::string& iconSrc, const std::string& bundleName, const std::string& moduleName) override {}; SetCancelIconColor(const Color & iconColor)98 void SetCancelIconColor(const Color& iconColor) override {}; SetCancelButtonSymbol(bool isShowSymbol)99 void SetCancelButtonSymbol(bool isShowSymbol) override {}; SetCancelSymbolIcon(const std::function<void (WeakPtr<NG::FrameNode>)> & iconSymbol)100 void SetCancelSymbolIcon(const std::function<void(WeakPtr<NG::FrameNode>)>& iconSymbol) override{}; SetIsShowCancelButton(bool isShowCancelButton)101 void SetIsShowCancelButton(bool isShowCancelButton) override {}; SetShowPasswordText(bool value)102 void SetShowPasswordText(bool value) override {} SetSelectAllValue(bool isSetSelectAllValue)103 void SetSelectAllValue(bool isSetSelectAllValue) override {}; SetFontFeature(const std::list<std::pair<std::string,int32_t>> & value)104 void SetFontFeature(const std::list<std::pair<std::string, int32_t>>& value) override {}; SetOnWillInsertValueEvent(std::function<bool (const InsertValueInfo &)> && func)105 void SetOnWillInsertValueEvent(std::function<bool(const InsertValueInfo&)>&& func) override {}; SetOnDidInsertValueEvent(std::function<void (const InsertValueInfo &)> && func)106 void SetOnDidInsertValueEvent(std::function<void(const InsertValueInfo&)>&& func) override {}; SetOnWillDeleteEvent(std::function<bool (const DeleteValueInfo &)> && func)107 void SetOnWillDeleteEvent(std::function<bool(const DeleteValueInfo&)>&& func) override {}; SetOnDidDeleteEvent(std::function<void (const DeleteValueInfo &)> && func)108 void SetOnDidDeleteEvent(std::function<void(const DeleteValueInfo&)>&& func) override {}; SetEnablePreviewText(bool enablePreviewText)109 void SetEnablePreviewText(bool enablePreviewText) override {}; SetEnableHapticFeedback(bool state)110 void SetEnableHapticFeedback(bool state) override {}; SetKeyboardAppearance(KeyboardAppearance value)111 void SetKeyboardAppearance(KeyboardAppearance value) override {}; 112 113 private: 114 static void UpdateDecoration(const RefPtr<BoxComponent>& boxComponent, const RefPtr<TextFieldComponent>& component, 115 const Border& boxBorder, const RefPtr<TextFieldTheme>& textFieldTheme); 116 }; 117 118 } // namespace OHOS::Ace::Framework 119 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_TEXT_FIELD_MODEL_IMPL_H 120