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     void UpdateFontFeature(LayoutWrapper* layoutWrapper);
61     void SetTextFieldLayoutConstraintHeight(LayoutConstraintF& contentConstraint, double textFieldHeight,
62         LayoutWrapper* layoutWrapper);
63 
64     // children frame size
65     SizeF searchIconSizeMeasure_;
66     SizeF cancelIconSizeMeasure_;
67     SizeF searchButtonSizeMeasure_;
68     SizeF cancelBtnSizeMeasure_;
69     SizeF textFieldSizeMeasure_;
70     SizeF dividerSizeMeasure_;
71     void LayoutSearchIcon(const LayoutSearchParams& params);
72     void LayoutSearchButton(const LayoutSearchParams& params);
73     void LayoutDivider(const LayoutSearchParams& params);
74     void LayoutCancelButton(const LayoutSearchParams& params);
75     void LayoutCancelImage(const LayoutSearchParams& params);
76     void LayoutTextField(const LayoutSearchParams& params);
77     void UpdateClipBounds(LayoutWrapper* layoutWrapper, float height);
78     double CalcSymbolIconHeight(LayoutWrapper* layoutWrapper, int32_t index, double defaultImageHeight);
79 
80     ACE_DISALLOW_COPY_AND_MOVE(SearchLayoutAlgorithm);
81 };
82 } // namespace OHOS::Ace::NG
83 
84 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SEARCH_SEARCH_LAYOUT_ALGORITHM_H
85