Home | History | Annotate | Download | only in parser
      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/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   VariablesThis
     28 };
     29 
     30 class CJX_Object;
     31 class CXFA_Document;
     32 class CXFA_Node;
     33 class CXFA_TreeList;
     34 class CXFA_WidgetAcc;
     35 
     36 class CXFA_Object : public CFXJSE_HostObject {
     37  public:
     38   ~CXFA_Object() override;
     39 
     40   CXFA_Document* GetDocument() const { return m_pDocument.Get(); }
     41   XFA_ObjectType GetObjectType() const { return m_objectType; }
     42 
     43   bool IsNode() const {
     44     return m_objectType == XFA_ObjectType::Node ||
     45            m_objectType == XFA_ObjectType::NodeC ||
     46            m_objectType == XFA_ObjectType::NodeV ||
     47            m_objectType == XFA_ObjectType::ModelNode ||
     48            m_objectType == XFA_ObjectType::TextNode ||
     49            m_objectType == XFA_ObjectType::ContainerNode ||
     50            m_objectType == XFA_ObjectType::ContentNode ||
     51            m_objectType == XFA_ObjectType::VariablesThis;
     52   }
     53   bool IsTreeList() const { return m_objectType == XFA_ObjectType::TreeList; }
     54   bool IsContentNode() const {
     55     return m_objectType == XFA_ObjectType::ContentNode;
     56   }
     57   bool IsContainerNode() const {
     58     return m_objectType == XFA_ObjectType::ContainerNode;
     59   }
     60   bool IsModelNode() const { return m_objectType == XFA_ObjectType::ModelNode; }
     61   bool IsNodeV() const { return m_objectType == XFA_ObjectType::NodeV; }
     62   bool IsVariablesThis() const {
     63     return m_objectType == XFA_ObjectType::VariablesThis;
     64   }
     65 
     66   CXFA_Node* AsNode();
     67   CXFA_TreeList* AsTreeList();
     68 
     69   const CXFA_Node* AsNode() const;
     70   const CXFA_TreeList* AsTreeList() const;
     71 
     72   CJX_Object* JSObject() { return m_pJSObject.get(); }
     73   const CJX_Object* JSObject() const { return m_pJSObject.get(); }
     74 
     75   bool HasCreatedUIWidget() const {
     76     return m_elementType == XFA_Element::Field ||
     77            m_elementType == XFA_Element::Draw ||
     78            m_elementType == XFA_Element::Subform ||
     79            m_elementType == XFA_Element::ExclGroup;
     80   }
     81   void CreateWidgetAcc();
     82   CXFA_WidgetAcc* GetWidgetAcc() { return acc_.get(); }
     83 
     84   XFA_Element GetElementType() const { return m_elementType; }
     85   WideStringView GetClassName() const { return m_elementName; }
     86   uint32_t GetClassHashCode() const { return m_elementNameHash; }
     87 
     88   WideString GetSOMExpression();
     89 
     90  protected:
     91   CXFA_Object(CXFA_Document* pDocument,
     92               XFA_ObjectType objectType,
     93               XFA_Element eType,
     94               const WideStringView& elementName,
     95               std::unique_ptr<CJX_Object> jsObject);
     96 
     97   UnownedPtr<CXFA_Document> const m_pDocument;
     98   const XFA_ObjectType m_objectType;
     99   const XFA_Element m_elementType;
    100 
    101   const uint32_t m_elementNameHash;
    102   const WideStringView m_elementName;
    103 
    104   std::unique_ptr<CJX_Object> m_pJSObject;
    105   std::unique_ptr<CXFA_WidgetAcc> acc_;
    106 };
    107 
    108 CXFA_Node* ToNode(CXFA_Object* pObj);
    109 const CXFA_Node* ToNode(const CXFA_Object* pObj);
    110 
    111 #endif  // XFA_FXFA_PARSER_CXFA_OBJECT_H_
    112