From 59955a0c565679711645f31070dce75e52e8ff46 Mon Sep 17 00:00:00 2001 From: yeyinglong Date: Sat, 2 Sep 2023 16:58:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DList=E9=AB=98=E5=BA=A6?= =?UTF-8?q?=E5=8F=98=E5=8C=96=E5=B8=83=E5=B1=80=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yeyinglong --- .../core/components_ng/base/frame_node.cpp | 41 +++++++++++-- .../core/components_ng/base/frame_node.h | 3 + .../components_ng/layout/layout_algorithm.h | 22 +++++++ .../components_ng/layout/layout_property.cpp | 57 +++++++++++++++++++ .../components_ng/layout/layout_property.h | 8 +++ .../property/layout_constraint.h | 16 ++++++ .../components_ng/property/measure_property.h | 38 +++++++++++++ .../test/mock/layout/mock_layout_property.cpp | 16 ++++++ 8 files changed, 196 insertions(+), 5 deletions(-) diff --git a/frameworks/core/components_ng/base/frame_node.cpp b/frameworks/core/components_ng/base/frame_node.cpp index 239a389a610..af5de153931 100644 --- a/frameworks/core/components_ng/base/frame_node.cpp +++ b/frameworks/core/components_ng/base/frame_node.cpp @@ -2201,6 +2201,39 @@ bool FrameNode::IsSecurityComponent() GetTag() == V2::SAVE_BUTTON_ETS_TAG; } +void FrameNode::GetPercentSensitive() +{ + auto res = layoutProperty_->GetPercentSensitive(); + if (res.first) { + if (layoutAlgorithm_) { + layoutAlgorithm_->SetPercentWidth(true); + } + } + if (res.second) { + if (layoutAlgorithm_) { + layoutAlgorithm_->SetPercentHeight(true); + } + } +} + +void FrameNode::UpdatePercentSensitive() +{ + auto res = layoutProperty_->UpdatePercentSensitive( + layoutAlgorithm_->GetPercentHeight(), layoutAlgorithm_->GetPercentWidth()); + if (res.first) { + auto parent = GetAncestorNodeOfFrame(); + if (parent && parent->layoutAlgorithm_) { + parent->layoutAlgorithm_->SetPercentWidth(true); + } + } + if (res.second) { + auto parent = GetAncestorNodeOfFrame(); + if (parent && parent->layoutAlgorithm_) { + parent->layoutAlgorithm_->SetPercentHeight(true); + } + } +} + // This will call child and self measure process. void FrameNode::Measure(const std::optional& parentConstraint) { @@ -2246,12 +2279,8 @@ void FrameNode::Measure(const std::optional& parentConstraint geometryNode_->UpdateMargin(layoutProperty_->CreateMargin()); geometryNode_->UpdatePaddingWithBorder(layoutProperty_->CreatePaddingAndBorder()); - isConstraintNotChanged_ = preConstraint ? preConstraint == layoutProperty_->GetLayoutConstraint() : false; + isConstraintNotChanged_ = layoutProperty_->ConstraintEqual(preConstraint, contentConstraint); - if (!isConstraintNotChanged_) { - isConstraintNotChanged_ = - contentConstraint ? contentConstraint == layoutProperty_->GetContentLayoutConstraint() : false; - } LOGD("Measure: %{public}s, depth: %{public}d, Constraint: %{public}s", GetTag().c_str(), GetDepth(), layoutProperty_->GetLayoutConstraint()->ToString().c_str()); @@ -2270,10 +2299,12 @@ void FrameNode::Measure(const std::optional& parentConstraint if (size.has_value()) { geometryNode_->SetContentSize(size.value()); } + GetPercentSensitive(); layoutAlgorithm_->Measure(this); if (overlayNode_) { overlayNode_->Measure(layoutProperty_->CreateChildConstraint()); } + UpdatePercentSensitive(); // check aspect radio. if (pattern_ && pattern_->IsNeedAdjustByAspectRatio()) { const auto& magicItemProperty = layoutProperty_->GetMagicItemProperty(); diff --git a/frameworks/core/components_ng/base/frame_node.h b/frameworks/core/components_ng/base/frame_node.h index 3b5e4060608..4410e272a19 100644 --- a/frameworks/core/components_ng/base/frame_node.h +++ b/frameworks/core/components_ng/base/frame_node.h @@ -600,6 +600,9 @@ private: // set costom background layoutConstraint void SetBackgroundLayoutConstraint(const RefPtr& customNode); + void GetPercentSensitive(); + void UpdatePercentSensitive(); + // sort in ZIndex. std::multiset, ZIndexComparator> frameChildren_; RefPtr geometryNode_ = MakeRefPtr(); diff --git a/frameworks/core/components_ng/layout/layout_algorithm.h b/frameworks/core/components_ng/layout/layout_algorithm.h index e12ec8d30a5..1a99891575f 100644 --- a/frameworks/core/components_ng/layout/layout_algorithm.h +++ b/frameworks/core/components_ng/layout/layout_algorithm.h @@ -158,11 +158,33 @@ public: return frameId != UITaskScheduler::GetFrameId(); } + void SetPercentHeight(bool value) + { + percentHeight_ = value; + } + + void SetPercentWidth(bool value) + { + percentWidth_ = value; + } + + bool GetPercentHeight() const + { + return percentHeight_; + } + + bool GetPercentWidth() const + { + return percentHeight_; + } + private: RefPtr layoutAlgorithm_; bool skipMeasure_ = false; bool skipLayout_ = false; + bool percentHeight_ = false; + bool percentWidth_ = false; uint64_t frameId = UITaskScheduler::GetFrameId(); ACE_DISALLOW_COPY_AND_MOVE(LayoutAlgorithmWrapper); diff --git a/frameworks/core/components_ng/layout/layout_property.cpp b/frameworks/core/components_ng/layout/layout_property.cpp index 6893290ad34..191eece4138 100644 --- a/frameworks/core/components_ng/layout/layout_property.cpp +++ b/frameworks/core/components_ng/layout/layout_property.cpp @@ -1002,4 +1002,61 @@ void LayoutProperty::UpdateAllGeometryTransition(const RefPtr& parent) } } } + +std::pair LayoutProperty::GetPercentSensitive() +{ + if (!contentConstraint_.has_value()) { + return { false, false }; + } + std::pair res = { false, false }; + const auto& constraint = contentConstraint_.value(); + if (GreaterOrEqualToInfinity(constraint.maxSize.Height())) { + if (calcLayoutConstraint_ && calcLayoutConstraint_->PercentHeight()) { + res.second = true; + } + } + if (GreaterOrEqualToInfinity(constraint.maxSize.Width())) { + if (calcLayoutConstraint_ && calcLayoutConstraint_->PercentWidth()) { + res.first = true; + } + } + return res; +} + +std::pair LayoutProperty::UpdatePercentSensitive(bool width, bool height) +{ + if (!contentConstraint_.has_value()) { + return { false, false }; + } + const auto& constraint = contentConstraint_.value(); + if (GreaterOrEqualToInfinity(constraint.maxSize.Height())) { + heightPercentSensitive_ = heightPercentSensitive_ || height; + } + if (GreaterOrEqualToInfinity(constraint.maxSize.Width())) { + widthPercentSensitive_ = heightPercentSensitive_ || width; + } + return { widthPercentSensitive_, heightPercentSensitive_ }; +} + +bool LayoutProperty::ConstraintEqual(const std::optional& preLayoutConstraint, + const std::optional& preContentConstraint) +{ + if (!preLayoutConstraint || !layoutConstraint_) { + return false; + } + if (!preContentConstraint || !contentConstraint_) { + return false; + } + const auto& layout = layoutConstraint_.value(); + const auto& content = contentConstraint_.value(); + if (GreaterOrEqualToInfinity(layout.maxSize.Width()) && !widthPercentSensitive_) { + return (layout.EqualWithoutPercentWidth(preLayoutConstraint.value()) && + content.EqualWithoutPercentWidth(preContentConstraint.value())); + } + if (GreaterOrEqualToInfinity(layout.maxSize.Height()) && !heightPercentSensitive_) { + return (layout.EqualWithoutPercentHeight(preLayoutConstraint.value()) && + content.EqualWithoutPercentHeight(preContentConstraint.value())); + } + return (preLayoutConstraint == layoutConstraint_ && preContentConstraint == contentConstraint_); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/layout/layout_property.h b/frameworks/core/components_ng/layout/layout_property.h index e2fa4647286..a528f85133b 100644 --- a/frameworks/core/components_ng/layout/layout_property.h +++ b/frameworks/core/components_ng/layout/layout_property.h @@ -270,6 +270,11 @@ public: static void UpdateAllGeometryTransition(const RefPtr& parent); + std::pair GetPercentSensitive(); + std::pair UpdatePercentSensitive(bool width, bool height); + bool ConstraintEqual(const std::optional& preLayoutConstraint, + const std::optional& preContentConstraint); + protected: void UpdateLayoutProperty(const LayoutProperty* layoutProperty); @@ -312,6 +317,9 @@ private: Dimension overlayOffsetX_; Dimension overlayOffsetY_; + bool heightPercentSensitive_ = false; + bool widthPercentSensitive_ = false; + ACE_DISALLOW_COPY_AND_MOVE(LayoutProperty); }; } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/property/layout_constraint.h b/frameworks/core/components_ng/property/layout_constraint.h index 8e26ed4f41d..548f6f2dd85 100644 --- a/frameworks/core/components_ng/property/layout_constraint.h +++ b/frameworks/core/components_ng/property/layout_constraint.h @@ -62,6 +62,22 @@ struct LayoutConstraintT { return !(*this == layoutConstraint); } + bool EqualWithoutPercentWidth(const LayoutConstraintT& layoutConstraint) const + { + return (scaleProperty == layoutConstraint.scaleProperty) && (minSize == layoutConstraint.minSize) && + (maxSize == layoutConstraint.maxSize) && (parentIdealSize == layoutConstraint.parentIdealSize) && + (percentReference.Height() == layoutConstraint.percentReference.Height()) && + (selfIdealSize == layoutConstraint.selfIdealSize); + } + + bool EqualWithoutPercentHeight(const LayoutConstraintT& layoutConstraint) const + { + return (scaleProperty == layoutConstraint.scaleProperty) && (minSize == layoutConstraint.minSize) && + (maxSize == layoutConstraint.maxSize) && (parentIdealSize == layoutConstraint.parentIdealSize) && + (percentReference.Width() == layoutConstraint.percentReference.Width()) && + (selfIdealSize == layoutConstraint.selfIdealSize); + } + bool UpdateSelfMarginSizeWithCheck(const OptionalSize& size) { if (selfIdealSize == size) { diff --git a/frameworks/core/components_ng/property/measure_property.h b/frameworks/core/components_ng/property/measure_property.h index a6e1a29af8e..f6fceaa6053 100644 --- a/frameworks/core/components_ng/property/measure_property.h +++ b/frameworks/core/components_ng/property/measure_property.h @@ -132,6 +132,16 @@ public: return height_ && height_->GetDimension().Unit() != DimensionUnit::PERCENT; } + bool PercentWidth() const + { + return width_ && width_->GetDimension().Unit() == DimensionUnit::PERCENT; + } + + bool PercentHeight() const + { + return height_ && height_->GetDimension().Unit() == DimensionUnit::PERCENT; + } + std::string ToString() const { static const int32_t precision = 2; @@ -212,6 +222,34 @@ struct MeasureProperty { return true; } + bool PercentWidth() const + { + if (selfIdealSize.has_value()) { + return selfIdealSize->PercentWidth(); + } + if (maxSize.has_value()) { + return maxSize->PercentWidth(); + } + if (minSize.has_value()) { + return minSize->PercentWidth(); + } + return false; + } + + bool PercentHeight() const + { + if (selfIdealSize.has_value()) { + return selfIdealSize->PercentHeight(); + } + if (maxSize.has_value()) { + return maxSize->PercentHeight(); + } + if (minSize.has_value()) { + return minSize->PercentHeight(); + } + return false; + } + std::string ToString() const { std::string str; diff --git a/frameworks/core/components_ng/test/mock/layout/mock_layout_property.cpp b/frameworks/core/components_ng/test/mock/layout/mock_layout_property.cpp index 106e9908fa5..6aa223714b2 100644 --- a/frameworks/core/components_ng/test/mock/layout/mock_layout_property.cpp +++ b/frameworks/core/components_ng/test/mock/layout/mock_layout_property.cpp @@ -181,4 +181,20 @@ PaddingPropertyF LayoutProperty::CreatePaddingAndBorder() { return PaddingPropertyF(); } + +std::pair LayoutProperty::GetPercentSensitive() +{ + return { false, false }; +} + +std::pair LayoutProperty::UpdatePercentSensitive(bool width, bool height) +{ + return { widthPercentSensitive_, heightPercentSensitive_ }; +} + +bool LayoutProperty::ConstraintEqual(const std::optional& preLayoutConstraint, + const std::optional& preContentConstraint) +{ + return false; +} } // namespace OHOS::Ace::NG -- Gitee