1 /* 2 * Copyright (c) 2022-2023 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_NG_PATTERN_SEARCH_SEARCH_LAYOUT_ALGORITHM_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SEARCH_SEARCH_LAYOUT_ALGORITHM_H 18 19 #include "core/components/search/search_theme.h" 20 #include "core/components_ng/layout/layout_algorithm.h" 21 #include "core/components_ng/layout/layout_wrapper.h" 22 #include "core/components_ng/pattern/search/search_layout_property.h" 23 24 namespace OHOS::Ace::NG { 25 26 class ACE_EXPORT SearchLayoutAlgorithm : public LayoutAlgorithm { 27 DECLARE_ACE_TYPE(SearchLayoutAlgorithm, LayoutAlgorithm); 28 29 public: 30 SearchLayoutAlgorithm() = default; 31 32 ~SearchLayoutAlgorithm() override = default; 33 OnReset()34 void OnReset() override {} 35 36 void Measure(LayoutWrapper* layoutWrapper) override; 37 void Layout(LayoutWrapper* layoutWrapper) override; 38 39 private: 40 struct LayoutSearchParams { 41 LayoutWrapper* layoutWrapper = nullptr; 42 RefPtr<SearchLayoutProperty> layoutProperty = nullptr; 43 RefPtr<SearchTheme> searchTheme = nullptr; 44 float searchFrameWidth = 0.0f; 45 float searchFrameHeight = 0.0f; 46 bool isRTL = false; 47 }; 48 void CancelImageMeasure(LayoutWrapper* layoutWrapper); 49 void CancelButtonMeasure(LayoutWrapper* layoutWrapper); 50 void TextFieldMeasure(LayoutWrapper* layoutWrapper); 51 void ImageMeasure(LayoutWrapper* layoutWrapper); 52 void SearchButtonMeasure(LayoutWrapper* layoutWrapper); 53 void DividerMeasure(LayoutWrapper* layoutWrapper); 54 void SelfMeasure(LayoutWrapper* layoutWrapper); 55 bool IsFixedHeightMode(LayoutWrapper* layoutWrapper); 56 double CalcSearchAdaptHeight(LayoutWrapper* layoutWrapper); 57 void CalcChildrenHotZone(LayoutWrapper* layoutWrapper); 58 double CalcSearchWidth(const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper); 59 double CalcSearchHeight(const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper); 60 float CalculateMaxFontScale(LayoutWrapper* layoutWrapper); 61 float CalculateMinFontScale(LayoutWrapper* layoutWrapper); 62 CalcSize searchButtonCalcSize(const RefPtr<SearchTheme>& searchTheme, RefPtr<SearchLayoutProperty> layoutProperty, 63 LayoutWrapper* layoutWrapper, float maxFontScale, float minFontScale); 64 void UpdateFontFeature(LayoutWrapper* layoutWrapper); 65 void UpdateTextFieldSize(LayoutWrapper* layoutWrapper); 66 void SetTextFieldLayoutConstraintHeight(LayoutConstraintF& contentConstraint, double textFieldHeight, 67 LayoutWrapper* layoutWrapper); 68 69 // children frame size 70 SizeF searchIconSizeMeasure_; 71 SizeF cancelIconSizeMeasure_; 72 SizeF searchButtonSizeMeasure_; 73 SizeF cancelBtnSizeMeasure_; 74 SizeF textFieldSizeMeasure_; 75 SizeF dividerSizeMeasure_; 76 void LayoutSearchIcon(const LayoutSearchParams& params); 77 void LayoutSearchButton(const LayoutSearchParams& params); 78 void LayoutDivider(const LayoutSearchParams& params); 79 void LayoutCancelButton(const LayoutSearchParams& params); 80 void LayoutCancelImage(const LayoutSearchParams& params); 81 void LayoutTextField(const LayoutSearchParams& params); 82 void UpdateClipBounds(LayoutWrapper* layoutWrapper, float height); 83 double CalcSymbolIconHeight(LayoutWrapper* layoutWrapper, int32_t index, double defaultImageHeight); 84 float CalculateTextFieldWidth( 85 LayoutWrapper* layoutWrapper, float searchWidthMax, const RefPtr<SearchTheme>& searchTheme); 86 float GetSearchFieldMinWidth(LayoutWrapper* layoutWrapper); 87 std::optional<float> GetSearchFixAtIdealMaxWidth(LayoutWrapper* layoutWrapper); 88 float GetTextFieldMinWidth(LayoutWrapper* layoutWrapper, const RefPtr<SearchTheme>& searchTheme); 89 float GetTextFieldMaxWidth(LayoutWrapper* layoutWrapper, LayoutCalPolicy layoutPolicy, float maxWidth); 90 void ResetChildrenMeasureSize(); 91 92 // cached data 93 float maxFontScale_; 94 float minFontScale_; 95 double searchHeight_; 96 float searchWidthReducedLength_ = 0.0f; 97 ACE_DISALLOW_COPY_AND_MOVE(SearchLayoutAlgorithm); 98 }; 99 } // namespace OHOS::Ace::NG 100 101 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SEARCH_SEARCH_LAYOUT_ALGORITHM_H 102