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_TOOL_BAR_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_TOOL_BAR_H 18 19 #include "core/components/option/option_component.h" 20 #include "core/components/tool_bar/tool_bar_component.h" 21 #include "core/components/tool_bar/tool_bar_item_component.h" 22 #include "frameworks/bridge/common/dom/dom_tool_bar_item.h" 23 24 namespace OHOS::Ace::Framework { 25 26 constexpr int32_t TOOL_BAR_DEFAULT_SIZE = 5; 27 constexpr int32_t TOOL_BAR_INVALID_INDEX = -1; 28 29 class DOMToolBar final : public DOMNode { 30 DECLARE_ACE_TYPE(DOMToolBar, DOMNode); 31 32 public: 33 DOMToolBar(NodeId nodeId, const std::string& nodeName); 34 ~DOMToolBar() override = default; 35 GetSpecializedComponent()36 RefPtr<Component> GetSpecializedComponent() override 37 { 38 return toolBarChild_; 39 } 40 GetMenuChildren()41 const std::list<RefPtr<Component>>& GetMenuChildren() const 42 { 43 return menuChildren_; 44 } 45 void InitializeStyle() override; 46 47 protected: 48 void OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot) override; 49 void OnChildNodeRemoved(const RefPtr<DOMNode>& child) override; 50 void PrepareSpecializedComponent() override; 51 52 private: 53 void AddChildNode(const RefPtr<DOMNode>& child, int32_t slot, bool isRebuild); 54 void Rebuild(); 55 56 RefPtr<ToolBarComponent> toolBarChild_; 57 std::list<RefPtr<Component>> menuChildren_; 58 RefPtr<DOMNode> preToolBarItem_; 59 }; 60 61 } // namespace OHOS::Ace::Framework 62 63 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_TOOL_BAR_H 64