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 namespace OHOS::Ace::Framework {
DOMXComponent(NodeId nodeId,const std::string & nodeName)19 DOMXComponent::DOMXComponent(NodeId nodeId, const std::string& nodeName) : DOMNode(nodeId, nodeName)
20 {
21     xComponentChild_ = AceType::MakeRefPtr<XComponentComponent>(nodeName);
22     xComponentChild_->SetNodeId(nodeId);
23 }
24 
PrepareSpecializedComponent()25 void DOMXComponent::PrepareSpecializedComponent()
26 {
27     auto xcomponentDeclaration = AceType::DynamicCast<XComponentDeclaration>(declaration_);
28     if (!xcomponentDeclaration) {
29         return;
30     }
31 
32     auto& commonAttr = declaration_->MaybeResetAttribute<CommonAttribute>(AttributeTag::COMMON_ATTR);
33     if (commonAttr.IsValid()) {
34         xcomponentDeclaration->SetXComponentId(commonAttr.id);
35     }
36 
37     xComponentChild_->SetDeclaration(xcomponentDeclaration);
38 }
39 
GetSurfaceId() const40 std::string DOMXComponent::GetSurfaceId() const
41 {
42     if (!xComponentChild_) {
43         return 0;
44     }
45     const auto& controller = xComponentChild_->GetXComponentController();
46     if (!controller) {
47         return 0;
48     }
49     auto surfaceId = controller->GetSurfaceId();
50     return surfaceId;
51 }
52 
SetSurfaceSize(uint32_t surfaceWidth,uint32_t surfaceHeight) const53 void DOMXComponent::SetSurfaceSize(uint32_t surfaceWidth, uint32_t surfaceHeight) const
54 {
55     if (!xComponentChild_) {
56         return;
57     }
58     const auto& controller = xComponentChild_->GetXComponentController();
59     if (!controller) {
60         return;
61     }
62     controller->ConfigSurface(surfaceWidth, surfaceHeight);
63 }
64 } // namespace OHOS::Ace::Framework
65