xref: /aosp_15_r20/external/pdfium/xfa/fxfa/parser/cxfa_object.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
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            m_elementType == XFA_Element::Delta;
64   }
IsTreeList()65   bool IsTreeList() const { return m_objectType == XFA_ObjectType::TreeList; }
IsContentNode()66   bool IsContentNode() const {
67     return m_objectType == XFA_ObjectType::ContentNode;
68   }
IsContainerNode()69   bool IsContainerNode() const {
70     return m_objectType == XFA_ObjectType::ContainerNode;
71   }
IsModelNode()72   bool IsModelNode() const { return m_objectType == XFA_ObjectType::ModelNode; }
IsNodeV()73   bool IsNodeV() const { return m_objectType == XFA_ObjectType::NodeV; }
IsThisProxy()74   bool IsThisProxy() const { return m_objectType == XFA_ObjectType::ThisProxy; }
75 
76   CXFA_List* AsList();
77   CXFA_Node* AsNode();
78   CXFA_TreeList* AsTreeList();
79   CXFA_ThisProxy* AsThisProxy();
80 
JSObject()81   CJX_Object* JSObject() { return m_pJSObject; }
JSObject()82   const CJX_Object* JSObject() const { return m_pJSObject; }
83 
HasCreatedUIWidget()84   bool HasCreatedUIWidget() const {
85     return m_elementType == XFA_Element::Field ||
86            m_elementType == XFA_Element::Draw ||
87            m_elementType == XFA_Element::Subform ||
88            m_elementType == XFA_Element::ExclGroup;
89   }
90 
GetElementType()91   XFA_Element GetElementType() const { return m_elementType; }
GetClassName()92   ByteStringView GetClassName() const { return m_elementName; }
GetClassHashCode()93   uint32_t GetClassHashCode() const { return m_elementNameHash; }
94 
95   WideString GetSOMExpression();
96 
97  protected:
98   CXFA_Object(CXFA_Document* pDocument,
99               XFA_ObjectType objectType,
100               XFA_Element eType,
101               CJX_Object* jsObject);
102 
103   const XFA_ObjectType m_objectType;
104   const XFA_Element m_elementType;
105   const ByteStringView m_elementName;
106   const uint32_t m_elementNameHash;
107   cppgc::WeakMember<CXFA_Document> m_pDocument;
108   cppgc::Member<CJX_Object> m_pJSObject;
109 };
110 
111 // Helper functions that permit nullptr arguments.
112 CXFA_List* ToList(CXFA_Object* pObj);
113 CXFA_Node* ToNode(CXFA_Object* pObj);
114 CXFA_TreeList* ToTreeList(CXFA_Object* pObj);
115 CXFA_ThisProxy* ToThisProxy(CXFA_Object* pObj);
116 
117 #endif  // XFA_FXFA_PARSER_CXFA_OBJECT_H_
118