• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_LAYOUT_ALGORITHM_H
16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_LAYOUT_ALGORITHM_H
17 
18 #include "base/geometry/ng/offset_t.h"
19 #include "core/components_ng/layout/box_layout_algorithm.h"
20 #include "core/components_ng/pattern/security_component/security_component_common.h"
21 #include "core/components_ng/pattern/security_component/security_component_layout_property.h"
22 #include "core/components_ng/pattern/security_component/security_component_theme.h"
23 
24 namespace OHOS::Ace::NG {
25 struct SecurityComponentLayoutPaddingParams {
26     double top = 0.0;
27     double right = 0.0;
28     double bottom = 0.0;
29     double left = 0.0;
30     double textIconSpace = 0.0;
31 };
32 
33 class ACE_EXPORT SecurityComponentLayoutAlgorithm : public BoxLayoutAlgorithm {
34     DECLARE_ACE_TYPE(SecurityComponentLayoutAlgorithm, BoxLayoutAlgorithm);
35 
36 public:
37     SecurityComponentLayoutAlgorithm() = default;
38     ~SecurityComponentLayoutAlgorithm() override = default;
39 
40     void Measure(LayoutWrapper* layoutWrapper) override;
41 
42 private:
43     RefPtr<LayoutWrapper> GetChildWrapper(LayoutWrapper* layoutWrapper, const std::string& tag);
44     void UpdateChildPosition(LayoutWrapper* layoutWrapper, const std::string& tag,
45         OffsetT<Dimension>& offset);
46     void InitLayoutParams(RefPtr<SecurityComponentLayoutProperty>& property);
47     void MeasureIcon(LayoutWrapper* layoutWrapper, RefPtr<SecurityComponentLayoutProperty>& securityComponentProperty);
48     void MeasureText(LayoutWrapper* layoutWrapper, RefPtr<SecurityComponentLayoutProperty>& securityComponentProperty);
49     void UpdateFrameMeasure(LayoutWrapper* layoutWrapper,
50         RefPtr<SecurityComponentLayoutProperty>& securityComponentProperty);
51     void MeasureButton(LayoutWrapper* layoutWrapper,
52         RefPtr<SecurityComponentLayoutProperty>& securityComponentProperty);
53     void FillPaddingParams(RefPtr<SecurityComponentLayoutProperty>& securityComponentProperty,
54         SecurityComponentLayoutPaddingParams& res);
55     void UpdateHorizontal(OffsetT<Dimension>& offsetIcon, OffsetT<Dimension>& offsetText,
56         const SecurityComponentLayoutPaddingParams& params);
57     void UpdateVertical(OffsetT<Dimension>& offsetIcon, OffsetT<Dimension>& offsetText,
58         const SecurityComponentLayoutPaddingParams& params);
59     void UpdateCircleBackground(OffsetT<Dimension>& offsetIcon, OffsetT<Dimension>& offsetText);
60     double componentWidth_ = 0.0;
61     double componentHeight_ = 0.0;
62     SizeF iconSizeF_;
63     SizeF textSizeF_;
64     SizeF buttonSizeF_;
65     int32_t buttonType_ = static_cast<int32_t>(ButtonType::NORMAL);
66     ACE_DISALLOW_COPY_AND_MOVE(SecurityComponentLayoutAlgorithm);
67 };
68 } // namespace OHOS::Ace::NG
69 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_LAYOUT_ALGORITHM_H
70