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_BUTTON_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_BUTTON_H
18 
19 #include "core/components/button/button_component.h"
20 #include "core/components/button/button_theme.h"
21 #include "core/components/image/image_component.h"
22 #include "core/components/padding/padding_component.h"
23 #include "core/components/text/text_component.h"
24 #include "frameworks/bridge/common/dom/dom_node.h"
25 #include "frameworks/bridge/common/dom/dom_type.h"
26 #include "frameworks/core/components/declaration/button/button_declaration.h"
27 
28 namespace OHOS::Ace::Framework {
29 
30 class DOMButton final : public DOMNode {
31     DECLARE_ACE_TYPE(DOMButton, DOMNode);
32 
33 public:
34     DOMButton(NodeId nodeId, const std::string& nodeName);
35     ~DOMButton() override = default;
36 
GetSpecializedComponent()37     RefPtr<Component> GetSpecializedComponent() override
38     {
39         return buttonChild_;
40     }
41 
42     Dimension GetHeight() const override;
43     Dimension GetWidth() const override;
44 
45 protected:
46     void PrepareSpecializedComponent() override;
47     void ResetInitializedStyle() override;
48 
49 private:
50     void PrepareBoxSize();
51     void PreparePseudoStyle();
52     void PrepareUniversalButton();
53     void PrepareDefaultButton();
54     void PrepareIconButton();
55     void PrepareCapsuleButton();
56     void PrepareTextButton();
57     void PrepareCircleButton();
58     void PrepareDownloadButton();
59     void PrepareArcButton();
60     void PrepareButtonState();
61     void PrepareDisabledBackgroundColor();
62     void PrepareDisabledChildStyle();
63     void PrepareClickedColor();
64     void PrepareWaiting();
65     void PrepareWaitingWithText(const RefPtr<LoadingProgressComponent>& progressComponent);
66     void PrepareBorderStyle();
67     void PrepareBackDecorationStyle();
68     void PrepareChildren();
69     void PrepareChildrenLayout();
70     void AddPadding();
71     void ResetBoxHeight(double height, DimensionUnit unit = DimensionUnit::PX);
72     void UpdateCustomizedColorFlag();
73     bool IsPlatformFive() const;
74 
75     RefPtr<ButtonComponent> buttonChild_;
76     RefPtr<TextComponent> textChild_;
77     RefPtr<PaddingComponent> paddingChild_;
78     RefPtr<ImageComponent> imageChild_;
79     RefPtr<ButtonTheme> buttonTheme_;
80     RefPtr<Decoration> backDecoration_;
81     RefPtr<PaddingComponent> innerPaddingChild_;
82     RefPtr<ButtonDeclaration> buttonDeclaration_;
83 
84     std::string buttonType_;
85     std::string placement_;
86     BorderEdge edge_;
87     TextStyle textStyle_;
88     Color focusColor_;
89     Color disabledColor_;
90     Color textColor_;
91     Color edgeColor_;
92     Dimension diameter_;
93     double blendOpacity_ = 0.0;
94     bool focusColorChanged_ = false;
95     bool textColorChanged_ = false;
96     bool isWatch_ = false;
97     bool isTv_ = false;
98     bool isCustomizedColor_ = false;
99     bool disabledColorEffected_ = false;
100 };
101 
102 } // namespace OHOS::Ace::Framework
103 
104 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_BUTTON_H
105