From 723c5d097fd2a343cb3ac1643b7944d527c25acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AE=87=E6=80=80?= Date: Fri, 25 Jul 2025 17:14:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈宇怀 --- .../cj_ffi/cj_pixel_unit_convert_ffi.cpp | 8 ++++++++ .../engine/jsi/jsi_view_register.cpp | 18 ++++++++++++++++++ .../pattern/navigation/navigation_pattern.cpp | 1 + .../implementation/global_scope_accessor.cpp | 18 ++++++++++++++++++ frameworks/core/pipeline/pipeline_base.cpp | 15 +++++++++++++++ frameworks/core/pipeline/pipeline_base.h | 14 ++++++++++++++ .../core/pipeline_ng/pipeline_context.cpp | 15 +++++++++++++++ frameworks/core/pipeline_ng/pipeline_context.h | 3 +++ 8 files changed, 92 insertions(+) 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 f3f6cedd8dc..9d19e62cc6c 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 da3a9684557..8b61c9ccb79 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 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/interfaces/native/implementation/global_scope_accessor.cpp b/frameworks/core/interfaces/native/implementation/global_scope_accessor.cpp index 2a95c43101e..687ad7b8e12 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 d8c4f548f47..2c072f6edff 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 a7cc02d5d3f..1eac3c6dcee 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 0db0cc10dda..f84f92a0529 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 20325bfbbd3..eeffd509f3b 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_; -- Gitee