From 215e2c05f155e96d0465f15e6b89cc29108feb1a Mon Sep 17 00:00:00 2001 From: Tintin9529 Date: Sat, 11 Jan 2025 14:50:59 +0800 Subject: [PATCH] =?UTF-8?q?popup=E6=8F=90=E4=BE=9B=E5=85=A8=E5=B1=80API?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=94=AF=E6=8C=81=E5=9C=A8=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E7=94=A8=E4=B8=AD=E4=BD=BF=E7=94=A8=20?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tintin9529 Change-Id: I99a986bbcaec2509f843b8cf1dc84596cb7cd929 --- .../core/components_ng/base/view_abstract.cpp | 156 +++++++++++------- .../core/components_ng/base/view_abstract.h | 6 +- .../core/base/view_abstract_test_ng.cpp | 9 +- 3 files changed, 107 insertions(+), 64 deletions(-) diff --git a/frameworks/core/components_ng/base/view_abstract.cpp b/frameworks/core/components_ng/base/view_abstract.cpp index 44a0844d57f..5ec0c40f1e5 100644 --- a/frameworks/core/components_ng/base/view_abstract.cpp +++ b/frameworks/core/components_ng/base/view_abstract.cpp @@ -2023,43 +2023,83 @@ void ViewAbstract::BindPopup( } } -RefPtr ViewAbstract::GetCurOverlayManager(const RefPtr& node) +PopupInfo ViewAbstract::GetPopupInfoWithCustomNode(const RefPtr& customNode) { - CHECK_NULL_RETURN(node, nullptr); - auto context = node->GetContextWithCheck(); - CHECK_NULL_RETURN(context, nullptr); - RefPtr overlayManager = nullptr; + PopupInfo popupInfoError; + popupInfoError.popupNode = nullptr; + auto context = customNode->GetContextWithCheck(); + CHECK_NULL_RETURN(context, popupInfoError); auto instanceId = context->GetInstanceId(); auto subwindow = SubwindowManager::GetInstance()->GetSubwindow(instanceId); if (subwindow) { - overlayManager = subwindow->GetOverlayManager(); - } else { - overlayManager = context->GetOverlayManager(); + auto overlayManager = subwindow->GetOverlayManager(); + if (overlayManager) { + auto popupInfo = overlayManager->GetPopupInfoWithExistContent(customNode); + if (popupInfo.popupNode) { + return popupInfo; + } + } } - return overlayManager; + auto overlayManager = context->GetOverlayManager(); + if (overlayManager) { + auto popupInfo = overlayManager->GetPopupInfoWithExistContent(customNode); + if (popupInfo.popupNode) { + return popupInfo; + } + } + return popupInfoError; } -int32_t ViewAbstract::OpenBindPopup( - const RefPtr& param, const RefPtr& targetNode, const RefPtr& customNode) +PopupInfo ViewAbstract::GetPopupInfoWithTargetId(const RefPtr& customNode, const int32_t targetId) { - BindPopup(param, targetNode, customNode); - auto overlayManager = GetCurOverlayManager(customNode); - if (!overlayManager) { - TAG_LOGE(AceLogTag::ACE_DIALOG, "The overlayManager of popup is null."); - return ERROR_CODE_INTERNAL_ERROR; + PopupInfo popupInfoError; + popupInfoError.popupNode = nullptr; + auto context = customNode->GetContextWithCheck(); + CHECK_NULL_RETURN(context, popupInfoError); + auto instanceId = context->GetInstanceId(); + auto subwindow = SubwindowManager::GetInstance()->GetSubwindow(instanceId); + if (subwindow) { + auto overlayManager = subwindow->GetOverlayManager(); + if (overlayManager) { + auto popupInfo = overlayManager->GetPopupInfo(targetId); + if (popupInfo.popupNode) { + return popupInfo; + } + } } - auto popupInfo = overlayManager->GetPopupInfo(targetNode->GetId()); - if (!popupInfo.popupNode) { - TAG_LOGE(AceLogTag::ACE_DIALOG, "The popupNode of popup is null."); - return ERROR_CODE_INTERNAL_ERROR; + auto overlayManager = context->GetOverlayManager(); + if (overlayManager) { + auto popupInfo = overlayManager->GetPopupInfo(targetId); + if (popupInfo.popupNode) { + return popupInfo; + } } - auto popupPattern = popupInfo.popupNode->GetPattern(); - if (!popupPattern) { - TAG_LOGE(AceLogTag::ACE_DIALOG, "The popupPattern does not exist."); - return ERROR_CODE_INTERNAL_ERROR; + return popupInfoError; +} + +RefPtr ViewAbstract::GetPopupOverlayManager(const RefPtr& customNode, const int32_t targetId) +{ + auto context = customNode->GetContextWithCheck(); + CHECK_NULL_RETURN(context, nullptr); + auto instanceId = context->GetInstanceId(); + auto subwindow = SubwindowManager::GetInstance()->GetSubwindow(instanceId); + if (subwindow) { + auto overlayManager = subwindow->GetOverlayManager(); + if (overlayManager) { + auto popupInfo = overlayManager->GetPopupInfo(targetId); + if (popupInfo.popupNode) { + return overlayManager; + } + } } - popupPattern->SetCustomNode(AceType::WeakClaim(AceType::RawPtr(customNode))); - return ERROR_CODE_NO_ERROR; + auto overlayManager = context->GetOverlayManager(); + if (overlayManager) { + auto popupInfo = overlayManager->GetPopupInfo(targetId); + if (popupInfo.popupNode) { + return overlayManager; + } + } + return nullptr; } int32_t ViewAbstract::OpenPopup(const RefPtr& param, const RefPtr& customNode) @@ -2072,19 +2112,6 @@ int32_t ViewAbstract::OpenPopup(const RefPtr& param, const RefPtrGetPopupInfoWithExistContent(customNode); - if (popupInfo.popupNode) { - TAG_LOGE(AceLogTag::ACE_DIALOG, "The customNode of popup is already existed."); - return ERROR_CODE_DIALOG_CONTENT_ALREADY_EXIST; - } - popupInfo = overlayManager->GetPopupInfo(std::stoi(param->GetTargetId())); - if (popupInfo.popupNode) { - TAG_LOGE(AceLogTag::ACE_DIALOG, "The customNode of popup is already existed."); - return ERROR_CODE_DIALOG_CONTENT_ALREADY_EXIST; - } - } if (param->GetTargetId().empty() || std::stoi(param->GetTargetId()) < 0) { TAG_LOGE(AceLogTag::ACE_DIALOG, "The targetId is error."); return ERROR_CODE_TARGET_INFO_NOT_EXIST; @@ -2099,7 +2126,29 @@ int32_t ViewAbstract::OpenPopup(const RefPtr& param, const RefPtrGetPattern(); + if (!popupPattern) { + TAG_LOGE(AceLogTag::ACE_DIALOG, "The popupPattern does not exist."); + return ERROR_CODE_INTERNAL_ERROR; + } + popupPattern->SetCustomNode(AceType::WeakClaim(AceType::RawPtr(customNode))); + return ERROR_CODE_NO_ERROR; } int32_t ViewAbstract::UpdatePopup(const RefPtr& param, const RefPtr& customNode) @@ -2122,12 +2171,7 @@ int32_t ViewAbstract::UpdatePopup(const RefPtr& param, const RefPtr< TAG_LOGE(AceLogTag::ACE_DIALOG, "The targetNode does not exist when update popup."); return ERROR_CODE_INTERNAL_ERROR; } - auto overlayManager = GetCurOverlayManager(customNode); - if (!overlayManager) { - TAG_LOGE(AceLogTag::ACE_DIALOG, "The overlayManager of popup is null."); - return ERROR_CODE_INTERNAL_ERROR; - } - auto popupInfo = overlayManager->GetPopupInfo(targetNode->GetId()); + auto popupInfo = GetPopupInfoWithTargetId(customNode, targetId); if (!popupInfo.popupNode) { TAG_LOGE(AceLogTag::ACE_DIALOG, "The popupNode of popup is null."); return ERROR_CODE_INTERNAL_ERROR; @@ -2162,12 +2206,7 @@ int32_t ViewAbstract::ClosePopup(const RefPtr& customNode) return ERROR_CODE_INTERNAL_ERROR; } int32_t targetId = std::stoi(param->GetTargetId()); - auto overlayManager = GetCurOverlayManager(customNode); - if (!overlayManager) { - TAG_LOGE(AceLogTag::ACE_DIALOG, "The overlayManager of popup is null."); - return ERROR_CODE_INTERNAL_ERROR; - } - auto popupInfo = overlayManager->GetPopupInfo(targetId); + auto popupInfo = GetPopupInfoWithTargetId(customNode, targetId); if (!popupInfo.popupNode) { TAG_LOGE(AceLogTag::ACE_DIALOG, "The popupNode of popup is null."); return ERROR_CODE_INTERNAL_ERROR; @@ -2177,11 +2216,12 @@ int32_t ViewAbstract::ClosePopup(const RefPtr& customNode) return ERROR_CODE_INTERNAL_ERROR; } popupInfo.markNeedUpdate = true; - if (param->IsShowInSubWindow()) { - SubwindowManager::GetInstance()->HidePopupNG(targetId); - } else { - overlayManager->HidePopup(targetId, popupInfo); + auto overlayManager = GetPopupOverlayManager(customNode, targetId); + if (!overlayManager) { + TAG_LOGE(AceLogTag::ACE_DIALOG, "The overlayManager of popup is null."); + return ERROR_CODE_INTERNAL_ERROR; } + overlayManager->HidePopup(targetId, popupInfo); return ERROR_CODE_NO_ERROR; } @@ -2189,9 +2229,7 @@ int32_t ViewAbstract::GetPopupParam(RefPtr& param, const RefPtrGetPopupInfoWithExistContent(customNode); + auto popupInfo = GetPopupInfoWithCustomNode(customNode); CHECK_NULL_RETURN(popupInfo.popupNode, ERROR_CODE_DIALOG_CONTENT_NOT_FOUND); auto popupPattern = popupInfo.popupNode->GetPattern(); CHECK_NULL_RETURN(popupPattern, ERROR_CODE_INTERNAL_ERROR); diff --git a/frameworks/core/components_ng/base/view_abstract.h b/frameworks/core/components_ng/base/view_abstract.h index e4d4e6a7635..9fe3f0120a8 100644 --- a/frameworks/core/components_ng/base/view_abstract.h +++ b/frameworks/core/components_ng/base/view_abstract.h @@ -357,7 +357,6 @@ public: // Bind properties static void BindPopup(const RefPtr ¶m, const RefPtr &targetNode, const RefPtr &customNode); - static RefPtr GetCurOverlayManager(const RefPtr& node); static int32_t OpenPopup(const RefPtr& param, const RefPtr& customNode); static int32_t UpdatePopup(const RefPtr& param, const RefPtr& customNode); static int32_t ClosePopup(const RefPtr& customNode); @@ -836,8 +835,9 @@ private: const std::optional& align, const std::optional& offsetX, const std::optional& offsetY); static void CheckIfParentNeedMarkDirty(FrameNode* frameNode); - static int32_t OpenBindPopup( - const RefPtr& param, const RefPtr& targetNode, const RefPtr& customNode); + static PopupInfo GetPopupInfoWithCustomNode(const RefPtr& customNode); + static PopupInfo GetPopupInfoWithTargetId(const RefPtr& customNode, const int32_t targetId); + static RefPtr GetPopupOverlayManager(const RefPtr& customNode, const int32_t targetId); static OEMVisualEffectFunc oemVisualEffectFunc; static std::mutex visualEffectMutex_; diff --git a/test/unittest/core/base/view_abstract_test_ng.cpp b/test/unittest/core/base/view_abstract_test_ng.cpp index a533a8a1efa..e18ac603786 100644 --- a/test/unittest/core/base/view_abstract_test_ng.cpp +++ b/test/unittest/core/base/view_abstract_test_ng.cpp @@ -1692,13 +1692,16 @@ HWTEST_F(ViewAbstractTestNg, UpdatePopup, TestSize.Level1) rootNode->MarkDirtyNode(); param->SetIsShow(true); param->SetUseCustomComponent(true); + param->SetShowInSubWindow(false); param->SetTargetId(std::to_string(targetNode->GetId())); /** * @tc.expected: Return expected results. */ EXPECT_EQ(ViewAbstract::OpenPopup(param, contentNode), ERROR_CODE_NO_ERROR); - auto overlayManager = ViewAbstract::GetCurOverlayManager(contentNode); + auto context = contentNode->GetContextWithCheck(); + ASSERT_NE(context, nullptr); + auto overlayManager = context->GetOverlayManager(); ASSERT_NE(overlayManager, nullptr); overlayManager->popupMap_[targetNode->GetId()].isCurrentOnShow = true; param->SetIsPartialUpdate(true); @@ -1740,7 +1743,9 @@ HWTEST_F(ViewAbstractTestNg, ClosePopup, TestSize.Level1) * @tc.expected: Return expected results. */ EXPECT_EQ(ViewAbstract::OpenPopup(param, contentNode), ERROR_CODE_NO_ERROR); - auto overlayManager = ViewAbstract::GetCurOverlayManager(contentNode); + auto context = contentNode->GetContextWithCheck(); + ASSERT_NE(context, nullptr); + auto overlayManager = context->GetOverlayManager(); ASSERT_NE(overlayManager, nullptr); overlayManager->popupMap_[targetNode->GetId()].isCurrentOnShow = true; EXPECT_EQ(ViewAbstract::ClosePopup(contentNode), ERROR_CODE_NO_ERROR); -- Gitee