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_use.h"
17 
18 namespace OHOS::Ace::Framework {
19 
DOMSvgUse(NodeId nodeId,const std::string & nodeName)20 DOMSvgUse::DOMSvgUse(NodeId nodeId, const std::string& nodeName) : DOMSvgBase(nodeId, nodeName) {}
21 
22 
GetSpecializedComponent()23 RefPtr<Component> DOMSvgUse::GetSpecializedComponent()
24 {
25     return useComponent_;
26 }
27 
OnChildNodeAdded(const RefPtr<DOMNode> & child,int32_t slot)28 void DOMSvgUse::OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot)
29 {
30     useComponent_->InsertChild(slot, child->GetSpecializedComponent());
31 }
32 
OnMounted(const RefPtr<DOMNode> & parentNode)33 void DOMSvgUse::OnMounted(const RefPtr<DOMNode>& parentNode)
34 {
35     DOMSvgBase::InheritAttrs(parentNode);
36 }
37 
PrepareSpecializedComponent()38 void DOMSvgUse::PrepareSpecializedComponent()
39 {
40     if (!useComponent_) {
41         useComponent_ = AceType::MakeRefPtr<SvgUseComponent>();
42     }
43     auto declaration = AceType::DynamicCast<SvgDeclaration>(declaration_);
44     if (declaration) {
45         useComponent_->SetDeclaration(declaration);
46     }
47 }
48 
49 } // namespace OHOS::Ace::Framework
50