From 3fe96d3124b24e637e3311283f3f78d6d50bef4a Mon Sep 17 00:00:00 2001 From: "DESKTOP-H8KLN8I\\lisitao" Date: Thu, 28 Aug 2025 20:58:54 +0800 Subject: [PATCH] =?UTF-8?q?[L]js=20InitMenuDefaultRadius=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9Signed-off-by:lisitaolisitao3@huawei.com?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: DESKTOP-H8KLN8I\lisitao --- .../enhance/container_modal_pattern_enhance.cpp | 15 +++++++++++++++ .../enhance/container_modal_pattern_enhance.h | 2 +- .../container_modal/interfaces/customtitle.js | 16 ++++++++++++++++ .../container_modal/source/custombutton.ets | 12 ++++++++++-- .../pattern/custom/custom_title_node.h | 2 +- .../container_modal_pattern_enhance_test_ng.cpp | 17 +++++++++++++++++ 6 files changed, 60 insertions(+), 4 deletions(-) diff --git a/frameworks/core/components_ng/pattern/container_modal/enhance/container_modal_pattern_enhance.cpp b/frameworks/core/components_ng/pattern/container_modal/enhance/container_modal_pattern_enhance.cpp index 1efd9b3f1e4..fc0b6be590f 100755 --- a/frameworks/core/components_ng/pattern/container_modal/enhance/container_modal_pattern_enhance.cpp +++ b/frameworks/core/components_ng/pattern/container_modal/enhance/container_modal_pattern_enhance.cpp @@ -33,6 +33,7 @@ #include "core/components_ng/pattern/text/text_pattern.h" #include "core/pipeline_ng/pipeline_context.h" #include "core/common/resource/resource_manager.h" +#include "core/components/select/select_theme.h" namespace OHOS::Ace::NG { namespace { @@ -327,6 +328,19 @@ void ContainerModalPatternEnhance::SetContainerButtonHide( controlButtonsNode->FireCustomCallback(EVENT_NAME_CLOSE_VISIBILITY, hideClose); } +void ContainerModalPatternEnhance::InitMenuDefaultRadius() +{ + auto containerNode = GetHost(); + CHECK_NULL_VOID(containerNode); + auto pipeline = containerNode->GetContextRefPtr(); + CHECK_NULL_VOID(pipeline); + auto customButtonNode = GetCustomButtonNode(); + CHECK_NULL_VOID(customButtonNode); + auto theme = pipeline->GetTheme(); + auto defaultRadius = theme->GetMenuDefaultRadius().Value(); + customButtonNode->FireCustomCallback(EVENT_NAME_BUTTON_MENU_DEFAULT_RADIUS, std::to_string(defaultRadius)); +} + void ContainerModalPatternEnhance::UpdateTitleInTargetPos(bool isShow, int32_t height) { auto floatingTitleNode = GetFloatingTitleRow(); @@ -729,6 +743,7 @@ void ContainerModalPatternEnhance::Init() InitTitle(); InitLayoutProperty(); SetColorConfigurationUpdate(); + InitMenuDefaultRadius(); } void ContainerModalPatternEnhance::SetColorConfigurationUpdate() diff --git a/frameworks/core/components_ng/pattern/container_modal/enhance/container_modal_pattern_enhance.h b/frameworks/core/components_ng/pattern/container_modal/enhance/container_modal_pattern_enhance.h index ec8c7fa4a7b..fa5d0d4a2e3 100755 --- a/frameworks/core/components_ng/pattern/container_modal/enhance/container_modal_pattern_enhance.h +++ b/frameworks/core/components_ng/pattern/container_modal/enhance/container_modal_pattern_enhance.h @@ -109,7 +109,7 @@ private: void SetColorConfigurationUpdate(); void SetMaximizeIconIsRecover(); void NotifyButtonsRectChange(const RectF& containerModal, const RectF& buttonsRect) override; - + void InitMenuDefaultRadius(); VisibleType controlButtonVisibleBeforeAnim_; RefPtr menuList_; OffsetF menuOffset_; diff --git a/frameworks/core/components_ng/pattern/container_modal/interfaces/customtitle.js b/frameworks/core/components_ng/pattern/container_modal/interfaces/customtitle.js index 035e9862e0f..1a4f1959604 100644 --- a/frameworks/core/components_ng/pattern/container_modal/interfaces/customtitle.js +++ b/frameworks/core/components_ng/pattern/container_modal/interfaces/customtitle.js @@ -213,6 +213,7 @@ const h2 = 'arkui_color_mode_locked'; const i2 = 'arkui_button_right_offset_change'; const k2 = 'arkui_button_icon_size_change'; const p2 = 'arkui_button_background_corner_radius_change'; +const a9 = 'arkui_button_menu_default_radius'; const PC_TITLE_BAR_MAXIMIZE = 'pc_title_bar_maximize'; const PC_TITLE_BAR_MINIMIZE = 'pc_title_bar_minimize'; const PC_TITLE_BAR_RESTORE = 'pc_title_bar_restore'; @@ -386,6 +387,7 @@ class c3 extends ViewPU { this.colorConfigurationLocked = false; this.n4 = new ObservedPropertySimplePU(20, this, 'buttonIconSize'); this.o4 = new ObservedPropertySimplePU(4, this, 'buttonBackgroundCornerRadius'); + this.t4 = new ObservedPropertySimplePU(4, this, 'buttonMenuRadius'); this.isFocused = true; this.isDark = false; this.isHoverShowMenu = false; @@ -555,6 +557,7 @@ class c3 extends ViewPU { this.m4.purgeDependencyOnElmtId(rmElmtId); this.n4.purgeDependencyOnElmtId(rmElmtId); this.o4.purgeDependencyOnElmtId(rmElmtId); + this.t4.purgeDependencyOnElmtId(rmElmtId); } aboutToBeDeleted() { this.f3.aboutToBeDeleted(); @@ -589,6 +592,7 @@ class c3 extends ViewPU { this.m4.aboutToBeDeleted(); this.n4.aboutToBeDeleted(); this.o4.aboutToBeDeleted(); + this.t4.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id__()); this.aboutToBeDeletedInternal(); } @@ -808,6 +812,12 @@ class c3 extends ViewPU { set buttonBackgroundCornerRadius(newValue) { this.o4.set(newValue); } + get buttonMenuRadius() { + return this.t4.get(); + } + set buttonMenuRadius(newValue) { + this.t4.set(newValue); + } onWindowFocused() { this.rowOpacity = 1.0; this.isFocused = true; @@ -865,6 +875,9 @@ class c3 extends ViewPU { else if (eventName === p2) { this.setButtonBackgroundCornerRadius(param); } + else if (eventName === a9) { + this.setButtonMenuRadius(param); + } } setButtonSpacing(param) { this.buttonSpacing = parseInt(param); @@ -902,6 +915,9 @@ class c3 extends ViewPU { setButtonBackgroundCornerRadius(param) { this.buttonBackgroundCornerRadius = parseInt(param); } + setButtonMenuRadius(param) { + this.buttonMenuRadius = parseInt(param) - 4; + } onMaximizeButtonClick() { this.onCancelMenuTimer(); ContainerModal.callNative(l1); diff --git a/frameworks/core/components_ng/pattern/container_modal/source/custombutton.ets b/frameworks/core/components_ng/pattern/container_modal/source/custombutton.ets index 5f6dac6c0cb..61c574539ef 100644 --- a/frameworks/core/components_ng/pattern/container_modal/source/custombutton.ets +++ b/frameworks/core/components_ng/pattern/container_modal/source/custombutton.ets @@ -39,6 +39,7 @@ const EVENT_NAME_COLOR_MODE_LOCKED: string = 'arkui_color_mode_locked' const EVENT_NAME_BUTTON_RIGHT_OFFSET_CHANGE: string = 'arkui_button_right_offset_change' const EVENT_NAME_BUTTON_ICON_SIZE_CHANGE: string = 'arkui_button_icon_size_change' const EVENT_NAME_BUTTON_BACKGROUND_CORNER_RADIUS_CHANGE: string = 'arkui_button_background_corner_radius_change' +const EVENT_NAME_BUTTON_MENU_DEFAULT_RADIUS: string = 'arkui_button_menu_default_radius' const PC_TITLE_BAR_MAXIMIZE: string = 'pc_title_bar_maximize' const PC_TITLE_BAR_MINIMIZE: string = 'pc_title_bar_minimize' @@ -232,6 +233,7 @@ struct custombutton { @State buttonIconSize: number = 20; // button background corner radius 4-8vp @State buttonBackgroundCornerRadius: number = 4; + @State buttonMenuRadius: number = 20; isFocused: boolean = true; isDark: boolean = false; @@ -287,9 +289,15 @@ struct custombutton { this.setButtonIconSize(param); } else if (eventName === EVENT_NAME_BUTTON_BACKGROUND_CORNER_RADIUS_CHANGE) { this.setButtonBackgroundCornerRadius(param); + }else if (eventName === EVENT_NAME_BUTTON_MENU_DEFAULT_RADIUS) { + this.setButtonMenuRadius(param); } } + setButtonMenuRadius(radius: string) { + this.buttonMenuRadius = parseInt(radius); + } + // set the spacing between buttons setButtonSpacing(param: string) { this.buttonSpacing = parseInt(param); @@ -505,7 +513,7 @@ struct custombutton { .maxLines(1) .margin({ top: MENU_TITLE_MARGIN_V, bottom: MENU_TITLE_MARGIN_V, right: MENU_MARGIN_H }) } - .borderRadius('4vp') + .borderRadius(this.buttonMenuRadius + 'vp') .width('100%') .backgroundColor(this.leftSplitBackgroundColor) .margin({ @@ -543,7 +551,7 @@ struct custombutton { .maxLines(1) .margin({ top: MENU_TITLE_MARGIN_V, bottom: MENU_TITLE_MARGIN_V, right: MENU_MARGIN_H }) } - .borderRadius('4vp') + .borderRadius(this.buttonMenuRadius + 'vp') .width('100%') .backgroundColor(this.rightSplitBackgroundColor) .margin({ diff --git a/frameworks/core/components_ng/pattern/custom/custom_title_node.h b/frameworks/core/components_ng/pattern/custom/custom_title_node.h index 7cbb2344937..9e4c44e4d3f 100644 --- a/frameworks/core/components_ng/pattern/custom/custom_title_node.h +++ b/frameworks/core/components_ng/pattern/custom/custom_title_node.h @@ -34,7 +34,7 @@ const std::string EVENT_NAME_BUTTON_SIZE_CHANGE = "arkui_button_size_change"; const std::string EVENT_NAME_BUTTON_RIGHT_OFFSET_CHANGE = "arkui_button_right_offset_change"; const std::string EVENT_NAME_BUTTON_ICON_SIZE_CHANGE = "arkui_button_icon_size_change"; const std::string EVENT_NAME_BUTTON_BACKGROUND_CORNER_RADIUS_CHANGE = "arkui_button_background_corner_radius_change"; - +const std::string EVENT_NAME_BUTTON_MENU_DEFAULT_RADIUS = "arkui_button_menu_default_radius"; namespace { inline std::string BoolToString(bool value) { diff --git a/test/unittest/core/pattern/container_modal/container_modal_pattern_enhance_test_ng.cpp b/test/unittest/core/pattern/container_modal/container_modal_pattern_enhance_test_ng.cpp index 8cbef6a65d8..c5b3ba07dba 100644 --- a/test/unittest/core/pattern/container_modal/container_modal_pattern_enhance_test_ng.cpp +++ b/test/unittest/core/pattern/container_modal/container_modal_pattern_enhance_test_ng.cpp @@ -921,4 +921,21 @@ HWTEST_F(ContainerModalPatternEnhanceTestNg, ContainerModalPatternEnhanceGetCont auto context = containerPattern->GetContextRefPtr(); EXPECT_NE(context, nullptr); } + +/** + * @tc.name: InitMenuDefaultRadius + * @tc.desc: Test InitMenuDefaultRadius + * @tc.type: FUNC + * @tc.author: + */ +HWTEST_F(ContainerModalPatternEnhanceTestNg, InitMenuDefaultRadius, TestSize.Level1) +{ + auto containerModalNode = + FrameNode::CreateFrameNode("ContainerModal", 1, AceType::MakeRefPtr()); + containerModalNode->AddChild( + FrameNode::CreateFrameNode(V2::BUTTON_ETS_TAG, 2, AceType::MakeRefPtr())); + auto containerPattern = containerModalNode->GetPattern(); + containerPattern->InitMenuDefaultRadius(); + EXPECT_NE(containerPattern, nullptr); +} } // namespace OHOS::Ace::NG \ No newline at end of file -- Gitee