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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_WITH_THEME_NODE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_WITH_THEME_NODE_H 18 19 #include <cstdint> 20 21 #include "base/utils/macros.h" 22 #include "core/components_ng/base/ui_node.h" 23 #include "core/components_ng/token_theme/token_theme.h" 24 #include "core/components_v2/inspector/inspector_constants.h" 25 26 namespace OHOS::Ace::NG { 27 28 using ThemeScopeDestroyCallback = std::function<void()>; 29 30 class ACE_EXPORT WithThemeNode : public UINode { 31 DECLARE_ACE_TYPE(WithThemeNode, UINode); 32 33 public: 34 static RefPtr<WithThemeNode> GetWithThemeNode(int32_t nodeId); 35 static RefPtr<WithThemeNode> CreateWithThemeNode(int32_t nodeId); 36 static RefPtr<WithThemeNode> GetOrCreateWithThemeNode(int32_t nodeId); 37 WithThemeNode(int32_t nodeId)38 explicit WithThemeNode(int32_t nodeId) : UINode(V2::JS_WITH_THEME_ETS_TAG, nodeId) { 39 SetThemeScopeId(nodeId); 40 } 41 ~WithThemeNode() override; 42 IsAtomicNode()43 bool IsAtomicNode() const override 44 { 45 return false; 46 } 47 IsSyntaxNode()48 bool IsSyntaxNode() const override 49 { 50 return true; 51 } 52 53 void UpdateThemeScopeId(int32_t themeScopeId) override; 54 void UpdateThemeScopeUpdate(int32_t themeScopeId) override; 55 void NotifyThemeScopeUpdate(); 56 void SetOnThemeScopeDestroy(ThemeScopeDestroyCallback&& callback); 57 58 private: 59 ThemeScopeDestroyCallback themeScopeDestroyCallback_; 60 61 ACE_DISALLOW_COPY_AND_MOVE(WithThemeNode); 62 }; 63 64 } // namespace OHOS::Ace::NG 65 66 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_WITH_THEME_NODE_H 67