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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEARCH_RENDER_SEARCH_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEARCH_RENDER_SEARCH_H 18 19 #include <functional> 20 21 #include "base/mousestyle/mouse_style.h" 22 #include "core/components/box/render_box.h" 23 #include "core/components/button/render_button.h" 24 #include "core/components/image/render_image.h" 25 #include "core/components/padding/render_padding.h" 26 #include "core/components/search/search_component.h" 27 #include "core/components/text_field/render_text_field.h" 28 #include "core/gestures/click_recognizer.h" 29 #include "core/gestures/raw_recognizer.h" 30 #include "core/pipeline/base/render_node.h" 31 namespace OHOS::Ace { 32 33 enum class SearchNodeType { 34 NONE = 0, 35 IMAGE, 36 BUTTON, 37 SEARCH, 38 }; 39 40 class RenderSearch : public RenderNode, public ValueChangeObserver { 41 DECLARE_ACE_TYPE(RenderSearch, RenderNode, ValueChangeObserver); 42 43 public: 44 static RefPtr<RenderNode> Create(); 45 46 void Update(const RefPtr<Component>& component) override; 47 void PerformLayout() override; 48 void OnValueChanged(bool needFireChangeEvent = true, bool needFireSelectChangeEvent = true) override; 49 void FireSubmitEvent(const std::string& searchKey); 50 51 bool HandleEnterEvent(); 52 bool HandleFocusEvent(bool vertical, bool reverse); 53 54 bool HandleMouseEvent(const MouseEvent& event) override; 55 void HandleMouseHoverEvent(MouseState mouseState) override; 56 GetSearchComponent()57 const RefPtr<SearchComponent>& GetSearchComponent() const 58 { 59 return searchComponent_; 60 } 61 62 protected: 63 bool TouchTest(const Point& globalPoint, const Point& parentLocalPoint, const TouchRestrict& touchRestrict, 64 TouchTestResult& result) override; 65 void OnTouchTestHit( 66 const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override; 67 68 bool MouseHoverTest(const Point& parentLocalPoint) override; 69 70 Dimension closeIconSize_; 71 Dimension closeIconHotZoneHorizontal_; 72 bool showCloseIcon_ = false; 73 bool needReverse_ = false; 74 std::string searchText_; 75 std::function<void(const std::string&)> changeEvent_; 76 std::function<void(const std::string&)> submitEvent_; 77 RefPtr<RenderImage> renderCloseIcon_; 78 RefPtr<RenderBox> renderSearchBox_; 79 RefPtr<TextEditController> textEditController_; 80 RefPtr<Decoration> decoration_; 81 RefPtr<SearchComponent> searchComponent_; 82 // Overlay color for hover and press. 83 Color overlayColor_ = Color::TRANSPARENT; 84 85 Rect closeIconRect_; 86 Rect closeIconHotZoneRect_; 87 Rect searchTextRect_; 88 Rect searchReactRect_; 89 Offset searchBoxOffset_; 90 SearchNodeType focusRender_ = SearchNodeType::NONE; 91 SearchNodeType hoverOrPressRender_ = SearchNodeType::NONE; 92 93 private: 94 void CreateRenderImage(const RefPtr<SearchComponent>& searchComponent); 95 void CreateRenderButton(const RefPtr<SearchComponent>& searchComponent); 96 97 void InitRect(const RefPtr<RenderTextField>& renderTextField); 98 void CancelTextFieldHover(); 99 void HandleClick(); 100 101 RefPtr<ClickRecognizer> clickRecognizer_; 102 RefPtr<RawRecognizer> rawRecognizer_; 103 104 Color hoverColor_; 105 Color pressColor_; 106 107 TextStyle placeHoldStyle_; 108 TextStyle editingStyle_; 109 bool isInSearchButton_ = false; 110 bool preIsInSearchButton_ = false; 111 }; 112 113 } // namespace OHOS::Ace 114 115 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEARCH_RENDER_SEARCH_H 116