1 /*
2 * Copyright (c) 2024 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 "compatible/components/badge/badge_loader.h"
17
18 #include "base/memory/ace_type.h"
19 #include "base/utils/utils.h"
20 #include "bridge/common/dom/dom_configs.h"
21 #include "compatible/components/badge/badge_composed_element.h"
22 #include "compatible/components/badge/badge_declaration.h"
23 #include "compatible/components/badge/badge_model_impl.h"
24 #include "compatible/components/badge/dom_badge.h"
25
26 namespace OHOS::Ace {
27
CreateDomNode(int32_t nodeId,const std::string & nodeName)28 RefPtr<Framework::DOMNode> BadgeLoader::CreateDomNode(int32_t nodeId, const std::string& nodeName)
29 {
30 return AceType::MakeRefPtr<Framework::DOMBadge>(nodeId, nodeName);
31 }
32
CreateModel()33 void* BadgeLoader::CreateModel()
34 {
35 return new Framework::BadgeModelImpl();
36 }
37
CreateInspectorElement(const std::string & id)38 RefPtr<V2::InspectorComposedElement> BadgeLoader::CreateInspectorElement(const std::string& id)
39 {
40 return AceType::MakeRefPtr<V2::BadgeComposedElement>(id);
41 }
42
CreateDeclaration()43 RefPtr<Declaration> BadgeLoader::CreateDeclaration()
44 {
45 return AceType::MakeRefPtr<BadgeDeclaration>();
46 }
47
UpdateDomConfig(const RefPtr<Framework::DOMNode> & node,void * config)48 void BadgeLoader::UpdateDomConfig(const RefPtr<Framework::DOMNode>& node, void* config)
49 {
50 CHECK_NULL_VOID(config);
51 auto domBadge = AceType::DynamicCast<Framework::DOMBadge>(node);
52 if (domBadge) {
53 domBadge->SetBadgeConfig(*reinterpret_cast<Framework::BadgeConfig*>(config));
54 }
55 }
56
57 } // namespace OHOS::Ace