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 <optional> 21 22 #include "base/geometry/axis.h" 23 #include "base/geometry/dimension.h" 24 #include "base/geometry/ng/size_t.h" 25 #include "base/memory/referenced.h" 26 #include "core/components_ng/layout/layout_algorithm.h" 27 #include "core/components_ng/layout/layout_wrapper.h" 28 #include "core/components_ng/pattern/linear_layout/linear_layout_algorithm.h" 29 #include "core/components_ng/pattern/overlay/sheet_presentation_property.h" 30 #include "core/components_ng/pattern/overlay/sheet_style.h" 31 32 namespace OHOS::Ace::NG { 33 class ACE_EXPORT SheetPresentationLayoutAlgorithm : public LinearLayoutAlgorithm { 34 DECLARE_ACE_TYPE(SheetPresentationLayoutAlgorithm, LayoutAlgorithm); 35 36 public: 37 SheetPresentationLayoutAlgorithm() = default; SheetPresentationLayoutAlgorithm(int32_t id,const std::string & tag,SheetType sheetType)38 SheetPresentationLayoutAlgorithm(int32_t id, const std::string& tag, SheetType sheetType) 39 : targetNodeId_(id), targetTag_(tag), sheetType_(sheetType) 40 {} 41 ~SheetPresentationLayoutAlgorithm() override = default; 42 OnReset()43 void OnReset() override {} 44 void Measure(LayoutWrapper* layoutWrapper) override; 45 void Layout(LayoutWrapper* layoutWrapper) override; GetSheetMaxHeight()46 float GetSheetMaxHeight() 47 { 48 return sheetMaxHeight_; 49 } 50 GetSheetMaxWidth()51 float GetSheetMaxWidth() 52 { 53 return sheetMaxWidth_; 54 } 55 GetCenterHeight()56 float GetCenterHeight() 57 { 58 return sheetHeight_; 59 } 60 GetSheetOffsetX()61 float GetSheetOffsetX() 62 { 63 return sheetOffsetX_; 64 } 65 GetSheetOffsetY()66 float GetSheetOffsetY() 67 { 68 return sheetOffsetY_; 69 } 70 71 private: 72 int32_t targetNodeId_ = -1; 73 std::string targetTag_; 74 OffsetF GetPopupStyleSheetOffset(); 75 float GetWidthByScreenSizeType(const SizeF& maxSize) const; 76 float GetHeightByScreenSizeType(const SizeF& maxSize) const; 77 float GetHeightBySheetStyle() const; 78 LayoutConstraintF CreateSheetChildConstraint(RefPtr<SheetPresentationProperty> layoutprop); 79 float sheetHeight_ = 0.0f; 80 float sheetWidth_ = 0.0f; 81 float sheetMaxHeight_ = 0.0f; 82 float sheetMaxWidth_ = 0.0f; 83 float sheetOffsetX_ = 0.0f; 84 float sheetOffsetY_ = 0.0f; 85 SheetType sheetType_ = SheetType::SHEET_BOTTOM; 86 SheetStyle sheetStyle_; 87 ACE_DISALLOW_COPY_AND_MOVE(SheetPresentationLayoutAlgorithm); 88 }; 89 } // namespace OHOS::Ace::NG 90 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_OVERLAY_SHEET_PRESENTATION_LAYOUT_ALGORITHM_H