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_BASE_COMPOSED_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_COMPOSED_COMPONENT_H 18 19 #include <string> 20 21 #include "core/pipeline/base/base_composed_component.h" 22 #include "core/pipeline/base/component.h" 23 #include "core/pipeline/base/single_child.h" 24 25 namespace OHOS::Ace { 26 27 using ComposeId = std::string; 28 29 // A component can compose others components. 30 class ACE_FORCE_EXPORT ComposedComponent : public BaseComposedComponent, public SingleChild { 31 DECLARE_ACE_TYPE(ComposedComponent, BaseComposedComponent, SingleChild); 32 33 public: 34 ComposedComponent(const ComposeId& id, const std::string& name, const RefPtr<Component>& child); ComposedComponent(const ComposeId & id,const std::string & name)35 ComposedComponent(const ComposeId& id, const std::string& name) : BaseComposedComponent(id, name) {} 36 ~ComposedComponent() override = default; 37 38 RefPtr<Element> CreateElement() override; 39 SetUpdateType(UpdateType updateType)40 void SetUpdateType(UpdateType updateType) override 41 { 42 BaseComposedComponent::SetUpdateType(updateType); 43 auto child = GetChild(); 44 if (child) { 45 child->SetUpdateType(updateType); 46 } 47 } 48 SetDisabledStatus(bool disabledStatus)49 void SetDisabledStatus(bool disabledStatus) override 50 { 51 BaseComposedComponent::SetDisabledStatus(disabledStatus); 52 auto child = GetChild(); 53 if (child) { 54 child->SetDisabledStatus(disabledStatus); 55 } 56 } 57 SetTextDirection(TextDirection direction)58 void SetTextDirection(TextDirection direction) override 59 { 60 BaseComposedComponent::SetTextDirection(direction); 61 auto child = GetChild(); 62 if (child) { 63 child->SetTextDirection(direction); 64 } 65 } 66 HasElementFunction()67 bool HasElementFunction() override 68 { 69 if (elementFunction_) { 70 return true; 71 } 72 return false; 73 } 74 75 void SetElementFunction(ElementFunction&& func) override; 76 void CallElementFunction(const RefPtr<Element>& element) override; IsInspector()77 virtual bool IsInspector() 78 { 79 return false; 80 } 81 GetNeedReserveChild()82 bool GetNeedReserveChild() { 83 return needReserveChild_; 84 } 85 SetNeedReserveChild(bool needReserve)86 void SetNeedReserveChild(bool needReserve) { 87 needReserveChild_ = needReserve; 88 } 89 90 private: 91 ElementFunction elementFunction_; 92 93 bool needReserveChild_ = false; 94 }; 95 96 } // namespace OHOS::Ace 97 98 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_COMPOSED_COMPONENT_H 99