• 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;
46     ~DialogLayoutAlgorithm() override = default;
47 
48     void Measure(LayoutWrapper* layoutWrapper) override;
49 
50     void Layout(LayoutWrapper* layoutWrapper) override;
51 
GetTouchRegion()52     RectF GetTouchRegion() const
53     {
54         return touchRegion_;
55     }
56 
57 private:
58     LayoutConstraintF CreateDialogChildConstraint(LayoutWrapper* layoutWrapper, float height, float width);
59     void Distribute(float& scrollHeight, float& listHeight, float restHeight);
60     void AnalysisHeightOfChild(LayoutWrapper* layoutWrapper);
61     void AnalysisLayoutOfContent(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& scroll);
62 
63     bool ComputeInnerLayoutSizeParam(LayoutConstraintF& innerLayout, const RefPtr<DialogLayoutProperty>& dialogProp);
64     bool IsGetExpandDisplayValidHeight();
65     RefPtr<PipelineContext> GetCurrentPipelineContext();
66     void ComputeInnerLayoutParam(LayoutConstraintF& innerLayout, const RefPtr<DialogLayoutProperty>& dialogProp);
67     double GetMaxWidthBasedOnGridType(const RefPtr<GridColumnInfo>& info, GridSizeType type, DeviceType deviceType);
68     int32_t GetDeviceColumns(GridSizeType type, DeviceType deviceType);
69     OffsetF ComputeChildPosition(
70         const SizeF& childSize, const RefPtr<DialogLayoutProperty>& prop, const SizeF& slefSize);
71     bool SetAlignmentSwitch(SizeF& maxSize, const SizeF& childSize, OffsetF& topLeftPoint);
72     bool SetAlignmentSwitchLessThanAPITwelve(const SizeF& maxSize, const SizeF& childSize, OffsetF& topLeftPoint);
73     bool IsAlignmentByWholeScreen();
74     void CaculateMaxSize(SizeF& maxSize);
75     bool IsDialogTouchingBoundary(OffsetF topLeftPoint, SizeF childSize, SizeF selfSize);
76     void MultipleDialog(const RefPtr<DialogLayoutProperty>& dialogProp, const SizeF& childSize, const SizeF& selfSize,
77         const RefPtr<OverlayManager> subOverlayManager);
78     void ProcessMaskRect(std::optional<DimensionRect> maskRect, const RefPtr<FrameNode>& dialog, bool isMask = false);
79     void SetSubWindowHotarea(
80         const RefPtr<DialogLayoutProperty>& dialogProp, SizeF childSize, SizeF selfSize, int32_t frameNodeId);
81     std::optional<DimensionRect> GetMaskRect(const RefPtr<FrameNode>& dialog);
82 
83     void UpdateTouchRegion();
84 
85     double GetPaddingBottom() const;
86     double GetKeyboardAvoidDistance() const;
87 
88     OffsetF AdjustChildPosition(
89         OffsetF& topLeftPoint, const OffsetF& dialogOffset, const SizeF& childSize, bool needAvoidKeyboard);
90 
91     SizeF UpdateHeightWithSafeArea(SizeF size);
92     void UpdateSafeArea(const RefPtr<FrameNode>& frameNode);
93     void UpdateChildLayoutConstraint(const RefPtr<DialogLayoutProperty>& dialogProp,
94         LayoutConstraintF& childLayoutConstraint, RefPtr<LayoutWrapper>& childLayoutWrapper);
95     void ClipUIExtensionSubWindowContent(const RefPtr<FrameNode>& dialog);
96     void AdjustHeightForKeyboard(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& child);
97     void UpdateIsScrollHeightNegative(LayoutWrapper* layoutWrapper, float height);
98     void UpdateChildMaxSizeHeight(SizeT<float>& maxSize);
99     void ParseSubwindowId(const RefPtr<DialogLayoutProperty>& dialogProp);
100 
101     void ResizeDialogSubwindow(bool expandDisplay, bool isShowInSubWindow, bool isShowInFloatingWindow);
102 
103     bool IsEmbeddedDialog(const RefPtr<FrameNode>& frameNode);
104     float GetEmbeddedDialogOffsetY(const RefPtr<FrameNode>& frameNode);
105 
106     RectF touchRegion_;
107     OffsetF topLeftPoint_;
108     bool customSize_ = false;
109     SafeAreaInsets safeAreaInsets_;
110     bool isModal_ = true;
111     bool isShowInSubWindow_ = false;
112     bool isSuitableForElderly_ = false;
113     bool isSuitOldMeasure_ = false;
114     float dialogMaxHeight_ = 0.0f;
115     int32_t gridCount_ = -1;
116     int32_t subWindowId_ = -1;
117     DimensionOffset dialogOffset_;
118     DialogAlignment alignment_ = DialogAlignment::DEFAULT;
119     TouchingBoundaryType touchingBoundaryFlag_ = TouchingBoundaryType::NotTouchBoundary;
120 
121     bool expandDisplay_ = false;
122     double expandDisplayValidHeight_ = 0.0;
123     bool isUIExtensionSubWindow_ = false;
124     RectF hostWindowRect_;
125 
126     SizeF dialogChildSize_;
127     bool resizeFlag_ = false;
128     bool isHoverMode_ = false;
129     bool isKeyBoardShow_ = false;
130     bool alignBottomScreen_ = false;
131     Rect foldCreaseRect = Rect(0.0, 0.0, 0.0, 0.0);
132     HoverModeAreaType hoverModeArea_ = HoverModeAreaType::BOTTOM_SCREEN;
133 
134     KeyboardAvoidMode keyboardAvoidMode_ = KeyboardAvoidMode::DEFAULT;
135     std::optional<Dimension> keyboardAvoidDistance_;
136 
137     bool isShowInFloatingWindow_ = false;
138 
139     float embeddedDialogOffsetY_ = 0.0f;
140     float safeAreaBottomLength_ = 0.0f;
141 
142     ACE_DISALLOW_COPY_AND_MOVE(DialogLayoutAlgorithm);
143 };
144 } // namespace OHOS::Ace::NG
145 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DIALOG_DIALOG_LAYOUT_ALGORITHM_H
146