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 #include "core/components/root/root_component.h"
17 
18 #include "core/components/root/render_root.h"
19 #include "core/components/root/root_element.h"
20 
21 namespace OHOS::Ace {
22 
RootComponent(const RefPtr<Component> & child)23 RootComponent::RootComponent(const RefPtr<Component>& child) : child_(child) {}
24 
CreateRenderNode()25 RefPtr<RenderNode> RootComponent::CreateRenderNode()
26 {
27     return RenderRoot::Create();
28 }
29 
CreateElement()30 RefPtr<Element> RootComponent::CreateElement()
31 {
32     return AceType::MakeRefPtr<RootElement>();
33 }
34 
Create(const RefPtr<Component> & child)35 RefPtr<RootComponent> RootComponent::Create(const RefPtr<Component>& child)
36 {
37     return AceType::MakeRefPtr<RootComponent>(child);
38 }
39 
SetupElementTree(const RefPtr<PipelineContext> & context)40 RefPtr<RootElement> RootComponent::SetupElementTree(const RefPtr<PipelineContext>& context)
41 {
42     RefPtr<RootElement> rootElement = AceType::DynamicCast<RootElement>(CreateElement());
43     rootElement->SetPipelineContext(context);
44     rootElement->SetNewComponent(AceType::Claim(this));
45     rootElement->Mount(nullptr);
46     return rootElement;
47 }
48 
49 } // namespace OHOS::Ace
50