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 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_NAVIGATION_NAVIGATION_LAYOUT_ALGORITHM_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_NAVIGATION_NAVIGATION_LAYOUT_ALGORITHM_H 18 19 #include <cstdint> 20 21 #include "base/memory/referenced.h" 22 #include "core/components_ng/layout/layout_algorithm.h" 23 #include "core/components_ng/layout/layout_wrapper.h" 24 #include "core/components_ng/pattern/navigation/navigation_declaration.h" 25 #include "core/components_ng/pattern/navigation/navigation_group_node.h" 26 #include "core/components_ng/pattern/navigation/navigation_layout_property.h" 27 28 namespace OHOS::Ace::NG { 29 30 class ACE_EXPORT NavigationLayoutAlgorithm : public LayoutAlgorithm { 31 DECLARE_ACE_TYPE(NavigationLayoutAlgorithm, LayoutAlgorithm); 32 33 public: 34 NavigationLayoutAlgorithm() = default; 35 ~NavigationLayoutAlgorithm() override = default; 36 void Measure(LayoutWrapper* layoutWrapper) override; 37 void Layout(LayoutWrapper* layoutWrapper) override; 38 GetNavigationMode()39 NavigationMode GetNavigationMode() const 40 { 41 return navigationMode_; 42 } 43 SetNavigationMode(NavigationMode navigationMode)44 void SetNavigationMode(NavigationMode navigationMode) 45 { 46 navigationMode_ = navigationMode; 47 } 48 SetRealNavBarWidth(float realNavBarWidth)49 void SetRealNavBarWidth(float realNavBarWidth) 50 { 51 realNavBarWidth_ = realNavBarWidth; 52 } 53 GetRealNavBarWidth()54 float GetRealNavBarWidth() 55 { 56 return realNavBarWidth_; 57 } 58 SetIfNeedInit(bool ifNeedInit)59 void SetIfNeedInit(bool ifNeedInit) 60 { 61 ifNeedInit_ = ifNeedInit; 62 } 63 GetRealNavBarHeight()64 float GetRealNavBarHeight() const 65 { 66 return realNavBarHeight_; 67 } 68 GetRealDividerWidth()69 float GetRealDividerWidth() const 70 { 71 return realDividerWidth_; 72 } 73 GetNavBarOffset()74 OffsetF GetNavBarOffset() const 75 { 76 return navBarOffset_; 77 } 78 79 static bool IsAutoHeight(const RefPtr<LayoutProperty>& layoutProperty); 80 81 private: 82 NavigationMode navigationMode_ = NavigationMode::AUTO; 83 ACE_DISALLOW_COPY_AND_MOVE(NavigationLayoutAlgorithm); 84 void MeasureNavBar(LayoutWrapper* layoutWrapper, const RefPtr<NavigationGroupNode>& hostNode, 85 const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty, const SizeF& navBarSize); 86 87 void MeasureContentChild(LayoutWrapper* layoutWrapper, const RefPtr<NavigationGroupNode>& hostNode, 88 const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty, const SizeF& contentSize_); 89 90 void RangeCalculation( 91 const RefPtr<NavigationGroupNode>& hostNode, const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty); 92 93 void GetRange(const RefPtr<NavigationGroupNode>& hostNode); 94 95 void UpdateNavigationMode(const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty, const SizeF& frameSize); 96 97 void SizeCalculation(LayoutWrapper* layoutWrapper, 98 const RefPtr<NavigationGroupNode>& hostNode, 99 const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty, const SizeF& frameSize); 100 101 void SizeCalculationSplit(const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty, const SizeF& frameSize); 102 void CheckSizeInSplit(const float frameWidth, const float userSetNavBarWidth, const float minNavBarWidth, 103 const float minContentWidth); 104 105 void SizeCalculationStack(const RefPtr<NavigationGroupNode>& hostNode, 106 const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty, const SizeF& frameSize); 107 108 void SetNavigationHeight(LayoutWrapper* layoutWrapper, SizeF& size); 109 110 bool ifNeedInit_ = true; 111 OffsetF navBarOffset_; 112 113 bool userSetNavBarRangeFlag_ = false; 114 bool userSetMinContentFlag_ = false; 115 bool userSetNavBarWidthFlag_ = false; 116 Dimension minNavBarWidthValue_ = 0.0_vp; 117 Dimension maxNavBarWidthValue_ = 0.0_vp; 118 Dimension minContentWidthValue_ = 0.0_vp; 119 120 float realNavBarWidth_ = 0.0f; 121 float realDividerWidth_ = 0.0f; 122 float realNavBarHeight_ = 0.0f; 123 float realContentWidth_ = 0.0f; 124 float realContentHeight_ = 0.0f; 125 126 SizeF navBarSize_ = SizeF(0.0f, 0.0f); 127 SizeF contentSize_ = SizeF(0.0f, 0.0f); 128 SizeF dividerSize_ = SizeF(0.0f, 0.0f); 129 }; 130 131 } // namespace OHOS::Ace::NG 132 133 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_NAVIGATION_NAVIGATION_LAYOUT_ALGORITHM_H 134