1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MENU_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MENU_PROPERTY_H
18 
19 #include "base/geometry/dimension.h"
20 #include "core/components/common/properties/placement.h"
21 #include "core/components_ng/event/gesture_event_hub.h"
22 #include "core/components_ng/property/border_property.h"
23 #include "core/components_ng/property/transition_property.h"
24 
25 namespace OHOS::Ace::NG {
26 
27 enum class MenuType {
28     // ----- Menu Containers ------
29     MENU,         // corresponds to .bindMenu attribute
30     CONTEXT_MENU, // corresponds to .bindContextMenu attribute, lives in a SubWindow
31     SUB_MENU,     // secondary menu container in a multi-level menu
32 
33     // ----- innerMenu Node, corersponds to <Menu> tag in the frontend ------
34     MULTI_MENU,   // called multi because it's a multi-leveled menu, its MenuItems can trigger subMenus
35     DESKTOP_MENU, // menu specialized for desktop UI, enabled when multiple sibiling <Menu> nodes are present
36 
37     // ----- special menu used in other components ------
38     NAVIGATION_MENU,               // menu used in a Navigation component
39     SELECT_OVERLAY_EXTENSION_MENU, // menu used in SelectOverlay Extension of text component,skip menu layout algorithm
40     SELECT_OVERLAY_CUSTOM_MENU,    // menu used in SelectOverlay for custom menu
41                                    // click menu item whill not trigger close menu
42     SELECT_OVERLAY_SUB_MENU,       // menu type used for select overlay sub menu
43     SELECT_OVERLAY_RIGHT_CLICK_MENU, // menu type used for select overlay menu triggered by right-click
44 };
45 
46 enum class ContextMenuRegisterType : char {
47     NORMAL_TYPE = 0,
48     CUSTOM_TYPE = 1,
49 };
50 
51 struct MenuParam {
52     std::string title;
53     OffsetF positionOffset;
54     bool setShow = false;
55     bool isShow = false;
56     MenuBindingType menuBindType = MenuBindingType::LONG_PRESS;
57     ContextMenuRegisterType contextMenuRegisterType = ContextMenuRegisterType::NORMAL_TYPE;
58     std::function<void(const std::string&)> onStateChange;
59     std::optional<Placement> placement;
60     std::function<void()> onAppear;
61     std::function<void()> onDisappear;
62     std::function<void()> aboutToAppear;
63     std::function<void()> aboutToDisappear;
64     std::optional<bool> enableArrow;
65     std::optional<Dimension> arrowOffset;
66     bool isShowInSubWindow = true;
67     bool hasTransitionEffect = false;
68     RefPtr<NG::ChainedTransitionEffect> transition;
69     bool hasPreviewTransitionEffect = false;
70     RefPtr<NG::ChainedTransitionEffect> previewTransition;
71     MenuType type = MenuType::MENU;
72     MenuPreviewMode previewMode = MenuPreviewMode::NONE;
73     MenuPreviewAnimationOptions previewAnimationOptions;
74     bool isShowHoverImage = false;
75     MenuPreviewAnimationOptions hoverImageAnimationOptions;
76     std::optional<EffectOption> backgroundEffectOption;
77     std::optional<Color> backgroundColor;
78     std::optional<int32_t> backgroundBlurStyle;
79     std::optional<NG::BorderRadiusProperty> borderRadius;
80     std::optional<NG::BorderRadiusProperty> previewBorderRadius;
81     std::optional<NG::MarginProperty> layoutRegionMargin;
82     bool isPreviewContainScale = false;
83 };
84 
85 } // namespace OHOS::Ace::NG
86 
87 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MENU_PROPERTY_H
88