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_NAV_BAR_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAV_BAR_NODE_H 18 19 #include <cstdint> 20 #include <list> 21 22 #include "core/components_ng/base/frame_node.h" 23 #include "core/components_ng/base/group_node.h" 24 #include "core/components_ng/pattern/navigation/bar_item_node.h" 25 #include "core/components_ng/pattern/navigation/navigation_declaration.h" 26 #include "core/components_ng/property/property.h" 27 28 namespace OHOS::Ace::NG { 29 30 class ACE_EXPORT NavBarNode : public GroupNode { DECLARE_ACE_TYPE(NavBarNode,GroupNode)31 DECLARE_ACE_TYPE(NavBarNode, GroupNode) 32 public: 33 NavBarNode(const std::string& tag, int32_t nodeId, const RefPtr<Pattern>& pattern) : GroupNode(tag, nodeId, pattern) 34 {} 35 ~NavBarNode() override = default; 36 void AddChildToGroup(const RefPtr<UINode>& child, int32_t slot = DEFAULT_NODE_SLOT) override; 37 static RefPtr<NavBarNode> GetOrCreateNavBarNode( 38 const std::string& tag, int32_t nodeId, const std::function<RefPtr<Pattern>(void)>& patternCreator); 39 IsAtomicNode()40 bool IsAtomicNode() const override 41 { 42 return false; 43 } SetBackButton(const RefPtr<UINode> & button)44 void SetBackButton(const RefPtr<UINode>& button) 45 { 46 backButton_ = button; 47 } 48 GetBackButton()49 const RefPtr<UINode>& GetBackButton() const 50 { 51 return backButton_; 52 } 53 SetTitle(const RefPtr<UINode> & title)54 void SetTitle(const RefPtr<UINode>& title) 55 { 56 title_ = title; 57 } 58 GetTitle()59 const RefPtr<UINode>& GetTitle() const 60 { 61 return title_; 62 } 63 SetSubtitle(const RefPtr<UINode> & subtitle)64 void SetSubtitle(const RefPtr<UINode>& subtitle) 65 { 66 subtitle_ = subtitle; 67 } 68 GetSubtitle()69 const RefPtr<UINode>& GetSubtitle() const 70 { 71 return subtitle_; 72 } 73 SetMenu(const RefPtr<UINode> & menu)74 void SetMenu(const RefPtr<UINode>& menu) 75 { 76 menu_ = menu; 77 } 78 GetMenu()79 const RefPtr<UINode>& GetMenu() const 80 { 81 return menu_; 82 } 83 SetMenuNode(const RefPtr<UINode> & menuNode)84 void SetMenuNode(const RefPtr<UINode>& menuNode) 85 { 86 moreMenuNode_ = menuNode; 87 } 88 SetTitleBarNode(const RefPtr<UINode> & title)89 void SetTitleBarNode(const RefPtr<UINode>& title) 90 { 91 titleBarNode_ = title; 92 } 93 GetTitleBarNode()94 const RefPtr<UINode>& GetTitleBarNode() const 95 { 96 return titleBarNode_; 97 } 98 SetNavBarContentNode(const RefPtr<UINode> & navBarContentNode)99 void SetNavBarContentNode(const RefPtr<UINode>& navBarContentNode) 100 { 101 navBarContentNode_ = navBarContentNode; 102 } 103 GetNavBarContentNode()104 const RefPtr<UINode>& GetNavBarContentNode() const 105 { 106 return navBarContentNode_; 107 } 108 SetToolBarNode(const RefPtr<UINode> & toolBarNode)109 void SetToolBarNode(const RefPtr<UINode>& toolBarNode) 110 { 111 toolBarNode_ = toolBarNode; 112 } 113 GetToolBarNode()114 const RefPtr<UINode>& GetToolBarNode() const 115 { 116 return toolBarNode_; 117 } 118 SetPreToolBarNode(const RefPtr<UINode> & preToolBarNode)119 void SetPreToolBarNode(const RefPtr<UINode>& preToolBarNode) 120 { 121 preToolBarNode_ = preToolBarNode; 122 } 123 GetPreToolBarNode()124 const RefPtr<UINode>& GetPreToolBarNode() const 125 { 126 return preToolBarNode_; 127 } 128 129 std::string GetTitleString() const; 130 std::string GetSubtitleString() const; 131 std::string GetBarItemsString(bool isMenu) const; 132 void ToJsonValue(std::unique_ptr<JsonValue>& json) const override; 133 134 // custom node checking 135 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(PrevTitleIsCustom, bool); OnPrevTitleIsCustomUpdate(bool value)136 void OnPrevTitleIsCustomUpdate(bool value) {} 137 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(PrevMenuIsCustom, bool); OnPrevMenuIsCustomUpdate(bool value)138 void OnPrevMenuIsCustomUpdate(bool value) {} 139 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(PrevToolBarIsCustom, bool); OnPrevToolBarIsCustomUpdate(bool value)140 void OnPrevToolBarIsCustomUpdate(bool value) {} 141 142 // node operation related 143 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(BackButtonNodeOperation, ChildNodeOperation); OnBackButtonNodeOperationUpdate(ChildNodeOperation value)144 void OnBackButtonNodeOperationUpdate(ChildNodeOperation value) {} 145 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(TitleNodeOperation, ChildNodeOperation); OnTitleNodeOperationUpdate(ChildNodeOperation value)146 void OnTitleNodeOperationUpdate(ChildNodeOperation value) {} 147 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(SubtitleNodeOperation, ChildNodeOperation); OnSubtitleNodeOperationUpdate(ChildNodeOperation value)148 void OnSubtitleNodeOperationUpdate(ChildNodeOperation value) {} 149 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(MenuNodeOperation, ChildNodeOperation); OnMenuNodeOperationUpdate(ChildNodeOperation value)150 void OnMenuNodeOperationUpdate(ChildNodeOperation value) {} 151 ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(ToolBarNodeOperation, ChildNodeOperation); OnToolBarNodeOperationUpdate(ChildNodeOperation value)152 void OnToolBarNodeOperationUpdate(ChildNodeOperation value) {} 153 154 private: 155 RefPtr<UINode> backButton_; 156 RefPtr<UINode> title_; 157 RefPtr<UINode> subtitle_; 158 RefPtr<UINode> menu_; 159 RefPtr<UINode> moreMenuNode_; 160 RefPtr<UINode> titleBarNode_; 161 RefPtr<UINode> navBarContentNode_; 162 RefPtr<UINode> toolBarNode_; 163 RefPtr<UINode> preToolBarNode_; 164 }; 165 166 } // namespace OHOS::Ace::NG 167 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAV_BAR_NODE_H