1 /* 2 * Copyright (c) 2021 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEARCH_SEARCH_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEARCH_SEARCH_COMPONENT_H 18 19 #include "base/resource/internal_resource.h" 20 #include "base/utils/utils.h" 21 #include "core/components/image/image_component.h" 22 #include "core/components/text_field/text_field_component.h" 23 #include "core/pipeline/base/constants.h" 24 #include "core/pipeline/base/element.h" 25 #include "core/pipeline/base/sole_child_component.h" 26 #include "core/components/declaration/search/search_declaration.h" 27 #include "core/components/text_field/textfield_theme.h" 28 29 namespace OHOS::Ace { 30 31 class ACE_EXPORT SearchComponent : public SoleChildComponent { 32 DECLARE_ACE_TYPE(SearchComponent, SoleChildComponent); 33 34 ACE_DEFINE_COMPONENT_EVENT(OnSubmit, void(const std::string&)); 35 ACE_DEFINE_COMPONENT_EVENT(OnChange, void(const std::string&)); 36 37 public: 38 SearchComponent(); 39 ~SearchComponent() override = default; 40 41 RefPtr<RenderNode> CreateRenderNode() override; 42 RefPtr<Element> CreateElement() override; 43 44 void SetCloseIconSize(const Dimension& closeIconSize); 45 const Dimension& GetCloseIconSize() const; 46 47 void SetCloseIconHotZoneHorizontal(const Dimension& closeIconHotZoneHorizontal); 48 const Dimension& GetCloseIconHotZoneHorizontal() const; 49 50 const std::string& GetSearchText() const; 51 void SetSearchText(const std::string& searchText); 52 53 const std::string& GetCloseIconSrc() const; 54 void SetCloseIconSrc(const std::string& closeIconSrc); 55 56 void SetChangeEventId(const EventMarker& changeEventId); 57 const EventMarker& GetChangeEventId() const; 58 59 void SetSubmitEventId(const EventMarker& submitEventId); 60 const EventMarker& GetSubmitEventId() const; 61 62 RefPtr<TextEditController> GetTextEditController() const; 63 void SetTextEditController(const RefPtr<TextEditController>& controller); 64 65 void SetSubmitEvent(const std::function<void(const std::string&)>& event); 66 const std::function<void(const std::string&)>& GetSubmitEvent() const; 67 68 RefPtr<Decoration> GetDecoration() const; 69 void SetDecoration(const RefPtr<Decoration>& decoration); 70 71 const Color& GetHoverColor() const; 72 void SetHoverColor(const Color& hoverColor); 73 74 const Color& GetPressColor() const; 75 void SetPressColor(const Color& pressColor); 76 77 void SetPlaceHoldStyle(const TextStyle& style); 78 const TextStyle& GetPlaceHoldStyle() const; 79 80 void SetEditingStyle(const TextStyle& style); 81 const TextStyle& GetEditingStyle() const; 82 83 void SetDeclaration(const RefPtr<SearchDeclaration>& declaration); 84 85 private: 86 RefPtr<SearchDeclaration> declaration_; 87 }; 88 89 } // namespace OHOS::Ace 90 91 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEARCH_SEARCH_COMPONENT_H 92