From 298fcfe0948625a95ce04371dd643d34e6dee3ea Mon Sep 17 00:00:00 2001 From: zhangdawei40 Date: Tue, 22 Jul 2025 22:45:42 +0800 Subject: [PATCH] add interface for pagewidth Signed-off-by: zhangdawei40 Change-Id: I67fed4521cf71d01cb56e58d23f32f98424306f1 Signed-off-by: zhangdawei40 --- .../pattern/navigation/navigation_pattern.cpp | 1 + frameworks/core/pipeline/pipeline_base.cpp | 25 +++++++++++++++++++ frameworks/core/pipeline/pipeline_base.h | 13 ++++++++++ .../pipeline/pipeline_context_test_ng.cpp | 18 +++++++++++++ 4 files changed, 57 insertions(+) diff --git a/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp b/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp index c53f19701b8..4a604118428 100644 --- a/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp +++ b/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp @@ -5195,6 +5195,7 @@ void NavigationPattern::TryForceSplitIfNeeded(const SizeF& frameSize) } forceSplitSuccess_ = forceSplitSuccess; forceSplitUseNavBar_ = forceSplitUseNavBar; + context->SetIsInForceSplitMode(forceSplitSuccess_); SwapNavDestinationAndPlaceHolder(true); } diff --git a/frameworks/core/pipeline/pipeline_base.cpp b/frameworks/core/pipeline/pipeline_base.cpp index 597d485c483..3d79e6826c8 100644 --- a/frameworks/core/pipeline/pipeline_base.cpp +++ b/frameworks/core/pipeline/pipeline_base.cpp @@ -200,6 +200,30 @@ uint64_t PipelineBase::GetTimeFromExternalTimer() return (ts.tv_sec * secToNanosec + ts.tv_nsec); } +double PipelineBase::Vp2PxInner(double vpValue) const +{ + double density = GetWindowDensity(); + if (LessOrEqual(density, 1.0)) { + density = GetDensity(); + } + return vpValue * density; +} + +double PipelineBase::GetPageWidthInner(double width) const +{ + if (!isInForceSplitMode_) { + return width; + } + // Divider Width equal to 1.0_vp + constexpr double HALF = 2.0; + return (width - Vp2PxInner(1.0)) / HALF; +} + +double PipelineBase::GetPageWidth() const +{ + return GetPageWidthInner(rootWidth_); +} + void PipelineBase::RequestFrame() { if (window_) { @@ -512,6 +536,7 @@ void PipelineBase::UpdateRootSizeAndScale(int32_t width, int32_t height) if (IsContainerModalVisible()) { pageWidth -= 2 * (CONTAINER_BORDER_WIDTH + CONTENT_PADDING).ConvertToPx(); } + pageWidth = GetPageWidthInner(pageWidth); designWidthScale_ = windowConfig.autoDesignWidth ? density_ : pageWidth / windowConfig.designWidth; windowConfig.designWidthScale = designWidthScale_; diff --git a/frameworks/core/pipeline/pipeline_base.h b/frameworks/core/pipeline/pipeline_base.h index f0b73439071..5d88c2d11fe 100644 --- a/frameworks/core/pipeline/pipeline_base.h +++ b/frameworks/core/pipeline/pipeline_base.h @@ -887,6 +887,16 @@ public: return viewScale_; } + void SetIsInForceSplitMode(bool split) + { + isInForceSplitMode_ = split; + } + bool IsInForceSplitMode() const + { + return isInForceSplitMode_; + } + double GetPageWidth() const; + double GetRootWidth() const { return rootWidth_; @@ -1674,6 +1684,7 @@ protected: float viewScale_ = 1.0f; double density_ = 1.0; double dipScale_ = 1.0; + bool isInForceSplitMode_ = false; double rootHeight_ = 0.0; double rootWidth_ = 0.0; int32_t width_ = 0; @@ -1759,6 +1770,8 @@ protected: private: void DumpFrontend() const; double ModifyKeyboardHeight(double keyboardHeight) const; + double Vp2PxInner(double vpValue) const; + double GetPageWidthInner(double width) const; StatusBarEventHandler statusBarBgColorEventHandler_; PopupEventHandler popupEventHandler_; MenuEventHandler menuEventHandler_; diff --git a/test/unittest/core/pipeline/pipeline_context_test_ng.cpp b/test/unittest/core/pipeline/pipeline_context_test_ng.cpp index fe496bb6262..8b162d68155 100644 --- a/test/unittest/core/pipeline/pipeline_context_test_ng.cpp +++ b/test/unittest/core/pipeline/pipeline_context_test_ng.cpp @@ -2580,5 +2580,23 @@ HWTEST_F(PipelineContextTestNg, PipelineContextTestNg128, TestSize.Level1) context_->SetIsTransFlag(false); EXPECT_FALSE(context_->isTransFlag_); } + +/** + * @tc.name: PipelineContextTestNg128 + * @tc.desc: Branch: if (!isInForceSplitMode_) { => true + * @tc.type: FUNC + */ +HWTEST_F(PipelineContextTestNg, GetPageWidth001, TestSize.Level1) +{ + constexpr double TEST_WIDTH = 50.0; + bool backupIsSplit = context_->isInForceSplitMode_; + context_->isInForceSplitMode_ = false; + double backupWidth = context_->rootWidth_; + context_->rootWidth_ = TEST_WIDTH; + auto pageWidth = context_->GetPageWidth(); + EXPECT_TRUE(NearEqual(pageWidth, TEST_WIDTH)); + context_->isInForceSplitMode_ = backupIsSplit; + context_->rootWidth_ = backupWidth; +} } // namespace NG } // namespace OHOS::Ace \ No newline at end of file -- Gitee