OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/src/foxitlib.h" | 7 #include "xfa/src/foxitlib.h" |
8 #include "xfa/src/fxfa/src/common/xfa_utils.h" | 8 #include "xfa/src/fxfa/src/common/xfa_utils.h" |
9 #include "xfa/src/fxfa/src/common/xfa_object.h" | 9 #include "xfa/src/fxfa/src/common/xfa_object.h" |
10 #include "xfa/src/fxfa/src/common/xfa_document.h" | 10 #include "xfa/src/fxfa/src/common/xfa_document.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 IXFA_Notify* CXFA_Document::GetNotify() const { | 90 IXFA_Notify* CXFA_Document::GetNotify() const { |
91 return m_pParser->GetNotify(); | 91 return m_pParser->GetNotify(); |
92 } | 92 } |
93 CXFA_Object* CXFA_Document::GetXFAObject(const CFX_WideStringC& wsNodeName) { | 93 CXFA_Object* CXFA_Document::GetXFAObject(const CFX_WideStringC& wsNodeName) { |
94 return GetXFAObject( | 94 return GetXFAObject( |
95 FX_HashCode_String_GetW(wsNodeName.GetPtr(), wsNodeName.GetLength())); | 95 FX_HashCode_String_GetW(wsNodeName.GetPtr(), wsNodeName.GetLength())); |
96 } | 96 } |
97 CXFA_Object* CXFA_Document::GetXFAObject(FX_DWORD dwNodeNameHash) { | 97 CXFA_Object* CXFA_Document::GetXFAObject(FX_DWORD dwNodeNameHash) { |
98 switch (dwNodeNameHash) { | 98 switch (dwNodeNameHash) { |
99 case XFA_HASHCODE_Data: { | 99 case XFA_HASHCODE_Data: { |
100 CXFA_Node* pDatasetsNode = | 100 CXFA_Node* pDatasetsNode = ToNode(GetXFAObject(XFA_HASHCODE_Datasets)); |
101 (CXFA_Node*)GetXFAObject(XFA_HASHCODE_Datasets); | |
102 if (!pDatasetsNode) { | 101 if (!pDatasetsNode) { |
103 return NULL; | 102 return NULL; |
104 } | 103 } |
105 for (CXFA_Node* pDatasetsChild = | 104 for (CXFA_Node* pDatasetsChild = |
106 pDatasetsNode->GetFirstChildByClass(XFA_ELEMENT_DataGroup); | 105 pDatasetsNode->GetFirstChildByClass(XFA_ELEMENT_DataGroup); |
107 pDatasetsChild; | 106 pDatasetsChild; |
108 pDatasetsChild = | 107 pDatasetsChild = |
109 pDatasetsChild->GetNextSameClassSibling(XFA_ELEMENT_DataGroup)) { | 108 pDatasetsChild->GetNextSameClassSibling(XFA_ELEMENT_DataGroup)) { |
110 if (pDatasetsChild->GetNameHash() != XFA_HASHCODE_Data) { | 109 if (pDatasetsChild->GetNameHash() != XFA_HASHCODE_Data) { |
111 continue; | 110 continue; |
112 } | 111 } |
113 CFX_WideString wsNamespaceURI; | 112 CFX_WideString wsNamespaceURI; |
114 if (!pDatasetsChild->TryNamespace(wsNamespaceURI)) { | 113 if (!pDatasetsChild->TryNamespace(wsNamespaceURI)) { |
115 continue; | 114 continue; |
116 } | 115 } |
117 CFX_WideString wsDatasetsURI; | 116 CFX_WideString wsDatasetsURI; |
118 if (!pDatasetsNode->TryNamespace(wsDatasetsURI)) { | 117 if (!pDatasetsNode->TryNamespace(wsDatasetsURI)) { |
119 continue; | 118 continue; |
120 } | 119 } |
121 if (wsNamespaceURI == wsDatasetsURI) { | 120 if (wsNamespaceURI == wsDatasetsURI) { |
122 return pDatasetsChild; | 121 return pDatasetsChild; |
123 } | 122 } |
124 } | 123 } |
125 } | 124 } |
126 return NULL; | 125 return NULL; |
127 case XFA_HASHCODE_Record: { | 126 case XFA_HASHCODE_Record: { |
128 CXFA_Node* pData = (CXFA_Node*)GetXFAObject(XFA_HASHCODE_Data); | 127 CXFA_Node* pData = ToNode(GetXFAObject(XFA_HASHCODE_Data)); |
129 return pData ? pData->GetFirstChildByClass(XFA_ELEMENT_DataGroup) : NULL; | 128 return pData ? pData->GetFirstChildByClass(XFA_ELEMENT_DataGroup) : NULL; |
130 } | 129 } |
131 case XFA_HASHCODE_DataWindow: { | 130 case XFA_HASHCODE_DataWindow: { |
132 if (m_pScriptDataWindow == NULL) { | 131 if (m_pScriptDataWindow == NULL) { |
133 m_pScriptDataWindow = new CScript_DataWindow(this); | 132 m_pScriptDataWindow = new CScript_DataWindow(this); |
134 } | 133 } |
135 return m_pScriptDataWindow; | 134 return m_pScriptDataWindow; |
136 } | 135 } |
137 case XFA_HASHCODE_Event: { | 136 case XFA_HASHCODE_Event: { |
138 if (m_pScriptEvent == NULL) { | 137 if (m_pScriptEvent == NULL) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 if (bOn) { | 205 if (bOn) { |
207 m_dwDocFlags |= dwFlag; | 206 m_dwDocFlags |= dwFlag; |
208 } else { | 207 } else { |
209 m_dwDocFlags &= ~dwFlag; | 208 m_dwDocFlags &= ~dwFlag; |
210 } | 209 } |
211 } | 210 } |
212 FX_BOOL CXFA_Document::IsInteractive() { | 211 FX_BOOL CXFA_Document::IsInteractive() { |
213 if (m_dwDocFlags & XFA_DOCFLAG_HasInteractive) { | 212 if (m_dwDocFlags & XFA_DOCFLAG_HasInteractive) { |
214 return m_dwDocFlags & XFA_DOCFLAG_Interactive; | 213 return m_dwDocFlags & XFA_DOCFLAG_Interactive; |
215 } | 214 } |
216 CXFA_Node* pConfig = (CXFA_Node*)this->GetXFAObject(XFA_HASHCODE_Config); | 215 CXFA_Node* pConfig = ToNode(GetXFAObject(XFA_HASHCODE_Config)); |
217 if (!pConfig) { | 216 if (!pConfig) { |
218 return FALSE; | 217 return FALSE; |
219 } | 218 } |
220 CFX_WideString wsInteractive; | 219 CFX_WideString wsInteractive; |
221 CXFA_Node* pPresent = pConfig->GetFirstChildByClass(XFA_ELEMENT_Present); | 220 CXFA_Node* pPresent = pConfig->GetFirstChildByClass(XFA_ELEMENT_Present); |
222 if (!pPresent) { | 221 if (!pPresent) { |
223 return FALSE; | 222 return FALSE; |
224 } | 223 } |
225 CXFA_Node* pPDF = pPresent->GetFirstChildByClass(XFA_ELEMENT_Pdf); | 224 CXFA_Node* pPDF = pPresent->GetFirstChildByClass(XFA_ELEMENT_Pdf); |
226 if (!pPDF) { | 225 if (!pPDF) { |
227 return FALSE; | 226 return FALSE; |
228 } | 227 } |
229 CXFA_Node* pInteractive = pPDF->GetChild(0, XFA_ELEMENT_Interactive); | 228 CXFA_Node* pInteractive = pPDF->GetChild(0, XFA_ELEMENT_Interactive); |
230 if (pInteractive) { | 229 if (pInteractive) { |
231 m_dwDocFlags |= XFA_DOCFLAG_HasInteractive; | 230 m_dwDocFlags |= XFA_DOCFLAG_HasInteractive; |
232 if (pInteractive->TryContent(wsInteractive) && | 231 if (pInteractive->TryContent(wsInteractive) && |
233 wsInteractive == FX_WSTRC(L"1")) { | 232 wsInteractive == FX_WSTRC(L"1")) { |
234 m_dwDocFlags |= XFA_DOCFLAG_Interactive; | 233 m_dwDocFlags |= XFA_DOCFLAG_Interactive; |
235 return TRUE; | 234 return TRUE; |
236 } | 235 } |
237 } | 236 } |
238 return FALSE; | 237 return FALSE; |
239 } | 238 } |
240 CXFA_LocaleMgr* CXFA_Document::GetLocalMgr() { | 239 CXFA_LocaleMgr* CXFA_Document::GetLocalMgr() { |
241 if (!m_pLocalMgr) { | 240 if (!m_pLocalMgr) { |
242 CFX_WideString wsLanguage; | 241 CFX_WideString wsLanguage; |
243 this->GetParser()->GetNotify()->GetAppProvider()->GetLanguage(wsLanguage); | 242 GetParser()->GetNotify()->GetAppProvider()->GetLanguage(wsLanguage); |
244 m_pLocalMgr = new CXFA_LocaleMgr( | 243 m_pLocalMgr = new CXFA_LocaleMgr( |
245 (CXFA_Node*)this->GetXFAObject(XFA_HASHCODE_LocaleSet), wsLanguage); | 244 ToNode(GetXFAObject(XFA_HASHCODE_LocaleSet)), wsLanguage); |
246 } | 245 } |
247 return m_pLocalMgr; | 246 return m_pLocalMgr; |
248 } | 247 } |
249 IXFA_ScriptContext* CXFA_Document::InitScriptContext(FXJSE_HRUNTIME hRuntime) { | 248 IXFA_ScriptContext* CXFA_Document::InitScriptContext(FXJSE_HRUNTIME hRuntime) { |
250 if (!m_pScriptContext) { | 249 if (!m_pScriptContext) { |
251 m_pScriptContext = XFA_ScriptContext_Create(this); | 250 m_pScriptContext = XFA_ScriptContext_Create(this); |
252 } | 251 } |
253 m_pScriptContext->Initialize(hRuntime); | 252 m_pScriptContext->Initialize(hRuntime); |
254 return m_pScriptContext; | 253 return m_pScriptContext; |
255 } | 254 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 348 } |
350 { | 349 { |
351 CXFA_NodeIterator sIterator(pDestNode); | 350 CXFA_NodeIterator sIterator(pDestNode); |
352 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; | 351 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; |
353 pNode = sIterator.MoveToNext()) { | 352 pNode = sIterator.MoveToNext()) { |
354 pNode->SetFlag(XFA_NODEFLAG_UnusedNode, FALSE); | 353 pNode->SetFlag(XFA_NODEFLAG_UnusedNode, FALSE); |
355 } | 354 } |
356 } | 355 } |
357 } | 356 } |
358 void CXFA_Document::DoProtoMerge() { | 357 void CXFA_Document::DoProtoMerge() { |
359 CXFA_Node* pTemplateRoot = (CXFA_Node*)GetXFAObject(XFA_HASHCODE_Template); | 358 CXFA_Node* pTemplateRoot = ToNode(GetXFAObject(XFA_HASHCODE_Template)); |
360 if (!pTemplateRoot) { | 359 if (!pTemplateRoot) { |
361 return; | 360 return; |
362 } | 361 } |
363 CFX_MapPtrTemplate<FX_DWORD, CXFA_Node*> mIDMap; | 362 CFX_MapPtrTemplate<FX_DWORD, CXFA_Node*> mIDMap; |
364 CXFA_NodeSet sUseNodes; | 363 CXFA_NodeSet sUseNodes; |
365 CXFA_NodeIterator sIterator(pTemplateRoot); | 364 CXFA_NodeIterator sIterator(pTemplateRoot); |
366 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; | 365 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; |
367 pNode = sIterator.MoveToNext()) { | 366 pNode = sIterator.MoveToNext()) { |
368 CFX_WideStringC wsIDVal; | 367 CFX_WideStringC wsIDVal; |
369 if (pNode->TryCData(XFA_ATTRIBUTE_Id, wsIDVal) && !wsIDVal.IsEmpty()) { | 368 if (pNode->TryCData(XFA_ATTRIBUTE_Id, wsIDVal) && !wsIDVal.IsEmpty()) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 } | 417 } |
419 CXFA_Node* pProtoNode = NULL; | 418 CXFA_Node* pProtoNode = NULL; |
420 if (!wsSOM.IsEmpty()) { | 419 if (!wsSOM.IsEmpty()) { |
421 FX_DWORD dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | | 420 FX_DWORD dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
422 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | | 421 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
423 XFA_RESOLVENODE_Siblings; | 422 XFA_RESOLVENODE_Siblings; |
424 XFA_RESOLVENODE_RS resoveNodeRS; | 423 XFA_RESOLVENODE_RS resoveNodeRS; |
425 int32_t iRet = m_pScriptContext->ResolveObjects(pUseHrefNode, wsSOM, | 424 int32_t iRet = m_pScriptContext->ResolveObjects(pUseHrefNode, wsSOM, |
426 resoveNodeRS, dwFlag); | 425 resoveNodeRS, dwFlag); |
427 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) { | 426 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) { |
428 pProtoNode = (CXFA_Node*)resoveNodeRS.nodes[0]; | 427 pProtoNode = resoveNodeRS.nodes[0]->AsNode(); |
429 } | 428 } |
430 } else if (!wsID.IsEmpty()) { | 429 } else if (!wsID.IsEmpty()) { |
431 if (!mIDMap.Lookup( | 430 if (!mIDMap.Lookup( |
432 FX_HashCode_String_GetW(wsID.GetPtr(), wsID.GetLength()), | 431 FX_HashCode_String_GetW(wsID.GetPtr(), wsID.GetLength()), |
433 pProtoNode)) { | 432 pProtoNode)) { |
434 continue; | 433 continue; |
435 } | 434 } |
436 } | 435 } |
437 if (!pProtoNode) { | 436 if (!pProtoNode) { |
438 continue; | 437 continue; |
439 } | 438 } |
440 XFA_ProtoMerge_MergeNode(this, pUseHrefNode, pProtoNode); | 439 XFA_ProtoMerge_MergeNode(this, pUseHrefNode, pProtoNode); |
441 } | 440 } |
442 } | 441 } |
OLD | NEW |