• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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();
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     void CalculateSheetHeightInOtherScenes(LayoutWrapper* layoutWrapper);
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 private:
84     float GetWidthByScreenSizeType(const float maxWidth, LayoutWrapper* layoutWrapper) const;
85     float GetHeightByScreenSizeType(const float maxHeight, const float maxWidth, LayoutWrapper* layoutWrapper) const;
86     void ComputeCenterStyleOffset(LayoutWrapper* layoutWrapper);
87     void ComputePopupStyleOffset(LayoutWrapper* layoutWrapper);
88     void ComputeWidthAndHeight(LayoutWrapper* layoutWrapper);
89     float ComputeMaxHeight(const float parentConstraintHeight, const float parentConstraintWidth,
90         LayoutWrapper* layoutWrapper) const;
91     float GetHeightBySheetStyle(const float parentConstraintHeight, const float parentConstraintWidth,
92         LayoutWrapper* layoutWrapper) const;
93     bool SheetInSplitWindow() const;
94     LayoutConstraintF CreateSheetChildConstraint(
95         RefPtr<SheetPresentationProperty> layoutprop, LayoutWrapper* layoutWrapper);
96     void UpdateMaxSizeWithPlacement(float& maxWidth, float& maxHeight);
97     void UpdateTranslateOffsetWithPlacement(OffsetF& translate);
98     void AddArrowHeightToSheetSize();
99     void RemeasureForPopup(const RefPtr<LayoutWrapper>& layoutWrapper);
100 
101     float sheetHeight_ = 0.0f;
102     float sheetWidth_ = 0.0f;
103     float sheetMaxHeight_ = 0.0f;
104     float sheetMaxWidth_ = 0.0f;
105     float sheetOffsetX_ = 0.0f;
106     float sheetOffsetY_ = 0.0f;
107     SheetType sheetType_ = SheetType::SHEET_BOTTOM;
108     SheetStyle sheetStyle_;
109     bool isKeyBoardShow_ = false;
110     bool isHoverMode_ = false;
111     HoverModeAreaType hoverModeArea_ = HoverModeAreaType::BOTTOM_SCREEN;
112     using DirectionCheckFunc = bool (SheetPresentationLayoutAlgorithm::*)(const SizeF&, const OffsetF&);
113     std::unordered_map<Placement, DirectionCheckFunc> directionCheckFunc_;
114     using PlacementCheckFunc = bool (SheetPresentationLayoutAlgorithm::*)(const SizeF&, const OffsetF&);
115     std::unordered_map<Placement, PlacementCheckFunc> placementCheckFunc_;
116     using OffsetGetFunc = OffsetF (SheetPresentationLayoutAlgorithm::*)(const SizeF&, const OffsetF&);
117     std::unordered_map<Placement, OffsetGetFunc> getOffsetFunc_;
118     ACE_DISALLOW_COPY_AND_MOVE(SheetPresentationLayoutAlgorithm);
119     SheetPopupInfo sheetPopupInfo_;
120 };
121 } // namespace OHOS::Ace::NG
122 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_OVERLAY_SHEET_PRESENTATION_LAYOUT_ALGORITHM_H