• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/transition_property.h"
23 
24 namespace OHOS::Ace::NG {
25 
26 enum class MenuType {
27     // ----- Menu Containers ------
28     MENU,         // corresponds to .bindMenu attribute
29     CONTEXT_MENU, // corresponds to .bindContextMenu attribute, lives in a SubWindow
30     SUB_MENU,     // secondary menu container in a multi-level menu
31 
32     // ----- innerMenu Node, corersponds to <Menu> tag in the frontend ------
33     MULTI_MENU,   // called multi because it's a multi-leveled menu, its MenuItems can trigger subMenus
34     DESKTOP_MENU, // menu specialized for desktop UI, enabled when multiple sibiling <Menu> nodes are present
35 
36     // ----- special menu used in other components ------
37     NAVIGATION_MENU,               // menu used in a Navigation component
38     SELECT_OVERLAY_EXTENSION_MENU, // menu used in SelectOverlay Extension of text component,skip menu layout algorithm
39     SELECT_OVERLAY_CUSTOM_MENU,    // menu used in SelectOverlay for custom menu
40                                    // click menu item whill not trigger close menu
41     SELECT_OVERLAY_SUB_MENU,       // menu type used for select overlay sub menu
42     SELECT_OVERLAY_RIGHT_CLICK_MENU, // menu type used for select overlay menu triggered by right-click
43 };
44 
45 enum class ContextMenuRegisterType : char {
46     NORMAL_TYPE = 0,
47     CUSTOM_TYPE = 1,
48 };
49 
50 struct MenuMaskType {
51     std::optional<Color> maskColor;
52     std::optional<BlurStyle> maskBackGroundBlurStyle;
53 };
54 
55 enum class PreviewScaleMode {
56     AUTO = 0,
57     CONSTANT = 1,
58     MAINTAIN = 2,
59 };
60 
61 enum class AvailableLayoutAreaMode {
62     SAFE_AREA = 0,
63 };
64 
65 struct MenuParam {
66     std::string title;
67     OffsetF positionOffset;
68     bool setShow = false;
69     bool isShow = false;
70     MenuBindingType menuBindType = MenuBindingType::LONG_PRESS;
71     ContextMenuRegisterType contextMenuRegisterType = ContextMenuRegisterType::NORMAL_TYPE;
72     std::function<void(const std::string&)> onStateChange;
73     std::optional<Placement> placement;
74     std::optional<bool> enableHoverMode = std::nullopt;
75     std::function<void()> onAppear;
76     std::function<void()> onDisappear;
77     std::function<void()> aboutToAppear;
78     std::function<void()> aboutToDisappear;
79     std::function<void()> onWillAppear;
80     std::function<void()> onDidAppear;
81     std::function<void()> onWillDisappear;
82     std::function<void()> onDidDisappear;
83     std::optional<bool> enableArrow;
84     std::optional<Dimension> arrowOffset;
85     bool isShowInSubWindow = true;
86     bool hasTransitionEffect = false;
87     RefPtr<NG::ChainedTransitionEffect> transition;
88     bool hasPreviewTransitionEffect = false;
89     RefPtr<NG::ChainedTransitionEffect> previewTransition;
90     MenuType type = MenuType::MENU;
91     MenuPreviewMode previewMode = MenuPreviewMode::NONE;
92     MenuPreviewAnimationOptions previewAnimationOptions;
93     bool isShowHoverImage = false;
94     bool hoverScaleInterruption = false;
95     MenuPreviewAnimationOptions hoverImageAnimationOptions;
96     std::optional<EffectOption> backgroundEffectOption;
97     std::optional<Color> backgroundColor;
98     std::optional<int32_t> backgroundBlurStyle;
99     std::optional<BlurStyleOption> backgroundBlurStyleOption;
100     std::optional<NG::BorderRadiusProperty> borderRadius;
101     std::optional<NG::BorderRadiusProperty> previewBorderRadius;
102     std::optional<NG::MarginProperty> layoutRegionMargin;
103     bool isPreviewContainScale = false;
104     std::optional<BlurStyleOption> blurStyleOption;
105     std::optional<EffectOption> effectOption;
106     HapticFeedbackMode hapticFeedbackMode = HapticFeedbackMode::DISABLED;
107     bool disappearScaleToTarget = false;
108     std::optional<NG::BorderWidthProperty> outlineWidth;
109     std::optional<NG::BorderColorProperty> outlineColor;
110     struct resourceUpdater {
111         RefPtr<ResourceObject> resObj;
112         std::function<void(const RefPtr<ResourceObject>&, MenuParam&)> updateFunc;
113     };
114     std::unordered_map<std::string, resourceUpdater> resMap_;
115 
AddResourceMenuParam116     void AddResource(const std::string& key, const RefPtr<ResourceObject>& resObj,
117         std::function<void(const RefPtr<ResourceObject>&, MenuParam&)>&& updateFunc)
118     {
119         if (resObj == nullptr || !updateFunc) {
120             return;
121         }
122         resMap_[key] = { resObj, std::move(updateFunc) };
123     }
124 
GetResourceMenuParam125     const RefPtr<ResourceObject> GetResource(const std::string& key) const
126     {
127         auto iter = resMap_.find(key);
128         if (iter != resMap_.end()) {
129             return iter->second.resObj;
130         }
131         return nullptr;
132     }
133 
HasResourcesMenuParam134     bool HasResources() const
135     {
136         return !resMap_.empty();
137     }
138 
ReloadResourcesMenuParam139     void ReloadResources()
140     {
141         for (const auto& [key, resourceUpdater] : resMap_) {
142             resourceUpdater.updateFunc(resourceUpdater.resObj, *this);
143         }
144     }
145     std::optional<bool> maskEnable;
146     std::optional<MenuMaskType> maskType;
147     std::optional<ModalMode> modalMode;
148     std::optional<PreviewScaleMode> previewScaleMode;
149     std::optional<AvailableLayoutAreaMode> availableLayoutAreaMode;
150     std::optional<OffsetF> anchorPosition;
151     bool isDarkMode = false;
152     bool isWithTheme = false;
153 };
154 
155 } // namespace OHOS::Ace::NG
156 
157 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MENU_PROPERTY_H
158