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_DECLARATION_SVG_SVG_ANIMATE_DECLARATION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_ANIMATE_DECLARATION_H
18 
19 #include "core/components/common/properties/svg_paint_state.h"
20 #include "core/components/declaration/common/declaration.h"
21 #include "frameworks/bridge/common/dom/dom_type.h"
22 
23 namespace OHOS::Ace {
24 
25 struct SvgAnimateAttribute : Attribute {
26     std::string attributeName;
27     int32_t begin = 0;
28     int32_t dur = 0;
29     int32_t end = 0;
30     int32_t repeatCount = 1;
31     std::string fillMode;
32     std::string calcMode;
33     std::vector<std::string> values;
34     std::vector<double> keyTimes;
35     std::vector<std::string> keySplines;
36     std::string from;
37     std::string to;
38     std::vector<std::string> keyPoints;
39     std::string path;
40     std::string rotate;
41     std::string transformType;
42 };
43 
44 class SvgAnimateDeclaration : public Declaration {
45     DECLARE_ACE_TYPE(SvgAnimateDeclaration, Declaration);
46 
47 public:
48     SvgAnimateDeclaration() = default;
49     ~SvgAnimateDeclaration() override = default;
50 
51     bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override;
52 
SetAttributeName(const std::string & attributeName)53     void SetAttributeName(const std::string& attributeName)
54     {
55         auto& attribute = MaybeResetAttribute<SvgAnimateAttribute>(AttributeTag::SPECIALIZED_ATTR);
56         attribute.attributeName = attributeName;
57     }
58 
GetAttributeName()59     const std::string& GetAttributeName() const
60     {
61         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
62         return attribute.attributeName;
63     }
64 
SetBegin(int32_t begin)65     void SetBegin(int32_t begin)
66     {
67         auto& attribute = MaybeResetAttribute<SvgAnimateAttribute>(AttributeTag::SPECIALIZED_ATTR);
68         attribute.begin = begin;
69     }
70 
GetBegin()71     int32_t GetBegin() const
72     {
73         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
74         return attribute.begin;
75     }
76 
SetDur(int32_t dur)77     void SetDur(int32_t dur)
78     {
79         auto& attribute = MaybeResetAttribute<SvgAnimateAttribute>(AttributeTag::SPECIALIZED_ATTR);
80         attribute.dur = dur;
81     }
82 
GetDur()83     int32_t GetDur() const
84     {
85         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
86         return attribute.dur;
87     }
88 
SetEnd(int32_t end)89     void SetEnd(int32_t end)
90     {
91         auto& attribute = MaybeResetAttribute<SvgAnimateAttribute>(AttributeTag::SPECIALIZED_ATTR);
92         attribute.end = end;
93     }
94 
GetEnd()95     int32_t GetEnd() const
96     {
97         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
98         return attribute.end;
99     }
100 
SetRepeatCount(int32_t repeatCount)101     void SetRepeatCount(int32_t repeatCount)
102     {
103         auto& attribute = MaybeResetAttribute<SvgAnimateAttribute>(AttributeTag::SPECIALIZED_ATTR);
104         attribute.repeatCount = repeatCount;
105     }
106 
GetRepeatCount()107     int32_t GetRepeatCount() const
108     {
109         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
110         return attribute.repeatCount;
111     }
112 
SetFillMode(const std::string & fillMode)113     void SetFillMode(const std::string& fillMode)
114     {
115         auto& attribute = MaybeResetAttribute<SvgAnimateAttribute>(AttributeTag::SPECIALIZED_ATTR);
116         attribute.fillMode = fillMode;
117     }
118 
GetFillMode()119     const std::string& GetFillMode() const
120     {
121         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
122         return attribute.fillMode;
123     }
124 
SetCalcMode(const std::string & calcMode)125     void SetCalcMode(const std::string& calcMode)
126     {
127         auto& attribute = MaybeResetAttribute<SvgAnimateAttribute>(AttributeTag::SPECIALIZED_ATTR);
128         attribute.calcMode = calcMode;
129     }
130 
GetCalcMode()131     const std::string& GetCalcMode() const
132     {
133         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
134         return attribute.calcMode;
135     }
136 
GetValues()137     const std::vector<std::string>& GetValues() const
138     {
139         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
140         return attribute.values;
141     }
142 
GetKeyTimes()143     const std::vector<double>& GetKeyTimes() const
144     {
145         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
146         return attribute.keyTimes;
147     }
148 
GetKeySplines()149     const std::vector<std::string>& GetKeySplines() const
150     {
151         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
152         return attribute.keySplines;
153     }
154 
GetFrom()155     const std::string& GetFrom() const
156     {
157         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
158         return attribute.from;
159     }
160 
SetFrom(const std::string & from)161     void SetFrom(const std::string& from)
162     {
163         auto& attribute = MaybeResetAttribute<SvgAnimateAttribute>(AttributeTag::SPECIALIZED_ATTR);
164         attribute.from = from;
165     }
166 
GetTo()167     const std::string& GetTo() const
168     {
169         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
170         return attribute.to;
171     }
172 
SetTo(const std::string & to)173     void SetTo(const std::string& to)
174     {
175         auto& attribute = MaybeResetAttribute<SvgAnimateAttribute>(AttributeTag::SPECIALIZED_ATTR);
176         attribute.to = to;
177     }
178 
GetPath()179     const std::string& GetPath() const
180     {
181         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
182         return attribute.path;
183     }
184 
SetPath(const std::string & path)185     void SetPath(const std::string& path)
186     {
187         auto& attribute = MaybeResetAttribute<SvgAnimateAttribute>(AttributeTag::SPECIALIZED_ATTR);
188         attribute.path = path;
189     }
190 
GetRotate()191     const std::string& GetRotate() const
192     {
193         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
194         return attribute.rotate;
195     }
196 
SetRotate(const std::string & rotate)197     void SetRotate(const std::string& rotate)
198     {
199         auto& attribute = MaybeResetAttribute<SvgAnimateAttribute>(AttributeTag::SPECIALIZED_ATTR);
200         attribute.rotate = rotate;
201     }
202 
GetKeyPoints()203     const std::vector<std::string>& GetKeyPoints() const
204     {
205         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
206         return attribute.keyPoints;
207     }
208 
GetTransformType()209     const std::string& GetTransformType() const
210     {
211         auto& attribute = static_cast<SvgAnimateAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
212         return attribute.transformType;
213     }
214 
SetTransformType(const std::string & transformType)215     void SetTransformType(const std::string& transformType)
216     {
217         auto& attribute = MaybeResetAttribute<SvgAnimateAttribute>(AttributeTag::SPECIALIZED_ATTR);
218         attribute.transformType = transformType;
219     }
220 
221 protected:
222     void InitSpecialized() override;
223     bool SetAnimateAttr(const std::pair<std::string, std::string>& attr);
224 };
225 } // namespace OHOS::Ace
226 
227 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SVG_SVG_ANIMATE_DECLARATION_H
228