1 /*
2  * Copyright (c) 2021-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_STACK_STACK_ELEMENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STACK_STACK_ELEMENT_H
18 
19 #include "core/components/bubble/bubble_element.h"
20 #include "core/components/dialog_tween/dialog_tween_element.h"
21 #include "core/pipeline/base/component_group_element.h"
22 
23 namespace OHOS::Ace {
24 
25 class ACE_FORCE_EXPORT StackElement : public ComponentGroupElement, public FocusGroup {
26     DECLARE_ACE_TYPE(StackElement, ComponentGroupElement, FocusGroup);
27 
28     enum class Operation {
29         NONE,
30         DIRECT_PUSH,
31         TOAST_PUSH,
32         TOAST_POP,
33         DIALOG_PUSH,
34         DIALOG_POP,
35         TEXT_OVERLAY_POP,
36         POPUP_POP,
37         PANEL_PUSH,
38         PANEL_POP,
39         DIRECT_POP,
40         MENU_POP,
41         VIDEO_POP,
42     };
43 
44     struct ToastInfo {
45         int32_t toastId = -1;
46         RefPtr<Element> child;
47     };
48 
49     struct PopupComponentInfo {
50         int32_t popId = -1;
51         ComposeId id = "-1";
52         Operation operation = Operation::NONE;
53         RefPtr<Component> component;
IsValidPopupComponentInfo54         bool IsValid()
55         {
56             return component != nullptr;
57         }
58     };
59 
60 public:
61     void PerformBuild() override;
62     void PushComponent(const RefPtr<Component>& newComponent, bool disableTouchEvent = true);
63     void PopComponent();
64     void PushToastComponent(const RefPtr<Component>& newComponent, int32_t toastId);
65     void PopToastComponent(int32_t toastPopId);
66     void PushPanel(const RefPtr<Component>& newComponent, bool disableTouchEvent = false);
67     void PopPanel();
68     bool PushDialog(const RefPtr<Component>& newComponent, bool disableTouchEvent = true);
69     bool PopDialog(int32_t id = -1);
70     void PopTextOverlay();
71     void PopPopup(const ComposeId& id);
72     bool PopPopupIfExist() const;
73     bool PopDialogIfExist() const;
74     void PopMenu();
75     void PopVideo();
76     void PopInstant();
77     void PushInstant(const RefPtr<Component>& newComponent, bool disableTouchEvent = true);
78     bool HasOverlayChild();
isPageElement()79     virtual bool isPageElement()
80     {
81         return false;
82     }
83 
84 protected:
85     void OnFocus() override;
86     void OnBlur() override;
87     bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect) override;
88 
89 private:
90     void PerformPopupChild(PopupComponentInfo& popupComponentInfo);
91     void PerformPushChild(PopupComponentInfo& popupComponentInfo);
92     void PerformPushToast(PopupComponentInfo& popupComponentInfo);
93     void PerformPopToastById(int32_t toastId);
94     void PerformPopToast();
95     void PerformPopDialog(int32_t id = -1);
96     void PerformPopDialogById(int32_t id);
97     void PerformPopTextOverlay();
98     void PerformPopPopup(const ComposeId& id);
99     void PerformPopMenu();
100     void PerformPopVideo();
101     void PerformDirectPop();
102     void PerformPopupChild();
103     void EnableTouchEventAndRequestFocus();
104     RefPtr<BubbleElement> GetBubble(const RefPtr<Element>& element) const;
105     RefPtr<DialogTweenElement> GetDialog(const RefPtr<Element>& element) const;
106 
107     void CreateInspectorComponent(PopupComponentInfo& componentInfo) const;
108 
109     std::list<PopupComponentInfo> popupComponentInfos_;
110     std::vector<ToastInfo> toastStack_;
111     bool disableTouchEvent_ = true;
112 };
113 
114 } // namespace OHOS::Ace
115 
116 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STACK_STACK_ELEMENT_H
117