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_mask.h"
17
18 #include "frameworks/bridge/common/utils/utils.h"
19
20 namespace OHOS::Ace::Framework {
21
DOMSvgMask(NodeId nodeId,const std::string & nodeName)22 DOMSvgMask::DOMSvgMask(NodeId nodeId, const std::string& nodeName) : DOMSvgBase(nodeId, nodeName) {}
23
GetSpecializedComponent()24 RefPtr<Component> DOMSvgMask::GetSpecializedComponent()
25 {
26 return maskComponent_;
27 }
28
OnChildNodeAdded(const RefPtr<DOMNode> & child,int32_t slot)29 void DOMSvgMask::OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot)
30 {
31 if (maskComponent_) {
32 maskComponent_->InsertChild(slot, child->GetSpecializedComponent());
33 }
34 }
35
OnMounted(const RefPtr<DOMNode> & parentNode)36 void DOMSvgMask::OnMounted(const RefPtr<DOMNode>& parentNode)
37 {
38 auto declaration = AceType::DynamicCast<SvgMaskDeclaration>(declaration_);
39 if (!declaration) {
40 return;
41 }
42 // inherit presentation attributes
43 auto svgNode = AceType::DynamicCast<DOMSvgBase>(parentNode);
44 if (svgNode) {
45 declaration->Inherit(svgNode->GetDeclaration());
46 }
47 }
48
PrepareSpecializedComponent()49 void DOMSvgMask::PrepareSpecializedComponent()
50 {
51 if (!maskComponent_) {
52 maskComponent_ = AceType::MakeRefPtr<SvgMaskComponent>();
53 }
54 auto declaration = AceType::DynamicCast<SvgMaskDeclaration>(declaration_);
55 if (declaration) {
56 maskComponent_->SetDeclaration(declaration);
57 }
58 }
59
60 } // namespace OHOS::Ace::Framework
61