• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "frameworks/bridge/common/dom/dom_svg_animate.h"
17 
18 #include "frameworks/bridge/common/utils/utils.h"
19 #include "frameworks/core/components/declaration/svg/svg_animate_declaration.h"
20 
21 namespace OHOS::Ace::Framework {
22 namespace {
23 
24 const char ANIMATION_FILL_MODE_FREEZE[] = "freeze";
25 const char ANIMATION_CALC_MODE_DISCRETE[] = "discrete";
26 const char ANIMATION_CALC_MODE_PACED[] = "paced";
27 const char ANIMATION_CALC_MODE_SPLINE[] = "spline";
28 
29 } // namespace
30 
DOMSvgAnimate(NodeId nodeId,const std::string & nodeName)31 DOMSvgAnimate::DOMSvgAnimate(NodeId nodeId, const std::string& nodeName) : DOMNode(nodeId, nodeName) {}
32 
PrepareSpecializedComponent()33 void DOMSvgAnimate::PrepareSpecializedComponent()
34 {
35     if (!animateComponent_) {
36         animateComponent_ = AceType::MakeRefPtr<SvgAnimateComponent>(std::to_string(GetNodeId()), GetTag());
37     }
38     SetAnimateAttrs();
39 }
40 
SetAnimateAttrs()41 void DOMSvgAnimate::SetAnimateAttrs()
42 {
43     auto declaration = AceType::DynamicCast<SvgAnimateDeclaration>(declaration_);
44     if (!declaration) {
45         return;
46     }
47     animateComponent_->SetBegin(declaration->GetBegin());
48     animateComponent_->SetDur(declaration->GetDur());
49     animateComponent_->SetEnd(declaration->GetEnd());
50     animateComponent_->SetRepeatCount(declaration->GetRepeatCount());
51     Fill fillMode = (declaration->GetFillMode() == ANIMATION_FILL_MODE_FREEZE ? Fill::FREEZE : Fill::REMOVE);
52     animateComponent_->SetFillMode(fillMode);
53     animateComponent_->SetCalcMode(ConvertCalcMode(declaration->GetCalcMode()));
54     animateComponent_->SetValues(declaration->GetValues());
55     animateComponent_->SetKeyTimes(declaration->GetKeyTimes());
56     animateComponent_->SetKeySplines(declaration->GetKeySplines());
57     animateComponent_->SetFrom(declaration->GetFrom());
58     animateComponent_->SetTo(declaration->GetTo());
59     animateComponent_->SetAttributeName(declaration->GetAttributeName());
60 
61     if (animateComponent_->GetSvgAnimateType() == SvgAnimateType::MOTION) {
62         animateComponent_->SetKeyPoints(declaration->GetKeyPoints());
63         animateComponent_->SetPath(declaration->GetPath());
64         animateComponent_->SetRotate(declaration->GetRotate());
65     }
66     if (animateComponent_->GetSvgAnimateType() == SvgAnimateType::TRANSFORM) {
67         animateComponent_->SetTransformType(declaration->GetTransformType());
68     }
69 }
70 
ConvertCalcMode(const std::string & val) const71 CalcMode DOMSvgAnimate::ConvertCalcMode(const std::string& val) const
72 {
73     CalcMode calcMode;
74     if (val == ANIMATION_CALC_MODE_DISCRETE) {
75         calcMode = CalcMode::DISCRETE;
76     } else if (val == ANIMATION_CALC_MODE_PACED) {
77         calcMode = CalcMode::PACED;
78     } else if (val == ANIMATION_CALC_MODE_SPLINE) {
79         calcMode = CalcMode::SPLINE;
80     } else {
81         calcMode = CalcMode::LINEAR;
82     }
83     return calcMode;
84 }
85 
86 } // namespace OHOS::Ace::Framework
87