1 /* 2 * Copyright (c) 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_FOR_EACH_ITEM_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_FOR_EACH_ITEM_H 18 19 #include <cstdint> 20 #include <string> 21 22 #include "base/utils/macros.h" 23 #include "base/utils/noncopyable.h" 24 #include "core/components_ng/base/ui_node.h" 25 #include "core/components_v2/inspector/inspector_constants.h" 26 #include "core/pipeline/base/element_register.h" 27 28 namespace OHOS::Ace::NG { 29 30 // Syntax nodes are used for ForEach, LazyForEach, and IfElse nodes to wrap up the generated sub components and are 31 // uniquely identified by keys. 32 class ACE_EXPORT SyntaxItem : public UINode { 33 DECLARE_ACE_TYPE(SyntaxItem, UINode); 34 35 public: SyntaxItem(const std::string & key)36 explicit SyntaxItem(const std::string& key) 37 : UINode(V2::JS_SYNTAX_ITEM_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId()), key_(key) 38 {} ~SyntaxItem()39 ~SyntaxItem() override 40 { 41 SetRemoveSilently(true); 42 } 43 IsAtomicNode()44 bool IsAtomicNode() const override 45 { 46 return false; 47 } 48 GetKey()49 const std::string& GetKey() const 50 { 51 return key_; 52 } 53 ToJsonValue(std::unique_ptr<JsonValue> & json)54 void ToJsonValue(std::unique_ptr<JsonValue>& json) const override 55 { 56 UINode::ToJsonValue(json); 57 json->Put("key", key_.c_str()); 58 } 59 FromJson(const std::unique_ptr<JsonValue> & json)60 void FromJson(const std::unique_ptr<JsonValue>& json) override 61 { 62 UINode::FromJson(json); 63 } 64 CreateSyntaxItemNode(const std::string & key)65 static RefPtr<SyntaxItem> CreateSyntaxItemNode(const std::string& key) 66 { 67 auto node = AceType::MakeRefPtr<SyntaxItem>(key); 68 ElementRegister::GetInstance()->AddUINode(node); 69 return node; 70 } 71 72 private: 73 std::string key_; 74 75 ACE_DISALLOW_COPY_AND_MOVE(SyntaxItem); 76 }; 77 78 } // namespace OHOS::Ace::NG 79 80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_FOR_EACH_ITEM_H 81