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