• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_PATTERNS_SELECT_OVERLAY_NODE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SELECT_OVERLAY_NODE_H
18 
19 #include <cstdint>
20 #include <memory>
21 
22 #include "base/utils/noncopyable.h"
23 #include "core/components_ng/base/frame_node.h"
24 #include "core/components_ng/pattern/select_overlay/select_overlay_property.h"
25 #include "core/components_ng/property/property.h"
26 
27 namespace OHOS::Ace::NG {
28 
29 enum class FrameNodeType {
30     SELECTMENU,
31     EXTENSIONMENU,
32     BACKBUTTON
33 };
34 
35 enum class FrameNodeStatus {
36     VISIBLE,
37     VISIBLETOGONE,
38     GONE,
39     GONETOVISIBLE
40 };
41 
42 enum class FrameNodeTrigger {
43     SHOW,
44     SHOWN,
45     HIDE,
46     HIDDEN
47 };
48 
49 class ACE_EXPORT SelectOverlayNode : public FrameNode {
50     DECLARE_ACE_TYPE(SelectOverlayNode, FrameNode)
51 public:
52     explicit SelectOverlayNode(const std::shared_ptr<SelectOverlayInfo>& info);
53     ~SelectOverlayNode() override = default;
54 
55     static RefPtr<FrameNode> CreateSelectOverlayNode(const std::shared_ptr<SelectOverlayInfo>& info);
56     RefPtr<FrameNode> CreateMoreSelectOverlayNode(const std::vector<MenuOptionsParam>& menuOptionItems, int32_t index);
57 
58     void UpdateToolBar(bool menuItemChanged);
59 
SetSelectInfo(const std::string & selectInfo)60     void SetSelectInfo(const std::string& selectInfo)
61     {
62         selectInfo_ = selectInfo;
63     }
64 
GetSelectInfo()65     const std::string& GetSelectInfo() const
66     {
67         return selectInfo_;
68     }
69 
70     void ChangeToolBar(bool isUseExtensionMenu);
71 
72     void MoreOrBackAnimation(bool isMore);
73 
74     bool IsInSelectedOrSelectOverlayArea(const PointF& point);
75 
76     void SetClosedByGlobalEvent(bool closedByGlobalEvent);
77 
GetAnimationStatus()78     bool GetAnimationStatus()
79     {
80         return isDoingAnimation_;
81     }
82 
GetIsExtensionMenu()83     bool GetIsExtensionMenu()
84     {
85         return isExtensionMenu_;
86     }
87 
88     void ShowSelectOverlay(bool animation);
89 
90     void HideSelectOverlay(const std::function<void()>& callback);
91 
92 private:
93     void CreateToolBar();
94     bool AddSystemDefaultOptions(float maxWidth, float& allocatedSize);
95     void AddExtensionMenuOptions(const std::vector<MenuOptionsParam>& menuOptionItems, int32_t index);
96     void GetDefaultButtonAndMenuWidth(float& maxWidth);
97 
98     void MoreAnimation();
99     void BackAnimation();
100 
101     void DispatchVisibleState(FrameNodeType type, FrameNodeTrigger trigger);
102     void DispatchVisibleToGoneState(FrameNodeType type, FrameNodeTrigger trigger);
103     void DispatchGoneState(FrameNodeType type, FrameNodeTrigger trigger);
104     void DispatchGoneToVisibleState(FrameNodeType type, FrameNodeTrigger trigger);
105     void ExecuteOverlayStatus(FrameNodeType type, FrameNodeTrigger trigger);
106     void SetFrameNodeStatus(FrameNodeType type, FrameNodeStatus status);
107     void SetFrameNodeVisibility(FrameNodeType type, VisibleType visibleType);
108     void SetFrameNodeOpacity(FrameNodeType type, float opacity);
109     void SetSelectMenuOpacity(float value);
110     void SetExtensionMenuOpacity(float value);
111     void SetBackButtonOpacity(float value);
112 
SetAnimationStatus(bool toDoAnimation)113     void SetAnimationStatus(bool toDoAnimation)
114     {
115         isDoingAnimation_ = toDoAnimation;
116     }
117 
118     static RefPtr<FrameNode> CreateMenuNode(const std::shared_ptr<SelectOverlayInfo>& info);
119 
120     using ExecuteStateFunc = void (SelectOverlayNode::*)(FrameNodeType type, FrameNodeTrigger trigger);
121 
122     /* Text selection menu node structure.
123         -rootNode
124             -selectOverlay
125                 -selectMenu_
126                     -selectMenuInner_
127                 -backButton_
128                 -extensionMenu_
129        Attention:
130         If the user-defined selection menu is bound by bindSelectionMenu, there will be only the selectMenu_.
131         Then, selectMenuInner_, backButton_, extensionMenu_ will be null.
132         Text selection menu node structure whill be like bellow:
133         -rootNode
134             -selectOverlay(menuWrapper)
135                 -selectMenu_(menu)
136                     -scroller
137                         -customBuilderMenu
138     */
139     RefPtr<FrameNode> selectMenu_;
140     RefPtr<FrameNode> selectMenuInner_;
141     RefPtr<FrameNode> extensionMenu_;
142     RefPtr<FrameNode> backButton_;
143 
144     FrameNodeStatus selectMenuStatus_ = FrameNodeStatus::VISIBLE;
145     FrameNodeStatus extensionMenuStatus_ = FrameNodeStatus::GONE;
146     FrameNodeStatus backButtonStatus_ = FrameNodeStatus::GONE;
147 
148     std::map<FrameNodeStatus, ExecuteStateFunc> stateFuncs_;
149 
150     std::string selectInfo_;
151 
152     // Marks whether it is currently in the animated state.
153     bool isDoingAnimation_ = false;
154 
155     // Controls that only default menus can be converted to extended menus, and extended menus can be converted to
156     // default menus.
157     bool isExtensionMenu_ = false;
158 
159     // Label whether the menu default button needs to appear within the extended menu
160     bool isShowInDefaultMenu_[7] = { false };
161 
162     ACE_DISALLOW_COPY_AND_MOVE(SelectOverlayNode);
163 };
164 
165 } // namespace OHOS::Ace::NG
166 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SELECT_OVERLAY_NODE_H
167