diff --git a/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp b/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp index b4f0f19fc903e9d2b3513824300de6b78d84b042..0c61ba89f9e88a52fdb947c245dc5c6e2bba0657 100644 --- a/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp +++ b/adapter/ohos/entrance/subwindow/subwindow_ohos.cpp @@ -47,8 +47,10 @@ #include "core/common/text_field_manager.h" #include "core/components/bubble/bubble_component.h" #include "core/components/popup/popup_component.h" -#include "core/components_ng/render/adapter/rosen_render_context.h" +#include "core/components_ng/pattern/menu/menu_view.h" +#include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h" #include "core/components_ng/pattern/overlay/overlay_manager.h" +#include "core/components_ng/render/adapter/rosen_render_context.h" #include "core/components_ng/render/adapter/rosen_window.h" #include "frameworks/bridge/common/utils/engine_helper.h" #include "frameworks/bridge/declarative_frontend/declarative_frontend.h" @@ -536,20 +538,59 @@ void SubwindowOhos::HidePreviewNG() HideSubWindowNG(); } -void SubwindowOhos::ShowMenuNG(const RefPtr menuNode, int32_t targetId, const NG::OffsetF& offset) +void SubwindowOhos::ShowMenuNG(const RefPtr menuNode, const NG::MenuParam& menuParam, + const RefPtr& targetNode, const NG::OffsetF& offset) { TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show menu ng enter"); - auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); - CHECK_NULL_VOID(aceContainer); - auto context = DynamicCast(aceContainer->GetPipelineContext()); + CHECK_NULL_VOID(menuNode); + CHECK_NULL_VOID(targetNode); + ContainerScope scope(childContainerId_); + auto container = Container::Current(); + CHECK_NULL_VOID(container); + auto context = DynamicCast(container->GetPipelineContext()); CHECK_NULL_VOID(context); auto overlay = context->GetOverlayManager(); CHECK_NULL_VOID(overlay); + auto menu = NG::MenuView::Create(menuNode, targetNode->GetId(), targetNode->GetTag(), menuParam, true); + auto menuWrapperPattern = menu->GetPattern(); + CHECK_NULL_VOID(menuWrapperPattern); + menuWrapperPattern->RegisterMenuCallback(menu, menuParam); + menuWrapperPattern->SetMenuTransitionEffect(menu, menuParam); ShowWindow(); ResizeWindow(); window_->SetTouchable(true); + overlay->ShowMenuInSubWindow(targetNode->GetId(), offset, menu); +} + +void SubwindowOhos::ShowMenuNG(std::function&& buildFunc, std::function&& previewBuildFunc, + const NG::MenuParam& menuParam, const RefPtr& targetNode, const NG::OffsetF& offset) +{ + TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show menu ng enter"); ContainerScope scope(childContainerId_); - overlay->ShowMenuInSubWindow(targetId, offset, menuNode); + auto container = Container::Current(); + CHECK_NULL_VOID(container); + auto context = DynamicCast(container->GetPipelineContext()); + CHECK_NULL_VOID(context); + auto overlay = context->GetOverlayManager(); + CHECK_NULL_VOID(overlay); + ShowWindow(); + ResizeWindow(); + window_->SetTouchable(true); + NG::ScopedViewStackProcessor builderViewStackProcessor; + buildFunc(); + auto customNode = NG::ViewStackProcessor::GetInstance()->Finish(); + RefPtr previewCustomNode; + if (previewBuildFunc && menuParam.previewMode == MenuPreviewMode::CUSTOM) { + previewBuildFunc(); + previewCustomNode = NG::ViewStackProcessor::GetInstance()->Finish(); + } + auto menuNode = + NG::MenuView::Create(customNode, targetNode->GetId(), targetNode->GetTag(), menuParam, true, previewCustomNode); + auto menuWrapperPattern = menuNode->GetPattern(); + CHECK_NULL_VOID(menuWrapperPattern); + menuWrapperPattern->RegisterMenuCallback(menuNode, menuParam); + menuWrapperPattern->SetMenuTransitionEffect(menuNode, menuParam); + overlay->ShowMenuInSubWindow(targetNode->GetId(), offset, menuNode); } void SubwindowOhos::HideMenuNG(bool showPreviewAnimation, bool startDrag) @@ -558,13 +599,13 @@ void SubwindowOhos::HideMenuNG(bool showPreviewAnimation, bool startDrag) if (!isShowed_) { return; } - auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_); - CHECK_NULL_VOID(aceContainer); - auto context = DynamicCast(aceContainer->GetPipelineContext()); + ContainerScope scope(childContainerId_); + auto container = Container::Current(); + CHECK_NULL_VOID(container); + auto context = DynamicCast(container->GetPipelineContext()); CHECK_NULL_VOID(context); auto overlay = context->GetOverlayManager(); CHECK_NULL_VOID(overlay); - ContainerScope scope(childContainerId_); overlay->HideMenuInSubWindow(showPreviewAnimation, startDrag); HideEventColumn(); HidePixelMap(startDrag, 0, 0, false); diff --git a/adapter/ohos/entrance/subwindow/subwindow_ohos.h b/adapter/ohos/entrance/subwindow/subwindow_ohos.h index a564f873d147d4938ab17751886e0c5d073e9f70..7570295e76c29e4c5fa788ab4af06a5b273b03f9 100644 --- a/adapter/ohos/entrance/subwindow/subwindow_ohos.h +++ b/adapter/ohos/entrance/subwindow/subwindow_ohos.h @@ -58,7 +58,10 @@ public: void ResizeWindow() override; NG::RectF GetRect() override; void ShowMenu(const RefPtr& newComponent) override; - void ShowMenuNG(const RefPtr menuNode, int32_t targetId, const NG::OffsetF& offset) override; + void ShowMenuNG(const RefPtr menuNode, const NG::MenuParam& menuParam, + const RefPtr& targetNode, const NG::OffsetF& offset) override; + void ShowMenuNG(std::function&& buildFunc, std::function&& previewBuildFunc, + const NG::MenuParam& menuParam, const RefPtr& targetNode, const NG::OffsetF& offset) override; bool ShowPreviewNG() override; void HidePreviewNG() override; void HideMenuNG(const RefPtr& menu, int32_t targetId) override; @@ -139,6 +142,7 @@ public: void ResizeWindowForFoldStatus() override; void ResizeWindowForFoldStatus(int32_t parentContainerId) override; void MarkDirtyDialogSafeArea() override; + private: RefPtr GetStack(); void AddMenu(const RefPtr& newComponent); diff --git a/frameworks/base/subwindow/subwindow.h b/frameworks/base/subwindow/subwindow.h index 6ff03657c652e97401ef5fab7def46f96177eeda..8da11faa516f8c793ebccd7d06801b05f14d08d9 100644 --- a/frameworks/base/subwindow/subwindow.h +++ b/frameworks/base/subwindow/subwindow.h @@ -24,6 +24,7 @@ #include "core/components/dialog/dialog_properties.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/pattern/overlay/overlay_manager.h" +#include "core/components_ng/property/menu_property.h" #include "core/pipeline/base/component.h" namespace OHOS::Ace { @@ -38,7 +39,10 @@ public: virtual void ResizeWindow() = 0; virtual NG::RectF GetRect() = 0; virtual void ShowMenu(const RefPtr& newComponent) = 0; - virtual void ShowMenuNG(const RefPtr menuNode, int32_t targetId, const NG::OffsetF& offset) = 0; + virtual void ShowMenuNG(const RefPtr menuNode, const NG::MenuParam& menuParam, + const RefPtr& targetNode, const NG::OffsetF& offset) = 0; + virtual void ShowMenuNG(std::function&& buildFunc, std::function&& previewBuildFunc, + const NG::MenuParam& menuParam, const RefPtr& targetNode, const NG::OffsetF& offset) = 0; virtual bool ShowPreviewNG() = 0; virtual void HidePreviewNG() = 0; virtual void HideMenuNG(const RefPtr& menu, int32_t targetId) = 0; @@ -126,6 +130,7 @@ public: virtual void RequestFocus() = 0; virtual void ResizeWindowForFoldStatus() = 0; virtual void ResizeWindowForFoldStatus(int32_t parentContainerId) = 0; + private: int32_t subwindowId_ = 0; int32_t uiExtensionHostWindowId_ = 0; diff --git a/frameworks/base/subwindow/subwindow_manager.cpp b/frameworks/base/subwindow/subwindow_manager.cpp index 6eba97ce8c179a498c417d8d5b9660ae0d2de4f6..41f0564c353e4a1c1862910259c357e19a82cbd6 100644 --- a/frameworks/base/subwindow/subwindow_manager.cpp +++ b/frameworks/base/subwindow/subwindow_manager.cpp @@ -206,10 +206,10 @@ RefPtr SubwindowManager::ShowPreviewNG() return subwindow; } -void SubwindowManager::ShowMenuNG( - const RefPtr& menuNode, int32_t targetId, const NG::OffsetF& offset, bool isAboveApps) +void SubwindowManager::ShowMenuNG(const RefPtr& menuNode, const NG::MenuParam& menuParam, + const RefPtr& targetNode, const NG::OffsetF& offset) { - TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show menung enter"); + TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show menu ng enter"); auto containerId = Container::CurrentId(); auto subwindow = GetSubwindow(containerId); if (!subwindow) { @@ -217,7 +217,21 @@ void SubwindowManager::ShowMenuNG( subwindow->InitContainer(); AddSubwindow(containerId, subwindow); } - subwindow->ShowMenuNG(menuNode, targetId, offset); + subwindow->ShowMenuNG(menuNode, menuParam, targetNode, offset); +} + +void SubwindowManager::ShowMenuNG(std::function&& buildFunc, std::function&& previewBuildFunc, + const NG::MenuParam& menuParam, const RefPtr& targetNode, const NG::OffsetF& offset) +{ + TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show menu ng enter"); + auto containerId = Container::CurrentId(); + auto subwindow = GetSubwindow(containerId); + if (!subwindow) { + subwindow = Subwindow::CreateSubwindow(containerId); + subwindow->InitContainer(); + AddSubwindow(containerId, subwindow); + } + subwindow->ShowMenuNG(std::move(buildFunc), std::move(previewBuildFunc), menuParam, targetNode, offset); } void SubwindowManager::HidePreviewNG() @@ -239,7 +253,7 @@ void SubwindowManager::HideMenuNG(const RefPtr& menu, int32_t tar void SubwindowManager::HideMenuNG(bool showPreviewAnimation, bool startDrag) { - TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "hide menung enter"); + TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "hide menu ng enter"); auto subwindow = GetCurrentWindow(); if (subwindow) { subwindow->HideMenuNG(showPreviewAnimation, startDrag); @@ -256,7 +270,7 @@ void SubwindowManager::UpdateHideMenuOffsetNG(const NG::OffsetF& offset) void SubwindowManager::ClearMenuNG(int32_t instanceId, int32_t targetId, bool inWindow, bool showAnimation) { - TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "clear menung enter"); + TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "clear menu ng enter"); RefPtr subwindow; if (instanceId != -1) { #ifdef OHOS_STANDARD_SYSTEM @@ -589,14 +603,14 @@ void SubwindowManager::ShowToast(const std::string& message, int32_t duration, c auto subwindow = GetOrCreateSubWindow(); CHECK_NULL_VOID(subwindow); TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "before show toast"); - subwindow->ShowToast(message, duration, bottom, showMode, alignment, offset); + subwindow->ShowToast(message, duration, bottom, showMode, alignment, offset); } else { // for ability auto container = Container::CurrentSafely(); auto taskExecutor = container->GetTaskExecutor(); CHECK_NULL_VOID(taskExecutor); taskExecutor->PostTask( - [containerId, message, duration, bottom, showMode, alignment, offset] { + [containerId, message, duration, bottom, showMode, alignment, offset] { auto manager = SubwindowManager::GetInstance(); CHECK_NULL_VOID(manager); auto subwindow = manager->GetSubwindow(containerId); @@ -607,7 +621,7 @@ void SubwindowManager::ShowToast(const std::string& message, int32_t duration, c manager->AddSubwindow(containerId, subwindow); } TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "before show toast : %{public}d", containerId); - subwindow->ShowToast(message, duration, bottom, showMode, alignment, offset); + subwindow->ShowToast(message, duration, bottom, showMode, alignment, offset); }, TaskExecutor::TaskType::PLATFORM, "ArkUISubwindowShowToast"); } @@ -847,7 +861,6 @@ void SubwindowManager::ResizeWindowForFoldStatus(int32_t parentContainerId) subwindow->ResizeWindowForFoldStatus(parentContainerId); } - void SubwindowManager::MarkDirtyDialogSafeArea() { auto containerId = Container::CurrentId(); diff --git a/frameworks/base/subwindow/subwindow_manager.h b/frameworks/base/subwindow/subwindow_manager.h index 060eb259093a86258b7b7795b2f45ddc34f92b3e..1258171364ddd17b4c945e33751c4d0f610dede0 100644 --- a/frameworks/base/subwindow/subwindow_manager.h +++ b/frameworks/base/subwindow/subwindow_manager.h @@ -65,8 +65,10 @@ public: RefPtr ShowPreviewNG(); void HidePreviewNG(); void ShowMenu(const RefPtr& newComponent); - void ShowMenuNG( - const RefPtr& menuNode, int32_t targetId, const NG::OffsetF& offset, bool isAboveApps = false); + void ShowMenuNG(const RefPtr& menuNode, const NG::MenuParam& menuParam, + const RefPtr& targetNode, const NG::OffsetF& offset); + void ShowMenuNG(std::function&& buildFunc, std::function&& previewBuildFunc, + const NG::MenuParam& menuParam, const RefPtr& targetNode, const NG::OffsetF& offset); void HideMenuNG(const RefPtr& menu, int32_t targetId); void HideMenuNG(bool showPreviewAnimation = true, bool startDrag = false); void UpdateHideMenuOffsetNG(const NG::OffsetF& offset = NG::OffsetF(0.0f, 0.0f)); @@ -125,6 +127,7 @@ public: bool GetShown(); void ResizeWindowForFoldStatus(int32_t parentContainerId); void MarkDirtyDialogSafeArea(); + private: RefPtr GetOrCreateSubWindow(bool isDialog = false); diff --git a/frameworks/core/components_ng/base/view_abstract.cpp b/frameworks/core/components_ng/base/view_abstract.cpp index 366412a9366a60443a6a60d48adf4da055669b1b..999ec589b7e7e18097619eff03bb9642155d36f3 100755 --- a/frameworks/core/components_ng/base/view_abstract.cpp +++ b/frameworks/core/components_ng/base/view_abstract.cpp @@ -23,7 +23,6 @@ #include "base/geometry/dimension.h" #include "base/geometry/matrix4.h" #include "base/geometry/ng/offset_t.h" -#include "base/log/log_wrapper.h" #include "base/memory/ace_type.h" #include "base/subwindow/subwindow.h" #include "base/utils/system_properties.h" @@ -55,61 +54,6 @@ #include "core/pipeline_ng/ui_task_scheduler.h" namespace OHOS::Ace::NG { -namespace { - -// common function to bind menu -void BindMenu(const RefPtr &menuNode, int32_t targetId, const NG::OffsetF &offset) -{ - TAG_LOGD(AceLogTag::ACE_DIALOG, "bind menu enter"); - auto container = Container::Current(); - CHECK_NULL_VOID(container); - auto pipelineContext = container->GetPipelineContext(); - CHECK_NULL_VOID(pipelineContext); - auto context = AceType::DynamicCast(pipelineContext); - CHECK_NULL_VOID(context); - auto overlayManager = context->GetOverlayManager(); - CHECK_NULL_VOID(overlayManager); - // pass in menuNode to register it in OverlayManager - overlayManager->ShowMenu(targetId, offset, menuNode); -} - -void RegisterMenuCallback(const RefPtr &menuWrapperNode, const MenuParam &menuParam) -{ - TAG_LOGD(AceLogTag::ACE_DIALOG, "register menu enter"); - CHECK_NULL_VOID(menuWrapperNode); - auto pattern = menuWrapperNode->GetPattern(); - CHECK_NULL_VOID(pattern); - pattern->RegisterMenuAppearCallback(menuParam.onAppear); - pattern->RegisterMenuDisappearCallback(menuParam.onDisappear); - pattern->RegisterMenuAboutToAppearCallback(menuParam.aboutToAppear); - pattern->RegisterMenuAboutToDisappearCallback(menuParam.aboutToDisappear); - pattern->RegisterMenuStateChangeCallback(menuParam.onStateChange); -} - -void SetMenuTransitionEffect(const RefPtr &menuWrapperNode, const MenuParam &menuParam) -{ - TAG_LOGD(AceLogTag::ACE_DIALOG, "set menu transition effect"); - CHECK_NULL_VOID(menuWrapperNode); - auto pattern = menuWrapperNode->GetPattern(); - CHECK_NULL_VOID(pattern); - pattern->SetHasTransitionEffect(menuParam.hasTransitionEffect); - if (menuParam.hasTransitionEffect) { - auto renderContext = menuWrapperNode->GetRenderContext(); - CHECK_NULL_VOID(renderContext); - CHECK_NULL_VOID(menuParam.transition); - renderContext->UpdateChainedTransition(menuParam.transition); - } - pattern->SetHasPreviewTransitionEffect(menuParam.hasPreviewTransitionEffect); - if (menuParam.hasPreviewTransitionEffect) { - auto previewChild = pattern->GetPreview(); - CHECK_NULL_VOID(previewChild); - auto renderContext = previewChild->GetRenderContext(); - CHECK_NULL_VOID(renderContext); - CHECK_NULL_VOID(menuParam.previewTransition); - renderContext->UpdateChainedTransition(menuParam.previewTransition); - } -} -} // namespace void ViewAbstract::SetWidth(const CalcLength &width) { @@ -1664,50 +1608,78 @@ void ViewAbstract::BindMenuWithItems(std::vector &¶ms, const Re } auto menuNode = MenuView::Create(std::move(params), targetNode->GetId(), targetNode->GetTag(), MenuType::MENU, menuParam); - RegisterMenuCallback(menuNode, menuParam); - SetMenuTransitionEffect(menuNode, menuParam); + auto menuWrapperPattern = menuNode->GetPattern(); + CHECK_NULL_VOID(menuWrapperPattern); + menuWrapperPattern->RegisterMenuCallback(menuNode, menuParam); + menuWrapperPattern->SetMenuTransitionEffect(menuNode, menuParam); auto pipeline = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipeline); auto theme = pipeline->GetTheme(); CHECK_NULL_VOID(theme); auto expandDisplay = theme->GetExpandDisplay(); if (expandDisplay && menuParam.isShowInSubWindow && targetNode->GetTag() != V2::SELECT_ETS_TAG) { - SubwindowManager::GetInstance()->ShowMenuNG(menuNode, targetNode->GetId(), offset, menuParam.isAboveApps); + SubwindowManager::GetInstance()->ShowMenuNG(menuNode, menuParam, targetNode, offset); return; } - BindMenu(menuNode, targetNode->GetId(), offset); + auto pipelineContext = NG::PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(pipelineContext); + auto overlayManager = pipelineContext->GetOverlayManager(); + CHECK_NULL_VOID(overlayManager); + overlayManager->ShowMenu(targetNode->GetId(), offset, menuNode); } -void ViewAbstract::BindMenuWithCustomNode(const RefPtr& customNode, const RefPtr& targetNode, - const NG::OffsetF& offset, const MenuParam& menuParam, const RefPtr& previewCustomNode) +void ViewAbstract::BindMenuWithCustomNode(std::function&& buildFunc, const RefPtr& targetNode, + const NG::OffsetF& offset, MenuParam menuParam, std::function&& previewBuildFunc) { + if (!buildFunc || !targetNode) { + return; + } +#ifdef PREVIEW + // unable to use the subWindow in the Previewer. + menuParam.type = MenuType::MENU; +#endif TAG_LOGD(AceLogTag::ACE_DIALOG, "bind menu with custom node enter"); auto pipeline = PipelineBase::GetCurrentContext(); CHECK_NULL_VOID(pipeline); auto theme = pipeline->GetTheme(); CHECK_NULL_VOID(theme); auto expandDisplay = theme->GetExpandDisplay(); - CHECK_NULL_VOID(customNode); - CHECK_NULL_VOID(targetNode); - auto menuNode = - MenuView::Create(customNode, targetNode->GetId(), targetNode->GetTag(), menuParam, true, previewCustomNode); - RegisterMenuCallback(menuNode, menuParam); - SetMenuTransitionEffect(menuNode, menuParam); + auto pipelineContext = NG::PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(pipelineContext); + auto overlayManager = pipelineContext->GetOverlayManager(); + CHECK_NULL_VOID(overlayManager); if (menuParam.type == MenuType::CONTEXT_MENU) { - SubwindowManager::GetInstance()->ShowMenuNG(menuNode, targetNode->GetId(), offset, menuParam.isAboveApps); + SubwindowManager::GetInstance()->ShowMenuNG( + std::move(buildFunc), std::move(previewBuildFunc), menuParam, targetNode, offset); return; } if (menuParam.type == MenuType::MENU && expandDisplay && menuParam.isShowInSubWindow && targetNode->GetTag() != V2::SELECT_ETS_TAG) { bool isShown = SubwindowManager::GetInstance()->GetShown(); if (!isShown) { - SubwindowManager::GetInstance()->ShowMenuNG(menuNode, targetNode->GetId(), offset, menuParam.isAboveApps); + SubwindowManager::GetInstance()->ShowMenuNG( + std::move(buildFunc), std::move(previewBuildFunc), menuParam, targetNode, offset); } else { + auto menuNode = overlayManager->GetMenuNode(targetNode->GetId()); SubwindowManager::GetInstance()->HideMenuNG(menuNode, targetNode->GetId()); } return; } - BindMenu(menuNode, targetNode->GetId(), offset); + NG::ScopedViewStackProcessor builderViewStackProcessor; + buildFunc(); + auto customNode = NG::ViewStackProcessor::GetInstance()->Finish(); + RefPtr previewCustomNode; + if (previewBuildFunc && menuParam.previewMode == MenuPreviewMode::CUSTOM) { + previewBuildFunc(); + previewCustomNode = NG::ViewStackProcessor::GetInstance()->Finish(); + } + auto menuNode = + NG::MenuView::Create(customNode, targetNode->GetId(), targetNode->GetTag(), menuParam, true, previewCustomNode); + auto menuWrapperPattern = menuNode->GetPattern(); + CHECK_NULL_VOID(menuWrapperPattern); + menuWrapperPattern->RegisterMenuCallback(menuNode, menuParam); + menuWrapperPattern->SetMenuTransitionEffect(menuNode, menuParam); + overlayManager->ShowMenu(targetNode->GetId(), offset, menuNode); } void ViewAbstract::SetBackdropBlur(const Dimension &radius, const BlurOption &blurOption) diff --git a/frameworks/core/components_ng/base/view_abstract.h b/frameworks/core/components_ng/base/view_abstract.h index 21c6078743f1f06d1b2d92e54651cc8b1ae5ab69..8f3aa782f7a82fe5c537a730bc2d46e1bfbf26cb 100644 --- a/frameworks/core/components_ng/base/view_abstract.h +++ b/frameworks/core/components_ng/base/view_abstract.h @@ -18,6 +18,7 @@ #include #include + #include "modifier.h" #include "base/geometry/dimension.h" @@ -43,6 +44,7 @@ #include "core/components_ng/property/calc_length.h" #include "core/components_ng/property/gradient_property.h" #include "core/components_ng/property/measure_property.h" +#include "core/components_ng/property/menu_property.h" #include "core/components_ng/property/overlay_property.h" #include "core/components_ng/property/progress_mask_property.h" #include "core/components_ng/property/transition_property.h" @@ -70,46 +72,12 @@ struct OptionParam { ~OptionParam() = default; }; -enum class ContextMenuRegisterType : char { - NORMAL_TYPE = 0, - CUSTOM_TYPE = 1, -}; - enum class OverlayType { BUILDER = 0, TEXT = 1, RESET = 2, }; -struct MenuParam { - std::string title; - OffsetF positionOffset; - bool setShow = false; - bool isShow = false; - ContextMenuRegisterType contextMenuRegisterType = ContextMenuRegisterType::NORMAL_TYPE; - std::function onStateChange; - std::optional placement; - std::function onAppear; - std::function onDisappear; - std::function aboutToAppear; - std::function aboutToDisappear; - std::optional enableArrow; - std::optional arrowOffset; - bool isAboveApps = false; - bool isShowInSubWindow = false; - bool hasTransitionEffect = false; - RefPtr transition; - bool hasPreviewTransitionEffect = false; - RefPtr previewTransition; - MenuType type = MenuType::MENU; - MenuPreviewMode previewMode = MenuPreviewMode::NONE; - MenuPreviewAnimationOptions previewAnimationOptions; - std::optional backgroundEffectOption; - std::optional backgroundColor; - std::optional backgroundBlurStyle; - std::optional borderRadius; -}; - class ACE_FORCE_EXPORT ViewAbstract { public: static void SetWidth(const CalcLength &width); @@ -310,8 +278,8 @@ public: static void DismissPopup(); static void BindMenuWithItems(std::vector &¶ms, const RefPtr &targetNode, const NG::OffsetF &offset, const MenuParam &menuParam); - static void BindMenuWithCustomNode(const RefPtr &customNode, const RefPtr &targetNode, - const NG::OffsetF &offset, const MenuParam &menuParam, const RefPtr &previewCustomNode = nullptr); + static void BindMenuWithCustomNode(std::function&& buildFunc, const RefPtr& targetNode, + const NG::OffsetF& offset, MenuParam menuParam, std::function&& previewBuildFunc); static void ShowMenu( int32_t targetId, const NG::OffsetF& offset, bool isShowInSubWindow, bool isContextMenu = false); // inspector diff --git a/frameworks/core/components_ng/base/view_abstract_model_ng.cpp b/frameworks/core/components_ng/base/view_abstract_model_ng.cpp index eef06b49a7177982a679d5e22849f006db3575d1..7d5647141fa0993769d2359071e8ea9322311c6d 100644 --- a/frameworks/core/components_ng/base/view_abstract_model_ng.cpp +++ b/frameworks/core/components_ng/base/view_abstract_model_ng.cpp @@ -29,13 +29,13 @@ #include "core/components_ng/base/frame_node.h" #include "core/components_ng/base/view_abstract.h" #include "core/components_ng/event/focus_hub.h" +#include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h" #include "core/components_ng/pattern/navrouter/navdestination_pattern.h" #include "core/components_ng/pattern/overlay/overlay_manager.h" #include "core/components_ng/pattern/stage/page_pattern.h" #include "core/components_v2/inspector/inspector_constants.h" #include "core/event/mouse_event.h" #include "core/pipeline_ng/pipeline_context.h" -#include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h" namespace OHOS::Ace::NG { namespace { @@ -82,29 +82,6 @@ RefPtr FindPageNodeOverlay(const RefPtr& targetNode, } } // namespace -void ViewAbstractModelNG::CreateCustomMenu(const std::function& buildFunc, - const RefPtr& targetNode, const NG::OffsetF& offset, std::function& previewBuildFunc, - MenuParam menuParam) -{ - NG::ScopedViewStackProcessor builderViewStackProcessor; - if (!buildFunc) { - return; - } - buildFunc(); - auto customNode = NG::ViewStackProcessor::GetInstance()->Finish(); - - RefPtr previewCustomNode; - if (previewBuildFunc && menuParam.previewMode == MenuPreviewMode::CUSTOM) { - previewBuildFunc(); - previewCustomNode = NG::ViewStackProcessor::GetInstance()->Finish(); - } -#ifdef PREVIEW - // unable to use the subWindow in the Previewer. - menuParam.type = MenuType::MENU; -#endif - NG::ViewAbstract::BindMenuWithCustomNode(customNode, targetNode, offset, menuParam, previewCustomNode); -} - void ViewAbstractModelNG::BindMenuGesture( std::vector&& params, std::function&& buildFunc, const MenuParam& menuParam) { @@ -127,7 +104,8 @@ void ViewAbstractModelNG::BindMenuGesture( NG::OffsetF menuPosition { info.GetGlobalLocation().GetX() + menuParam.positionOffset.GetX(), info.GetGlobalLocation().GetY() + menuParam.positionOffset.GetY() }; std::function previewBuildFunc; - CreateCustomMenu(builderFunc, targetNode, menuPosition, previewBuildFunc, menuParam); + NG::ViewAbstract::BindMenuWithCustomNode( + std::move(builderFunc), targetNode, menuPosition, menuParam, std::move(previewBuildFunc)); }; } else { return; @@ -165,7 +143,8 @@ void ViewAbstractModelNG::BindMenu( NG::ViewAbstract::BindMenuWithItems(std::move(params), targetNode, menuParam.positionOffset, menuParam); } else if (buildFunc) { std::function previewBuildFunc; - CreateCustomMenu(buildFunc, targetNode, menuParam.positionOffset, previewBuildFunc, menuParam); + NG::ViewAbstract::BindMenuWithCustomNode( + std::move(buildFunc), targetNode, menuParam.positionOffset, menuParam, std::move(previewBuildFunc)); } } if (!menuParam.setShow) { @@ -222,8 +201,8 @@ void CreateCustomMenuWithPreview( gestureHub->SetPixelMap(pixelMap); } auto refTargetNode = AceType::Claim(targetNode); - ViewAbstractModelNG::CreateCustomMenu( - buildFunc, refTargetNode, menuParam.positionOffset, previewBuildFunc, menuParam); + NG::ViewAbstract::BindMenuWithCustomNode( + std::move(buildFunc), refTargetNode, menuParam.positionOffset, menuParam, std::move(previewBuildFunc)); } void BindContextMenuSingle( @@ -255,7 +234,7 @@ void BindContextMenuSingle( CreateCustomMenuWithPreview(buildFunc, menuParam, previewBuildFunc); } } else { - //first response for build subwindow and menu + // first response for build subwindow and menu if (menuParam.isShow && buildFunc) { CreateCustomMenuWithPreview(buildFunc, menuParam, previewBuildFunc); } @@ -294,8 +273,8 @@ void ViewAbstractModelNG::BindContextMenu(ResponseType type, std::function previewBuildFunc; - NG::ViewAbstractModelNG::CreateCustomMenu( - builder, targetNode, menuPosition, previewBuildFunc, menuParam); + NG::ViewAbstract::BindMenuWithCustomNode( + std::move(builder), targetNode, menuPosition, menuParam, std::move(previewBuildFunc)); } }, TaskExecutor::TaskType::PLATFORM, "ArkUIRightClickCreateCustomMenu"); @@ -336,8 +315,8 @@ void ViewAbstractModelNG::BindContextMenu(ResponseType type, std::functionGetDisplayWindowRectInfo(); menuPosition += NG::OffsetF { windowRect.Left(), windowRect.Top() }; - NG::ViewAbstractModelNG::CreateCustomMenu( - builder, targetNode, menuPosition, previewBuildFunc, menuParam); + NG::ViewAbstract::BindMenuWithCustomNode( + std::move(builder), targetNode, menuPosition, menuParam, std::move(previewBuildFunc)); }, TaskExecutor::TaskType::PLATFORM, "ArkUILongPressCreateCustomMenu"); }; @@ -444,7 +423,8 @@ void ViewAbstractModelNG::RegisterContextMenuKeyEvent( param.placement = Placement::BOTTOM_LEFT; } std::function previewBuildFunc = nullptr; - CreateCustomMenu(builder, targetNode, OffsetF(), previewBuildFunc, param); + NG::ViewAbstract::BindMenuWithCustomNode( + std::move(builder), targetNode, OffsetF(), param, std::move(previewBuildFunc)); return true; } return false; diff --git a/frameworks/core/components_ng/base/view_abstract_model_ng.h b/frameworks/core/components_ng/base/view_abstract_model_ng.h index a5b1abd9d0837f28330eb46a08e3bb687eef8a10..b27f04696b102c08549c6f2e3ca509c0942527d1 100755 --- a/frameworks/core/components_ng/base/view_abstract_model_ng.h +++ b/frameworks/core/components_ng/base/view_abstract_model_ng.h @@ -48,9 +48,6 @@ class ACE_EXPORT ViewAbstractModelNG : public ViewAbstractModel { public: ~ViewAbstractModelNG() override = default; - static void CreateCustomMenu(const std::function& buildFunc, const RefPtr& targetNode, - const NG::OffsetF& offset, std::function& previewBuildFunc, MenuParam menuParam); - void SetWidth(const CalcDimension& width) override { if (width.Unit() == DimensionUnit::CALC) { @@ -674,16 +671,16 @@ public: { ViewAbstract::SetDynamicLightUp(rate, lightUpDegree); } - + void SetBgDynamicBrightness(const BrightnessOption& brightnessOption) override { ViewAbstract::SetBgDynamicBrightness(brightnessOption); } void SetFgDynamicBrightness(const BrightnessOption& brightnessOption) override - { + { ViewAbstract::SetFgDynamicBrightness(brightnessOption); - } + } void SetFrontBlur(const Dimension& radius, const BlurOption& blurOption) override { @@ -1112,12 +1109,12 @@ public: { ViewAbstract::SetForegroundColorStrategy(strategy); } - + void SetForegroundEffect(float radius) override { ViewAbstract::SetForegroundEffect(radius); } - + void DisableOnClick() override { ViewAbstract::DisableOnClick(); diff --git a/frameworks/core/components_ng/pattern/container_modal/enhance/container_modal_view_enhance.cpp b/frameworks/core/components_ng/pattern/container_modal/enhance/container_modal_view_enhance.cpp index ba3145e369f69fde8ec88ee15a17f84f830aeb0d..cf84eb0a360fa833f5306586314042a5531eaa5b 100755 --- a/frameworks/core/components_ng/pattern/container_modal/enhance/container_modal_view_enhance.cpp +++ b/frameworks/core/components_ng/pattern/container_modal/enhance/container_modal_view_enhance.cpp @@ -338,10 +338,9 @@ RefPtr ContainerModalViewEnhance::ShowMaxMenu(const RefPtr if ((!subWindowManger->GetSubwindow(Container::CurrentId()) || !subWindowManger->GetSubwindow(Container::CurrentId())->GetShown())) { ACE_SCOPED_TRACE("ContainerModalViewEnhance::ShowMaxMenu"); - MenuParam menu {}; - menu.isAboveApps = true; - menu.type = MenuType::CONTEXT_MENU; - ViewAbstract::BindMenuWithCustomNode(menuList, targetNode, menuPosition, menu); + MenuParam menuParam {}; + menuParam.type = MenuType::CONTEXT_MENU; + SubwindowManager::GetInstance()->ShowMenuNG(menuList, menuParam, targetNode, menuPosition); } ResetHoverTimer(); return menuList; @@ -555,4 +554,4 @@ RefPtr ContainerModalViewEnhance::BuildGestureRow(RefPtr& return gestureRow; } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/menu/menu_pattern.h b/frameworks/core/components_ng/pattern/menu/menu_pattern.h index 23ee7d89480264ca70bb5f1c309b4b7054ae1d16..b56e36b7ac62f956eb62b5a7617625f480059f50 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_pattern.h +++ b/frameworks/core/components_ng/pattern/menu/menu_pattern.h @@ -30,29 +30,12 @@ #include "core/components_ng/pattern/pattern.h" #include "core/components_ng/pattern/select/select_model.h" #include "core/components_ng/property/border_property.h" +#include "core/components_ng/property/menu_property.h" #include "core/components_v2/inspector/inspector_constants.h" constexpr int32_t DEFAULT_CLICK_DISTANCE = 15; constexpr uint32_t MAX_SEARCH_DEPTH = 5; namespace OHOS::Ace::NG { -enum class MenuType { - // ----- Menu Containers ------ - MENU, // corresponds to .bindMenu attribute - CONTEXT_MENU, // corresponds to .bindContextMenu attribute, lives in a SubWindow - SUB_MENU, // secondary menu container in a multi-level menu - - // ----- innerMenu Node, corersponds to tag in the frontend ------ - MULTI_MENU, // called multi because it's a multi-leveled menu, its MenuItems can trigger subMenus - DESKTOP_MENU, // menu specialized for desktop UI, enabled when multiple sibiling nodes are present - - // ----- special menu used in other components ------ - NAVIGATION_MENU, // menu used in a Navigation component - SELECT_OVERLAY_EXTENSION_MENU, // menu used in SelectOverlay Extension of text component,skip menu layout algorithm - SELECT_OVERLAY_CUSTOM_MENU, // menu used in SelectOverlay for custom menu - // click menu item whill not trigger close menu - SELECT_OVERLAY_SUB_MENU, // menu type used for select overlay sub menu - SELECT_OVERLAY_RIGHT_CLICK_MENU, // menu type used for select overlay menu triggered by right-click -}; struct SelectProperties { std::string value; @@ -284,17 +267,17 @@ public: { return showedSubMenu_; } - + void SetIsWidthModifiedBySelect(bool isModified) { isWidthModifiedBySelect_ = isModified; } - + bool IsWidthModifiedBySelect() const { return isWidthModifiedBySelect_; } - + float GetSelectMenuWidth(); void HideSubMenu(); void OnModifyDone() override; @@ -357,12 +340,12 @@ public: { return targetSize_; } - + void SetIsHeightModifiedBySelect(bool isModified) { isHeightModifiedBySelect_ = isModified; } - + bool IsHeightModifiedBySelect() const { return isHeightModifiedBySelect_; @@ -377,7 +360,7 @@ public: { makeFunc_ = std::move(makeFunc); } - + void ResetBuilderFunc() { makeFunc_ = std::nullopt; diff --git a/frameworks/core/components_ng/pattern/menu/menu_view.cpp b/frameworks/core/components_ng/pattern/menu/menu_view.cpp index 87668fb9059a09278184805bfa9199cd3378ed08..0e1cff11c22229f92129f67fd68f78f30e6581c1 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_view.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_view.cpp @@ -413,7 +413,14 @@ void SetFilter(const RefPtr& targetNode, const RefPtr& men parent = parent->GetParent(); CHECK_NULL_VOID(parent); } - auto pipelineContext = PipelineContext::GetCurrentContext(); + auto containerId = Container::CurrentId(); + if (containerId >= MIN_SUBCONTAINER_ID) { + containerId = SubwindowManager::GetInstance()->GetParentContainerId(containerId); + } + ContainerScope scope(containerId); + auto container = Container::Current(); + CHECK_NULL_VOID(container); + auto pipelineContext = AceType::DynamicCast(container->GetPipelineContext()); CHECK_NULL_VOID(pipelineContext); auto manager = pipelineContext->GetOverlayManager(); CHECK_NULL_VOID(manager); @@ -426,8 +433,6 @@ void SetFilter(const RefPtr& targetNode, const RefPtr& men AceType::MakeRefPtr(true)); columnNode->GetLayoutProperty()->UpdateMeasureType(MeasureType::MATCH_PARENT); // set filter - auto container = Container::Current(); - CHECK_NULL_VOID(container); if (container->IsScenceBoardWindow()) { auto windowScene = manager->FindWindowScene(targetNode); manager->MountFilterToWindowScene(columnNode, windowScene); diff --git a/frameworks/core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.cpp b/frameworks/core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.cpp index 5530221579a37eae6f4fec6a2ad89da896101837..842660cf4e64b00171d673cc73d4b02247dcef05 100644 --- a/frameworks/core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.cpp +++ b/frameworks/core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.cpp @@ -316,6 +316,43 @@ bool MenuWrapperPattern::IsSelectOverlayCustomMenu(const RefPtr& menu return menuPattern->IsSelectOverlayCustomMenu(); } +void MenuWrapperPattern::RegisterMenuCallback(const RefPtr& menuWrapperNode, const MenuParam& menuParam) +{ + TAG_LOGD(AceLogTag::ACE_DIALOG, "register menu enter"); + CHECK_NULL_VOID(menuWrapperNode); + auto pattern = menuWrapperNode->GetPattern(); + CHECK_NULL_VOID(pattern); + pattern->RegisterMenuAppearCallback(menuParam.onAppear); + pattern->RegisterMenuDisappearCallback(menuParam.onDisappear); + pattern->RegisterMenuAboutToAppearCallback(menuParam.aboutToAppear); + pattern->RegisterMenuAboutToDisappearCallback(menuParam.aboutToDisappear); + pattern->RegisterMenuStateChangeCallback(menuParam.onStateChange); +} + +void MenuWrapperPattern::SetMenuTransitionEffect(const RefPtr& menuWrapperNode, const MenuParam& menuParam) +{ + TAG_LOGD(AceLogTag::ACE_DIALOG, "set menu transition effect"); + CHECK_NULL_VOID(menuWrapperNode); + auto pattern = menuWrapperNode->GetPattern(); + CHECK_NULL_VOID(pattern); + pattern->SetHasTransitionEffect(menuParam.hasTransitionEffect); + if (menuParam.hasTransitionEffect) { + auto renderContext = menuWrapperNode->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + CHECK_NULL_VOID(menuParam.transition); + renderContext->UpdateChainedTransition(menuParam.transition); + } + pattern->SetHasPreviewTransitionEffect(menuParam.hasPreviewTransitionEffect); + if (menuParam.hasPreviewTransitionEffect) { + auto previewChild = pattern->GetPreview(); + CHECK_NULL_VOID(previewChild); + auto renderContext = previewChild->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + CHECK_NULL_VOID(menuParam.previewTransition); + renderContext->UpdateChainedTransition(menuParam.previewTransition); + } +} + void MenuWrapperPattern::DumpInfo() { DumpLog::GetInstance().AddDesc( diff --git a/frameworks/core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h b/frameworks/core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h index 22762edff2084f3cd9adc17fbdcd5a84c22479bb..5567be35abef9b8ab9c75dd7ce9ddb9bf20b4442 100644 --- a/frameworks/core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h +++ b/frameworks/core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h @@ -154,6 +154,8 @@ public: isFirstShow_ = true; } + void RegisterMenuCallback(const RefPtr& menuWrapperNode, const MenuParam& menuParam); + void RegisterMenuAppearCallback(const std::function& onAppear) { onAppearCallback_ = onAppear; @@ -244,6 +246,8 @@ public: hasTransitionEffect_ = hasTransitionEffect; } + void SetMenuTransitionEffect(const RefPtr& menuWrapperNode, const MenuParam& menuParam); + bool HasPreviewTransitionEffect() const { return hasPreviewTransitionEffect_; @@ -263,7 +267,7 @@ public: { return filterColumnNode_; } - + void DumpInfo() override; MenuDumpInfo GetDumpInfo() const diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index 7c8ff0b7998c7a90cdcd48f2850d905a30e698f5..98644033f5d794b992db168f4b57b6c8db59e118 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -3883,7 +3883,6 @@ void OverlayManager::ComputeDetentsSheetOffset(NG::SheetStyle& sheetStyle, RefPt sheetHeight_ = height; } } - } void OverlayManager::DestroySheet(const RefPtr& sheetNode, int32_t targetId) @@ -4615,7 +4614,8 @@ bool OverlayManager::ShowUIExtensionMenu(const RefPtr& uiExtNode, CHECK_NULL_RETURN(theme, false); auto expandDisplay = theme->GetExpandDisplay(); if (expandDisplay) { - SubwindowManager::GetInstance()->ShowMenuNG(menuWrapperNode, targetNode->GetId(), aiRect.GetOffset()); + MenuParam menuParam {}; + SubwindowManager::GetInstance()->ShowMenuNG(menuWrapperNode, menuParam, targetNode, aiRect.GetOffset()); } else { ShowMenu(targetNode->GetId(), aiRect.GetOffset(), menuWrapperNode); } diff --git a/frameworks/core/components_ng/property/menu_property.h b/frameworks/core/components_ng/property/menu_property.h new file mode 100644 index 0000000000000000000000000000000000000000..82e807bd9204be36fc18222324a396d1e043410c --- /dev/null +++ b/frameworks/core/components_ng/property/menu_property.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MENU_PROPERTY_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MENU_PROPERTY_H + +#include "base/geometry/dimension.h" +#include "core/components/common/properties/placement.h" +#include "core/components_ng/event/gesture_event_hub.h" +#include "core/components_ng/property/transition_property.h" + +namespace OHOS::Ace::NG { + +enum class MenuType { + // ----- Menu Containers ------ + MENU, // corresponds to .bindMenu attribute + CONTEXT_MENU, // corresponds to .bindContextMenu attribute, lives in a SubWindow + SUB_MENU, // secondary menu container in a multi-level menu + + // ----- innerMenu Node, corersponds to tag in the frontend ------ + MULTI_MENU, // called multi because it's a multi-leveled menu, its MenuItems can trigger subMenus + DESKTOP_MENU, // menu specialized for desktop UI, enabled when multiple sibiling nodes are present + + // ----- special menu used in other components ------ + NAVIGATION_MENU, // menu used in a Navigation component + SELECT_OVERLAY_EXTENSION_MENU, // menu used in SelectOverlay Extension of text component,skip menu layout algorithm + SELECT_OVERLAY_CUSTOM_MENU, // menu used in SelectOverlay for custom menu + // click menu item whill not trigger close menu + SELECT_OVERLAY_SUB_MENU, // menu type used for select overlay sub menu + SELECT_OVERLAY_RIGHT_CLICK_MENU, // menu type used for select overlay menu triggered by right-click +}; + +enum class ContextMenuRegisterType : char { + NORMAL_TYPE = 0, + CUSTOM_TYPE = 1, +}; + +struct MenuParam { + std::string title; + OffsetF positionOffset; + bool setShow = false; + bool isShow = false; + ContextMenuRegisterType contextMenuRegisterType = ContextMenuRegisterType::NORMAL_TYPE; + std::function onStateChange; + std::optional placement; + std::function onAppear; + std::function onDisappear; + std::function aboutToAppear; + std::function aboutToDisappear; + std::optional enableArrow; + std::optional arrowOffset; + bool isShowInSubWindow = false; + bool hasTransitionEffect = false; + RefPtr transition; + bool hasPreviewTransitionEffect = false; + RefPtr previewTransition; + MenuType type = MenuType::MENU; + MenuPreviewMode previewMode = MenuPreviewMode::NONE; + MenuPreviewAnimationOptions previewAnimationOptions; + std::optional backgroundEffectOption; + std::optional backgroundColor; + std::optional backgroundBlurStyle; + std::optional borderRadius; +}; + +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MENU_PROPERTY_H diff --git a/test/mock/base/mock_subwindow.h b/test/mock/base/mock_subwindow.h index dcccd4826231294b62baf0f2e6335a1f36d2fc01..4d9a922b68a1451168fd85b8b84688d7d3814a6c 100644 --- a/test/mock/base/mock_subwindow.h +++ b/test/mock/base/mock_subwindow.h @@ -29,7 +29,11 @@ public: MOCK_METHOD0(ResizeWindow, void()); MOCK_METHOD0(GetRect, NG::RectF()); MOCK_METHOD1(ShowMenu, void(const RefPtr& newComponent)); - MOCK_METHOD3(ShowMenuNG, void(const RefPtr menuNode, int32_t targetId, const NG::OffsetF& offset)); + MOCK_METHOD4(ShowMenuNG, void(const RefPtr menuNode, const NG::MenuParam& menuParam, + const RefPtr& targetNode, const NG::OffsetF& offset)); + MOCK_METHOD5(ShowMenuNG, + void(std::function&& buildFunc, std::function&& previewBuildFunc, + const NG::MenuParam& menuParam, const RefPtr& targetNode, const NG::OffsetF& offset)); MOCK_METHOD0(ShowPreviewNG, bool()); MOCK_METHOD0(HidePreviewNG, void()); MOCK_METHOD2(HideMenuNG, void(const RefPtr& menu, int32_t targetId)); diff --git a/test/unittest/core/base/view_abstract_test_ng.cpp b/test/unittest/core/base/view_abstract_test_ng.cpp index d716c312c558ef1658c51cd8d05143f0103f6128..639bdb7c5f2f19d619b7490b43d7719079aadca6 100644 --- a/test/unittest/core/base/view_abstract_test_ng.cpp +++ b/test/unittest/core/base/view_abstract_test_ng.cpp @@ -2139,12 +2139,14 @@ HWTEST_F(ViewAbstractTestNg, ViewAbstractTest040, TestSize.Level1) std::vector param; ViewAbstract::BindMenuWithItems(std::move(param), targetNode, OFFSETF, menuParam); menuParam.type = MenuType::MULTI_MENU; - ViewAbstract::BindMenuWithCustomNode(mainNode, targetNode, OFFSETF, menuParam); + ViewAbstract::BindMenuWithCustomNode(std::move(buildFunc), targetNode, OFFSETF, menuParam, + std::move(previewBuildFunc)); EXPECT_FALSE(mouseInfo.IsStopPropagation()); param.push_back(OptionParam()); ViewAbstract::BindMenuWithItems(std::move(param), targetNode, OFFSETF, menuParam); menuParam.type = MenuType::CONTEXT_MENU; - ViewAbstract::BindMenuWithCustomNode(mainNode, targetNode, OFFSETF, menuParam); + ViewAbstract::BindMenuWithCustomNode(std::move(buildFunc), targetNode, OFFSETF, menuParam, + std::move(previewBuildFunc)); EXPECT_FALSE(mouseInfo.IsStopPropagation()); }