• 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, bool noAnimation = false);
59 
60     void UpdateMenuInner(const std::shared_ptr<SelectOverlayInfo>& info);
61 
SetSelectInfo(const std::string & selectInfo)62     void SetSelectInfo(const std::string& selectInfo)
63     {
64         selectInfo_ = selectInfo;
65     }
66 
GetSelectInfo()67     const std::string& GetSelectInfo() const
68     {
69         return selectInfo_;
70     }
71 
72     void ChangeToolBar(bool isUseExtensionMenu);
73 
74     void MoreOrBackAnimation(bool isMore);
75 
76     bool IsInSelectedOrSelectOverlayArea(const PointF& point);
77 
78     void SetClosedByGlobalEvent(bool closedByGlobalEvent);
79 
GetAnimationStatus()80     bool GetAnimationStatus()
81     {
82         return isDoingAnimation_;
83     }
84 
GetIsExtensionMenu()85     bool GetIsExtensionMenu()
86     {
87         return isExtensionMenu_;
88     }
89 
90     void ShowSelectOverlay(bool animation);
91 
92     void HideSelectOverlay(const std::function<void()>& callback);
93 
94 private:
95     void CreateToolBar();
96     bool AddSystemDefaultOptions(float maxWidth, float& allocatedSize);
97     void AddExtensionMenuOptions(const std::vector<MenuOptionsParam>& menuOptionItems, int32_t index);
98     void GetDefaultButtonAndMenuWidth(float& maxWidth);
99 
100     void MoreAnimation();
101     void BackAnimation();
102 
103     void DispatchVisibleState(FrameNodeType type, FrameNodeTrigger trigger);
104     void DispatchVisibleToGoneState(FrameNodeType type, FrameNodeTrigger trigger);
105     void DispatchGoneState(FrameNodeType type, FrameNodeTrigger trigger);
106     void DispatchGoneToVisibleState(FrameNodeType type, FrameNodeTrigger trigger);
107     void ExecuteOverlayStatus(FrameNodeType type, FrameNodeTrigger trigger);
108     void SetFrameNodeStatus(FrameNodeType type, FrameNodeStatus status);
109     void SetFrameNodeVisibility(FrameNodeType type, VisibleType visibleType);
110     void SetFrameNodeOpacity(FrameNodeType type, float opacity);
111     void SetSelectMenuOpacity(float value);
112     void SetExtensionMenuOpacity(float value);
113     void SetBackButtonOpacity(float value);
114     void HideFrameNodeImmediately(FrameNodeType type);
115     void CreateCustomSelectOverlay(const std::shared_ptr<SelectOverlayInfo>& info);
116 
SetAnimationStatus(bool toDoAnimation)117     void SetAnimationStatus(bool toDoAnimation)
118     {
119         isDoingAnimation_ = toDoAnimation;
120     }
121 
122     static RefPtr<FrameNode> CreateMenuNode(const std::shared_ptr<SelectOverlayInfo>& info);
123 
124     using ExecuteStateFunc = void (SelectOverlayNode::*)(FrameNodeType type, FrameNodeTrigger trigger);
125 
126     /* Text selection menu node structure.
127         -rootNode
128             -selectOverlay
129                 -selectMenu_
130                     -selectMenuInner_
131                 -backButton_
132                 -extensionMenu_
133        Attention:
134         If the user-defined selection menu is bound by bindSelectionMenu, there will be only the selectMenu_.
135         Then, selectMenuInner_, backButton_, extensionMenu_ will be null.
136         Text selection menu node structure whill be like bellow:
137         -rootNode
138             -selectOverlay(menuWrapper)
139                 -selectMenu_(menu)
140                     -scroller
141                         -customBuilderMenu
142     */
143     RefPtr<FrameNode> selectMenu_;
144     RefPtr<FrameNode> selectMenuInner_;
145     RefPtr<FrameNode> extensionMenu_;
146     RefPtr<FrameNode> backButton_;
147 
148     FrameNodeStatus selectMenuStatus_ = FrameNodeStatus::VISIBLE;
149     FrameNodeStatus extensionMenuStatus_ = FrameNodeStatus::GONE;
150     FrameNodeStatus backButtonStatus_ = FrameNodeStatus::GONE;
151 
152     std::map<FrameNodeStatus, ExecuteStateFunc> stateFuncs_;
153 
154     std::string selectInfo_;
155 
156     // Marks whether it is currently in the animated state.
157     bool isDoingAnimation_ = false;
158 
159     // Controls that only default menus can be converted to extended menus, and extended menus can be converted to
160     // default menus.
161     bool isExtensionMenu_ = false;
162 
163     // Label whether the menu default button needs to appear within the extended menu
164     bool isShowInDefaultMenu_[8] = { false };
165 
166     ACE_DISALLOW_COPY_AND_MOVE(SelectOverlayNode);
167 };
168 
169 } // namespace OHOS::Ace::NG
170 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SELECT_OVERLAY_NODE_H
171