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/dialog/dialog_theme.h" 29 #include "core/components_ng/layout/layout_algorithm.h" 30 #include "core/components_ng/pattern/dialog/dialog_layout_property.h" 31 #include "core/components_ng/pattern/overlay/overlay_manager.h" 32 33 namespace OHOS::Ace::NG { 34 enum class TouchingBoundaryType { 35 NotTouchBoundary = 0, 36 TouchBottomBoundary, 37 TouchRightBoundary, 38 }; 39 // DialogLayoutAlgorithm uses for Dialog Node. 40 class ACE_EXPORT DialogLayoutAlgorithm : public LayoutAlgorithm { 41 DECLARE_ACE_TYPE(DialogLayoutAlgorithm, LayoutAlgorithm); 42 43 public: 44 DialogLayoutAlgorithm() = default; 45 ~DialogLayoutAlgorithm() override = default; 46 47 void Measure(LayoutWrapper* layoutWrapper) override; 48 49 void Layout(LayoutWrapper* layoutWrapper) override; 50 GetTouchRegion()51 RectF GetTouchRegion() const 52 { 53 return touchRegion_; 54 } 55 56 private: 57 LayoutConstraintF CreateDialogChildConstraint(LayoutWrapper* layoutWrapper, float height, float width); 58 void Distribute(float& scrollHeight, float& listHeight, float restHeight); 59 void AnalysisHeightOfChild(LayoutWrapper* layoutWrapper); 60 void AnalysisLayoutOfContent(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& scroll); 61 62 bool ComputeInnerLayoutSizeParam(LayoutConstraintF& innerLayout, const RefPtr<DialogLayoutProperty>& dialogProp); 63 bool IsGetExpandDisplayValidHeight(); 64 RefPtr<PipelineContext> GetCurrentPipelineContext(); 65 void ComputeInnerLayoutParam(LayoutConstraintF& innerLayout, const RefPtr<DialogLayoutProperty>& dialogProp); 66 double GetMaxWidthBasedOnGridType(const RefPtr<GridColumnInfo>& info, GridSizeType type, DeviceType deviceType); 67 int32_t GetDeviceColumns(GridSizeType type, DeviceType deviceType); 68 OffsetF ComputeChildPosition( 69 const SizeF& childSize, const RefPtr<DialogLayoutProperty>& prop, const SizeF& slefSize); 70 bool SetAlignmentSwitch(const SizeF& maxSize, const SizeF& childSize, OffsetF& topLeftPoint); 71 bool SetAlignmentSwitchLessThanAPITwelve(const SizeF& maxSize, const SizeF& childSize, OffsetF& topLeftPoint); 72 bool IsAlignmentByWholeScreen(); 73 bool IsDialogTouchingBoundary(OffsetF topLeftPoint, SizeF childSize, SizeF selfSize); 74 void MultipleDialog(const RefPtr<DialogLayoutProperty>& dialogProp, const SizeF& childSize, const SizeF& selfSize, 75 const RefPtr<OverlayManager> subOverlayManager); 76 void ProcessMaskRect(std::optional<DimensionRect> maskRect, const RefPtr<FrameNode>& dialog, bool isMask = false); 77 void SetSubWindowHotarea( 78 const RefPtr<DialogLayoutProperty>& dialogProp, SizeF childSize, SizeF selfSize, int32_t frameNodeId); 79 std::optional<DimensionRect> GetMaskRect(const RefPtr<FrameNode>& dialog); 80 81 void UpdateTouchRegion(); 82 83 double GetPaddingBottom() const; 84 85 OffsetF AdjustChildPosition( 86 OffsetF& topLeftPoint, const OffsetF& dialogOffset, const SizeF& childSize, bool needAvoidKeyboard); 87 88 SizeF UpdateHeightWithSafeArea(SizeF size); 89 void UpdateSafeArea(); 90 void UpdateChildLayoutConstraint(const RefPtr<DialogLayoutProperty>& dialogProp, 91 LayoutConstraintF& childLayoutConstraint, RefPtr<LayoutWrapper>& childLayoutWrapper); 92 void ClipUIExtensionSubWindowContent(const RefPtr<FrameNode>& dialog, bool isClip); 93 void AdjustHeightForKeyboard(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& child); 94 void UpdateIsScrollHeightNegative(LayoutWrapper* layoutWrapper, float height); 95 96 RectF touchRegion_; 97 OffsetF topLeftPoint_; 98 bool customSize_ = false; 99 SafeAreaInsets safeAreaInsets_; 100 bool isModal_ = true; 101 bool isShowInSubWindow_ = false; 102 bool isSuitableForElderly_ = false; 103 bool isSuitOldMeasure_ = false; 104 float dialogMaxHeight_ = 0.0f; 105 int32_t gridCount_ = -1; 106 int32_t subWindowId_ = -1; 107 DimensionOffset dialogOffset_; 108 DialogAlignment alignment_ = DialogAlignment::DEFAULT; 109 TouchingBoundaryType touchingBoundaryFlag_ = TouchingBoundaryType::NotTouchBoundary; 110 111 bool expandDisplay_ = false; 112 double expandDisplayValidHeight_ = 0.0; 113 bool isUIExtensionSubWindow_ = false; 114 RectF hostWindowRect_; 115 116 SizeF dialogChildSize_; 117 bool resizeFlag_ = false; 118 119 KeyboardAvoidMode keyboardAvoidMode_ = KeyboardAvoidMode::DEFAULT; 120 121 ACE_DISALLOW_COPY_AND_MOVE(DialogLayoutAlgorithm); 122 }; 123 } // namespace OHOS::Ace::NG 124 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_DIALOG_DIALOG_LAYOUT_ALGORITHM_H 125