1 // Copyright 2014 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_DOCUMENT_H_ 8 #define XFA_FXFA_PARSER_CXFA_DOCUMENT_H_ 9 10 #include <map> 11 #include <memory> 12 #include <set> 13 #include <vector> 14 15 #include "xfa/fxfa/fxfa.h" 16 #include "xfa/fxfa/parser/cxfa_localemgr.h" 17 18 enum XFA_VERSION { 19 XFA_VERSION_UNKNOWN = 0, 20 XFA_VERSION_200 = 200, 21 XFA_VERSION_202 = 202, 22 XFA_VERSION_204 = 204, 23 XFA_VERSION_205 = 205, 24 XFA_VERSION_206 = 206, 25 XFA_VERSION_207 = 207, 26 XFA_VERSION_208 = 208, 27 XFA_VERSION_300 = 300, 28 XFA_VERSION_301 = 301, 29 XFA_VERSION_303 = 303, 30 XFA_VERSION_306 = 306, 31 XFA_VERSION_DEFAULT = XFA_VERSION_303, 32 XFA_VERSION_MIN = 200, 33 XFA_VERSION_MAX = 400, 34 }; 35 36 enum XFA_DocFlag { 37 XFA_DOCFLAG_StrictScoping = 0x0001, 38 XFA_DOCFLAG_HasInteractive = 0x0002, 39 XFA_DOCFLAG_Interactive = 0x0004, 40 XFA_DOCFLAG_Scripting = 0x0008 41 }; 42 43 class CFX_XMLDoc; 44 class CFXJSE_Engine; 45 class CScript_DataWindow; 46 class CScript_EventPseudoModel; 47 class CScript_HostPseudoModel; 48 class CScript_LogPseudoModel; 49 class CScript_LayoutPseudoModel; 50 class CScript_SignaturePseudoModel; 51 class CXFA_ContainerLayoutItem; 52 class CXFA_DocumentParser; 53 class CXFA_FFNotify; 54 class CXFA_LayoutItem; 55 class CXFA_LayoutProcessor; 56 class CXFA_Node; 57 class CXFA_Object; 58 59 class CXFA_Document { 60 public: 61 explicit CXFA_Document(CXFA_DocumentParser* pParser); 62 ~CXFA_Document(); 63 64 CFXJSE_Engine* InitScriptContext(v8::Isolate* pIsolate); 65 GetRoot()66 CXFA_Node* GetRoot() const { return m_pRootNode; } 67 68 CFX_XMLDoc* GetXMLDoc() const; 69 CXFA_FFNotify* GetNotify() const; 70 CXFA_LocaleMgr* GetLocalMgr(); 71 CXFA_Object* GetXFAObject(XFA_HashCode wsNodeNameHash); 72 CXFA_Node* GetNodeByID(CXFA_Node* pRoot, const WideStringView& wsID); 73 CXFA_Node* GetNotBindNode(const std::vector<CXFA_Object*>& arrayNodes); 74 CXFA_LayoutProcessor* GetLayoutProcessor(); 75 CXFA_LayoutProcessor* GetDocLayout(); 76 CFXJSE_Engine* GetScriptContext(); 77 78 void SetRoot(CXFA_Node* pNewRoot); 79 80 void AddPurgeNode(CXFA_Node* pNode); 81 bool RemovePurgeNode(CXFA_Node* pNode); 82 HasFlag(uint32_t dwFlag)83 bool HasFlag(uint32_t dwFlag) { return (m_dwDocFlags & dwFlag) == dwFlag; } 84 void SetFlag(uint32_t dwFlag, bool bOn); 85 86 bool IsInteractive(); GetCurVersionMode()87 XFA_VERSION GetCurVersionMode() { return m_eCurVersionMode; } 88 XFA_VERSION RecognizeXFAVersionNumber(const WideString& wsTemplateNS); 89 90 CXFA_Node* CreateNode(XFA_PacketType packet, XFA_Element eElement); 91 92 void DoProtoMerge(); 93 void DoDataMerge(); 94 void DoDataRemerge(bool bDoDataMerge); 95 CXFA_Node* DataMerge_CopyContainer(CXFA_Node* pTemplateNode, 96 CXFA_Node* pFormNode, 97 CXFA_Node* pDataScope, 98 bool bOneInstance, 99 bool bDataMerge, 100 bool bUpLevel); 101 void DataMerge_UpdateBindingRelations(CXFA_Node* pFormUpdateRoot); 102 103 void ClearLayoutData(); 104 105 std::map<uint32_t, CXFA_Node*> m_rgGlobalBinding; 106 std::vector<CXFA_Node*> m_pPendingPageSet; 107 108 private: 109 CXFA_DocumentParser* m_pParser; 110 CXFA_Node* m_pRootNode; 111 std::unique_ptr<CFXJSE_Engine> m_pScriptContext; 112 std::unique_ptr<CXFA_LayoutProcessor> m_pLayoutProcessor; 113 std::unique_ptr<CXFA_LocaleMgr> m_pLocalMgr; 114 std::unique_ptr<CScript_DataWindow> m_pScriptDataWindow; 115 std::unique_ptr<CScript_EventPseudoModel> m_pScriptEvent; 116 std::unique_ptr<CScript_HostPseudoModel> m_pScriptHost; 117 std::unique_ptr<CScript_LogPseudoModel> m_pScriptLog; 118 std::unique_ptr<CScript_LayoutPseudoModel> m_pScriptLayout; 119 std::unique_ptr<CScript_SignaturePseudoModel> m_pScriptSignature; 120 std::set<CXFA_Node*> m_PurgeNodes; 121 XFA_VERSION m_eCurVersionMode; 122 uint32_t m_dwDocFlags; 123 }; 124 125 #endif // XFA_FXFA_PARSER_CXFA_DOCUMENT_H_ 126