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_SVG_SVG_GRADIENT_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SVG_SVG_GRADIENT_COMPONENT_H 18 19 #include "core/components/declaration/svg/svg_gradient_declaration.h" 20 #include "frameworks/core/pipeline/base/component_group.h" 21 22 namespace OHOS::Ace { 23 24 class SvgGradientComponent : public ComponentGroup { 25 DECLARE_ACE_TYPE(SvgGradientComponent, ComponentGroup); 26 27 public: SvgGradientComponent()28 SvgGradientComponent() 29 { 30 InitDeclaration(); 31 } 32 SvgGradientComponent(const std::list<RefPtr<Component>> & children)33 explicit SvgGradientComponent(const std::list<RefPtr<Component>>& children) : ComponentGroup(children) 34 { 35 InitDeclaration(); 36 } 37 38 ~SvgGradientComponent() override = default; CreateRenderNode()39 RefPtr<RenderNode> CreateRenderNode() override 40 { 41 return nullptr; 42 } 43 CreateElement()44 RefPtr<Element> CreateElement() override 45 { 46 return nullptr; 47 } 48 InitDeclaration()49 void InitDeclaration() 50 { 51 if (!declaration_) { 52 declaration_ = AceType::MakeRefPtr<SvgGradientDeclaration>(); 53 declaration_->Init(); 54 declaration_->InitializeStyle(); 55 } 56 } 57 SetDeclaration(const RefPtr<SvgGradientDeclaration> & declaration)58 void SetDeclaration(const RefPtr<SvgGradientDeclaration>& declaration) 59 { 60 if (declaration) { 61 declaration_ = declaration; 62 } 63 } 64 GetDeclaration()65 const RefPtr<SvgGradientDeclaration>& GetDeclaration() const 66 { 67 return declaration_; 68 } 69 GetGradient()70 const Gradient& GetGradient() const 71 { 72 return declaration_->GetGradient(); 73 } 74 AddGradientColor(const GradientColor & gradientColor)75 void AddGradientColor(const GradientColor& gradientColor) 76 { 77 declaration_->AddGradientColor(gradientColor); 78 } 79 80 private: 81 RefPtr<SvgGradientDeclaration> declaration_; 82 }; 83 84 } // namespace OHOS::Ace 85 86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SVG_SVG_GRADIENT_COMPONENT_H 87