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 "core/components_ng/syntax/with_theme_node.h" 17 18 #include "core/components_ng/token_theme/token_theme_storage.h" 19 #include "core/pipeline/base/element_register.h" 20 21 namespace OHOS::Ace::NG { 22 ~WithThemeNode()23WithThemeNode::~WithThemeNode() 24 { 25 if (themeScopeDestroyCallback_) { 26 themeScopeDestroyCallback_(); 27 } 28 TokenThemeStorage::GetInstance()->RemoveThemeScope(GetId()); 29 } 30 GetWithThemeNode(int32_t nodeId)31RefPtr<WithThemeNode> WithThemeNode::GetWithThemeNode(int32_t nodeId) 32 { 33 return ElementRegister::GetInstance()->GetSpecificItemById<WithThemeNode>(nodeId); 34 } 35 CreateWithThemeNode(int32_t nodeId)36RefPtr<WithThemeNode> WithThemeNode::CreateWithThemeNode(int32_t nodeId) 37 { 38 auto node = MakeRefPtr<WithThemeNode>(nodeId); 39 ElementRegister::GetInstance()->AddUINode(node); 40 return node; 41 } 42 GetOrCreateWithThemeNode(int32_t nodeId)43RefPtr<WithThemeNode> WithThemeNode::GetOrCreateWithThemeNode(int32_t nodeId) 44 { 45 auto node = WithThemeNode::GetWithThemeNode(nodeId); 46 if (!node) { 47 node = WithThemeNode::CreateWithThemeNode(nodeId); 48 } 49 return node; 50 } 51 NotifyThemeScopeUpdate()52void WithThemeNode::NotifyThemeScopeUpdate() 53 { 54 UINode::UpdateThemeScopeUpdate(GetThemeScopeId()); 55 } 56 UpdateThemeScopeId(int32_t themeScopeId)57void WithThemeNode::UpdateThemeScopeId(int32_t themeScopeId) 58 { 59 // do nothing 60 } 61 UpdateThemeScopeUpdate(int32_t themeScopeId)62void WithThemeNode::UpdateThemeScopeUpdate(int32_t themeScopeId) 63 { 64 // do nothing 65 } 66 SetOnThemeScopeDestroy(ThemeScopeDestroyCallback && callback)67void WithThemeNode::SetOnThemeScopeDestroy(ThemeScopeDestroyCallback&& callback) 68 { 69 themeScopeDestroyCallback_ = std::move(callback); 70 } 71 72 } // namespace OHOS::Ace::NG