From 3292875688cefd08a43b7b94a6bb400da45a1e99 Mon Sep 17 00:00:00 2001 From: cheng-feiwang Date: Wed, 6 Aug 2025 18:01:17 +0800 Subject: [PATCH] sheet shows in pc mode Signed-off-by: cheng-feiwang Change-Id: I5ae67bf48d537c02c522ee0d9ddf8d2cd9799fe3 --- adapter/ohos/osal/system_properties.cpp | 7 ++++ adapter/preview/osal/system_properties.cpp | 5 +++ frameworks/base/utils/system_properties.h | 3 ++ .../overlay/sheet_presentation_pattern.cpp | 13 ++++-- .../overlay/sheet_presentation_pattern.h | 5 ++- test/mock/base/mock_system_properties.cpp | 6 +++ .../sheet_presentation_test_two_ng.cpp | 41 +++++++++++++++++++ 7 files changed, 74 insertions(+), 6 deletions(-) diff --git a/adapter/ohos/osal/system_properties.cpp b/adapter/ohos/osal/system_properties.cpp index 708ad528ca8..1a77a4bd838 100644 --- a/adapter/ohos/osal/system_properties.cpp +++ b/adapter/ohos/osal/system_properties.cpp @@ -755,6 +755,7 @@ int32_t SystemProperties::velocityTrackerPointNumber_ = ReadVelocityTrackerPoint bool SystemProperties::isVelocityWithinTimeWindow_ = ReadIsVelocityWithinTimeWindow(); bool SystemProperties::isVelocityWithoutUpPoint_ = ReadIsVelocityWithoutUpPoint(); bool SystemProperties::prebuildInMultiFrameEnabled_ = IsPrebuildInMultiFrameEnabled(); +bool SystemProperties::isPCMode_ = false; bool SystemProperties::IsOpIncEnable() { @@ -932,6 +933,7 @@ void SystemProperties::InitDeviceInfo( } InitDeviceTypeBySystemProperty(); GetLayoutBreakpoints(widthLayoutBreakpoints_, heightLayoutBreakpoints_); + isPCMode_ = system::GetParameter("persist.sceneboard.ispcmode", "false") == "true"; } ACE_WEAK_SYM void SystemProperties::SetDeviceOrientation(int32_t orientation) @@ -1056,6 +1058,11 @@ bool SystemProperties::GetResourceDecoupling() return resourceDecoupling_; } +bool SystemProperties::IsPCMode() +{ + return isPCMode_; +} + bool SystemProperties::ConfigChangePerform() { return configChangePerform_; diff --git a/adapter/preview/osal/system_properties.cpp b/adapter/preview/osal/system_properties.cpp index 12769be3a42..ea0efb01796 100644 --- a/adapter/preview/osal/system_properties.cpp +++ b/adapter/preview/osal/system_properties.cpp @@ -291,6 +291,11 @@ bool SystemProperties::GetResourceDecoupling() return true; } +bool SystemProperties::IsPCMode() +{ + return false; +} + bool SystemProperties::ConfigChangePerform() { return false; diff --git a/frameworks/base/utils/system_properties.h b/frameworks/base/utils/system_properties.h index 2405a5bf22e..296b11369b7 100644 --- a/frameworks/base/utils/system_properties.h +++ b/frameworks/base/utils/system_properties.h @@ -650,6 +650,8 @@ public: static bool GetResourceDecoupling(); + static bool IsPCMode(); + static bool ConfigChangePerform(); static void SetConfigChangePerform(); @@ -930,6 +932,7 @@ private: static std::string mapSearchPrefix_; static bool debugThreadSafeNodeEnable_; static bool prebuildInMultiFrameEnabled_; + static bool isPCMode_; }; } // namespace OHOS::Ace diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp index 7f0330b0594..b3ffd4009cf 100644 --- a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp +++ b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.cpp @@ -1951,9 +1951,8 @@ SheetType SheetPresentationPattern::GetSheetTypeFromSheetManager() const if (sheetStyle.showInSubWindow.value_or(false)) { return ComputeSheetTypeInSubWindow(); } - DeviceType deviceType = SystemProperties::GetDeviceType(); if (sheetStyle.sheetType.has_value() && sheetStyle.sheetType.value() == SheetType::SHEET_BOTTOM) { - return sheetStyle.bottomOffset.has_value() && deviceType == DeviceType::TWO_IN_ONE ? + return sheetStyle.bottomOffset.has_value() && IsPcOrPadFreeMultiWindowMode() ? SheetType::SHEET_BOTTOM_OFFSET : SheetType::SHEET_BOTTOM; } auto pipeline = host->GetContext(); @@ -1997,11 +1996,10 @@ SheetType SheetPresentationPattern::GetSheetType() const if (sheetStyle.sheetType.has_value() && sheetStyle.sheetType.value() == SheetType::SHEET_CONTENT_COVER) { return SheetType::SHEET_CONTENT_COVER; } - DeviceType deviceType = SystemProperties::GetDeviceType(); // only bottom when width is less than 600vp if ((windowGlobalRect.Width() < SHEET_DEVICE_WIDTH_BREAKPOINT.ConvertToPx()) || (sheetStyle.sheetType.has_value() && sheetStyle.sheetType.value() == SheetType::SHEET_BOTTOM)) { - return sheetStyle.bottomOffset.has_value() && deviceType == DeviceType::TWO_IN_ONE ? + return sheetStyle.bottomOffset.has_value() && IsPcOrPadFreeMultiWindowMode() ? SheetType::SHEET_BOTTOM_OFFSET : SheetType::SHEET_BOTTOM; } if (sheetStyle.sheetType.has_value() && sheetStyle.sheetType.value() == SheetType::SHEET_SIDE) { @@ -4629,4 +4627,11 @@ void SheetPresentationPattern::OnLanguageConfigurationUpdate() { sheetObject_->OnLanguageConfigurationUpdate(); } + +bool SheetPresentationPattern::IsPcOrPadFreeMultiWindowMode() const +{ + DeviceType deviceType = SystemProperties::GetDeviceType(); + TAG_LOGD(AceLogTag::ACE_SHEET, "IsPCMode: %{public}d", SystemProperties::IsPCMode()); + return deviceType == DeviceType::TWO_IN_ONE || SystemProperties::IsPCMode(); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.h b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.h index a362aab2eee..98f130f0579 100644 --- a/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.h +++ b/frameworks/core/components_ng/pattern/overlay/sheet_presentation_pattern.h @@ -372,10 +372,11 @@ public: bool GetWindowButtonRect(NG::RectF& floatButtons); bool GetWindowButtonRectForAllAPI(NG::RectF& floatButtons); + bool IsPcOrPadFreeMultiWindowMode() const; + void SetBottomOffset(const SheetStyle &sheetStyle) { - DeviceType deviceType = SystemProperties::GetDeviceType(); - if (deviceType != DeviceType::TWO_IN_ONE) { + if (!IsPcOrPadFreeMultiWindowMode()) { TAG_LOGI(AceLogTag::ACE_SHEET, "Bottom offset invalid"); return; } diff --git a/test/mock/base/mock_system_properties.cpp b/test/mock/base/mock_system_properties.cpp index 67226059db0..33a93f71d0d 100644 --- a/test/mock/base/mock_system_properties.cpp +++ b/test/mock/base/mock_system_properties.cpp @@ -111,6 +111,7 @@ bool g_isConfigChangePerform = false; bool g_isMultiInstanceEnabled = false; WidthLayoutBreakPoint SystemProperties::widthLayoutBreakpoints_ = WidthLayoutBreakPoint(); HeightLayoutBreakPoint SystemProperties::heightLayoutBreakpoints_ = HeightLayoutBreakPoint(); +bool SystemProperties::isPCMode_ = false; float SystemProperties::GetFontWeightScale() { @@ -325,6 +326,11 @@ bool SystemProperties::GetResourceDecoupling() return g_isResourceDecoupling; } +bool SystemProperties::IsPCMode() +{ + return isPCMode_; +} + bool SystemProperties::ConfigChangePerform() { return g_isConfigChangePerform; diff --git a/test/unittest/core/pattern/overlay/sheet_presentation_test_two_ng.cpp b/test/unittest/core/pattern/overlay/sheet_presentation_test_two_ng.cpp index 6c5f1725e4e..1550b5dacdb 100644 --- a/test/unittest/core/pattern/overlay/sheet_presentation_test_two_ng.cpp +++ b/test/unittest/core/pattern/overlay/sheet_presentation_test_two_ng.cpp @@ -1839,6 +1839,47 @@ HWTEST_F(SheetPresentationTestTwoNg, SheetOffset006, TestSize.Level1) EXPECT_EQ(sheetPattern->sheetHeightUp_, 0.0f); } +/** + * @tc.name: SheetOffset007 + * @tc.desc: Test SetBottomOffset when in pc mode. + * @tc.type: FUNC + */ +HWTEST_F(SheetPresentationTestTwoNg, SheetOffset007, TestSize.Level1) +{ + /** + * @tc.steps: step1. set up bind sheet and theme. + */ + SetOnBindSheet(); + SystemProperties::SetDeviceType(DeviceType::TABLET); + SystemProperties::isPCMode_ = true; + auto callback = [](const std::string&) {}; + auto sheetNode = FrameNode::CreateFrameNode( + "Sheet", 101, AceType::MakeRefPtr(201, "SheetPresentation", std::move(callback))); + auto layoutProperty = sheetNode->GetLayoutProperty(); + ASSERT_NE(layoutProperty, nullptr); + auto sheetPattern = sheetNode->GetPattern(); + + /** + * @tc.steps: step2. sheet is center style. + * @tc.expected: bottom offsets are zero when style is center. + */ + auto sheetStyle = layoutProperty->GetSheetStyleValue(SheetStyle()); + sheetStyle.bottomOffset = { 10.0f, -10.0f }; + sheetStyle.sheetType = SheetType::SHEET_CENTER; + sheetPattern->SetBottomOffset(sheetStyle); + EXPECT_EQ(sheetPattern->bottomOffsetX_, 0.0f); + EXPECT_EQ(sheetPattern->bottomOffsetY_, 0.0f); + + /** + * @tc.steps: step3. sheet is bottom style. + * @tc.expected: bottom offsets are valid when style is Bottom. + */ + sheetStyle.sheetType = SheetType::SHEET_BOTTOM; + sheetPattern->SetBottomOffset(sheetStyle); + EXPECT_FLOAT_EQ(sheetPattern->bottomOffsetX_, 10.0f); + EXPECT_FLOAT_EQ(sheetPattern->bottomOffsetY_, -10.0f); +} + /** * @tc.name: SheetHoverStatus001 * @tc.desc: Test InitFoldCreaseRegion function. -- Gitee