1 /*
2  * Copyright (c) 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_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::string>& value,
30         const std::optional<std::string>& 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 {}
SetSearchIconSize(const Dimension & value)35     void SetSearchIconSize(const Dimension& value) override {}
SetSearchIconColor(const Color & color)36     void SetSearchIconColor(const Color& color) override {}
SetSearchSrcPath(const std::string & src,const std::string & bundleName,const std::string & moduleName)37     void SetSearchSrcPath(
38         const std::string& src, const std::string& bundleName, const std::string& moduleName) override {}
SetRightIconSrcPath(const std::string & src)39     void SetRightIconSrcPath(const std::string& src) override {}
SetSearchSymbolIcon(std::function<void (WeakPtr<NG::FrameNode>)> iconSymbol)40     void SetSearchSymbolIcon(std::function<void(WeakPtr<NG::FrameNode>)> iconSymbol) override{}
SetSearchDefaultIcon()41     void SetSearchDefaultIcon() override{}
SetSearchImageIcon(NG::IconOptions & iconOptions)42     void SetSearchImageIcon(NG::IconOptions& iconOptions) override{}
SetCancelSymbolIcon(std::function<void (WeakPtr<NG::FrameNode>)> iconSymbol)43     void SetCancelSymbolIcon(std::function<void(WeakPtr<NG::FrameNode>)> iconSymbol) override{}
SetCancelDefaultIcon()44     void SetCancelDefaultIcon() override{}
SetCancelImageIcon(NG::IconOptions & iconOptions)45     void SetCancelImageIcon(NG::IconOptions& iconOptions) override{}
SetCancelButtonStyle(OHOS::Ace::CancelButtonStyle cancelButtonStyle)46     void SetCancelButtonStyle(OHOS::Ace::CancelButtonStyle cancelButtonStyle) override {}
SetCancelIconSize(const Dimension & value)47     void SetCancelIconSize(const Dimension& value) override {}
SetCancelIconColor(const Color & color)48     void SetCancelIconColor(const Color& color) override {}
SetSearchButtonFontSize(const Dimension & value)49     void SetSearchButtonFontSize(const Dimension& value) override {}
SetSearchButtonFontColor(const Color & color)50     void SetSearchButtonFontColor(const Color& color) override {}
51     void SetPlaceholderColor(const Color& color) override;
52     void SetPlaceholderFont(const Font& font) override;
53     void SetTextFont(const Font& font) override;
SetTextColor(const Color & color)54     void SetTextColor(const Color& color) override {}
55     void SetTextAlign(const TextAlign& textAlign) override;
56     void SetCopyOption(const CopyOptions& copyOptions) override;
57     void SetFocusable(bool focusable) override;
58     void SetFocusNode(bool isFocusNode) override;
59     void SetHeight(const Dimension& value) override;
60     void SetBackBorder() override;
61     void SetOnSubmit(std::function<void(const std::string&)>&& onSubmit) override;
SetOnSubmit(std::function<void (const std::string &,NG::TextFieldCommonEvent &)> && onSubmit)62     void SetOnSubmit(std::function<void(const std::string&, NG::TextFieldCommonEvent&)>&& onSubmit) override {};
63     void SetOnChange(std::function<void(const std::string&, PreviewText&)>&& onChange) override;
SetOnTextSelectionChange(std::function<void (int32_t,int32_t)> && func)64     void SetOnTextSelectionChange(std::function<void(int32_t, int32_t)>&& func) override {};
SetOnScroll(std::function<void (float,float)> && func)65     void SetOnScroll(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 {};
SetOnWillInsertValueEvent(std::function<bool (const InsertValueInfo &)> && func)70     void SetOnWillInsertValueEvent(std::function<bool(const InsertValueInfo&)>&& func) override {};
SetOnDidInsertValueEvent(std::function<void (const InsertValueInfo &)> && func)71     void SetOnDidInsertValueEvent(std::function<void(const InsertValueInfo&)>&& func) override {};
SetOnWillDeleteEvent(std::function<bool (const DeleteValueInfo &)> && func)72     void SetOnWillDeleteEvent(std::function<bool(const DeleteValueInfo&)>&& func) override {};
SetOnDidDeleteEvent(std::function<void (const DeleteValueInfo &)> && func)73     void SetOnDidDeleteEvent(std::function<void(const DeleteValueInfo&)>&& func) override {};
SetOnChangeEvent(std::function<void (const std::string &)> && onChangeEvent)74     void SetOnChangeEvent(std::function<void(const std::string&)>&& onChangeEvent) override {};
SetSelectionMenuHidden(bool selectionMenuHidden)75     void SetSelectionMenuHidden(bool selectionMenuHidden) override {};
76 
77     void SetCustomKeyboard(const std::function<void ()> &&buildFunc, bool supportAvoidance = false) override {};
SetFontFeature(const std::list<std::pair<std::string,int32_t>> & value)78     void SetFontFeature(const std::list<std::pair<std::string, int32_t>>& value) override {};
SetSearchEnterKeyType(TextInputAction value)79     void SetSearchEnterKeyType(TextInputAction value) override {};
SetMaxLength(uint32_t value)80     void SetMaxLength(uint32_t value) override {};
ResetMaxLength()81     void ResetMaxLength() override {};
SetType(TextInputType type)82     void SetType(TextInputType type) override {};
SetEnablePreviewText(bool enablePreviewText)83     void SetEnablePreviewText(bool enablePreviewText) override {};
SetEnableHapticFeedback(bool state)84     void SetEnableHapticFeedback(bool state) override {};
85 
86 private:
87     void InitializeDefaultValue(const RefPtr<BoxComponent>& boxComponent, const RefPtr<TextFieldComponent>& component,
88         const RefPtr<TextFieldTheme>& theme);
89     void UpdateDecorationStyle(const RefPtr<BoxComponent>& boxComponent, const RefPtr<TextFieldComponent>& component,
90         const Border& boxBorder, bool hasBoxRadius);
91     void InitializeComponent(OHOS::Ace::RefPtr<OHOS::Ace::SearchComponent>& searchComponent,
92         OHOS::Ace::RefPtr<OHOS::Ace::TextFieldComponent>& textFieldComponent,
93         const OHOS::Ace::RefPtr<OHOS::Ace::SearchTheme>& searchTheme,
94         const OHOS::Ace::RefPtr<OHOS::Ace::TextFieldTheme>& textFieldTheme);
95     void PrepareSpecializedComponent(OHOS::Ace::RefPtr<OHOS::Ace::SearchComponent>& searchComponent,
96         OHOS::Ace::RefPtr<OHOS::Ace::TextFieldComponent>& textFieldComponent);
97 };
98 
99 } // namespace OHOS::Ace::Framework
100 
101 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_SEARCH_MODEL_IMPL_H
102