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_g.h"
17 #include "frameworks/bridge/common/dom/dom_svg_animate.h"
18 
19 namespace OHOS::Ace::Framework {
20 
DOMSvgG(NodeId nodeId,const std::string & nodeName)21 DOMSvgG::DOMSvgG(NodeId nodeId, const std::string& nodeName) : DOMSvgBase(nodeId, nodeName)
22 {
23     transformComponent_ = AceType::MakeRefPtr<TransformComponent>();
24     if (declaration_) {
25         declaration_->SetHasDisplayStyle(true);
26         auto& overflowStyle = declaration_->MaybeResetStyle<CommonOverflowStyle>(StyleTag::COMMON_OVERFLOW_STYLE);
27         if (overflowStyle.IsValid()) {
28             overflowStyle.overflow = Overflow::CLIP;
29         }
30     }
31 }
32 
GetSpecializedComponent()33 RefPtr<Component> DOMSvgG::GetSpecializedComponent()
34 {
35     return gComponent_;
36 }
37 
OnChildNodeAdded(const RefPtr<DOMNode> & child,int32_t slot)38 void DOMSvgG::OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot)
39 {
40     if (!child) {
41         return;
42     }
43     if (AceType::InstanceOf<SvgAnimateComponent>(child->GetSpecializedComponent())) {
44         gComponent_->InsertChild(slot, child->GetSpecializedComponent());
45     } else {
46         gComponent_->InsertChild(slot, child->GetRootComponent());
47     }
48 }
49 
OnMounted(const RefPtr<DOMNode> & parentNode)50 void DOMSvgG::OnMounted(const RefPtr<DOMNode>& parentNode)
51 {
52     auto declaration = AceType::DynamicCast<SvgDeclaration>(declaration_);
53     if (!declaration) {
54         return;
55     }
56     declaration->Inherit(parentNode->GetDeclaration());
57     auto box = GetBoxComponent();
58     if (box) {
59         box->SetOverflow(Overflow::FORCE_CLIP);
60     }
61 }
62 
PrepareSpecializedComponent()63 void DOMSvgG::PrepareSpecializedComponent()
64 {
65     if (!gComponent_) {
66         gComponent_ = AceType::MakeRefPtr<SvgGComponent>();
67     }
68     auto declaration = AceType::DynamicCast<SvgDeclaration>(declaration_);
69     if (declaration) {
70         gComponent_->SetDeclaration(declaration);
71     }
72 }
73 
74 } // namespace OHOS::Ace::Framework
75