1 /*
2 * Copyright (c) 2021-2022 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_xcomponent.h"
17
18 #include "base/log/log.h"
19 #include "core/components/declaration/xcomponent/xcomponent_declaration.h"
20 #include "frameworks/bridge/common/dom/dom_type.h"
21
22 namespace OHOS::Ace::Framework {
DOMXComponent(NodeId nodeId,const std::string & nodeName)23 DOMXComponent::DOMXComponent(NodeId nodeId, const std::string& nodeName) : DOMNode(nodeId, nodeName)
24 {
25 xComponentChild_ = AceType::MakeRefPtr<XComponentComponent>(nodeName);
26 xComponentChild_->SetNodeId(nodeId);
27 }
28
PrepareSpecializedComponent()29 void DOMXComponent::PrepareSpecializedComponent()
30 {
31 auto xcomponentDeclaration = AceType::DynamicCast<XComponentDeclaration>(declaration_);
32 if (!xcomponentDeclaration) {
33 return;
34 }
35
36 auto& commonAttr = declaration_->MaybeResetAttribute<CommonAttribute>(AttributeTag::COMMON_ATTR);
37 if (commonAttr.IsValid()) {
38 xcomponentDeclaration->SetXComponentId(commonAttr.id);
39 }
40
41 xComponentChild_->SetDeclaration(xcomponentDeclaration);
42 }
43
GetSurfaceId() const44 std::string DOMXComponent::GetSurfaceId() const
45 {
46 if (!xComponentChild_) {
47 return 0;
48 }
49 const auto& controller = xComponentChild_->GetXComponentController();
50 if (!controller) {
51 return 0;
52 }
53 auto surfaceId = controller->GetSurfaceId();
54 return surfaceId;
55 }
56
SetSurfaceSize(uint32_t surfaceWidth,uint32_t surfaceHeight) const57 void DOMXComponent::SetSurfaceSize(uint32_t surfaceWidth, uint32_t surfaceHeight) const
58 {
59 if (!xComponentChild_) {
60 return;
61 }
62 const auto& controller = xComponentChild_->GetXComponentController();
63 if (!controller) {
64 return;
65 }
66 controller->ConfigSurface(surfaceWidth, surfaceHeight);
67 }
68 } // namespace OHOS::Ace::Framework
69