• 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 #include "core/components_ng/pattern/overlay/overlay_manager.h"
31 
32 namespace OHOS::Ace::NG {
33 enum class TouchingBoundaryType {
34     NotTouchBoundary = 0,
35     TouchBottomBoundary,
36     TouchRightBoundary,
37 };
38 // DialogLayoutAlgorithm uses for Dialog Node.
39 class ACE_EXPORT DialogLayoutAlgorithm : public LayoutAlgorithm {
40     DECLARE_ACE_TYPE(DialogLayoutAlgorithm, LayoutAlgorithm);
41 
42 public:
43     DialogLayoutAlgorithm() = default;
44     ~DialogLayoutAlgorithm() override = default;
45 
46     void Measure(LayoutWrapper* layoutWrapper) override;
47 
48     void Layout(LayoutWrapper* layoutWrapper) override;
49 
GetTouchRegion()50     RectF GetTouchRegion() const
51     {
52         return touchRegion_;
53     }
54 
55 private:
56     LayoutConstraintF CreateDialogChildConstraint(LayoutWrapper* layoutWrapper, float height, float width);
57     void Distribute(float& scrollHeight, float& listHeight, float restHeight);
58     void AnalysisHeightOfChild(LayoutWrapper* layoutWrapper);
59     void AnalysisLayoutOfContent(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& scroll);
60 
61     void ComputeInnerLayoutParam(LayoutConstraintF& innerLayout);
62     double GetMaxWidthBasedOnGridType(const RefPtr<GridColumnInfo>& info, GridSizeType type, DeviceType deviceType);
63 
64     OffsetF ComputeChildPosition(
65         const SizeF& childSize, const RefPtr<DialogLayoutProperty>& prop, const SizeF& slefSize);
66     bool SetAlignmentSwitch(const SizeF& maxSize, const SizeF& childSize, OffsetF& topLeftPoint);
67     bool IsDialogTouchingBoundary(OffsetF topLeftPoint, SizeF childSize, SizeF selfSize);
68     void MultipleDialog(const RefPtr<DialogLayoutProperty>& dialogProp, const SizeF& childSize, const SizeF& selfSize,
69         const RefPtr<OverlayManager> subOverlayManager);
70     void ProcessMaskRect(std::optional<DimensionRect> maskRect, const RefPtr<FrameNode>& dialog);
71     void SetSubWindowHotarea(
72         const RefPtr<DialogLayoutProperty>& dialogProp, SizeF childSize, SizeF selfSize, int32_t frameNodeId);
73 
74     void UpdateTouchRegion();
75 
76     double GetPaddingBottom() const;
77 
78     OffsetF AdjustChildPosition(
79         OffsetF& topLeftPoint, const OffsetF& dialogOffset, const SizeF& childSize, bool needAvoidKeyboard) const;
80 
81     SizeF UpdateHeightWithSafeArea(SizeF size);
82 
83     RectF touchRegion_;
84     OffsetF topLeftPoint_;
85     bool customSize_ = false;
86 
87     int32_t gridCount_ = -1;
88     int32_t subWindowId_ = -1;
89     DimensionOffset dialogOffset_;
90     DialogAlignment alignment_ = DialogAlignment::DEFAULT;
91     TouchingBoundaryType touchingBoundaryFlag_ = TouchingBoundaryType::NotTouchBoundary;
92 
93     bool expandDisplay_ = false;
94 
95     ACE_DISALLOW_COPY_AND_MOVE(DialogLayoutAlgorithm);
96 };
97 } // namespace OHOS::Ace::NG
98 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DIALOG_DIALOG_LAYOUT_ALGORITHM_H
99