• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_NG_PATTERNS_ROOT_ROOT_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_ROOT_ROOT_PATTERN_H
18 
19 #include "base/utils/noncopyable.h"
20 #include "core/components_ng/pattern/pattern.h"
21 
22 namespace OHOS::Ace::NG {
23 // RootPattern is the base class for root render node.
24 class ACE_EXPORT RootPattern : public Pattern {
25     DECLARE_ACE_TYPE(RootPattern, Pattern);
26 
27 public:
28     RootPattern() = default;
29     ~RootPattern() override = default;
30 
IsRootPattern()31     bool IsRootPattern() const override
32     {
33         return true;
34     }
35 
IsMeasureBoundary()36     bool IsMeasureBoundary() const override
37     {
38         return true;
39     }
40 
IsAtomicNode()41     bool IsAtomicNode() const override
42     {
43         return false;
44     }
45 
CreateLayoutAlgorithm()46     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
47     {
48         return MakeRefPtr<BoxLayoutAlgorithm>();
49     }
50 
OnAttachToFrameNode()51     void OnAttachToFrameNode() override
52     {
53         auto host = GetHost();
54         CHECK_NULL_VOID(host);
55         host->GetLayoutProperty()->UpdateAlignment(Alignment::TOP_LEFT);
56     }
57 
SetAppBgColor(const Color & color,bool isContainerModal)58     void SetAppBgColor(const Color& color, bool isContainerModal)
59     {
60         auto rootNode = GetHost();
61         CHECK_NULL_VOID(rootNode);
62         RefPtr<FrameNode> stage;
63         if (isContainerModal) {
64             auto container = DynamicCast<FrameNode>(rootNode->GetChildren().front());
65             CHECK_NULL_VOID(container);
66             auto column = DynamicCast<FrameNode>(container->GetChildren().front());
67             CHECK_NULL_VOID(column);
68             auto stack = DynamicCast<FrameNode>(column->GetChildren().back());
69             CHECK_NULL_VOID(stack);
70             stage = DynamicCast<FrameNode>(stack->GetChildren().front());
71         } else {
72             stage = DynamicCast<FrameNode>(rootNode->GetChildren().front());
73         }
74         CHECK_NULL_VOID(stage);
75         LOGI("SetAppBgColor in page node successfully, bgColor is %{public}u", color.GetValue());
76         stage->GetRenderContext()->UpdateBackgroundColor(color);
77     }
78 
GetFocusPattern()79     FocusPattern GetFocusPattern() const override
80     {
81         return { FocusType::SCOPE, true };
82     }
83 
84 private:
85     ACE_DISALLOW_COPY_AND_MOVE(RootPattern);
86 };
87 } // namespace OHOS::Ace::NG
88 
89 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_ROOT_ROOT_PATTERN_H
90