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_CORE_COMPONENTS_POSITIONED_POSITIONED_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_POSITIONED_POSITIONED_COMPONENT_H
18 
19 #include "core/components/positioned/positioned_element.h"
20 #include "core/components/positioned/render_positioned.h"
21 #include "core/pipeline/base/sole_child_component.h"
22 
23 namespace OHOS::Ace {
24 
25 class PositionedComponent : public SoleChildComponent {
26     DECLARE_ACE_TYPE(PositionedComponent, SoleChildComponent);
27 
28 public:
29     PositionedComponent() = default;
PositionedComponent(const RefPtr<Component> & child)30     explicit PositionedComponent(const RefPtr<Component>& child) : SoleChildComponent(child) {}
31     ~PositionedComponent() override = default;
32 
CreateRenderNode()33     RefPtr<RenderNode> CreateRenderNode() override
34     {
35         return RenderPositioned::Create();
36     }
37 
CreateElement()38     RefPtr<Element> CreateElement() override
39     {
40         RefPtr<PositionedElement> positionedElement = AceType::MakeRefPtr<PositionedElement>();
41         positionedElement->SetIsAutoFocus(isAutoFocus_);
42         return positionedElement;
43     }
44 
GetBottom()45     const Dimension& GetBottom() const override
46     {
47         return bottom_;
48     }
49 
SetBottom(const Dimension & bottom)50     void SetBottom(const Dimension& bottom) override
51     {
52         bottom_ = bottom;
53         hasBottom_ = true;
54     }
55 
GetHeight()56     double GetHeight() const
57     {
58         return height_;
59     }
60 
SetHeight(double height)61     void SetHeight(double height)
62     {
63         height_ = height;
64     }
65 
GetLeft()66     const Dimension& GetLeft() const override
67     {
68         return left_;
69     }
70 
SetLeft(const Dimension & left)71     void SetLeft(const Dimension& left) override
72     {
73         left_ = left;
74         hasLeft_ = true;
75     }
76 
GetRight()77     const Dimension& GetRight() const override
78     {
79         return right_;
80     }
81 
SetRight(const Dimension & right)82     void SetRight(const Dimension& right) override
83     {
84         right_ = right;
85         hasRight_ = true;
86     }
87 
GetTop()88     const Dimension& GetTop() const override
89     {
90         return top_;
91     }
92 
SetTop(const Dimension & top)93     void SetTop(const Dimension& top) override
94     {
95         top_ = top;
96         hasTop_ = true;
97     }
98 
GetWidth()99     double GetWidth() const
100     {
101         return width_;
102     }
103 
SetWidth(double width)104     void SetWidth(double width)
105     {
106         width_ = width;
107     }
108 
IsAutoFocus()109     bool IsAutoFocus() const
110     {
111         return isAutoFocus_;
112     }
113 
SetAutoFocus(bool isAutoFocus)114     void SetAutoFocus(bool isAutoFocus)
115     {
116         isAutoFocus_ = isAutoFocus;
117     }
118 
HasLeft()119     bool HasLeft() const override
120     {
121         return hasLeft_;
122     }
123 
SetHasLeft(bool hasLeft)124     void SetHasLeft(bool hasLeft)
125     {
126         hasLeft_ = hasLeft;
127     }
128 
HasTop()129     bool HasTop() const override
130     {
131         return hasTop_;
132     }
133 
SetHasTop(bool hasTop)134     void SetHasTop(bool hasTop)
135     {
136         hasTop_ = hasTop;
137     }
138 
HasRight()139     bool HasRight() const override
140     {
141         return hasRight_;
142     }
143 
SetHasRight(bool hasRight)144     void SetHasRight(bool hasRight)
145     {
146         hasRight_ = hasRight;
147     }
148 
HasBottom()149     bool HasBottom() const override
150     {
151         return hasBottom_;
152     }
153 
SetHasBottom(bool hasBottom)154     void SetHasBottom(bool hasBottom)
155     {
156         hasBottom_ = hasBottom;
157     }
158 
HasPositionStyle()159     bool HasPositionStyle() const
160     {
161         return hasPositionStyle_;
162     }
163 
SetHasPositionStyle(bool hasPositionStyle)164     void SetHasPositionStyle(bool hasPositionStyle)
165     {
166         hasPositionStyle_ = hasPositionStyle;
167     }
168 
GetUpdatePositionFuncId()169     const UpdatePositionFunc& GetUpdatePositionFuncId() const
170     {
171         return updatePositionFunc_;
172     }
173 
SetUpdatePositionFuncId(const UpdatePositionFunc & updatePositionFunc)174     void SetUpdatePositionFuncId(const UpdatePositionFunc& updatePositionFunc)
175     {
176         updatePositionFunc_ = updatePositionFunc;
177     }
178 
179 private:
180     Dimension bottom_;
181     Dimension left_;
182     Dimension right_;
183     Dimension top_;
184     double height_ = 0.0;
185     double width_ = 0.0;
186 
187     bool hasLeft_ = false;
188     bool hasTop_ = false;
189     bool hasRight_ = false;
190     bool hasBottom_ = false;
191     bool hasPositionStyle_ = false;
192 
193     bool isAutoFocus_ = false;
194 
195     UpdatePositionFunc updatePositionFunc_;
196 };
197 
198 } // namespace OHOS::Ace
199 
200 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_POSITIONED_POSITIONED_COMPONENT_H
201