| 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/fxfa/parser/xfa_document_datamerger_imp.h" | 7 #include "xfa/fxfa/parser/xfa_document_datamerger_imp.h" |
| 8 | 8 |
| 9 #include <map> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "core/fxcrt/fx_ext.h" | 12 #include "core/fxcrt/fx_ext.h" |
| 12 #include "third_party/base/stl_util.h" | 13 #include "third_party/base/stl_util.h" |
| 13 #include "xfa/fde/xml/fde_xml_imp.h" | 14 #include "xfa/fde/xml/fde_xml_imp.h" |
| 14 #include "xfa/fxfa/parser/cxfa_document.h" | 15 #include "xfa/fxfa/parser/cxfa_document.h" |
| 15 #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" | 16 #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" |
| 16 #include "xfa/fxfa/parser/cxfa_occur.h" | 17 #include "xfa/fxfa/parser/cxfa_occur.h" |
| 17 #include "xfa/fxfa/parser/cxfa_scriptcontext.h" | 18 #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
| 18 #include "xfa/fxfa/parser/xfa_localemgr.h" | 19 #include "xfa/fxfa/parser/xfa_localemgr.h" |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 case XFA_Element::Signature: | 350 case XFA_Element::Signature: |
| 350 case XFA_Element::TextEdit: | 351 case XFA_Element::TextEdit: |
| 351 default: | 352 default: |
| 352 FormValueNode_SetChildContent(defValue.GetNode(), wsNormalizeValue, | 353 FormValueNode_SetChildContent(defValue.GetNode(), wsNormalizeValue, |
| 353 XFA_Element::Text); | 354 XFA_Element::Text); |
| 354 break; | 355 break; |
| 355 } | 356 } |
| 356 } | 357 } |
| 357 | 358 |
| 358 CXFA_Node* GetGlobalBinding(CXFA_Document* pDocument, uint32_t dwNameHash) { | 359 CXFA_Node* GetGlobalBinding(CXFA_Document* pDocument, uint32_t dwNameHash) { |
| 359 CXFA_Node* pNode = nullptr; | 360 auto it = pDocument->m_rgGlobalBinding.find(dwNameHash); |
| 360 pDocument->m_rgGlobalBinding.Lookup(dwNameHash, pNode); | 361 return it != pDocument->m_rgGlobalBinding.end() ? it->second : nullptr; |
| 361 return pNode; | |
| 362 } | 362 } |
| 363 | 363 |
| 364 void RegisterGlobalBinding(CXFA_Document* pDocument, | 364 void RegisterGlobalBinding(CXFA_Document* pDocument, |
| 365 uint32_t dwNameHash, | 365 uint32_t dwNameHash, |
| 366 CXFA_Node* pDataNode) { | 366 CXFA_Node* pDataNode) { |
| 367 pDocument->m_rgGlobalBinding.SetAt(dwNameHash, pDataNode); | 367 pDocument->m_rgGlobalBinding[dwNameHash] = pDataNode; |
| 368 } | 368 } |
| 369 | 369 |
| 370 CXFA_Node* ScopeMatchGlobalBinding(CXFA_Node* pDataScope, | 370 CXFA_Node* ScopeMatchGlobalBinding(CXFA_Node* pDataScope, |
| 371 uint32_t dwNameHash, | 371 uint32_t dwNameHash, |
| 372 XFA_Element eMatchDataNodeType, | 372 XFA_Element eMatchDataNodeType, |
| 373 bool bUpLevel) { | 373 bool bUpLevel) { |
| 374 for (CXFA_Node *pCurDataScope = pDataScope, *pLastDataScope = nullptr; | 374 for (CXFA_Node *pCurDataScope = pDataScope, *pLastDataScope = nullptr; |
| 375 pCurDataScope && pCurDataScope->GetPacketID() == XFA_XDPPACKET_Datasets; | 375 pCurDataScope && pCurDataScope->GetPacketID() == XFA_XDPPACKET_Datasets; |
| 376 pLastDataScope = pCurDataScope, | 376 pLastDataScope = pCurDataScope, |
| 377 pCurDataScope = | 377 pCurDataScope = |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 : XFA_ATTRIBUTEENUM_Ordered; | 746 : XFA_ATTRIBUTEENUM_Ordered; |
| 747 int32_t iCurRepeatIndex = 0; | 747 int32_t iCurRepeatIndex = 0; |
| 748 XFA_ATTRIBUTEENUM eParentBindMatch = XFA_ATTRIBUTEENUM_None; | 748 XFA_ATTRIBUTEENUM eParentBindMatch = XFA_ATTRIBUTEENUM_None; |
| 749 if (bDataMerge) { | 749 if (bDataMerge) { |
| 750 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> | 750 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> |
| 751 sNodeIterator(pTemplateNode); | 751 sNodeIterator(pTemplateNode); |
| 752 bool bAccessedDataDOM = false; | 752 bool bAccessedDataDOM = false; |
| 753 if (eType == XFA_Element::SubformSet || eType == XFA_Element::Area) { | 753 if (eType == XFA_Element::SubformSet || eType == XFA_Element::Area) { |
| 754 sNodeIterator.MoveToNext(); | 754 sNodeIterator.MoveToNext(); |
| 755 } else { | 755 } else { |
| 756 CFX_MapPtrTemplate<CXFA_Node*, CXFA_Node*> subformMapArray; | 756 std::map<CXFA_Node*, CXFA_Node*> subformMapArray; |
| 757 CXFA_NodeArray nodeArray; | 757 CXFA_NodeArray nodeArray; |
| 758 for (; iMax < 0 || iCurRepeatIndex < iMax; iCurRepeatIndex++) { | 758 for (; iMax < 0 || iCurRepeatIndex < iMax; iCurRepeatIndex++) { |
| 759 bool bSelfMatch = false; | 759 bool bSelfMatch = false; |
| 760 XFA_ATTRIBUTEENUM eBindMatch = XFA_ATTRIBUTEENUM_None; | 760 XFA_ATTRIBUTEENUM eBindMatch = XFA_ATTRIBUTEENUM_None; |
| 761 CXFA_Node* pDataNode = FindMatchingDataNode( | 761 CXFA_Node* pDataNode = FindMatchingDataNode( |
| 762 pDocument, pTemplateNode, pDataScope, bAccessedDataDOM, false, | 762 pDocument, pTemplateNode, pDataScope, bAccessedDataDOM, false, |
| 763 &sNodeIterator, bSelfMatch, eBindMatch, true); | 763 &sNodeIterator, bSelfMatch, eBindMatch, true); |
| 764 if (!pDataNode || sNodeIterator.GetCurrent() != pTemplateNode) | 764 if (!pDataNode || sNodeIterator.GetCurrent() != pTemplateNode) |
| 765 break; | 765 break; |
| 766 | 766 |
| 767 eParentBindMatch = eBindMatch; | 767 eParentBindMatch = eBindMatch; |
| 768 CXFA_Node* pSubformNode = XFA_NodeMerge_CloneOrMergeContainer( | 768 CXFA_Node* pSubformNode = XFA_NodeMerge_CloneOrMergeContainer( |
| 769 pDocument, pFormParentNode, pTemplateNode, false, pSearchArray); | 769 pDocument, pFormParentNode, pTemplateNode, false, pSearchArray); |
| 770 if (!pFirstInstance) | 770 if (!pFirstInstance) |
| 771 pFirstInstance = pSubformNode; | 771 pFirstInstance = pSubformNode; |
| 772 | 772 |
| 773 CreateDataBinding(pSubformNode, pDataNode, true); | 773 CreateDataBinding(pSubformNode, pDataNode, true); |
| 774 ASSERT(pSubformNode); | 774 ASSERT(pSubformNode); |
| 775 subformMapArray.SetAt(pSubformNode, pDataNode); | 775 subformMapArray[pSubformNode] = pDataNode; |
| 776 nodeArray.Add(pSubformNode); | 776 nodeArray.Add(pSubformNode); |
| 777 } | 777 } |
| 778 | 778 |
| 779 subformMapArray.GetStartPosition(); | |
| 780 for (int32_t iIndex = 0; iIndex < nodeArray.GetSize(); iIndex++) { | 779 for (int32_t iIndex = 0; iIndex < nodeArray.GetSize(); iIndex++) { |
| 781 CXFA_Node* pSubform = nodeArray[iIndex]; | 780 CXFA_Node* pSubform = nodeArray[iIndex]; |
| 782 CXFA_Node* pDataNode = | 781 CXFA_Node* pDataNode = nullptr; |
| 783 reinterpret_cast<CXFA_Node*>(subformMapArray.GetValueAt(pSubform)); | 782 auto it = subformMapArray.find(pSubform); |
| 783 if (it != subformMapArray.end()) |
| 784 pDataNode = it->second; |
| 784 for (CXFA_Node* pTemplateChild = | 785 for (CXFA_Node* pTemplateChild = |
| 785 pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); | 786 pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 786 pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( | 787 pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( |
| 787 XFA_NODEITEM_NextSibling)) { | 788 XFA_NODEITEM_NextSibling)) { |
| 788 if (NeedGenerateForm(pTemplateChild, bUseInstanceManager)) { | 789 if (NeedGenerateForm(pTemplateChild, bUseInstanceManager)) { |
| 789 XFA_NodeMerge_CloneOrMergeContainer(pDocument, pSubform, | 790 XFA_NodeMerge_CloneOrMergeContainer(pDocument, pSubform, |
| 790 pTemplateChild, true, nullptr); | 791 pTemplateChild, true, nullptr); |
| 791 } else if (pTemplateChild->IsContainerNode()) { | 792 } else if (pTemplateChild->IsContainerNode()) { |
| 792 pDocument->DataMerge_CopyContainer(pTemplateChild, pSubform, | 793 pDocument->DataMerge_CopyContainer(pTemplateChild, pSubform, |
| 793 pDataNode, false, true, false); | 794 pDataNode, false, true, false); |
| 794 } | 795 } |
| 795 } | 796 } |
| 796 } | 797 } |
| 797 subformMapArray.RemoveAll(); | 798 subformMapArray.clear(); |
| 798 } | 799 } |
| 799 | 800 |
| 800 for (; iMax < 0 || iCurRepeatIndex < iMax; iCurRepeatIndex++) { | 801 for (; iMax < 0 || iCurRepeatIndex < iMax; iCurRepeatIndex++) { |
| 801 bool bSelfMatch = false; | 802 bool bSelfMatch = false; |
| 802 XFA_ATTRIBUTEENUM eBindMatch = XFA_ATTRIBUTEENUM_None; | 803 XFA_ATTRIBUTEENUM eBindMatch = XFA_ATTRIBUTEENUM_None; |
| 803 if (!FindMatchingDataNode(pDocument, pTemplateNode, pDataScope, | 804 if (!FindMatchingDataNode(pDocument, pTemplateNode, pDataScope, |
| 804 bAccessedDataDOM, false, &sNodeIterator, | 805 bAccessedDataDOM, false, &sNodeIterator, |
| 805 bSelfMatch, eBindMatch, true)) { | 806 bSelfMatch, eBindMatch, true)) { |
| 806 break; | 807 break; |
| 807 } | 808 } |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 } | 1515 } |
| 1515 } | 1516 } |
| 1516 | 1517 |
| 1517 void CXFA_Document::DoDataRemerge(bool bDoDataMerge) { | 1518 void CXFA_Document::DoDataRemerge(bool bDoDataMerge) { |
| 1518 CXFA_Node* pFormRoot = ToNode(GetXFAObject(XFA_HASHCODE_Form)); | 1519 CXFA_Node* pFormRoot = ToNode(GetXFAObject(XFA_HASHCODE_Form)); |
| 1519 if (pFormRoot) { | 1520 if (pFormRoot) { |
| 1520 while (CXFA_Node* pNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) | 1521 while (CXFA_Node* pNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) |
| 1521 pFormRoot->RemoveChild(pNode); | 1522 pFormRoot->RemoveChild(pNode); |
| 1522 pFormRoot->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); | 1523 pFormRoot->SetObject(XFA_ATTRIBUTE_BindingNode, nullptr); |
| 1523 } | 1524 } |
| 1524 m_rgGlobalBinding.RemoveAll(); | 1525 m_rgGlobalBinding.clear(); |
| 1525 if (bDoDataMerge) | 1526 if (bDoDataMerge) |
| 1526 DoDataMerge(); | 1527 DoDataMerge(); |
| 1527 | 1528 |
| 1528 CXFA_LayoutProcessor* pLayoutProcessor = GetLayoutProcessor(); | 1529 CXFA_LayoutProcessor* pLayoutProcessor = GetLayoutProcessor(); |
| 1529 pLayoutProcessor->SetForceReLayout(true); | 1530 pLayoutProcessor->SetForceReLayout(true); |
| 1530 } | 1531 } |
| OLD | NEW |