1 /* 2 * Copyright (c) 2022-2025 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_SEARCH_MODEL_IMPL_H 17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_SEARCH_MODEL_IMPL_H 18 19 #include "core/components/image/image_component.h" 20 #include "core/components/search/search_component.h" 21 #include "core/components/search/search_theme.h" 22 #include "core/components/text_field/text_field_component.h" 23 #include "core/components_ng/pattern/search/search_model.h" 24 25 namespace OHOS::Ace::Framework { 26 27 class ACE_EXPORT SearchModelImpl : public OHOS::Ace::SearchModel { 28 public: 29 RefPtr<TextFieldControllerBase> Create(const std::optional<std::u16string>& value, 30 const std::optional<std::u16string>& placeholder, const std::optional<std::string>& icon) override; RequestKeyboardOnFocus(bool needToRequest)31 void RequestKeyboardOnFocus(bool needToRequest) override {}; 32 void SetSearchButton(const std::string& text) override; SetCaretWidth(const Dimension & value)33 void SetCaretWidth(const Dimension& value) override {} SetCaretColor(const Color & color)34 void SetCaretColor(const Color& color) override {} ResetCaretColor()35 void ResetCaretColor() override {} SetSearchIconSize(const Dimension & value)36 void SetSearchIconSize(const Dimension& value) override {} SetSearchIconColor(const Color & color)37 void SetSearchIconColor(const Color& color) override {} ResetSearchIconColor()38 void ResetSearchIconColor() override {} SetSearchSrcPath(const std::string & src,const std::string & bundleName,const std::string & moduleName)39 void SetSearchSrcPath( 40 const std::string& src, const std::string& bundleName, const std::string& moduleName) override {} SetRightIconSrcPath(const std::string & src)41 void SetRightIconSrcPath(const std::string& src) override {} SetSearchSymbolIcon(std::function<void (WeakPtr<NG::FrameNode>)> iconSymbol)42 void SetSearchSymbolIcon(std::function<void(WeakPtr<NG::FrameNode>)> iconSymbol) override{} SetSearchDefaultIcon()43 void SetSearchDefaultIcon() override{} SetSearchImageIcon(NG::IconOptions & iconOptions)44 void SetSearchImageIcon(NG::IconOptions& iconOptions) override{} SetCancelSymbolIcon(std::function<void (WeakPtr<NG::FrameNode>)> iconSymbol)45 void SetCancelSymbolIcon(std::function<void(WeakPtr<NG::FrameNode>)> iconSymbol) override{} SetCancelDefaultIcon()46 void SetCancelDefaultIcon() override{} SetCancelImageIcon(NG::IconOptions & iconOptions)47 void SetCancelImageIcon(NG::IconOptions& iconOptions) override{} SetCancelButtonStyle(OHOS::Ace::CancelButtonStyle cancelButtonStyle)48 void SetCancelButtonStyle(OHOS::Ace::CancelButtonStyle cancelButtonStyle) override {} SetCancelIconSize(const Dimension & value)49 void SetCancelIconSize(const Dimension& value) override {} SetCancelIconColor(const Color & color)50 void SetCancelIconColor(const Color& color) override {} ResetCancelIconColor()51 void ResetCancelIconColor() override {} SetSearchButtonFontSize(const Dimension & value)52 void SetSearchButtonFontSize(const Dimension& value) override {} SetSearchButtonFontColor(const Color & color)53 void SetSearchButtonFontColor(const Color& color) override {} ResetSearchButtonFontColor()54 void ResetSearchButtonFontColor() override {} SetSearchButtonAutoDisable(bool needToDisable)55 void SetSearchButtonAutoDisable(bool needToDisable) override {}; 56 void SetPlaceholderColor(const Color& color) override; ResetPlaceholderColor()57 void ResetPlaceholderColor() override {}; 58 void SetPlaceholderFont(const Font& font) override; 59 void SetTextFont(const Font& font) override; 60 void SetMinFontScale(const float value) override; 61 void SetMaxFontScale(const float value) override; SetTextColor(const Color & color)62 void SetTextColor(const Color& color) override {} ResetTextColor()63 void ResetTextColor() override {} SetBackgroundColor(const Color & color)64 void SetBackgroundColor(const Color& color) override {} ResetBackgroundColor()65 void ResetBackgroundColor() override {} 66 void SetTextAlign(const TextAlign& textAlign) override; 67 void SetCopyOption(const CopyOptions& copyOptions) override; 68 void SetFocusable(bool focusable) override; 69 void SetFocusNode(bool isFocusNode) override; 70 void SetHeight(const Dimension& value) override; 71 void SetBackBorder() override; 72 void SetOnSubmit(std::function<void(const std::string&)>&& onSubmit) override; SetOnSubmit(std::function<void (const std::u16string &,NG::TextFieldCommonEvent &)> && onSubmit)73 void SetOnSubmit(std::function<void(const std::u16string&, NG::TextFieldCommonEvent&)>&& onSubmit) override {}; SetOnChange(std::function<void (const ChangeValueInfo &)> && onChange)74 void SetOnChange(std::function<void(const ChangeValueInfo&)>&& onChange) override {}; SetOnTextSelectionChange(std::function<void (int32_t,int32_t)> && func)75 void SetOnTextSelectionChange(std::function<void(int32_t, int32_t)>&& func) override {}; SetOnScroll(std::function<void (float,float)> && func)76 void SetOnScroll(std::function<void(float, float)>&& func) override {}; 77 void SetOnCopy(std::function<void(const std::u16string&)>&& func) override; 78 void SetOnCut(std::function<void(const std::u16string&)>&& func) override; 79 void SetOnPaste(std::function<void(const std::u16string&)>&& func) override; SetOnPasteWithEvent(std::function<void (const std::u16string &,NG::TextCommonEvent &)> && func)80 void SetOnPasteWithEvent(std::function<void(const std::u16string&, NG::TextCommonEvent&)>&& func) override {}; SetOnWillInsertValueEvent(std::function<bool (const InsertValueInfo &)> && func)81 void SetOnWillInsertValueEvent(std::function<bool(const InsertValueInfo&)>&& func) override {}; SetOnDidInsertValueEvent(std::function<void (const InsertValueInfo &)> && func)82 void SetOnDidInsertValueEvent(std::function<void(const InsertValueInfo&)>&& func) override {}; SetOnWillDeleteEvent(std::function<bool (const DeleteValueInfo &)> && func)83 void SetOnWillDeleteEvent(std::function<bool(const DeleteValueInfo&)>&& func) override {}; SetOnDidDeleteEvent(std::function<void (const DeleteValueInfo &)> && func)84 void SetOnDidDeleteEvent(std::function<void(const DeleteValueInfo&)>&& func) override {}; SetOnWillChangeEvent(std::function<bool (const ChangeValueInfo &)> && func)85 void SetOnWillChangeEvent(std::function<bool(const ChangeValueInfo&)>&& func) override {}; SetOnChangeEvent(std::function<void (const std::u16string &)> && onChangeEvent)86 void SetOnChangeEvent(std::function<void(const std::u16string&)>&& onChangeEvent) override {}; SetSelectionMenuHidden(bool selectionMenuHidden)87 void SetSelectionMenuHidden(bool selectionMenuHidden) override {}; 88 89 void SetCustomKeyboard(const std::function<void ()> &&buildFunc, bool supportAvoidance = false) override {}; SetFontFeature(const std::list<std::pair<std::string,int32_t>> & value)90 void SetFontFeature(const std::list<std::pair<std::string, int32_t>>& value) override {}; SetSearchEnterKeyType(TextInputAction value)91 void SetSearchEnterKeyType(TextInputAction value) override {}; SetMaxLength(uint32_t value)92 void SetMaxLength(uint32_t value) override {}; ResetMaxLength()93 void ResetMaxLength() override {}; SetType(TextInputType type)94 void SetType(TextInputType type) override {}; SetEnablePreviewText(bool enablePreviewText)95 void SetEnablePreviewText(bool enablePreviewText) override {}; SetEnableHapticFeedback(bool state)96 void SetEnableHapticFeedback(bool state) override {}; SetKeyboardAppearance(KeyboardAppearance value)97 void SetKeyboardAppearance(KeyboardAppearance value) override {}; 98 99 private: 100 void InitializeDefaultValue(const RefPtr<BoxComponent>& boxComponent, const RefPtr<TextFieldComponent>& component, 101 const RefPtr<TextFieldTheme>& theme); 102 void UpdateDecorationStyle(const RefPtr<BoxComponent>& boxComponent, const RefPtr<TextFieldComponent>& component, 103 const Border& boxBorder, bool hasBoxRadius); 104 void InitializeComponent(OHOS::Ace::RefPtr<OHOS::Ace::SearchComponent>& searchComponent, 105 OHOS::Ace::RefPtr<OHOS::Ace::TextFieldComponent>& textFieldComponent, 106 const OHOS::Ace::RefPtr<OHOS::Ace::SearchTheme>& searchTheme, 107 const OHOS::Ace::RefPtr<OHOS::Ace::TextFieldTheme>& textFieldTheme); 108 void PrepareSpecializedComponent(OHOS::Ace::RefPtr<OHOS::Ace::SearchComponent>& searchComponent, 109 OHOS::Ace::RefPtr<OHOS::Ace::TextFieldComponent>& textFieldComponent); 110 }; 111 112 } // namespace OHOS::Ace::Framework 113 114 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_SEARCH_MODEL_IMPL_H 115