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 LOGE("child is null");
44 return;
45 }
46 if (AceType::InstanceOf<SvgAnimateComponent>(child->GetSpecializedComponent())) {
47 gComponent_->InsertChild(slot, child->GetSpecializedComponent());
48 } else {
49 gComponent_->InsertChild(slot, child->GetRootComponent());
50 }
51 }
52
OnMounted(const RefPtr<DOMNode> & parentNode)53 void DOMSvgG::OnMounted(const RefPtr<DOMNode>& parentNode)
54 {
55 auto declaration = AceType::DynamicCast<SvgDeclaration>(declaration_);
56 if (!declaration) {
57 LOGE("declaration is null");
58 return;
59 }
60 declaration->Inherit(parentNode->GetDeclaration());
61 auto box = GetBoxComponent();
62 if (box) {
63 box->SetOverflow(Overflow::FORCE_CLIP);
64 }
65 }
66
PrepareSpecializedComponent()67 void DOMSvgG::PrepareSpecializedComponent()
68 {
69 if (!gComponent_) {
70 gComponent_ = AceType::MakeRefPtr<SvgGComponent>();
71 }
72 auto declaration = AceType::DynamicCast<SvgDeclaration>(declaration_);
73 if (declaration) {
74 gComponent_->SetDeclaration(declaration);
75 }
76 }
77
78 } // namespace OHOS::Ace::Framework
79