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_BRIDGE_COMMON_DOM_DOM_TABS_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_TABS_H
18 
19 #include "core/components/flex/flex_component.h"
20 #include "core/components/tab_bar/tab_controller.h"
21 #include "frameworks/bridge/common/dom/dom_node.h"
22 
23 namespace OHOS::Ace::Framework {
24 
25 class DOMTabs final : public DOMNode {
26     DECLARE_ACE_TYPE(DOMTabs, DOMNode);
27 
28 public:
29     DOMTabs(NodeId nodeId, const std::string& nodeName);
30     ~DOMTabs() override = default;
31 
GetTabIndex()32     uint32_t GetTabIndex() const
33     {
34         return tabIndex_;
35     }
36 
GetTabControllerId()37     uint32_t GetTabControllerId() const
38     {
39         return tabControllerId_;
40     }
41 
GetTabController()42     const RefPtr<TabController>& GetTabController() const
43     {
44         return tabController_;
45     }
46 
GetTabPageId()47     uint32_t GetTabPageId() const
48     {
49         return tabPageId_;
50     }
51 
GetTabEventId()52     const std::string& GetTabEventId() const
53     {
54         return tabEventId_;
55     }
56 
GetTabEventType()57     const std::string& GetTabEventType() const
58     {
59         return tabEventType_;
60     }
61 
IsVertical()62     bool IsVertical() const
63     {
64         return vertical_;
65     }
66 
GetSpecializedComponent()67     RefPtr<Component> GetSpecializedComponent() override
68     {
69         return flexChild_;
70     }
71 
OnPageLoadFinish()72     void OnPageLoadFinish() override
73     {
74         if (tabController_) {
75             tabController_->SetPageReady(true);
76         }
77     }
78 
79 protected:
OnMounted(const RefPtr<DOMNode> & parentNode)80     void OnMounted(const RefPtr<DOMNode>& parentNode) override {};
81     void OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot) override;
82     void OnChildNodeRemoved(const RefPtr<DOMNode>& child) override;
83     bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override;
84     bool AddSpecializedEvent(int32_t pageId, const std::string& event) override;
85 
86 private:
87     static uint32_t GetGlobalTabControllerId();
88     RefPtr<FlexComponent> CreateChild() const;
89 
90     RefPtr<FlexComponent> flexChild_;
91     RefPtr<TabController> tabController_;
92 
93     // Record the tabs component info for its children (tab_bars and tab_contents)
94     uint32_t tabIndex_ = 0;
95     uint32_t tabControllerId_ = 0;
96     uint32_t tabPageId_ = 0;
97     std::string tabEventId_;
98     std::string tabEventType_;
99 
100     // Record the tab is vertical or horizontal
101     bool vertical_ = false;
102 };
103 
104 } // namespace OHOS::Ace::Framework
105 
106 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_TABS_H
107