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_BASE_SOLE_CHILD_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_SOLE_CHILD_COMPONENT_H
18 
19 #include "core/pipeline/base/render_component.h"
20 #include "core/pipeline/base/single_child.h"
21 #include "core/pipeline/base/sole_child_element.h"
22 
23 namespace OHOS::Ace {
24 
25 class SoleChildComponent : public RenderComponent, public SingleChild {
26     DECLARE_ACE_TYPE(SoleChildComponent, RenderComponent, SingleChild);
27 
28 public:
29     SoleChildComponent() = default;
SoleChildComponent(const RefPtr<Component> & child)30     explicit SoleChildComponent(const RefPtr<Component>& child) : SingleChild(child) {}
31     ~SoleChildComponent() override = default;
32 
CreateElement()33     RefPtr<Element> CreateElement() override
34     {
35         return AceType::MakeRefPtr<SoleChildElement>();
36     }
37 
SetUpdateType(UpdateType updateType)38     void SetUpdateType(UpdateType updateType) override
39     {
40         RenderComponent::SetUpdateType(updateType);
41         auto child = GetChild();
42         if (child) {
43             child->SetUpdateType(updateType);
44         }
45     }
46 
SetDisabledStatus(bool disabledStatus)47     void SetDisabledStatus(bool disabledStatus) override
48     {
49         RenderComponent::SetDisabledStatus(disabledStatus);
50         auto child = GetChild();
51         if (child) {
52             child->SetDisabledStatus(disabledStatus);
53         }
54     }
55 
SetTextDirection(TextDirection direction)56     void SetTextDirection(TextDirection direction) override
57     {
58         RenderComponent::SetTextDirection(direction);
59         auto child = GetChild();
60         if (child) {
61             child->SetTextDirection(direction);
62         }
63     }
64 };
65 
66 } // namespace OHOS::Ace
67 
68 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_SOLE_CHILD_COMPONENT_H
69