1 /* 2 * Copyright (c) 2025 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_CONTAINER_MODAL_CONTAINER_MODAL_TOOLBAR_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CONTAINER_MODAL_CONTAINER_MODAL_TOOLBAR_H 18 19 #include "base/memory/referenced.h" 20 #include "core/components/container_modal/container_modal_constants.h" 21 #include "core/components_ng/manager/toolbar/toolbar_manager.h" 22 #include "core/components_ng/property/property.h" 23 24 namespace OHOS::Ace::NG { 25 enum class ItemPlacementType { 26 NONE = -1, 27 SIDE_BAR_START = 0, 28 SIDE_BAR_END, 29 NAV_BAR_START, 30 NAV_BAR_END, 31 NAVDEST_START, 32 NAVDEST_END, 33 }; 34 class ContainerModalPattern; 35 36 class ACE_EXPORT ContainerModalToolBar : public AceType { 37 DECLARE_ACE_TYPE(ContainerModalToolBar, AceType); 38 39 public: ContainerModalToolBar(WeakPtr<NG::ContainerModalPattern> pattern,const RefPtr<FrameNode> title,bool isFloating)40 ContainerModalToolBar(WeakPtr<NG::ContainerModalPattern> pattern, const RefPtr<FrameNode> title, bool isFloating) 41 : pattern_(std::move(pattern)), title_(title), isFloating_(isFloating) {}; 42 ~ContainerModalToolBar() = default; 43 44 void InitToolBarManager(); 45 void SetOnChangeCallback(); 46 void SetToolbarBuilder(const RefPtr<FrameNode>& parent, std::function<RefPtr<UINode>()>& builder); 47 void OnToolBarLayoutChange(); 48 void AdjustNavDestRowWidth(); 49 void UpdateToolbarShow(bool isTitleShow, bool customTitleSettedShow); 50 void AdjustContainerModalTitleHeight(); 51 52 bool GetNavOrSideBarNodes(); 53 void ToInitNavOrSideBarNode(); 54 55 void UpdateSideTitleBgColor( 56 const Color& sideBarColor, const Color& sideBarContainerColor, const BlurStyle& blurStyle); 57 void UpdateTargetNodesBarMargin(bool reset = false); 58 void ExpandStackNodeLayout(bool reset = false); 59 void ResetExpandStackNode(); GetIsUpdateTargetNode()60 bool GetIsUpdateTargetNode() const 61 { 62 return isUpdateTargetNode_; 63 } 64 65 protected: 66 void UpdateTitleAfterRemove(); 67 void RemoveAllToolbarItem(); 68 void RemoveToolbarItem(const RefPtr<FrameNode>& frameNode); 69 void UpdateTitleLayout(); 70 71 private: 72 void ParsePlacementType(); 73 bool HandleToolbarItemList(const RefPtr<FrameNode>& parentNode, std::list<RefPtr<UINode>>& list); 74 ItemPlacementType GetItemTypeFromTag(const std::string& tag, uint32_t placement); 75 76 void AddToolbarItemToContainer(); 77 bool AddToolbarItemToRow(ItemPlacementType placeMent, const RefPtr<FrameNode>& node); 78 bool AddToolbarItemToSpecificRow(ItemPlacementType placeMent, const RefPtr<FrameNode>& frameNode); 79 bool AddToolbarItemToNavBarStart(const RefPtr<FrameNode>& frameNode); 80 bool AddToolbarItemToNavBarEnd(const RefPtr<FrameNode>& frameNode); 81 bool AddToolbarItemToNavDestStart(const RefPtr<FrameNode>& frameNode); 82 bool AddToolbarItemToNavDestEnd(const RefPtr<FrameNode>& frameNode); 83 84 void AddNavBarRow(); 85 void AddLeftNavRow(); 86 void AddRightNavRow(); 87 void AddNavDestBarRow(); 88 void AddLeftNavDestRow(); 89 void AddRightNavDestRow(); 90 void RemoveToolbarRowContainers(); 91 92 void AdjustTitleNodeWidth(); 93 void AdjustNavbarRowWidth(); 94 void SetCustomTitleRowBlurStyle(BlurStyle& blurStyle); 95 void UpdateSidebarMargin(); 96 void UpdateNavbarTitlebarMargin(); 97 void UpdateNavDestinationTitlebarMargin(); 98 HasNavOrSideBarNodes()99 bool HasNavOrSideBarNodes() 100 { 101 return hasNavOrSideBarNodes_; 102 } 103 SetHasNavOrSideBarNodes(bool hasNavOrSideBarNodes)104 void SetHasNavOrSideBarNodes(bool hasNavOrSideBarNodes) 105 { 106 hasNavOrSideBarNodes_ = hasNavOrSideBarNodes; 107 } 108 109 std::string GetTagFromNode(RefPtr<UINode> node); 110 bool IsTragetNavigationNodeParse(const RefPtr<FrameNode>& childFrameNode, float pageWidth, float sideBarHeight, 111 bool isNavigationFound, bool isSideBarFound); 112 bool IsTragetSideBarNodeParse( 113 const RefPtr<FrameNode>& childFrameNode, float pageWidth, float& sideBarHeight, bool isSideBarFound); 114 bool GetNavOrSideBarNodesParseChildren(const RefPtr<UINode>& page, float pageWidth); 115 RefPtr<ToolbarManager> toolbarManager_; 116 std::map<ItemPlacementType, std::list<RefPtr<FrameNode>>> itemWillAdd_; 117 std::map<RefPtr<FrameNode>, std::list<RefPtr<UINode>>> itemsWillOnTree_; 118 std::map<RefPtr<FrameNode>, std::list<RefPtr<UINode>>> itemsOnTree_; 119 WeakPtr<ContainerModalPattern> pattern_; 120 121 float toolbarItemMaxHeight_ = 0.0f; 122 123 RefPtr<FrameNode> navbarRow_ = nullptr; 124 RefPtr<FrameNode> leftNavRow_ = nullptr; 125 RefPtr<FrameNode> rightNavRow_ = nullptr; 126 RefPtr<FrameNode> navDestbarRow_ = nullptr; 127 RefPtr<FrameNode> leftNavDestRow_ = nullptr; 128 RefPtr<FrameNode> rightNavDestRow_ = nullptr; 129 const RefPtr<FrameNode> title_; 130 bool isFloating_; 131 WeakPtr<FrameNode> sideBarNode_; 132 WeakPtr<FrameNode> navigationNode_; 133 WeakPtr<FrameNode> navDestNode_; 134 bool hasNavOrSideBarNodes_ = false; 135 bool hasSetOnchangeCallback_ = false; 136 137 bool hasSetNavigationModeChangeCallback_ = false; 138 bool hasSetUpdateSideTitleBgColor_ = false; 139 bool isUpdateTargetNode_ = false; 140 bool isTitleShow_ = true; 141 bool customTitleShow_ = true; 142 }; 143 } // namespace OHOS::Ace::NG 144 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_CONTAINER_MODAL_CONTAINER_MODAL_TOOLBAR_H