Chromium Code Reviews| 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 } | 108 } |
| 109 return NULL; | 109 return nullptr; |
|
Lei Zhang
2016/06/23 18:27:41
Funny indentation heer.
dsinclair
2016/06/23 18:46:54
It's the wacky {} thing they do were they put the
| |
| 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 } |
| 118 return m_pScriptDataWindow; | 119 return m_pScriptDataWindow; |
| 119 } | 120 } |
| 120 case XFA_HASHCODE_Event: { | 121 case XFA_HASHCODE_Event: { |
| 121 if (m_pScriptEvent == NULL) { | 122 if (!m_pScriptEvent) { |
| 122 m_pScriptEvent = new CScript_EventPseudoModel(this); | 123 m_pScriptEvent = new CScript_EventPseudoModel(this); |
| 123 } | 124 } |
| 124 return m_pScriptEvent; | 125 return m_pScriptEvent; |
| 125 } | 126 } |
| 126 case XFA_HASHCODE_Host: { | 127 case XFA_HASHCODE_Host: { |
| 127 if (m_pScriptHost == NULL) { | 128 if (!m_pScriptHost) { |
| 128 m_pScriptHost = new CScript_HostPseudoModel(this); | 129 m_pScriptHost = new CScript_HostPseudoModel(this); |
| 129 } | 130 } |
| 130 return m_pScriptHost; | 131 return m_pScriptHost; |
| 131 } | 132 } |
| 132 case XFA_HASHCODE_Log: { | 133 case XFA_HASHCODE_Log: { |
| 133 if (m_pScriptLog == NULL) { | 134 if (!m_pScriptLog) { |
| 134 m_pScriptLog = new CScript_LogPseudoModel(this); | 135 m_pScriptLog = new CScript_LogPseudoModel(this); |
| 135 } | 136 } |
| 136 return m_pScriptLog; | 137 return m_pScriptLog; |
| 137 } | 138 } |
| 138 case XFA_HASHCODE_Signature: { | 139 case XFA_HASHCODE_Signature: { |
| 139 if (m_pScriptSignature == NULL) { | 140 if (!m_pScriptSignature) { |
| 140 m_pScriptSignature = new CScript_SignaturePseudoModel(this); | 141 m_pScriptSignature = new CScript_SignaturePseudoModel(this); |
| 141 } | 142 } |
| 142 return m_pScriptSignature; | 143 return m_pScriptSignature; |
| 143 } | 144 } |
| 144 case XFA_HASHCODE_Layout: { | 145 case XFA_HASHCODE_Layout: { |
| 145 if (m_pScriptLayout == NULL) { | 146 if (!m_pScriptLayout) { |
| 146 m_pScriptLayout = new CScript_LayoutPseudoModel(this); | 147 m_pScriptLayout = new CScript_LayoutPseudoModel(this); |
| 147 } | 148 } |
| 148 return m_pScriptLayout; | 149 return m_pScriptLayout; |
| 149 } | 150 } |
| 150 default: | 151 default: |
| 151 return m_pRootNode->GetFirstChildByName(dwNodeNameHash); | 152 return m_pRootNode->GetFirstChildByName(dwNodeNameHash); |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 CXFA_Node* CXFA_Document::CreateNode(uint32_t dwPacket, XFA_Element eElement) { | 155 CXFA_Node* CXFA_Document::CreateNode(uint32_t dwPacket, XFA_Element eElement) { |
| 155 return CreateNode(XFA_GetPacketByID(dwPacket), eElement); | 156 return CreateNode(XFA_GetPacketByID(dwPacket), eElement); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 XFA_VERSION eVersion = (XFA_VERSION)((int32_t)iMajor * 100 + iMinor); | 262 XFA_VERSION eVersion = (XFA_VERSION)((int32_t)iMajor * 100 + iMinor); |
| 262 if (eVersion < XFA_VERSION_MIN || eVersion > XFA_VERSION_MAX) { | 263 if (eVersion < XFA_VERSION_MIN || eVersion > XFA_VERSION_MAX) { |
| 263 return XFA_VERSION_UNKNOWN; | 264 return XFA_VERSION_UNKNOWN; |
| 264 } | 265 } |
| 265 m_eCurVersionMode = eVersion; | 266 m_eCurVersionMode = eVersion; |
| 266 return eVersion; | 267 return eVersion; |
| 267 } | 268 } |
| 268 CXFA_Node* CXFA_Document::GetNodeByID(CXFA_Node* pRoot, | 269 CXFA_Node* CXFA_Document::GetNodeByID(CXFA_Node* pRoot, |
| 269 const CFX_WideStringC& wsID) { | 270 const CFX_WideStringC& wsID) { |
| 270 if (!pRoot || wsID.IsEmpty()) { | 271 if (!pRoot || wsID.IsEmpty()) { |
| 271 return NULL; | 272 return nullptr; |
| 272 } | 273 } |
| 273 CXFA_NodeIterator sIterator(pRoot); | 274 CXFA_NodeIterator sIterator(pRoot); |
| 274 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; | 275 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; |
| 275 pNode = sIterator.MoveToNext()) { | 276 pNode = sIterator.MoveToNext()) { |
| 276 CFX_WideStringC wsIDVal; | 277 CFX_WideStringC wsIDVal; |
| 277 if (pNode->TryCData(XFA_ATTRIBUTE_Id, wsIDVal) && !wsIDVal.IsEmpty()) { | 278 if (pNode->TryCData(XFA_ATTRIBUTE_Id, wsIDVal) && !wsIDVal.IsEmpty()) { |
| 278 if (wsIDVal == wsID) { | 279 if (wsIDVal == wsID) { |
| 279 return pNode; | 280 return pNode; |
| 280 } | 281 } |
| 281 } | 282 } |
| 282 } | 283 } |
| 283 return NULL; | 284 return nullptr; |
| 284 } | 285 } |
| 285 static void XFA_ProtoMerge_MergeNodeRecurse(CXFA_Document* pDocument, | 286 static void XFA_ProtoMerge_MergeNodeRecurse(CXFA_Document* pDocument, |
| 286 CXFA_Node* pDestNodeParent, | 287 CXFA_Node* pDestNodeParent, |
| 287 CXFA_Node* pProtoNode) { | 288 CXFA_Node* pProtoNode) { |
| 288 CXFA_Node* pExistingNode = NULL; | 289 CXFA_Node* pExistingNode = nullptr; |
| 289 for (CXFA_Node* pFormChild = | 290 for (CXFA_Node* pFormChild = |
| 290 pDestNodeParent->GetNodeItem(XFA_NODEITEM_FirstChild); | 291 pDestNodeParent->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 291 pFormChild; | 292 pFormChild; |
| 292 pFormChild = pFormChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { | 293 pFormChild = pFormChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 293 if (pFormChild->GetElementType() == pProtoNode->GetElementType() && | 294 if (pFormChild->GetElementType() == pProtoNode->GetElementType() && |
| 294 pFormChild->GetNameHash() == pProtoNode->GetNameHash() && | 295 pFormChild->GetNameHash() == pProtoNode->GetNameHash() && |
| 295 pFormChild->IsUnusedNode()) { | 296 pFormChild->IsUnusedNode()) { |
| 296 pFormChild->ClearFlag(XFA_NodeFlag_UnusedNode); | 297 pFormChild->ClearFlag(XFA_NodeFlag_UnusedNode); |
| 297 pExistingNode = pFormChild; | 298 pExistingNode = pFormChild; |
| 298 break; | 299 break; |
| 299 } | 300 } |
| 300 } | 301 } |
| 301 if (pExistingNode) { | 302 if (pExistingNode) { |
| 302 pExistingNode->SetTemplateNode(pProtoNode); | 303 pExistingNode->SetTemplateNode(pProtoNode); |
| 303 for (CXFA_Node* pTemplateChild = | 304 for (CXFA_Node* pTemplateChild = |
| 304 pProtoNode->GetNodeItem(XFA_NODEITEM_FirstChild); | 305 pProtoNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 305 pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( | 306 pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( |
| 306 XFA_NODEITEM_NextSibling)) { | 307 XFA_NODEITEM_NextSibling)) { |
| 307 XFA_ProtoMerge_MergeNodeRecurse(pDocument, pExistingNode, pTemplateChild); | 308 XFA_ProtoMerge_MergeNodeRecurse(pDocument, pExistingNode, pTemplateChild); |
| 308 } | 309 } |
| 309 return; | 310 return; |
| 310 } | 311 } |
| 311 CXFA_Node* pNewNode = pProtoNode->Clone(TRUE); | 312 CXFA_Node* pNewNode = pProtoNode->Clone(TRUE); |
| 312 pNewNode->SetTemplateNode(pProtoNode); | 313 pNewNode->SetTemplateNode(pProtoNode); |
| 313 pDestNodeParent->InsertChild(pNewNode, NULL); | 314 pDestNodeParent->InsertChild(pNewNode, nullptr); |
| 314 } | 315 } |
| 315 static void XFA_ProtoMerge_MergeNode(CXFA_Document* pDocument, | 316 static void XFA_ProtoMerge_MergeNode(CXFA_Document* pDocument, |
| 316 CXFA_Node* pDestNode, | 317 CXFA_Node* pDestNode, |
| 317 CXFA_Node* pProtoNode) { | 318 CXFA_Node* pProtoNode) { |
| 318 { | 319 { |
| 319 CXFA_NodeIterator sIterator(pDestNode); | 320 CXFA_NodeIterator sIterator(pDestNode); |
| 320 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; | 321 for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; |
| 321 pNode = sIterator.MoveToNext()) { | 322 pNode = sIterator.MoveToNext()) { |
| 322 pNode->SetFlag(XFA_NodeFlag_UnusedNode, true); | 323 pNode->SetFlag(XFA_NodeFlag_UnusedNode, true); |
| 323 } | 324 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 !wsUseVal.IsEmpty()) { | 386 !wsUseVal.IsEmpty()) { |
| 386 if (wsUseVal[0] == '#') { | 387 if (wsUseVal[0] == '#') { |
| 387 wsID = CFX_WideStringC(wsUseVal.c_str() + 1, wsUseVal.GetLength() - 1); | 388 wsID = CFX_WideStringC(wsUseVal.c_str() + 1, wsUseVal.GetLength() - 1); |
| 388 } else { | 389 } else { |
| 389 wsSOM = CFX_WideStringC(wsUseVal.c_str(), wsUseVal.GetLength()); | 390 wsSOM = CFX_WideStringC(wsUseVal.c_str(), wsUseVal.GetLength()); |
| 390 } | 391 } |
| 391 } | 392 } |
| 392 if (!wsURI.IsEmpty() && wsURI != FX_WSTRC(L".")) { | 393 if (!wsURI.IsEmpty() && wsURI != FX_WSTRC(L".")) { |
| 393 continue; | 394 continue; |
| 394 } | 395 } |
| 395 CXFA_Node* pProtoNode = NULL; | 396 CXFA_Node* pProtoNode = nullptr; |
| 396 if (!wsSOM.IsEmpty()) { | 397 if (!wsSOM.IsEmpty()) { |
| 397 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | | 398 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes | |
| 398 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | | 399 XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Parent | |
| 399 XFA_RESOLVENODE_Siblings; | 400 XFA_RESOLVENODE_Siblings; |
| 400 XFA_RESOLVENODE_RS resoveNodeRS; | 401 XFA_RESOLVENODE_RS resoveNodeRS; |
| 401 int32_t iRet = m_pScriptContext->ResolveObjects(pUseHrefNode, wsSOM, | 402 int32_t iRet = m_pScriptContext->ResolveObjects(pUseHrefNode, wsSOM, |
| 402 resoveNodeRS, dwFlag); | 403 resoveNodeRS, dwFlag); |
| 403 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) { | 404 if (iRet > 0 && resoveNodeRS.nodes[0]->IsNode()) { |
| 404 pProtoNode = resoveNodeRS.nodes[0]->AsNode(); | 405 pProtoNode = resoveNodeRS.nodes[0]->AsNode(); |
| 405 } | 406 } |
| 406 } else if (!wsID.IsEmpty()) { | 407 } else if (!wsID.IsEmpty()) { |
| 407 if (!mIDMap.Lookup(FX_HashCode_GetW(wsID, false), pProtoNode)) { | 408 if (!mIDMap.Lookup(FX_HashCode_GetW(wsID, false), pProtoNode)) { |
| 408 continue; | 409 continue; |
| 409 } | 410 } |
| 410 } | 411 } |
| 411 if (!pProtoNode) { | 412 if (!pProtoNode) { |
| 412 continue; | 413 continue; |
| 413 } | 414 } |
| 414 XFA_ProtoMerge_MergeNode(this, pUseHrefNode, pProtoNode); | 415 XFA_ProtoMerge_MergeNode(this, pUseHrefNode, pProtoNode); |
| 415 } | 416 } |
| 416 } | 417 } |
| OLD | NEW |