1 /* 2 * Copyright (c) 2021-2022 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; 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 SetCaretColor(const Color& value) override; 44 void SetCaretStyle(const CaretStyle& value) override; 45 void SetCaretPosition(const int32_t& value) override; 46 void SetSelectedBackgroundColor(const Color& value) override; 47 void SetMaxLength(uint32_t value) override; 48 void SetMaxLines(uint32_t value) override; 49 void SetFontSize(const Dimension& value) override; 50 void SetFontWeight(FontWeight value) override; 51 void SetTextColor(const Color& value) override; 52 void SetFontStyle(FontStyle value) override; 53 void SetFontFamily(const std::vector<std::string>& value) override; 54 void SetInputFilter(const std::string& value, const std::function<void(const std::string&)>& onError) override; 55 void SetInputStyle(InputStyle value) override; 56 void SetShowPasswordIcon(bool value) override; 57 void SetOnEditChanged(std::function<void(bool)>&& func) override; 58 void SetOnSubmit(std::function<void(int32_t)>&& func) override; SetOnSubmit(std::function<void (int32_t,NG::TextFieldCommonEvent &)> && func)59 void SetOnSubmit(std::function<void(int32_t, NG::TextFieldCommonEvent&)>&& func) override {}; 60 void SetOnChange(std::function<void(const std::string&)>&& func) override; SetOnTextSelectionChange(std::function<void (int32_t,int32_t)> && func)61 void SetOnTextSelectionChange(std::function<void(int32_t, int32_t)>&& func) override {}; SetOnContentScroll(std::function<void (float,float)> && func)62 void SetOnContentScroll(std::function<void(float, float)>&& func) override {}; 63 void SetOnCopy(std::function<void(const std::string&)>&& func) override; 64 void SetOnCut(std::function<void(const std::string&)>&& func) override; 65 void SetOnPaste(std::function<void(const std::string&)>&& func) override; SetOnPasteWithEvent(std::function<void (const std::string &,NG::TextCommonEvent &)> && func)66 void SetOnPasteWithEvent(std::function<void(const std::string&, NG::TextCommonEvent&)>&& func) override {}; 67 void SetCopyOption(CopyOptions copyOption) override; 68 void SetMenuOptionItems(std::vector<NG::MenuOptionsParam>&& menuOptionsItems) override; ResetMaxLength()69 void ResetMaxLength() override {}; 70 static void InitTextInputDefaultStyle(); SetForegroundColor(const Color & value)71 void SetForegroundColor(const Color& value) override {}; SetShowUnit(std::function<void ()> && unitAction)72 void SetShowUnit(std::function<void()>&& unitAction) override {}; SetOnChangeEvent(std::function<void (const std::string &)> && func)73 void SetOnChangeEvent(std::function<void(const std::string&)>&& func) override {}; 74 void SetBackgroundColor(const Color& color, bool tmp) override; 75 void SetHeight(const Dimension& value) override; 76 void SetPadding(NG::PaddingProperty& newPadding, Edge oldPadding, bool tmp) override; 77 void SetBackBorder() override; 78 void SetHoverEffect(HoverEffectType value) override; 79 void SetOnClick(std::function<void(const ClickInfo&)>&& func) override; 80 void SetFocusableAndFocusNode() override; SetSelectionMenuHidden(bool contextMenuHidden)81 void SetSelectionMenuHidden(bool contextMenuHidden) override {}; SetCustomKeyboard(const std::function<void ()> && buildFunc)82 void SetCustomKeyboard(const std::function<void()>&& buildFunc) override {}; SetPasswordRules(const std::string & passwordRules)83 void SetPasswordRules(const std::string& passwordRules) override {}; SetEnableAutoFill(bool enableAutoFill)84 void SetEnableAutoFill(bool enableAutoFill) override {}; SetCleanNodeStyle(CleanNodeStyle cleanNodeStyle)85 void SetCleanNodeStyle(CleanNodeStyle cleanNodeStyle) override {}; SetCancelIconSize(const CalcDimension & iconSize)86 void SetCancelIconSize(const CalcDimension& iconSize) override {}; SetCanacelIconSrc(const std::string & iconSrc)87 void SetCanacelIconSrc(const std::string& iconSrc) override {}; SetCancelIconColor(const Color & iconColor)88 void SetCancelIconColor(const Color& iconColor) override {}; SetIsShowCancelButton(bool isShowCancelButton)89 void SetIsShowCancelButton(bool isShowCancelButton) override {}; SetSelectAllValue(bool isSetSelectAllValue)90 void SetSelectAllValue(bool isSetSelectAllValue) override {}; 91 92 private: 93 static void UpdateDecoration(const RefPtr<BoxComponent>& boxComponent, const RefPtr<TextFieldComponent>& component, 94 const Border& boxBorder, const RefPtr<TextFieldTheme>& textFieldTheme); 95 }; 96 97 } // namespace OHOS::Ace::Framework 98 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_TEXT_FIELD_MODEL_IMPL_H 99