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 SetRealNavBarWidth(float realNavBarWidth)39 void SetRealNavBarWidth(float realNavBarWidth) 40 { 41 realNavBarWidth_ = realNavBarWidth; 42 } 43 SetIfNeedInit(bool ifNeedInit)44 void SetIfNeedInit(bool ifNeedInit) 45 { 46 ifNeedInit_ = ifNeedInit; 47 } 48 49 static bool IsAutoHeight(const RefPtr<LayoutProperty>& layoutProperty); 50 51 private: 52 ACE_DISALLOW_COPY_AND_MOVE(NavigationLayoutAlgorithm); 53 void MeasureNavBar(LayoutWrapper* layoutWrapper, const RefPtr<NavigationGroupNode>& hostNode, 54 const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty, const SizeF& navBarSize); 55 56 void MeasureContentChild(LayoutWrapper* layoutWrapper, const RefPtr<NavigationGroupNode>& hostNode, 57 const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty, const SizeF& contentSize_); 58 59 void RangeCalculation( 60 const RefPtr<NavigationGroupNode>& hostNode, const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty); 61 62 void GetRange(const RefPtr<NavigationGroupNode>& hostNode); 63 64 void UpdateNavigationMode(const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty, const SizeF& frameSize, 65 const RefPtr<NavigationGroupNode>& hostNode); 66 67 void SizeCalculation(LayoutWrapper* layoutWrapper, const RefPtr<NavigationGroupNode>& hostNode, 68 const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty, const SizeF& frameSize); 69 70 void SizeCalculationSplit(const RefPtr<NavigationGroupNode>& hostNode, 71 const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty, const SizeF& frameSize); 72 void CheckSizeInSplit(const float frameWidth, const float userSetNavBarWidth, const float minNavBarWidth, 73 const float minContentWidth); 74 75 void SizeCalculationStack(const RefPtr<NavigationGroupNode>& hostNode, 76 const RefPtr<NavigationLayoutProperty>& navigationLayoutProperty, const SizeF& frameSize); 77 78 float CalculateNavigationWidth(const RefPtr<NavigationGroupNode>& hostNode); 79 80 void SetNavigationHeight(LayoutWrapper* layoutWrapper, SizeF& size); 81 82 bool ifNeedInit_ = true; 83 84 bool userSetNavBarRangeFlag_ = false; 85 bool userSetMinContentFlag_ = false; 86 bool userSetNavBarWidthFlag_ = false; 87 Dimension minNavBarWidthValue_ = 0.0_vp; 88 Dimension maxNavBarWidthValue_ = 0.0_vp; 89 Dimension minContentWidthValue_ = 0.0_vp; 90 91 float realNavBarWidth_ = 0.0f; 92 float realDividerWidth_ = 0.0f; 93 float realNavBarHeight_ = 0.0f; 94 float realContentWidth_ = 0.0f; 95 float realContentHeight_ = 0.0f; 96 97 SizeF navBarSize_ = SizeF(0.0f, 0.0f); 98 SizeF contentSize_ = SizeF(0.0f, 0.0f); 99 SizeF dividerSize_ = SizeF(0.0f, 0.0f); 100 }; 101 102 } // namespace OHOS::Ace::NG 103 104 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_NAVIGATION_NAVIGATION_LAYOUT_ALGORITHM_H 105