1 /* 2 * Copyright (c) 2023 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 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_OVERLAY_SHEET_PRESENTATION_LAYOUT_ALGORITHM_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_OVERLAY_SHEET_PRESENTATION_LAYOUT_ALGORITHM_H 18 19 #include <cstdint> 20 #include <functional> 21 #include <optional> 22 #include <unordered_map> 23 24 #include "base/geometry/axis.h" 25 #include "base/geometry/dimension.h" 26 #include "base/geometry/ng/size_t.h" 27 #include "base/memory/referenced.h" 28 #include "core/components/common/properties/placement.h" 29 #include "core/components_ng/layout/layout_algorithm.h" 30 #include "core/components_ng/layout/layout_wrapper.h" 31 #include "core/components_ng/pattern/linear_layout/linear_layout_algorithm.h" 32 #include "core/components_ng/pattern/overlay/sheet_presentation_property.h" 33 #include "core/components_ng/pattern/overlay/sheet_style.h" 34 35 namespace OHOS::Ace::NG { 36 class ACE_EXPORT SheetPresentationLayoutAlgorithm : public LinearLayoutAlgorithm { 37 DECLARE_ACE_TYPE(SheetPresentationLayoutAlgorithm, LayoutAlgorithm); 38 39 public: 40 SheetPresentationLayoutAlgorithm() = default; SheetPresentationLayoutAlgorithm(SheetType sheetType,SheetPopupInfo popupInfo)41 SheetPresentationLayoutAlgorithm(SheetType sheetType, SheetPopupInfo popupInfo) 42 : sheetType_(sheetType), sheetPopupInfo_(popupInfo) {} 43 ~SheetPresentationLayoutAlgorithm() override = default; 44 45 void InitParameter(LayoutWrapper* layoutWrapper); OnReset()46 void OnReset() override {} 47 void Measure(LayoutWrapper* layoutWrapper) override; 48 void Layout(LayoutWrapper* layoutWrapper) override; GetSheetMaxHeight()49 float GetSheetMaxHeight() 50 { 51 return sheetMaxHeight_; 52 } 53 GetSheetMaxWidth()54 float GetSheetMaxWidth() 55 { 56 return sheetMaxWidth_; 57 } 58 GetCenterHeight()59 float GetCenterHeight() 60 { 61 return sheetHeight_; 62 } 63 GetSheetOffsetX()64 float GetSheetOffsetX() 65 { 66 return sheetOffsetX_; 67 } 68 GetSheetOffsetY()69 float GetSheetOffsetY() 70 { 71 return sheetOffsetY_; 72 } 73 74 void UpdatePopupInfoAndRemeasure(LayoutWrapper* layoutWrapper, const SheetPopupInfo& sheetPopupInfo, 75 const float& sheetWidth, const float& sheetHeight); 76 77 float CalculateSheetHeightInOtherScenes(LayoutWrapper* layoutWrapper, const float heightBefore) const; 78 void CalculateSheetOffsetInOtherScenes(LayoutWrapper* layoutWrapper); 79 80 void LayoutTitleBuilder(const NG::OffsetF& translate, LayoutWrapper* layoutWrapper); 81 void LayoutScrollNode(const NG::OffsetF& translate, LayoutWrapper* layoutWrapper); 82 void LayoutCloseIcon(const NG::OffsetF& translate, LayoutWrapper* layoutWrapper); 83 void LayoutDragBar(const NG::OffsetF& translate, LayoutWrapper* layoutWrapper); 84 85 private: 86 float GetWidthByScreenSizeType(const float maxWidth, LayoutWrapper* layoutWrapper) const; 87 float GetHeightByScreenSizeType(const float maxHeight, const float maxWidth, LayoutWrapper* layoutWrapper) const; 88 void ComputeCenterStyleOffset(LayoutWrapper* layoutWrapper); 89 void ComputeCenterOffsetForUECSubwindow(LayoutWrapper* layoutWrapper); 90 void ComputeCenterOffsetForNotUECSubwindow(LayoutWrapper* layoutWrapper); 91 void ComputePopupStyleOffset(LayoutWrapper* layoutWrapper); 92 void ComputeWidthAndHeight(LayoutWrapper* layoutWrapper); 93 float ComputeMaxHeight(const float parentConstraintHeight, const float parentConstraintWidth, 94 LayoutWrapper* layoutWrapper) const; 95 float GetHeightBySheetStyle(const float parentConstraintHeight, const float parentConstraintWidth, 96 LayoutWrapper* layoutWrapper) const; 97 bool SheetInSplitWindow() const; 98 LayoutConstraintF CreateSheetChildConstraint( 99 RefPtr<SheetPresentationProperty> layoutprop, LayoutWrapper* layoutWrapper); 100 void UpdateMaxSizeWithPlacement(float& maxWidth, float& maxHeight, LayoutWrapper* layoutWrapper); 101 void UpdateTranslateOffsetWithPlacement(OffsetF& translate, LayoutWrapper* layoutWrapper); 102 void AddArrowHeightToSheetSize(); 103 void RemeasureForPopup(const RefPtr<LayoutWrapper>& layoutWrapper); 104 void MinusSubwindowDistance(const RefPtr<FrameNode>& sheetWrapper); 105 float GetCenterDefaultWidth(const RefPtr<FrameNode>& host) const; 106 void MeasureOperation(LayoutWrapper* layoutWrapper, LayoutConstraintF constraint); 107 void MeasureDragBar(LayoutWrapper* layoutWrapper, LayoutConstraintF constraint); 108 void MeasureCloseIcon(LayoutWrapper* layoutWrapper, LayoutConstraintF constraint); 109 110 float sheetHeight_ = 0.0f; 111 float sheetWidth_ = 0.0f; 112 float sheetMaxHeight_ = 0.0f; 113 float sheetMaxWidth_ = 0.0f; 114 float sheetOffsetX_ = 0.0f; 115 float sheetOffsetY_ = 0.0f; 116 SheetType sheetType_ = SheetType::SHEET_BOTTOM; 117 SheetStyle sheetStyle_; 118 bool isKeyBoardShow_ = false; 119 bool isHoverMode_ = false; 120 bool isWaterfallWindowMode_ = false; 121 HoverModeAreaType hoverModeArea_ = HoverModeAreaType::BOTTOM_SCREEN; 122 using DirectionCheckFunc = bool (SheetPresentationLayoutAlgorithm::*)(const SizeF&, const OffsetF&); 123 std::unordered_map<Placement, DirectionCheckFunc> directionCheckFunc_; 124 using PlacementCheckFunc = bool (SheetPresentationLayoutAlgorithm::*)(const SizeF&, const OffsetF&); 125 std::unordered_map<Placement, PlacementCheckFunc> placementCheckFunc_; 126 using OffsetGetFunc = OffsetF (SheetPresentationLayoutAlgorithm::*)(const SizeF&, const OffsetF&); 127 std::unordered_map<Placement, OffsetGetFunc> getOffsetFunc_; 128 ACE_DISALLOW_COPY_AND_MOVE(SheetPresentationLayoutAlgorithm); 129 SheetPopupInfo sheetPopupInfo_; 130 }; 131 } // namespace OHOS::Ace::NG 132 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_OVERLAY_SHEET_PRESENTATION_LAYOUT_ALGORITHM_H