• 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 "base/geometry/dimension.h"
24 #include "core/components/common/layout/grid_layout_info.h"
25 #include "core/components/common/layout/grid_system_manager.h"
26 #include "core/components/common/properties/border.h"
27 #include "core/components/common/properties/edge.h"
28 #include "core/components/common/properties/placement.h"
29 #include "core/components/dialog/dialog_theme.h"
30 #include "core/components_ng/layout/layout_algorithm.h"
31 #include "core/components_ng/pattern/dialog/dialog_layout_property.h"
32 #include "core/components_ng/pattern/overlay/overlay_manager.h"
33 
34 namespace OHOS::Ace::NG {
35 enum class TouchingBoundaryType {
36     NotTouchBoundary = 0,
37     TouchBottomBoundary,
38     TouchRightBoundary,
39 };
40 // DialogLayoutAlgorithm uses for Dialog Node.
41 class ACE_EXPORT DialogLayoutAlgorithm : public LayoutAlgorithm {
42     DECLARE_ACE_TYPE(DialogLayoutAlgorithm, LayoutAlgorithm);
43 
44 public:
45     DialogLayoutAlgorithm() = default;
DialogLayoutAlgorithm(WeakPtr<PipelineContext> context)46     DialogLayoutAlgorithm(WeakPtr<PipelineContext> context) : context_(context) {}
47     ~DialogLayoutAlgorithm() override = default;
48 
49     void Measure(LayoutWrapper* layoutWrapper) override;
50 
51     void Layout(LayoutWrapper* layoutWrapper) override;
52 
GetTouchRegion()53     RectF GetTouchRegion() const
54     {
55         return touchRegion_;
56     }
57 
58 private:
59     void ClipCustomMaskNode(const RefPtr<FrameNode>& dialog, const RectF& rect);
60     void UpdateCustomMaskNodeLayout(const RefPtr<FrameNode>& dialog);
61     LayoutConstraintF CreateDialogChildConstraint(LayoutWrapper* layoutWrapper, float height, float width);
62     void Distribute(float& scrollHeight, float& listHeight, float restHeight);
63     void AnalysisHeightOfChild(LayoutWrapper* layoutWrapper);
64     void AnalysisLayoutOfContent(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& scroll);
65     void AvoidScreen(OffsetF& topLeftPoint, const RefPtr<DialogLayoutProperty>& prop, SizeF childSize);
66 
67     bool ComputeInnerLayoutSizeParam(LayoutConstraintF& innerLayout, const RefPtr<DialogLayoutProperty>& dialogProp);
68     bool IsGetExpandDisplayValidHeight(const RefPtr<DialogLayoutProperty>& dialogProp);
69     RefPtr<PipelineContext> GetPipelineContext() const;
70     void ComputeInnerLayoutParam(LayoutConstraintF& innerLayout, const RefPtr<DialogLayoutProperty>& dialogProp);
71     double GetMaxWidthBasedOnGridType(const RefPtr<GridColumnInfo>& info, GridSizeType type, DeviceType deviceType);
72     int32_t GetDeviceColumns(GridSizeType type, DeviceType deviceType);
73     OffsetF ComputeChildPosition(
74         const SizeF& childSize, const RefPtr<DialogLayoutProperty>& prop, const SizeF& slefSize);
75     bool SetAlignmentSwitch(SizeF& maxSize, const SizeF& childSize, OffsetF& topLeftPoint);
76     bool SetAlignmentSwitchLessThanAPITwelve(const SizeF& maxSize, const SizeF& childSize, OffsetF& topLeftPoint);
77     bool IsAlignmentByWholeScreen();
78     void CaculateMaxSize(SizeF& maxSize);
79     bool IsDialogTouchingBoundary(OffsetF topLeftPoint, SizeF childSize, SizeF selfSize);
80     void MultipleDialog(const RefPtr<DialogLayoutProperty>& dialogProp, const SizeF& childSize, const SizeF& selfSize,
81         const RefPtr<OverlayManager> subOverlayManager);
82     void ProcessMaskRect(std::optional<DimensionRect> maskRect, const RefPtr<FrameNode>& dialog, bool isMask = false);
83     void SetSubWindowHotarea(
84         const RefPtr<DialogLayoutProperty>& dialogProp, SizeF childSize, SizeF selfSize, int32_t frameNodeId);
85     std::optional<DimensionRect> GetMaskRect(const RefPtr<FrameNode>& dialog);
86 
87     void UpdateTouchRegion();
88 
89     double GetPaddingBottom() const;
90     double GetKeyboardAvoidDistance() const;
91 
92     OffsetF AdjustChildPosition(
93         OffsetF& topLeftPoint, const OffsetF& dialogOffset, const SizeF& childSize, bool needAvoidKeyboard);
94 
95     SizeF UpdateHeightWithSafeArea(SizeF size);
96     void UpdateSafeArea(const RefPtr<FrameNode>& frameNode);
97     void UpdateChildLayoutConstraint(const RefPtr<DialogLayoutProperty>& dialogProp,
98         LayoutConstraintF& childLayoutConstraint, RefPtr<LayoutWrapper>& childLayoutWrapper);
99     void AdjustHeightForKeyboard(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& child);
100     void UpdateIsScrollHeightNegative(LayoutWrapper* layoutWrapper, float height);
101     void UpdateChildMaxSizeHeight(SizeT<float>& maxSize);
102     void ParseSubwindowId(const RefPtr<DialogLayoutProperty>& dialogProp);
103 
104     void ResizeDialogSubwindow(bool expandDisplay, bool isShowInSubWindow, bool isShowInFloatingWindow);
105 
106     bool IsEmbeddedDialog(const RefPtr<FrameNode>& frameNode);
107     float GetEmbeddedDialogOffsetY(const RefPtr<FrameNode>& frameNode);
108     float GetStackRootDialogOffsetY(const RefPtr<FrameNode>& frameNode);
109     void AdjustHoverModeForWaterfall(const RefPtr<FrameNode>& frameNode);
110     bool IsDefaultPosition(const RefPtr<DialogLayoutProperty>& dialogProp);
111 
112     RectF touchRegion_;
113     OffsetF topLeftPoint_;
114     bool customSize_ = false;
115     SafeAreaInsets safeAreaInsets_;
116     bool isModal_ = true;
117     bool hasAddMaskNode_ = false;
118     bool isShowInSubWindow_ = false;
119     bool isSuitableForElderly_ = false;
120     bool isSuitOldMeasure_ = false;
121     float dialogMaxHeight_ = 0.0f;
122     int32_t gridCount_ = -1;
123     int32_t subWindowId_ = -1;
124     DimensionOffset dialogOffset_;
125     DialogAlignment alignment_ = DialogAlignment::DEFAULT;
126     TouchingBoundaryType touchingBoundaryFlag_ = TouchingBoundaryType::NotTouchBoundary;
127 
128     bool expandDisplay_ = false;
129     double expandDisplayValidHeight_ = 0.0;
130     bool isUIExtensionSubWindow_ = false;
131     RectF hostWindowRect_;
132 
133     SizeF dialogChildSize_;
134     bool resizeFlag_ = false;
135     bool isHoverMode_ = false;
136     bool isKeyBoardShow_ = false;
137     bool alignBottomScreen_ = false;
138     Rect foldCreaseRect = Rect(0.0, 0.0, 0.0, 0.0);
139     HoverModeAreaType hoverModeArea_ = HoverModeAreaType::BOTTOM_SCREEN;
140     OffsetF wrapperOffset_ = OffsetF(0.0, 0.0);
141     SizeF wrapperSize_ = SizeF(0.0, 0.0);
142 
143     KeyboardAvoidMode keyboardAvoidMode_ = KeyboardAvoidMode::DEFAULT;
144     std::optional<Dimension> keyboardAvoidDistance_;
145 
146     bool isShowInFloatingWindow_ = false;
147 
148     float embeddedDialogOffsetY_ = 0.0f;
149     float stackRootDialogOffsetY_ = 0.0f;
150     float safeAreaBottomLength_ = 0.0f;
151     float floatButtonsHeight_ = 0.0f;
152 
153     WeakPtr<PipelineContext> context_ = nullptr;
154 
155     ACE_DISALLOW_COPY_AND_MOVE(DialogLayoutAlgorithm);
156 };
157 } // namespace OHOS::Ace::NG
158 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DIALOG_DIALOG_LAYOUT_ALGORITHM_H
159