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_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
44 #ifdef OHOS_STANDARD_SYSTEM
GetSurfaceId() const45 uint64_t DOMXComponent::GetSurfaceId() const
46 {
47 if (!xComponentChild_) {
48 LOGE("GetSurfaceId failed, The xComponent is not created.");
49 return 0;
50 }
51 const auto& controller = xComponentChild_->GetXComponentController();
52 if (!controller) {
53 LOGE("GetSurfaceId failed, controller is null.");
54 return 0;
55 }
56 auto surfaceId = controller->GetSurfaceId();
57 return surfaceId;
58 }
59 #endif
60 } // namespace OHOS::Ace::Framework
61