1 // Copyright 2017 PDFium Authors. All rights reserved. 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 <memory> 11 12 #include "core/fxcrt/fx_string.h" 13 #include "fxjs/xfa/fxjse.h" 14 #include "xfa/fxfa/fxfa_basic.h" 15 16 enum class XFA_ObjectType { 17 Object, 18 List, 19 Node, 20 NodeC, 21 NodeV, 22 ModelNode, 23 TextNode, 24 TreeList, 25 ContainerNode, 26 ContentNode, 27 ThisProxy, 28 }; 29 30 class CJX_Object; 31 class CXFA_Document; 32 class CXFA_List; 33 class CXFA_Node; 34 class CXFA_ThisProxy; 35 class CXFA_TreeList; 36 37 class CXFA_Object : public CFXJSE_HostObject { 38 public: 39 ~CXFA_Object() override; 40 41 // CFXJSE_HostObject: 42 CXFA_Object* AsCXFAObject() override; 43 GetDocument()44 CXFA_Document* GetDocument() const { return m_pDocument.Get(); } GetObjectType()45 XFA_ObjectType GetObjectType() const { return m_objectType; } 46 IsList()47 bool IsList() const { 48 return m_objectType == XFA_ObjectType::List || 49 m_objectType == XFA_ObjectType::TreeList; 50 } IsNode()51 bool IsNode() const { 52 return m_objectType == XFA_ObjectType::Node || 53 m_objectType == XFA_ObjectType::NodeC || 54 m_objectType == XFA_ObjectType::NodeV || 55 m_objectType == XFA_ObjectType::ModelNode || 56 m_objectType == XFA_ObjectType::TextNode || 57 m_objectType == XFA_ObjectType::ContainerNode || 58 m_objectType == XFA_ObjectType::ContentNode; 59 } IsTreeList()60 bool IsTreeList() const { return m_objectType == XFA_ObjectType::TreeList; } IsContentNode()61 bool IsContentNode() const { 62 return m_objectType == XFA_ObjectType::ContentNode; 63 } IsContainerNode()64 bool IsContainerNode() const { 65 return m_objectType == XFA_ObjectType::ContainerNode; 66 } IsModelNode()67 bool IsModelNode() const { return m_objectType == XFA_ObjectType::ModelNode; } IsNodeV()68 bool IsNodeV() const { return m_objectType == XFA_ObjectType::NodeV; } IsThisProxy()69 bool IsThisProxy() const { return m_objectType == XFA_ObjectType::ThisProxy; } 70 71 CXFA_List* AsList(); 72 CXFA_Node* AsNode(); 73 CXFA_TreeList* AsTreeList(); 74 CXFA_ThisProxy* AsThisProxy(); 75 JSObject()76 CJX_Object* JSObject() { return m_pJSObject.get(); } JSObject()77 const CJX_Object* JSObject() const { return m_pJSObject.get(); } 78 HasCreatedUIWidget()79 bool HasCreatedUIWidget() const { 80 return m_elementType == XFA_Element::Field || 81 m_elementType == XFA_Element::Draw || 82 m_elementType == XFA_Element::Subform || 83 m_elementType == XFA_Element::ExclGroup; 84 } 85 GetElementType()86 XFA_Element GetElementType() const { return m_elementType; } GetClassName()87 ByteStringView GetClassName() const { return m_elementName; } GetClassHashCode()88 uint32_t GetClassHashCode() const { return m_elementNameHash; } 89 90 WideString GetSOMExpression(); 91 92 protected: 93 CXFA_Object(CXFA_Document* pDocument, 94 XFA_ObjectType objectType, 95 XFA_Element eType, 96 std::unique_ptr<CJX_Object> jsObject); 97 98 UnownedPtr<CXFA_Document> const m_pDocument; 99 const XFA_ObjectType m_objectType; 100 const XFA_Element m_elementType; 101 const ByteStringView m_elementName; 102 const uint32_t m_elementNameHash; 103 std::unique_ptr<CJX_Object> m_pJSObject; 104 }; 105 106 // Helper functions that permit nullptr arguments. 107 CXFA_List* ToList(CXFA_Object* pObj); 108 CXFA_Node* ToNode(CXFA_Object* pObj); 109 CXFA_TreeList* ToTreeList(CXFA_Object* pObj); 110 CXFA_ThisProxy* ToThisProxy(CXFA_Object* pObj); 111 112 #endif // XFA_FXFA_PARSER_CXFA_OBJECT_H_ 113