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