diff --git a/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_pixel_unit_convert_ffi.cpp b/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_pixel_unit_convert_ffi.cpp index f3f6cedd8dce732f0b733d1a25504b6c142c22ae..9d19e62cc6c668f95d82cbb59db10928a505a7be 100644 --- a/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_pixel_unit_convert_ffi.cpp +++ b/frameworks/bridge/cj_frontend/interfaces/cj_ffi/cj_pixel_unit_convert_ffi.cpp @@ -88,6 +88,14 @@ double GetdesignWidthScale() return NAN; } auto windowConfig = frontend->GetWindowConfig(); + + // 在强制分屏模式下调整计算宽度 + if (pipelineContext && pipelineContext->IsInForceSplitMode()) { + double effectiveWidth = pipelineContext->GetForceSplitEffectiveWidth(width); + if (effectiveWidth > 0) { + width = effectiveWidth; + } + } windowConfig.UpdateDesignWidthScale(width); return windowConfig.GetDesignWidthScale(width); diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp index da3a96845571724171e4459401a5d671a11c5fa7..8b61c9ccb795ecf7f208af561698170526cbcad5 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp @@ -1124,6 +1124,15 @@ panda::Local Lpx2Px(panda::JsiRuntimeCallInfo* runtimeCallInf if (pipelineContext && pipelineContext->IsContainerModalVisible()) { width -= 2 * (CONTAINER_BORDER_WIDTH + CONTENT_PADDING).ConvertToPx(); } + + // 在强制分屏模式下调整计算宽度 + if (pipelineContext && pipelineContext->IsInForceSplitMode()) { + double effectiveWidth = pipelineContext->GetForceSplitEffectiveWidth(width); + if (effectiveWidth > 0) { + width = effectiveWidth; + } + } + if (!windowConfig.autoDesignWidth) { windowConfig.UpdateDesignWidthScale(width); } @@ -1158,6 +1167,15 @@ panda::Local Px2Lpx(panda::JsiRuntimeCallInfo* runtimeCallInf if (pipelineContext && pipelineContext->IsContainerModalVisible()) { width -= 2 * (CONTAINER_BORDER_WIDTH + CONTENT_PADDING).ConvertToPx(); } + + // 在强制分屏模式下调整计算宽度 + if (pipelineContext && pipelineContext->IsInForceSplitMode()) { + double effectiveWidth = pipelineContext->GetForceSplitEffectiveWidth(width); + if (effectiveWidth > 0) { + width = effectiveWidth; + } + } + if (!windowConfig.autoDesignWidth) { windowConfig.UpdateDesignWidthScale(width); } 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/interfaces/native/implementation/global_scope_accessor.cpp b/frameworks/core/interfaces/native/implementation/global_scope_accessor.cpp index 2a95c43101e78b0c31ba42616e4f49422123166e..687ad7b8e12d6389fe6d424a6833c6af96111866 100644 --- a/frameworks/core/interfaces/native/implementation/global_scope_accessor.cpp +++ b/frameworks/core/interfaces/native/implementation/global_scope_accessor.cpp @@ -130,6 +130,15 @@ Ark_Number Lpx2pxImpl(const Ark_Number* value) int32_t multiplier = 2; width -= multiplier * (CONTAINER_BORDER_WIDTH + CONTENT_PADDING).ConvertToPx(); } + + // 在强制分屏模式下调整计算宽度 + if (pipelineContext && pipelineContext->IsInForceSplitMode()) { + double effectiveWidth = pipelineContext->GetForceSplitEffectiveWidth(width); + if (effectiveWidth > 0) { + width = effectiveWidth; + } + } + if (!windowConfig.autoDesignWidth) { windowConfig.UpdateDesignWidthScale(width); } @@ -161,6 +170,15 @@ Ark_Number Px2lpxImpl(const Ark_Number* value) int32_t multiplier = 2; width -= multiplier * (CONTAINER_BORDER_WIDTH + CONTENT_PADDING).ConvertToPx(); } + + // 在强制分屏模式下调整计算宽度 + if (pipelineContext && pipelineContext->IsInForceSplitMode()) { + double effectiveWidth = pipelineContext->GetForceSplitEffectiveWidth(width); + if (effectiveWidth > 0) { + width = effectiveWidth; + } + } + if (!windowConfig.autoDesignWidth) { windowConfig.UpdateDesignWidthScale(width); } diff --git a/frameworks/core/pipeline/pipeline_base.cpp b/frameworks/core/pipeline/pipeline_base.cpp index d8c4f548f47920be258ead58317667ff1d23f333..2c072f6edffd2cc31902f148baed6c3469206f44 100644 --- a/frameworks/core/pipeline/pipeline_base.cpp +++ b/frameworks/core/pipeline/pipeline_base.cpp @@ -512,6 +512,15 @@ void PipelineBase::UpdateRootSizeAndScale(int32_t width, int32_t height) if (IsContainerModalVisible()) { pageWidth -= 2 * (CONTAINER_BORDER_WIDTH + CONTENT_PADDING).ConvertToPx(); } + + if (IsInForceSplitMode()) { + // 获取Navigation的有效内容宽度 + double effectiveContentWidth = GetForceSplitEffectiveWidth(pageWidth); + if (effectiveContentWidth > 0) { + pageWidth = effectiveContentWidth; + } + } + designWidthScale_ = windowConfig.autoDesignWidth ? density_ : pageWidth / windowConfig.designWidth; windowConfig.designWidthScale = designWidthScale_; @@ -1141,4 +1150,10 @@ void PipelineBase::SetUiDVSyncCommandTime(uint64_t vsyncTime) commandTimeUpdate_ = true; dvsyncTimeUpdate_ = true; } + +double PipelineBase::GetForceSplitEffectiveWidth(double totalWidth) const +{ + // 默认实现:返回原始宽度,子类可以重写 + return totalWidth; +} } // namespace OHOS::Ace diff --git a/frameworks/core/pipeline/pipeline_base.h b/frameworks/core/pipeline/pipeline_base.h index a7cc02d5d3f73812d01a1afc0bc93f342816f67c..1eac3c6dcee96476ea2e646d6d325268d5902b49 100644 --- a/frameworks/core/pipeline/pipeline_base.h +++ b/frameworks/core/pipeline/pipeline_base.h @@ -887,6 +887,19 @@ public: return viewScale_; } + void SetIsInForceSplitMode(bool isInForceSplitMode) + { + IsInForceSplitMode_ = isInForceSplitMode; + } + + bool IsInForceSplitMode() const + { + return IsInForceSplitMode_; + } + + // 获取强制分屏模式下的有效内容宽度,用于LPX计算 + virtual double GetForceSplitEffectiveWidth(double totalWidth) const; + double GetRootWidth() const { return rootWidth_; @@ -1674,6 +1687,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; diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index 0db0cc10ddae8c275f23412b5ea211143a3c6880..f84f92a0529cd0d6e2066703613066aa1d597e6f 100755 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -31,6 +31,7 @@ #include "base/geometry/ng/offset_t.h" #include "base/geometry/ng/rect_t.h" #include "base/log/ace_performance_monitor.h" +#include "core/components_ng/pattern/navigation/navigation_declaration.h" #include "base/log/ace_trace.h" #include "base/log/ace_tracker.h" #include "base/log/dump_log.h" @@ -6569,4 +6570,18 @@ void PipelineContext::OnDumpBindAICaller(const std::vector& params) } } +double PipelineContext::GetForceSplitEffectiveWidth(double totalWidth) const +{ + // 强制分屏模式下,按照去掉中间分割线后除以2计算 + // 使用Navigation组件定义的标准分割线宽度 + double dividerWidth = DIVIDER_WIDTH.ConvertToPx(); // 使用标准分割线宽度 + double effectiveContentWidth = (totalWidth - dividerWidth) / 2.0; + + TAG_LOGI(AceLogTag::ACE_NAVIGATION, + "Force split mode: adjust lpx calculation from total width %{public}f to half width %{public}f (divider: %{public}f)", + totalWidth, effectiveContentWidth, dividerWidth); + + return effectiveContentWidth > 0 ? effectiveContentWidth : totalWidth; +} + } // namespace OHOS::Ace::NG diff --git a/frameworks/core/pipeline_ng/pipeline_context.h b/frameworks/core/pipeline_ng/pipeline_context.h index 20325bfbbd3f192afe3199032b51e420b63d5ffc..eeffd509f3b6d93ec420d03e4fbe76111b991752 100755 --- a/frameworks/core/pipeline_ng/pipeline_context.h +++ b/frameworks/core/pipeline_ng/pipeline_context.h @@ -948,6 +948,9 @@ public: return memoryMgr_; } + // 重写强制分屏模式下的有效内容宽度计算 + double GetForceSplitEffectiveWidth(double totalWidth) const override; + const RefPtr& GetNavigationManager() const { return navigationMgr_;