• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DIALOG_DIALOG_LAYOUT_ALGORITHM_H
16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DIALOG_DIALOG_LAYOUT_ALGORITHM_H
17 
18 #include <string>
19 
20 #include "base/geometry/ng/offset_t.h"
21 #include "base/geometry/ng/rect_t.h"
22 #include "base/geometry/ng/size_t.h"
23 #include "core/components/common/layout/grid_layout_info.h"
24 #include "core/components/common/layout/grid_system_manager.h"
25 #include "core/components/common/properties/border.h"
26 #include "core/components/common/properties/edge.h"
27 #include "core/components/common/properties/placement.h"
28 #include "core/components_ng/layout/layout_algorithm.h"
29 #include "core/components_ng/pattern/dialog/dialog_layout_property.h"
30 
31 namespace OHOS::Ace::NG {
32 // DialogLayoutAlgorithm uses for Dialog Node.
33 class ACE_EXPORT DialogLayoutAlgorithm : public LayoutAlgorithm {
34     DECLARE_ACE_TYPE(DialogLayoutAlgorithm, LayoutAlgorithm);
35 
36 public:
37     DialogLayoutAlgorithm() = default;
38     ~DialogLayoutAlgorithm() override = default;
39 
40     void Measure(LayoutWrapper* layoutWrapper) override;
41 
42     void Layout(LayoutWrapper* layoutWrapper) override;
43 
GetTouchRegion()44     RectF GetTouchRegion() const
45     {
46         return touchRegion_;
47     }
48 
49 private:
50     LayoutConstraintF CreateDialogChildConstraint(LayoutWrapper* layoutWrapper, float height, float width);
51     void Distribute(float& scrollHeight, float& listHeight, float restHeight);
52     void AnalysisHeightOfChild(LayoutWrapper* layoutWrapper);
53     void AnalysisLayoutOfContent(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& scroll);
54 
55     void ComputeInnerLayoutParam(LayoutConstraintF& innerLayout);
56     double GetMaxWidthBasedOnGridType(const RefPtr<GridColumnInfo>& info, GridSizeType type, DeviceType deviceType);
57 
58     OffsetF ComputeChildPosition(
59         const SizeF& childSize, const RefPtr<DialogLayoutProperty>& prop, const SizeF& slefSize);
60     bool SetAlignmentSwitch(const SizeF& maxSize, const SizeF& childSize, OffsetF& topLeftPoint);
61 
62     void UpdateTouchRegion();
63 
64     double GetPaddingBottom() const;
65 
66     OffsetF AdjustChildPosition(
67         OffsetF& topLeftPoint, const OffsetF& dialogOffset, const SizeF& childSize, bool needAvoidKeyboard) const;
68 
69     RectF touchRegion_;
70     OffsetF topLeftPoint_;
71     bool customSize_ = false;
72 
73     int32_t gridCount_ = -1;
74     DimensionOffset dialogOffset_;
75     DialogAlignment alignment_ = DialogAlignment::DEFAULT;
76 
77     ACE_DISALLOW_COPY_AND_MOVE(DialogLayoutAlgorithm);
78 };
79 } // namespace OHOS::Ace::NG
80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DIALOG_DIALOG_LAYOUT_ALGORITHM_H
81