1 // Copyright 2017 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef XFA_FXFA_PARSER_CXFA_OBJECT_H_ 8 #define XFA_FXFA_PARSER_CXFA_OBJECT_H_ 9 10 #include "core/fxcrt/fx_string.h" 11 #include "fxjs/gc/heap.h" 12 #include "fxjs/xfa/fxjse.h" 13 #include "v8/include/cppgc/garbage-collected.h" 14 #include "v8/include/cppgc/member.h" 15 #include "xfa/fxfa/fxfa_basic.h" 16 17 namespace cppgc { 18 class Visitor; 19 } // namespace cppgc 20 21 enum class XFA_ObjectType { 22 Object, 23 List, 24 Node, 25 NodeC, 26 NodeV, 27 ModelNode, 28 TextNode, 29 TreeList, 30 ContainerNode, 31 ContentNode, 32 ThisProxy, 33 }; 34 35 class CJX_Object; 36 class CXFA_Document; 37 class CXFA_List; 38 class CXFA_Node; 39 class CXFA_ThisProxy; 40 class CXFA_TreeList; 41 42 class CXFA_Object : public cppgc::GarbageCollected<CXFA_Object> { 43 public: 44 virtual ~CXFA_Object(); 45 46 virtual void Trace(cppgc::Visitor* visitor) const; 47 GetDocument()48 CXFA_Document* GetDocument() const { return m_pDocument.Get(); } GetObjectType()49 XFA_ObjectType GetObjectType() const { return m_objectType; } 50 IsList()51 bool IsList() const { 52 return m_objectType == XFA_ObjectType::List || 53 m_objectType == XFA_ObjectType::TreeList; 54 } IsNode()55 bool IsNode() const { 56 return m_objectType == XFA_ObjectType::Node || 57 m_objectType == XFA_ObjectType::NodeC || 58 m_objectType == XFA_ObjectType::NodeV || 59 m_objectType == XFA_ObjectType::ModelNode || 60 m_objectType == XFA_ObjectType::TextNode || 61 m_objectType == XFA_ObjectType::ContainerNode || 62 m_objectType == XFA_ObjectType::ContentNode; 63 } IsTreeList()64 bool IsTreeList() const { return m_objectType == XFA_ObjectType::TreeList; } IsContentNode()65 bool IsContentNode() const { 66 return m_objectType == XFA_ObjectType::ContentNode; 67 } IsContainerNode()68 bool IsContainerNode() const { 69 return m_objectType == XFA_ObjectType::ContainerNode; 70 } IsModelNode()71 bool IsModelNode() const { return m_objectType == XFA_ObjectType::ModelNode; } IsNodeV()72 bool IsNodeV() const { return m_objectType == XFA_ObjectType::NodeV; } IsThisProxy()73 bool IsThisProxy() const { return m_objectType == XFA_ObjectType::ThisProxy; } 74 75 CXFA_List* AsList(); 76 CXFA_Node* AsNode(); 77 CXFA_TreeList* AsTreeList(); 78 CXFA_ThisProxy* AsThisProxy(); 79 JSObject()80 CJX_Object* JSObject() { return m_pJSObject; } JSObject()81 const CJX_Object* JSObject() const { return m_pJSObject; } 82 HasCreatedUIWidget()83 bool HasCreatedUIWidget() const { 84 return m_elementType == XFA_Element::Field || 85 m_elementType == XFA_Element::Draw || 86 m_elementType == XFA_Element::Subform || 87 m_elementType == XFA_Element::ExclGroup; 88 } 89 GetElementType()90 XFA_Element GetElementType() const { return m_elementType; } GetClassName()91 ByteStringView GetClassName() const { return m_elementName; } GetClassHashCode()92 uint32_t GetClassHashCode() const { return m_elementNameHash; } 93 94 WideString GetSOMExpression(); 95 96 protected: 97 CXFA_Object(CXFA_Document* pDocument, 98 XFA_ObjectType objectType, 99 XFA_Element eType, 100 CJX_Object* jsObject); 101 102 const XFA_ObjectType m_objectType; 103 const XFA_Element m_elementType; 104 const ByteStringView m_elementName; 105 const uint32_t m_elementNameHash; 106 cppgc::WeakMember<CXFA_Document> m_pDocument; 107 cppgc::Member<CJX_Object> m_pJSObject; 108 }; 109 110 // Helper functions that permit nullptr arguments. 111 CXFA_List* ToList(CXFA_Object* pObj); 112 CXFA_Node* ToNode(CXFA_Object* pObj); 113 CXFA_TreeList* ToTreeList(CXFA_Object* pObj); 114 CXFA_ThisProxy* ToThisProxy(CXFA_Object* pObj); 115 116 #endif // XFA_FXFA_PARSER_CXFA_OBJECT_H_ 117