Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Side by Side Diff: xfa/fxfa/parser/xfa_document_datamerger_imp.cpp

Issue 1890563003: Simplify XFA event handling. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: address comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "core/fxcrt/include/fx_ext.h" 9 #include "core/fxcrt/include/fx_ext.h"
10 #include "xfa/fde/xml/fde_xml_imp.h" 10 #include "xfa/fde/xml/fde_xml_imp.h"
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 pExistingNode = pSubformArray->GetAt(0); 518 pExistingNode = pSubformArray->GetAt(0);
519 pSubformArray->RemoveAt(0); 519 pSubformArray->RemoveAt(0);
520 } 520 }
521 if (pExistingNode) { 521 if (pExistingNode) {
522 if (pSubformArray) { 522 if (pSubformArray) {
523 pFormParent->InsertChild(pExistingNode); 523 pFormParent->InsertChild(pExistingNode);
524 } else if (pExistingNode->IsContainerNode()) { 524 } else if (pExistingNode->IsContainerNode()) {
525 pFormParent->RemoveChild(pExistingNode); 525 pFormParent->RemoveChild(pExistingNode);
526 pFormParent->InsertChild(pExistingNode); 526 pFormParent->InsertChild(pExistingNode);
527 } 527 }
528 pExistingNode->SetFlag(XFA_NODEFLAG_UnusedNode, FALSE); 528 pExistingNode->ClearFlag(XFA_NODEFLAG_UnusedNode);
529 pExistingNode->SetTemplateNode(pTemplateNode); 529 pExistingNode->SetTemplateNode(pTemplateNode);
530 if (bRecursive && pExistingNode->GetClassID() != XFA_ELEMENT_Items) { 530 if (bRecursive && pExistingNode->GetClassID() != XFA_ELEMENT_Items) {
531 for (CXFA_Node* pTemplateChild = 531 for (CXFA_Node* pTemplateChild =
532 pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); 532 pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild);
533 pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( 533 pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem(
534 XFA_NODEITEM_NextSibling)) { 534 XFA_NODEITEM_NextSibling)) {
535 if (XFA_NeedGenerateForm(pTemplateChild)) { 535 if (XFA_NeedGenerateForm(pTemplateChild)) {
536 XFA_NodeMerge_CloneOrMergeContainer(pDocument, pExistingNode, 536 XFA_NodeMerge_CloneOrMergeContainer(pDocument, pExistingNode,
537 pTemplateChild, bRecursive); 537 pTemplateChild, bRecursive);
538 } 538 }
539 } 539 }
540 } 540 }
541 pExistingNode->SetFlag(XFA_NODEFLAG_Initialized); 541 pExistingNode->SetFlag(XFA_NODEFLAG_Initialized, true);
542 return pExistingNode; 542 return pExistingNode;
543 } 543 }
544 CXFA_Node* pNewNode = pTemplateNode->CloneTemplateToForm(FALSE); 544 CXFA_Node* pNewNode = pTemplateNode->CloneTemplateToForm(FALSE);
545 pFormParent->InsertChild(pNewNode, NULL); 545 pFormParent->InsertChild(pNewNode, NULL);
546 if (bRecursive) { 546 if (bRecursive) {
547 for (CXFA_Node* pTemplateChild = 547 for (CXFA_Node* pTemplateChild =
548 pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild); 548 pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild);
549 pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem( 549 pTemplateChild; pTemplateChild = pTemplateChild->GetNodeItem(
550 XFA_NODEITEM_NextSibling)) { 550 XFA_NODEITEM_NextSibling)) {
551 if (XFA_NeedGenerateForm(pTemplateChild)) { 551 if (XFA_NeedGenerateForm(pTemplateChild)) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 if (dwNameHash != pNode->GetNameHash()) { 584 if (dwNameHash != pNode->GetNameHash()) {
585 break; 585 break;
586 } 586 }
587 CXFA_Node* pNextNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); 587 CXFA_Node* pNextNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling);
588 pFormParent->RemoveChild(pNode); 588 pFormParent->RemoveChild(pNode);
589 subforms.Add(pNode); 589 subforms.Add(pNode);
590 pNode = pNextNode; 590 pNode = pNextNode;
591 } 591 }
592 pFormParent->RemoveChild(pExistingNode); 592 pFormParent->RemoveChild(pExistingNode);
593 pFormParent->InsertChild(pExistingNode); 593 pFormParent->InsertChild(pExistingNode);
594 pExistingNode->SetFlag(XFA_NODEFLAG_UnusedNode, FALSE); 594 pExistingNode->ClearFlag(XFA_NODEFLAG_UnusedNode);
595 pExistingNode->SetTemplateNode(pTemplateNode); 595 pExistingNode->SetTemplateNode(pTemplateNode);
596 return pExistingNode; 596 return pExistingNode;
597 } 597 }
598 CXFA_Node* pNewNode = pDocument->GetParser()->GetFactory()->CreateNode( 598 CXFA_Node* pNewNode = pDocument->GetParser()->GetFactory()->CreateNode(
599 XFA_XDPPACKET_Form, XFA_ELEMENT_InstanceManager); 599 XFA_XDPPACKET_Form, XFA_ELEMENT_InstanceManager);
600 FXSYS_assert(pNewNode); 600 FXSYS_assert(pNewNode);
601 wsInstMgrNodeName = 601 wsInstMgrNodeName =
602 FX_WSTRC(L"_") + pTemplateNode->GetCData(XFA_ATTRIBUTE_Name); 602 FX_WSTRC(L"_") + pTemplateNode->GetCData(XFA_ATTRIBUTE_Name);
603 pNewNode->SetCData(XFA_ATTRIBUTE_Name, wsInstMgrNodeName); 603 pNewNode->SetCData(XFA_ATTRIBUTE_Name, wsInstMgrNodeName);
604 pFormParent->InsertChild(pNewNode, NULL); 604 pFormParent->InsertChild(pNewNode, NULL);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 : NULL; 778 : NULL;
779 if (CXFA_Node* pOccurTemplateNode = 779 if (CXFA_Node* pOccurTemplateNode =
780 pTemplateNode->GetFirstChildByClass(XFA_ELEMENT_Occur)) { 780 pTemplateNode->GetFirstChildByClass(XFA_ELEMENT_Occur)) {
781 pOccurNode = pInstMgrNode 781 pOccurNode = pInstMgrNode
782 ? XFA_NodeMerge_CloneOrMergeContainer( 782 ? XFA_NodeMerge_CloneOrMergeContainer(
783 pDocument, pInstMgrNode, pOccurTemplateNode, FALSE) 783 pDocument, pInstMgrNode, pOccurTemplateNode, FALSE)
784 : pOccurTemplateNode; 784 : pOccurTemplateNode;
785 } else if (pInstMgrNode) { 785 } else if (pInstMgrNode) {
786 pOccurNode = pInstMgrNode->GetFirstChildByClass(XFA_ELEMENT_Occur); 786 pOccurNode = pInstMgrNode->GetFirstChildByClass(XFA_ELEMENT_Occur);
787 if (pOccurNode) { 787 if (pOccurNode) {
788 pOccurNode->SetFlag(XFA_NODEFLAG_UnusedNode, FALSE); 788 pOccurNode->ClearFlag(XFA_NODEFLAG_UnusedNode);
789 } 789 }
790 } 790 }
791 if (pInstMgrNode) { 791 if (pInstMgrNode) {
792 pInstMgrNode->SetFlag(XFA_NODEFLAG_Initialized); 792 pInstMgrNode->SetFlag(XFA_NODEFLAG_Initialized, true);
793 pSearchArray = &subformArray; 793 pSearchArray = &subformArray;
794 if (pFormParentNode->GetClassID() == XFA_ELEMENT_PageArea) { 794 if (pFormParentNode->GetClassID() == XFA_ELEMENT_PageArea) {
795 bOneInstance = TRUE; 795 bOneInstance = TRUE;
796 if (subformArray.GetSize() < 1) { 796 if (subformArray.GetSize() < 1) {
797 pSearchArray = NULL; 797 pSearchArray = NULL;
798 } 798 }
799 } else if ((pTemplateNode->GetNameHash() == 0) && 799 } else if ((pTemplateNode->GetNameHash() == 0) &&
800 (subformArray.GetSize() < 1)) { 800 (subformArray.GetSize() < 1)) {
801 pSearchArray = NULL; 801 pSearchArray = NULL;
802 } 802 }
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 bEmptyForm = TRUE; 1341 bEmptyForm = TRUE;
1342 pFormRoot = CreateNode(XFA_XDPPACKET_Form, XFA_ELEMENT_Form); 1342 pFormRoot = CreateNode(XFA_XDPPACKET_Form, XFA_ELEMENT_Form);
1343 FXSYS_assert(pFormRoot); 1343 FXSYS_assert(pFormRoot);
1344 pFormRoot->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"form")); 1344 pFormRoot->SetCData(XFA_ATTRIBUTE_Name, FX_WSTRC(L"form"));
1345 m_pRootNode->InsertChild(pFormRoot, NULL); 1345 m_pRootNode->InsertChild(pFormRoot, NULL);
1346 } else { 1346 } else {
1347 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFANode> 1347 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFANode>
1348 sIterator(pFormRoot); 1348 sIterator(pFormRoot);
1349 for (CXFA_Node* pNode = sIterator.MoveToNext(); pNode; 1349 for (CXFA_Node* pNode = sIterator.MoveToNext(); pNode;
1350 pNode = sIterator.MoveToNext()) { 1350 pNode = sIterator.MoveToNext()) {
1351 pNode->SetFlag(XFA_NODEFLAG_UnusedNode); 1351 pNode->SetFlag(XFA_NODEFLAG_UnusedNode, true);
1352 } 1352 }
1353 } 1353 }
1354 CXFA_Node* pSubformSetNode = XFA_NodeMerge_CloneOrMergeContainer( 1354 CXFA_Node* pSubformSetNode = XFA_NodeMerge_CloneOrMergeContainer(
1355 this, pFormRoot, pTemplateChosen, FALSE); 1355 this, pFormRoot, pTemplateChosen, FALSE);
1356 FXSYS_assert(pSubformSetNode); 1356 FXSYS_assert(pSubformSetNode);
1357 if (!pDataTopLevel) { 1357 if (!pDataTopLevel) {
1358 CFX_WideStringC wsFormName = pSubformSetNode->GetCData(XFA_ATTRIBUTE_Name); 1358 CFX_WideStringC wsFormName = pSubformSetNode->GetCData(XFA_ATTRIBUTE_Name);
1359 CFX_WideString wsDataTopLevelName = 1359 CFX_WideString wsDataTopLevelName =
1360 wsFormName.IsEmpty() ? FX_WSTRC(L"form") : wsFormName; 1360 wsFormName.IsEmpty() ? FX_WSTRC(L"form") : wsFormName;
1361 CFDE_XMLElement* pDataTopLevelXMLNode = 1361 CFDE_XMLElement* pDataTopLevelXMLNode =
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 sIterator(pFormRoot); 1399 sIterator(pFormRoot);
1400 CXFA_Node* pNode = sIterator.MoveToNext(); 1400 CXFA_Node* pNode = sIterator.MoveToNext();
1401 while (pNode) { 1401 while (pNode) {
1402 if (pNode->HasFlag(XFA_NODEFLAG_UnusedNode)) { 1402 if (pNode->HasFlag(XFA_NODEFLAG_UnusedNode)) {
1403 if (pNode->GetObjectType() == XFA_OBJECTTYPE_ContainerNode || 1403 if (pNode->GetObjectType() == XFA_OBJECTTYPE_ContainerNode ||
1404 pNode->GetClassID() == XFA_ELEMENT_InstanceManager) { 1404 pNode->GetClassID() == XFA_ELEMENT_InstanceManager) {
1405 CXFA_Node* pNext = sIterator.SkipChildrenAndMoveToNext(); 1405 CXFA_Node* pNext = sIterator.SkipChildrenAndMoveToNext();
1406 pNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pNode); 1406 pNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pNode);
1407 pNode = pNext; 1407 pNode = pNext;
1408 } else { 1408 } else {
1409 pNode->SetFlag(XFA_NODEFLAG_UnusedNode, FALSE); 1409 pNode->ClearFlag(XFA_NODEFLAG_UnusedNode);
1410 pNode->SetFlag(XFA_NODEFLAG_Initialized); 1410 pNode->SetFlag(XFA_NODEFLAG_Initialized, true);
1411 pNode = sIterator.MoveToNext(); 1411 pNode = sIterator.MoveToNext();
1412 } 1412 }
1413 } else { 1413 } else {
1414 pNode->SetFlag(XFA_NODEFLAG_Initialized); 1414 pNode->SetFlag(XFA_NODEFLAG_Initialized, true);
1415 pNode = sIterator.MoveToNext(); 1415 pNode = sIterator.MoveToNext();
1416 } 1416 }
1417 } 1417 }
1418 } 1418 }
1419 } 1419 }
1420 void CXFA_Document::DoDataRemerge(FX_BOOL bDoDataMerge) { 1420 void CXFA_Document::DoDataRemerge(FX_BOOL bDoDataMerge) {
1421 CXFA_Node* pFormRoot = ToNode(GetXFAObject(XFA_HASHCODE_Form)); 1421 CXFA_Node* pFormRoot = ToNode(GetXFAObject(XFA_HASHCODE_Form));
1422 if (pFormRoot) { 1422 if (pFormRoot) {
1423 while (CXFA_Node* pNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) { 1423 while (CXFA_Node* pNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild)) {
1424 pFormRoot->RemoveChild(pNode); 1424 pFormRoot->RemoveChild(pNode);
1425 } 1425 }
1426 pFormRoot->SetObject(XFA_ATTRIBUTE_BindingNode, NULL); 1426 pFormRoot->SetObject(XFA_ATTRIBUTE_BindingNode, NULL);
1427 } 1427 }
1428 XFA_DataMerge_ClearGlobalBinding(this); 1428 XFA_DataMerge_ClearGlobalBinding(this);
1429 if (bDoDataMerge) { 1429 if (bDoDataMerge) {
1430 DoDataMerge(); 1430 DoDataMerge();
1431 } 1431 }
1432 CXFA_LayoutProcessor* pLayoutProcessor = GetLayoutProcessor(); 1432 CXFA_LayoutProcessor* pLayoutProcessor = GetLayoutProcessor();
1433 pLayoutProcessor->SetForceReLayout(TRUE); 1433 pLayoutProcessor->SetForceReLayout(TRUE);
1434 } 1434 }
OLDNEW
« no previous file with comments | « xfa/fxfa/parser/xfa_document_datadescription_imp.cpp ('k') | xfa/fxfa/parser/xfa_document_imp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698