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_ROOT_RENDER_ROOT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ROOT_RENDER_ROOT_H
18 
19 #include "core/animation/animator.h"
20 #include "core/pipeline/base/render_node.h"
21 
22 namespace OHOS::Ace {
23 
24 class RenderRoot : public RenderNode {
25     DECLARE_ACE_TYPE(RenderRoot, RenderNode);
26 
27 public:
28     ~RenderRoot() override = default;
29 
30     static RefPtr<RenderNode> Create();
31 
32     void Update(const RefPtr<Component>& component) override;
33     void PerformLayout() override;
34 
35     // Set the design size directly proportional to the real physical pixels.
SetScale(float scale)36     void SetScale(float scale)
37     {
38         if (!NearEqual(scale_, scale)) {
39             scale_ = scale;
40             MarkNeedSyncGeometryProperties();
41         }
42     }
43 
GetScale()44     float GetScale() const
45     {
46         return scale_;
47     }
48 
49     virtual void DumpLayerTree();
50 
IsRepaintBoundary()51     bool IsRepaintBoundary() const override
52     {
53         return true;
54     }
55 
SetReset(bool reset)56     void SetReset(bool reset)
57     {
58         isReset_ = reset;
59     }
60 
61     void AnimateToShow(int32_t duration);
62 
63     void AnimateToHide(int32_t duration);
64 
65     void SetBgColor(const Color& color);
66 
67     Color GetBgColor() const;
68 
69     void SetDefaultBgColor(bool isTransparent = false);
70 
NotifyOnShow()71     void NotifyOnShow() const
72     {
73         for (const auto& child : GetChildren()) {
74             child->OnAppShow();
75         }
76     }
77 
NotifyOnHide()78     void NotifyOnHide() const
79     {
80         for (const auto& child : GetChildren()) {
81             child->OnAppHide();
82         }
83     }
84 
85 protected:
86     RenderRoot();
87 
88     float scale_ = 1.0f;
89     Color bgColor_ = Color::WHITE;
90     bool forceColor_ = false;
91     bool isBgColorInit_ = false;
92     bool isReset_ = false;
93     RefPtr<Animator> controller_;
94     bool isContextMenu_ = false;
95 };
96 
97 } // namespace OHOS::Ace
98 
99 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ROOT_RENDER_ROOT_H
100