diff --git a/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp b/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp index c53f19701b8d4e49fdb2e9a9efe41c8b652abcb8..4a604118428aefa35917db2463d4613aedca0c34 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 597d485c4837ecd17fdb84b0299fb19e1b924dbf..3d79e6826c8955a7e8f47dacb99d5675bfeef35d 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 f0b73439071c6bb19072317bbff289257835c138..5d88c2d11fe8253d7bbca65cc4d4bcc7a022ee92 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 fe496bb62626090d22d35b34b1a9a7b136d6d617..8b162d681555de8d2220890f4f4009e0cdb807dc 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