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