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_ITEM_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_TOOL_BAR_ITEM_H
18 
19 #include "core/components/button/button_component.h"
20 #include "core/components/flex/flex_component.h"
21 #include "core/components/image/image_component.h"
22 #include "core/components/option/option_component.h"
23 #include "core/components/text/text_component.h"
24 #include "core/components/theme/theme_manager.h"
25 #include "core/components/tool_bar/tool_bar_item_component.h"
26 #include "core/components/tool_bar/tool_bar_theme.h"
27 #include "frameworks/bridge/common/dom/dom_node.h"
28 
29 namespace OHOS::Ace::Framework {
30 
31 class DOMToolBarItem final : public DOMNode {
32     DECLARE_ACE_TYPE(DOMToolBarItem, DOMNode);
33 
34 public:
35     DOMToolBarItem(NodeId nodeId, const std::string& nodeName);
36     ~DOMToolBarItem() override = default;
37 
GetSpecializedComponent()38     RefPtr<Component> GetSpecializedComponent() override
39     {
40         if (icon_.empty() && value_.empty()) {
41             return nullptr;
42         }
43         return toolBarItemChild_;
44     }
45 
SetIsEndItem(bool isEndItem)46     void SetIsEndItem(bool isEndItem)
47     {
48         isEndItem_ = isEndItem;
49         PrepareSpecializedComponent();
50     }
51 
SetPosition(PositionType positionType)52     void SetPosition(PositionType positionType)
53     {
54         toolBarItemChild_->SetPositionType(positionType);
55     }
56 
57     RefPtr<OptionComponent> BuildOptionComponent();
58     void InitializeStyle() override;
59 
60 protected:
61     bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override;
62     bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override;
63     bool AddSpecializedEvent(int32_t pageId, const std::string& event) override;
64     void PrepareSpecializedComponent() override;
65     void ResetInitializedStyle() override;
66 
67 private:
68     void InitImageStyle();
69     void InitTextStyle();
70     void InitializedToolBarItemChild();
71     void BuildEndItemComponent(std::list<RefPtr<Component>>& children);
72     void BuildCommonComponent(std::list<RefPtr<Component>>& children);
73     const RefPtr<Component> SetPadding(const RefPtr<Component>& component, Edge&& edge);
74 
75     RefPtr<ToolBarItemComponent> toolBarItemChild_;
76     RefPtr<TextComponent> textChild_;
77     RefPtr<ImageComponent> imageChild_;
78     TextStyle textStyle_;
79     RefPtr<ToolBarTheme> theme_;
80 
81     EventMarker clickEventId_;
82     bool isEndItem_ = false;
83     std::string value_;
84     std::string icon_;
85 };
86 
87 } // namespace OHOS::Ace::Framework
88 
89 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_TOOL_BAR_ITEM_H
90