1 /*
2  * Copyright (c) 2021-2022 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_STACK_RENDER_STACK_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STACK_RENDER_STACK_H
18 
19 #include "core/components/common/layout/constants.h"
20 #include "core/components/common/properties/alignment.h"
21 #include "core/components/positioned/render_positioned.h"
22 #include "core/pipeline/base/render_node.h"
23 
24 namespace OHOS::Ace {
25 
26 class ACE_FORCE_EXPORT RenderStack : public RenderNode {
27     DECLARE_ACE_TYPE(RenderStack, RenderNode);
28 
29 public:
30     static RefPtr<RenderNode> Create();
31 
32     void Update(const RefPtr<Component>& component) override;
33 
34     void PerformLayout() override;
35 
GetOverflowFlag()36     Overflow GetOverflowFlag() const
37     {
38         return overflow_;
39     }
40 
IsChildOverflow()41     bool IsChildOverflow() const
42     {
43         return isChildOverflow_;
44     }
45 
SetStackFit(StackFit fit)46     void SetStackFit(StackFit fit)
47     {
48         fit_ = fit;
49     }
50 
SetMainStackSize(MainStackSize mainStackSize)51     void SetMainStackSize(MainStackSize mainStackSize)
52     {
53         mainStackSize_ = mainStackSize;
54     }
55 
GetAlignment()56     const Alignment& GetAlignment() const
57     {
58         return align_;
59     }
60 
GetStackFit()61     StackFit GetStackFit() const
62     {
63         return fit_;
64     }
65 
GetOverflow()66     Overflow GetOverflow() const
67     {
68         return overflow_;
69     }
70 
IsRightToLeft()71     bool IsRightToLeft() const
72     {
73         return (GetTextDirection() == TextDirection::RTL);
74     }
75 
76     void OnAttachContext() override;
77 
78 protected:
79     LayoutParam MakeNonPositionedInnerLayoutParam(const RefPtr<RenderNode>& firstChild) const;
80     LayoutParam MakePositionedInnerLayoutParam(
81         const RefPtr<RenderPositioned>& item, const RefPtr<RenderNode>& firstChild) const;
82 
83     Offset GetNonPositionedChildOffset(const Size& childSize);
84     Offset GetPositionedChildOffset(const RefPtr<RenderPositioned>& item);
85 
86     virtual void DetermineStackSize(bool hasNonPositioned);
SetChildrenStatus()87     virtual void SetChildrenStatus() {}
88 private:
89     Alignment align_;
90     StackFit fit_ = StackFit::KEEP;
91     Overflow overflow_ = Overflow::OBSERVABLE;
92     bool isChildOverflow_ = false;
93     MainStackSize mainStackSize_ = MainStackSize::NORMAL;
94 };
95 
96 } // namespace OHOS::Ace
97 
98 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_STACK_RENDER_STACK_H
99