• 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_NAVIGATION_TITLE_BAR_NODE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_TITLE_BAR_NODE_H
18 
19 #include "core/components_ng/base/frame_node.h"
20 #include "core/components_ng/pattern/navigation/navigation_declaration.h"
21 #include "core/components_ng/property/property.h"
22 
23 namespace OHOS::Ace::NG {
24 
25 class ACE_EXPORT TitleBarNode : public FrameNode {
26     DECLARE_ACE_TYPE(TitleBarNode, FrameNode);
27 public:
28     TitleBarNode(const std::string& tag, int32_t nodeId);
TitleBarNode(const std::string & tag,int32_t nodeId,const RefPtr<Pattern> & pattern)29     TitleBarNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern)
30         : FrameNode(tag, nodeId, pattern) {}
31     ~TitleBarNode() override;
32     static RefPtr<TitleBarNode> GetOrCreateTitleBarNode(
33         const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator);
34 
IsAtomicNode()35     bool IsAtomicNode() const override
36     {
37         return false;
38     }
39 
SetBackButton(const RefPtr<UINode> & button)40     void SetBackButton(const RefPtr<UINode>& button)
41     {
42         backButton_ = button;
43     }
44 
GetBackButton()45     const RefPtr<UINode>& GetBackButton() const
46     {
47         return backButton_;
48     }
49 
SetCustomBackButton(const RefPtr<UINode> & button)50     void SetCustomBackButton(const RefPtr<UINode>& button)
51     {
52         customBackButton_ = button;
53     }
54 
GetCustomBackButton()55     const RefPtr<UINode>& GetCustomBackButton() const
56     {
57         return customBackButton_;
58     }
59 
SetTitle(const RefPtr<UINode> & title)60     void SetTitle(const RefPtr<UINode>& title)
61     {
62         title_ = title;
63     }
64 
GetTitle()65     const RefPtr<UINode>& GetTitle() const
66     {
67         return title_;
68     }
69 
SetSubtitle(const RefPtr<UINode> & subtitle)70     void SetSubtitle(const RefPtr<UINode>& subtitle)
71     {
72         subtitle_ = subtitle;
73     }
74 
GetSubtitle()75     const RefPtr<UINode>& GetSubtitle() const
76     {
77         return subtitle_;
78     }
79 
SetMenu(const RefPtr<UINode> & menu)80     void SetMenu(const RefPtr<UINode>& menu)
81     {
82         menu_ = menu;
83     }
84 
GetMenu()85     const RefPtr<UINode>& GetMenu() const
86     {
87         return menu_;
88     }
89 
SetInnerParentId(const std::string & id)90     void SetInnerParentId(const std::string& id)
91     {
92         innerChildId_ = id;
93     }
94 
GetInnerParentId()95     std::string GetInnerParentId() const
96     {
97         return innerChildId_;
98     }
99 
100     // The function is only used for fast preview.
101     void FastPreviewUpdateChild(int32_t slot, const RefPtr<UINode>& newChild) override;
102 
103     void MarkIsInitialTitle(bool isInitialTitle);
104 
SetUseContainerModalTitleHeight(bool use)105     void SetUseContainerModalTitleHeight(bool use)
106     {
107         useContainerModalTitleHeight_ = use;
108     }
UseContainerModalTitleHeight()109     bool UseContainerModalTitleHeight() const
110     {
111         return useContainerModalTitleHeight_;
112     }
SetNeedAvoidContainerModal(bool need)113     void SetNeedAvoidContainerModal(bool need)
114     {
115         needAvoidContainerModal_ = need;
116     }
NeedAvoidContainerModal()117     bool NeedAvoidContainerModal() const
118     {
119         return needAvoidContainerModal_;
120     }
121     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
122 
123     void OnAttachToMainTree(bool recursive) override;
124     void OnDetachFromMainTree(bool recursive, PipelineContext* context) override;
125 
126 private:
127     RefPtr<UINode> backButton_;
128     RefPtr<UINode> customBackButton_;
129     RefPtr<UINode> title_;
130     RefPtr<UINode> subtitle_;
131     RefPtr<UINode> menu_;
132     std::string innerChildId_;
133     bool needAvoidContainerModal_ = false;
134     bool useContainerModalTitleHeight_ = false;
135     int32_t menuBarChangeListenerId_ = -1;
136 };
137 
138 } // namespace OHOS::Ace::NG
139 
140 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_TITLE_BAR_NODE_H
141