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 "core/fxcrt/include/fx_ext.h" | 7 #include "core/fxcrt/include/fx_ext.h" |
8 #include "xfa/fxfa/app/xfa_ffnotify.h" | 8 #include "xfa/fxfa/app/xfa_ffnotify.h" |
9 #include "xfa/fxfa/parser/xfa_basic_imp.h" | 9 #include "xfa/fxfa/parser/xfa_basic_imp.h" |
10 #include "xfa/fxfa/parser/xfa_doclayout.h" | 10 #include "xfa/fxfa/parser/xfa_doclayout.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 CXFA_FFNotify* CXFA_Document::GetNotify() const { | 77 CXFA_FFNotify* CXFA_Document::GetNotify() const { |
78 return m_pParser->GetNotify(); | 78 return m_pParser->GetNotify(); |
79 } | 79 } |
80 | 80 |
81 CXFA_Object* CXFA_Document::GetXFAObject(XFA_HashCode dwNodeNameHash) { | 81 CXFA_Object* CXFA_Document::GetXFAObject(XFA_HashCode dwNodeNameHash) { |
82 switch (dwNodeNameHash) { | 82 switch (dwNodeNameHash) { |
83 case XFA_HASHCODE_Data: { | 83 case XFA_HASHCODE_Data: { |
84 CXFA_Node* pDatasetsNode = ToNode(GetXFAObject(XFA_HASHCODE_Datasets)); | 84 CXFA_Node* pDatasetsNode = ToNode(GetXFAObject(XFA_HASHCODE_Datasets)); |
85 if (!pDatasetsNode) { | 85 if (!pDatasetsNode) { |
86 return NULL; | 86 return nullptr; |
87 } | 87 } |
88 for (CXFA_Node* pDatasetsChild = | 88 for (CXFA_Node* pDatasetsChild = |
89 pDatasetsNode->GetFirstChildByClass(XFA_Element::DataGroup); | 89 pDatasetsNode->GetFirstChildByClass(XFA_Element::DataGroup); |
90 pDatasetsChild; | 90 pDatasetsChild; |
91 pDatasetsChild = pDatasetsChild->GetNextSameClassSibling( | 91 pDatasetsChild = pDatasetsChild->GetNextSameClassSibling( |
92 XFA_Element::DataGroup)) { | 92 XFA_Element::DataGroup)) { |
93 if (pDatasetsChild->GetNameHash() != XFA_HASHCODE_Data) { | 93 if (pDatasetsChild->GetNameHash() != XFA_HASHCODE_Data) { |
94 continue; | 94 continue; |
95 } | 95 } |
96 CFX_WideString wsNamespaceURI; | 96 CFX_WideString wsNamespaceURI; |
97 if (!pDatasetsChild->TryNamespace(wsNamespaceURI)) { | 97 if (!pDatasetsChild->TryNamespace(wsNamespaceURI)) { |
98 continue; | 98 continue; |
99 } | 99 } |
100 CFX_WideString wsDatasetsURI; | 100 CFX_WideString wsDatasetsURI; |
101 if (!pDatasetsNode->TryNamespace(wsDatasetsURI)) { | 101 if (!pDatasetsNode->TryNamespace(wsDatasetsURI)) { |
102 continue; | 102 continue; |
103 } | 103 } |
104 if (wsNamespaceURI == wsDatasetsURI) { | 104 if (wsNamespaceURI == wsDatasetsURI) { |
105 return pDatasetsChild; | 105 return pDatasetsChild; |
106 } | 106 } |
107 } | 107 } |
| 108 return nullptr; |
108 } | 109 } |
109 return NULL; | |
110 case XFA_HASHCODE_Record: { | 110 case XFA_HASHCODE_Record: { |
111 CXFA_Node* pData = ToNode(GetXFAObject(XFA_HASHCODE_Data)); | 111 CXFA_Node* pData = ToNode(GetXFAObject(XFA_HASHCODE_Data)); |
112 return pData ? pData->GetFirstChildByClass(XFA_Element::DataGroup) : NULL; | 112 return pData ? pData->GetFirstChildByClass(XFA_Element::DataGroup) |
| 113 : nullptr; |
113 } | 114 } |
114 case XFA_HASHCODE_DataWindow: { | 115 case XFA_HASHCODE_DataWindow: { |
115 if (m_pScriptDataWindow == NULL) { | 116 if (!m_pScriptDataWindow) |
116 m_pScriptDataWindow = new CScript_DataWindow(this); | 117 m_pScriptDataWindow = new CScript_DataWindow(this); |
117 } | |
118 return m_pScriptDataWindow; | 118 return m_pScriptDataWindow; |
119 } | 119 } |
120 case XFA_HASHCODE_Event: { | 120 case XFA_HASHCODE_Event: { |
121 if (m_pScriptEvent == NULL) { | 121 if (!m_pScriptEvent) |
122 m_pScriptEvent = new CScript_EventPseudoModel(this); | 122 m_pScriptEvent = new CScript_EventPseudoModel(this); |
123 } | |
124 return m_pScriptEvent; | 123 return m_pScriptEvent; |
125 } | 124 } |
126 case XFA_HASHCODE_Host: { | 125 case XFA_HASHCODE_Host: { |
127 if (m_pScriptHost == NULL) { | 126 if (!m_pScriptHost) |
128 m_pScriptHost = new CScript_HostPseudoModel(this); | 127 m_pScriptHost = new CScript_HostPseudoModel(this); |
129 } | |
130 return m_pScriptHost; | 128 return m_pScriptHost; |
131 } | 129 } |
132 case XFA_HASHCODE_Log: { | 130 case XFA_HASHCODE_Log: { |
133 if (m_pScriptLog == NULL) { | 131 if (!m_pScriptLog) |
134 m_pScriptLog = new CScript_LogPseudoModel(this); | 132 m_pScriptLog = new CScript_LogPseudoModel(this); |
135 } | |
136 return m_pScriptLog; | 133 return m_pScriptLog; |
137 } | 134 } |
138 case XFA_HASHCODE_Signature: { | 135 case XFA_HASHCODE_Signature: { |
139 if (m_pScriptSignature == NULL) { | 136 if (!m_pScriptSignature) |
140 m_pScriptSignature = new CScript_SignaturePseudoModel(this); | 137 m_pScriptSignature = new CScript_SignaturePseudoModel(this); |
141 } | |
142 return m_pScriptSignature; | 138 return m_pScriptSignature; |
143 } | 139 } |
144 case XFA_HASHCODE_Layout: { | 140 case XFA_HASHCODE_Layout: { |
145 if (m_pScriptLayout == NULL) { | 141 if (!m_pScriptLayout) |
146 m_pScriptLayout = new CScript_LayoutPseudoModel(this); | 142 m_pScriptLayout = new CScript_LayoutPseudoModel(this); |
147 } | |
148 return m_pScriptLayout; | 143 return m_pScriptLayout; |
149 } | 144 } |
150 default: | 145 default: |
151 return m_pRootNode->GetFirstChildByName(dwNodeNameHash); | 146 return m_pRootNode->GetFirstChildByName(dwNodeNameHash); |
152 } | 147 } |
153 } | 148 } |
154 CXFA_Node* CXFA_Document::CreateNode(uint32_t dwPacket, XFA_Element eElement) { | 149 CXFA_Node* CXFA_Document::CreateNode(uint32_t dwPacket, XFA_Element eElement) { |
155 return CreateNode(XFA_GetPacketByID(dwPacket), eElement); | 150 return CreateNode(XFA_GetPacketByID(dwPacket), eElement); |
156 } | 151 } |
157 | 152 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 XFA_VERSION eVersion = (XFA_VERSION)((int32_t)iMajor * 100 + iMinor); | 256 XFA_VERSION eVersion = (XFA_VERSION)((int32_t)iMajor * 100 + iMinor); |
262 if (eVersion < XFA_VERSION_MIN || eVersion > XFA_VERSION_MAX) { | 257 if (eVersion < XFA_VERSION_MIN || eVersion > XFA_VERSION_MAX) { |
263 return XFA_VERSION_UNKNOWN; | 258 return XFA_VERSION_UNKNOWN; |
264 } | 259 } |
265 m_eCurVersionMode = eVersion; | 260 m_eCurVersionMode = eVersion; |
266 return eVersion; | 261 return eVersion; |
267 } | 262 } |
268 CXFA_Node* CXFA_Document::GetNodeByID(CXFA_Node* pRoot, | 263 CXFA_Node* CXFA_Document::GetNodeByID(CXFA_Node* pRoot, |
269 const CFX_WideStringC& wsID) { | 264 const CFX_WideStringC& wsID) { |
270 if (!pRoot || wsID.IsEmpty()) { | 265 if (!pRoot || wsID.IsEmpty()) { |
271 return NULL; | 266 return nullptr; |
272 } | 267 } |
273 CXFA_NodeIterator sIterator(pRoot); | 268 CXFA_NodeIterator sIterator(pRoot); |
274 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; | 269 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; |
275 pNode = sIterator.MoveToNext()) { | 270 pNode = sIterator.MoveToNext()) { |
276 CFX_WideStringC wsIDVal; | 271 CFX_WideStringC wsIDVal; |
277 if (pNode->TryCData(XFA_ATTRIBUTE_Id, wsIDVal) && !wsIDVal.IsEmpty()) { | 272 if (pNode->TryCData(XFA_ATTRIBUTE_Id, wsIDVal) && !wsIDVal.IsEmpty()) { |
278 if (wsIDVal == wsID) { | 273 if (wsIDVal == wsID) { |
279 return pNode; | 274 return pNode; |
280 } | 275 } |
281 } | 276 } |
282 } | 277 } |
283 return NULL; | 278 return nullptr; |
284 } | 279 } |
285 static void XFA_ProtoMerge_MergeNodeRecurse(CXFA_Document* pDocument, | 280 static void XFA_ProtoMerge_MergeNodeRecurse(CXFA_Document* pDocument, |
286 CXFA_Node* pDestNodeParent, | 281 CXFA_Node* pDestNodeParent, |
287 CXFA_Node* pProtoNode) { | 282 CXFA_Node* pProtoNode) { |
288 CXFA_Node* pExistingNode = NULL; | 283 CXFA_Node* pExistingNode = nullptr; |
289 for (CXFA_Node* pFormChild = | 284 for (CXFA_Node* pFormChild = |
290 pDestNodeParent->GetNodeItem(XFA_NODEITEM_FirstChild); | 285 pDestNodeParent->GetNodeItem(XFA_NODEITEM_FirstChild); |
291 pFormChild; | 286 pFormChild; |
292 pFormChild = pFormChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { | 287 pFormChild = pFormChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
293 if (pFormChild->GetElementType() == pProtoNode->GetElementType() && | 288 if (pFormChild->GetElementType() == pProtoNode->GetElementType() && |
294 pFormChild->GetNameHash() == pProtoNode->GetNameHash() && | 289 pFormChild->GetNameHash() == pProtoNode->GetNameHash() && |
295 pFormChild->IsUnusedNode()) { | 290 pFormChild->IsUnusedNode()) { |
296 pFormChild->ClearFlag(XFA_NodeFlag_UnusedNode); | 291 pFormChild->ClearFlag(XFA_NodeFlag_UnusedNode); |
297 pExistingNode = pFormChild; | 292 pExistingNode = pFormChild; |
298 break; | 293 break; |
299 } | 294 } |
300 } | 295 } |
301 if (pExistingNode) { | 296 if (pExistingNode) { |
302 pExistingNode->SetTemplateNode(pProtoNode); | 297 pExistingNode->SetTemplateNode(pProtoNode); |
303 for (CXFA_Node* pTemplateChild = | 298 for (CXFA_Node* pTemplateChild = |
304 pProtoNode->GetNodeItem(XFA_NODEITEM_FirstChild); | 299 pProtoNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
305 pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( | 300 pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( |
306 XFA_NODEITEM_NextSibling)) { | 301 XFA_NODEITEM_NextSibling)) { |
307 XFA_ProtoMerge_MergeNodeRecurse(pDocument, pExistingNode, pTemplateChild); | 302 XFA_ProtoMerge_MergeNodeRecurse(pDocument, pExistingNode, pTemplateChild); |
308 } | 303 } |
309 return; | 304 return; |
310 } | 305 } |
311 CXFA_Node* pNewNode = pProtoNode->Clone(TRUE); | 306 CXFA_Node* pNewNode = pProtoNode->Clone(TRUE); |
312 pNewNode->SetTemplateNode(pProtoNode); | 307 pNewNode->SetTemplateNode(pProtoNode); |
313 pDestNodeParent->InsertChild(pNewNode, NULL); | 308 pDestNodeParent->InsertChild(pNewNode, nullptr); |
314 } | 309 } |
315 static void XFA_ProtoMerge_MergeNode(CXFA_Document* pDocument, | 310 static void XFA_ProtoMerge_MergeNode(CXFA_Document* pDocument, |
316 CXFA_Node* pDestNode, | 311 CXFA_Node* pDestNode, |
317 CXFA_Node* pProtoNode) { | 312 CXFA_Node* pProtoNode) { |
318 { | 313 { |
319 CXFA_NodeIterator sIterator(pDestNode); | 314 CXFA_NodeIterator sIterator(pDestNode); |
320 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; | 315 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; |
321 pNode = sIterator.MoveToNext()) { | 316 pNode = sIterator.MoveToNext()) { |
322 pNode->SetFlag(XFA_NodeFlag_UnusedNode, true); | 317 pNode->SetFlag(XFA_NodeFlag_UnusedNode, true); |
323 } | 318 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 !wsUseVal.IsEmpty()) { | 380 !wsUseVal.IsEmpty()) { |
386 if (wsUseVal[0] == '#') { | 381 if (wsUseVal[0] == '#') { |
387 wsID = CFX_WideStringC(wsUseVal.c_str() + 1, wsUseVal.GetLength() - 1); | 382 wsID = CFX_WideStringC(wsUseVal.c_str() + 1, wsUseVal.GetLength() - 1); |
388 } else { | 383 } else { |
389 wsSOM = CFX_WideStringC(wsUseVal.c_str(), wsUseVal.GetLength()); | 384 wsSOM = CFX_WideStringC(wsUseVal.c_str(), wsUseVal.GetLength()); |
390 } | 385 } |
391 } | 386 } |
392 if (!wsURI.IsEmpty() && wsURI != FX_WSTRC(L".")) { | 387 if (!wsURI.IsEmpty() && wsURI != FX_WSTRC(L".")) { |
393 continue; | 388 continue; |
394 } | 389 } |
395 CXFA_Node* pProtoNode = NULL; | 390 CXFA_Node* pProtoNode = nullptr; |
396 if (!wsSOM.IsEmpty()) { | 391 if (!wsSOM.IsEmpty()) { |
397 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | | 392 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
398 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | | 393 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
399 XFA_RESOLVENODE_Siblings; | 394 XFA_RESOLVENODE_Siblings; |
400 XFA_RESOLVENODE_RS resoveNodeRS; | 395 XFA_RESOLVENODE_RS resoveNodeRS; |
401 int32_t iRet = m_pScriptContext->ResolveObjects(pUseHrefNode, wsSOM, | 396 int32_t iRet = m_pScriptContext->ResolveObjects(pUseHrefNode, wsSOM, |
402 resoveNodeRS, dwFlag); | 397 resoveNodeRS, dwFlag); |
403 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) { | 398 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) { |
404 pProtoNode = resoveNodeRS.nodes[0]->AsNode(); | 399 pProtoNode = resoveNodeRS.nodes[0]->AsNode(); |
405 } | 400 } |
406 } else if (!wsID.IsEmpty()) { | 401 } else if (!wsID.IsEmpty()) { |
407 if (!mIDMap.Lookup(FX_HashCode_GetW(wsID, false), pProtoNode)) { | 402 if (!mIDMap.Lookup(FX_HashCode_GetW(wsID, false), pProtoNode)) { |
408 continue; | 403 continue; |
409 } | 404 } |
410 } | 405 } |
411 if (!pProtoNode) { | 406 if (!pProtoNode) { |
412 continue; | 407 continue; |
413 } | 408 } |
414 XFA_ProtoMerge_MergeNode(this, pUseHrefNode, pProtoNode); | 409 XFA_ProtoMerge_MergeNode(this, pUseHrefNode, pProtoNode); |
415 } | 410 } |
416 } | 411 } |
OLD | NEW |