• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         LOGE("GetSurfaceId failed, The xComponent is not created.");
48         return 0;
49     }
50     const auto& controller = xComponentChild_->GetXComponentController();
51     if (!controller) {
52         LOGE("GetSurfaceId failed, controller is null.");
53         return 0;
54     }
55     auto surfaceId = controller->GetSurfaceId();
56     return surfaceId;
57 }
58 
SetSurfaceSize(uint32_t surfaceWidth,uint32_t surfaceHeight) const59 void DOMXComponent::SetSurfaceSize(uint32_t surfaceWidth, uint32_t surfaceHeight) const
60 {
61     if (!xComponentChild_) {
62         LOGE("SetSurfaceSize failed, The xComponent is not created.");
63         return;
64     }
65     const auto& controller = xComponentChild_->GetXComponentController();
66     if (!controller) {
67         LOGE("SetSurfaceSize failed, controller is null.");
68         return;
69     }
70     controller->ConfigSurface(surfaceWidth, surfaceHeight);
71 }
72 } // namespace OHOS::Ace::Framework
73