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 "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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 ASSERT(FALSE); | 97 ASSERT(FALSE); |
98 break; | 98 break; |
99 } | 99 } |
100 return TRUE; | 100 return TRUE; |
101 } | 101 } |
102 static void XFA_DataMerge_CreateDataBinding(CXFA_Node* pFormNode, | 102 static void XFA_DataMerge_CreateDataBinding(CXFA_Node* pFormNode, |
103 CXFA_Node* pDataNode, | 103 CXFA_Node* pDataNode, |
104 FX_BOOL bDataToForm = TRUE) { | 104 FX_BOOL bDataToForm = TRUE) { |
105 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, pDataNode); | 105 pFormNode->SetObject(XFA_ATTRIBUTE_BindingNode, pDataNode); |
106 pDataNode->AddBindItem(pFormNode); | 106 pDataNode->AddBindItem(pFormNode); |
107 XFA_Element eClass = pFormNode->GetElementType(); | 107 XFA_Element eType = pFormNode->GetElementType(); |
108 if (eClass != XFA_Element::Field && eClass != XFA_Element::ExclGroup) { | 108 if (eType != XFA_Element::Field && eType != XFA_Element::ExclGroup) { |
109 return; | 109 return; |
110 } | 110 } |
111 CXFA_WidgetData* pWidgetData = pFormNode->GetWidgetData(); | 111 CXFA_WidgetData* pWidgetData = pFormNode->GetWidgetData(); |
112 ASSERT(pWidgetData); | 112 ASSERT(pWidgetData); |
113 XFA_Element eUIType = pWidgetData->GetUIType(); | 113 XFA_Element eUIType = pWidgetData->GetUIType(); |
114 CXFA_Value defValue(pFormNode->GetProperty(0, XFA_Element::Value)); | 114 CXFA_Value defValue(pFormNode->GetProperty(0, XFA_Element::Value)); |
115 if (!bDataToForm) { | 115 if (!bDataToForm) { |
116 CFX_WideString wsValue; | 116 CFX_WideString wsValue; |
117 CFX_WideString wsFormatedValue; | 117 CFX_WideString wsFormatedValue; |
118 switch (eUIType) { | 118 switch (eUIType) { |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 CXFA_Object* pObject = (rs.nodes.GetSize() > 0) ? rs.nodes[0] : NULL; | 458 CXFA_Object* pObject = (rs.nodes.GetSize() > 0) ? rs.nodes[0] : NULL; |
459 CXFA_Node* pNode = ToNode(pObject); | 459 CXFA_Node* pNode = ToNode(pObject); |
460 if (!bForceBind && pNode && pNode->HasBindItem()) { | 460 if (!bForceBind && pNode && pNode->HasBindItem()) { |
461 pNode = NULL; | 461 pNode = NULL; |
462 } | 462 } |
463 return pNode; | 463 return pNode; |
464 } | 464 } |
465 return NULL; | 465 return NULL; |
466 } | 466 } |
467 CXFA_Node* XFA_DataMerge_FindFormDOMInstance(CXFA_Document* pDocument, | 467 CXFA_Node* XFA_DataMerge_FindFormDOMInstance(CXFA_Document* pDocument, |
468 XFA_Element eClassID, | 468 XFA_Element eType, |
Lei Zhang
2016/06/23 15:01:23
Fix the header too.
dsinclair
2016/06/23 15:57:28
Done.
| |
469 uint32_t dwNameHash, | 469 uint32_t dwNameHash, |
470 CXFA_Node* pFormParent) { | 470 CXFA_Node* pFormParent) { |
471 CXFA_Node* pFormChild = pFormParent->GetNodeItem(XFA_NODEITEM_FirstChild); | 471 CXFA_Node* pFormChild = pFormParent->GetNodeItem(XFA_NODEITEM_FirstChild); |
472 for (; pFormChild; | 472 for (; pFormChild; |
473 pFormChild = pFormChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { | 473 pFormChild = pFormChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
474 if (pFormChild->GetElementType() == eClassID && | 474 if (pFormChild->GetElementType() == eType && |
475 pFormChild->GetNameHash() == dwNameHash && pFormChild->IsUnusedNode()) { | 475 pFormChild->GetNameHash() == dwNameHash && pFormChild->IsUnusedNode()) { |
476 return pFormChild; | 476 return pFormChild; |
477 } | 477 } |
478 } | 478 } |
479 return NULL; | 479 return NULL; |
480 } | 480 } |
481 static FX_BOOL XFA_NeedGenerateForm(CXFA_Node* pTemplateChild, | 481 static FX_BOOL XFA_NeedGenerateForm(CXFA_Node* pTemplateChild, |
482 FX_BOOL bUseInstanceManager = TRUE) { | 482 FX_BOOL bUseInstanceManager = TRUE) { |
483 XFA_Element eType = pTemplateChild->GetElementType(); | 483 XFA_Element eType = pTemplateChild->GetElementType(); |
484 if (eType == XFA_Element::Variables) { | 484 if (eType == XFA_Element::Variables) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 rgRecords.Copy(rgResultRecord); | 743 rgRecords.Copy(rgResultRecord); |
744 } | 744 } |
745 } | 745 } |
746 static CXFA_Node* XFA_DataMerge_CopyContainer_SubformSet( | 746 static CXFA_Node* XFA_DataMerge_CopyContainer_SubformSet( |
747 CXFA_Document* pDocument, | 747 CXFA_Document* pDocument, |
748 CXFA_Node* pTemplateNode, | 748 CXFA_Node* pTemplateNode, |
749 CXFA_Node* pFormParentNode, | 749 CXFA_Node* pFormParentNode, |
750 CXFA_Node* pDataScope, | 750 CXFA_Node* pDataScope, |
751 FX_BOOL bOneInstance, | 751 FX_BOOL bOneInstance, |
752 FX_BOOL bDataMerge) { | 752 FX_BOOL bDataMerge) { |
753 XFA_Element eElement = pTemplateNode->GetElementType(); | 753 XFA_Element eType = pTemplateNode->GetElementType(); |
754 CXFA_Node* pOccurNode = NULL; | 754 CXFA_Node* pOccurNode = NULL; |
755 CXFA_Node* pFirstInstance = NULL; | 755 CXFA_Node* pFirstInstance = NULL; |
756 FX_BOOL bUseInstanceManager = | 756 FX_BOOL bUseInstanceManager = |
757 pFormParentNode->GetElementType() != XFA_Element::Area; | 757 pFormParentNode->GetElementType() != XFA_Element::Area; |
758 CXFA_Node* pInstMgrNode = NULL; | 758 CXFA_Node* pInstMgrNode = NULL; |
759 CXFA_NodeArray subformArray; | 759 CXFA_NodeArray subformArray; |
760 CXFA_NodeArray* pSearchArray = NULL; | 760 CXFA_NodeArray* pSearchArray = NULL; |
761 if (!bOneInstance && (eElement == XFA_Element::SubformSet || | 761 if (!bOneInstance && |
762 eElement == XFA_Element::Subform)) { | 762 (eType == XFA_Element::SubformSet || eType == XFA_Element::Subform)) { |
763 pInstMgrNode = | 763 pInstMgrNode = |
764 bUseInstanceManager | 764 bUseInstanceManager |
765 ? XFA_NodeMerge_CloneOrMergeInstanceManager( | 765 ? XFA_NodeMerge_CloneOrMergeInstanceManager( |
766 pDocument, pFormParentNode, pTemplateNode, subformArray) | 766 pDocument, pFormParentNode, pTemplateNode, subformArray) |
767 : NULL; | 767 : NULL; |
768 if (CXFA_Node* pOccurTemplateNode = | 768 if (CXFA_Node* pOccurTemplateNode = |
769 pTemplateNode->GetFirstChildByClass(XFA_Element::Occur)) { | 769 pTemplateNode->GetFirstChildByClass(XFA_Element::Occur)) { |
770 pOccurNode = pInstMgrNode | 770 pOccurNode = pInstMgrNode |
771 ? XFA_NodeMerge_CloneOrMergeContainer( | 771 ? XFA_NodeMerge_CloneOrMergeContainer( |
772 pDocument, pInstMgrNode, pOccurTemplateNode, FALSE) | 772 pDocument, pInstMgrNode, pOccurTemplateNode, FALSE) |
(...skipping 16 matching lines...) Expand all Loading... | |
789 (subformArray.GetSize() < 1)) { | 789 (subformArray.GetSize() < 1)) { |
790 pSearchArray = NULL; | 790 pSearchArray = NULL; |
791 } | 791 } |
792 } | 792 } |
793 } | 793 } |
794 int32_t iMax = 1, iInit = 1, iMin = 1; | 794 int32_t iMax = 1, iInit = 1, iMin = 1; |
795 if (!bOneInstance) { | 795 if (!bOneInstance) { |
796 XFA_GetOccurInfo(pOccurNode, iMin, iMax, iInit); | 796 XFA_GetOccurInfo(pOccurNode, iMin, iMax, iInit); |
797 } | 797 } |
798 XFA_ATTRIBUTEENUM eRelation = | 798 XFA_ATTRIBUTEENUM eRelation = |
799 eElement == XFA_Element::SubformSet | 799 eType == XFA_Element::SubformSet |
800 ? pTemplateNode->GetEnum(XFA_ATTRIBUTE_Relation) | 800 ? pTemplateNode->GetEnum(XFA_ATTRIBUTE_Relation) |
801 : XFA_ATTRIBUTEENUM_Ordered; | 801 : XFA_ATTRIBUTEENUM_Ordered; |
802 int32_t iCurRepeatIndex = 0; | 802 int32_t iCurRepeatIndex = 0; |
803 XFA_ATTRIBUTEENUM eParentBindMatch = XFA_ATTRIBUTEENUM_None; | 803 XFA_ATTRIBUTEENUM eParentBindMatch = XFA_ATTRIBUTEENUM_None; |
804 if (bDataMerge) { | 804 if (bDataMerge) { |
805 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> | 805 CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFAContainerNode> |
806 sNodeIterator(pTemplateNode); | 806 sNodeIterator(pTemplateNode); |
807 FX_BOOL bAccessedDataDOM = FALSE; | 807 FX_BOOL bAccessedDataDOM = FALSE; |
808 if (eElement == XFA_Element::SubformSet || eElement == XFA_Element::Area) { | 808 if (eType == XFA_Element::SubformSet || eType == XFA_Element::Area) { |
809 sNodeIterator.MoveToNext(); | 809 sNodeIterator.MoveToNext(); |
810 } else { | 810 } else { |
811 CFX_MapPtrTemplate<CXFA_Node*, CXFA_Node*> subformMapArray; | 811 CFX_MapPtrTemplate<CXFA_Node*, CXFA_Node*> subformMapArray; |
812 CXFA_NodeArray nodeArray; | 812 CXFA_NodeArray nodeArray; |
813 for (; iMax < 0 || iCurRepeatIndex < iMax; iCurRepeatIndex++) { | 813 for (; iMax < 0 || iCurRepeatIndex < iMax; iCurRepeatIndex++) { |
814 FX_BOOL bSelfMatch = FALSE; | 814 FX_BOOL bSelfMatch = FALSE; |
815 XFA_ATTRIBUTEENUM eBindMatch = XFA_ATTRIBUTEENUM_None; | 815 XFA_ATTRIBUTEENUM eBindMatch = XFA_ATTRIBUTEENUM_None; |
816 CXFA_Node* pDataNode = XFA_DataMerge_FindMatchingDataNode( | 816 CXFA_Node* pDataNode = XFA_DataMerge_FindMatchingDataNode( |
817 pDocument, pTemplateNode, pDataScope, bAccessedDataDOM, FALSE, | 817 pDocument, pTemplateNode, pDataScope, bAccessedDataDOM, FALSE, |
818 &sNodeIterator, bSelfMatch, eBindMatch); | 818 &sNodeIterator, bSelfMatch, eBindMatch); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1084 } | 1084 } |
1085 return NULL; | 1085 return NULL; |
1086 } | 1086 } |
1087 | 1087 |
1088 static void XFA_DataMerge_UpdateBindingRelations(CXFA_Document* pDocument, | 1088 static void XFA_DataMerge_UpdateBindingRelations(CXFA_Document* pDocument, |
1089 CXFA_Node* pFormNode, | 1089 CXFA_Node* pFormNode, |
1090 CXFA_Node* pDataScope, | 1090 CXFA_Node* pDataScope, |
1091 FX_BOOL bDataRef, | 1091 FX_BOOL bDataRef, |
1092 FX_BOOL bParentDataRef) { | 1092 FX_BOOL bParentDataRef) { |
1093 FX_BOOL bMatchRef = TRUE; | 1093 FX_BOOL bMatchRef = TRUE; |
1094 XFA_Element eClassID = pFormNode->GetElementType(); | 1094 XFA_Element eType = pFormNode->GetElementType(); |
1095 CXFA_Node* pDataNode = pFormNode->GetBindData(); | 1095 CXFA_Node* pDataNode = pFormNode->GetBindData(); |
1096 if (eClassID == XFA_Element::Subform || eClassID == XFA_Element::ExclGroup || | 1096 if (eType == XFA_Element::Subform || eType == XFA_Element::ExclGroup || |
1097 eClassID == XFA_Element::Field) { | 1097 eType == XFA_Element::Field) { |
1098 CXFA_Node* pTemplateNode = pFormNode->GetTemplateNode(); | 1098 CXFA_Node* pTemplateNode = pFormNode->GetTemplateNode(); |
1099 CXFA_Node* pTemplateNodeBind = | 1099 CXFA_Node* pTemplateNodeBind = |
1100 pTemplateNode ? pTemplateNode->GetFirstChildByClass(XFA_Element::Bind) | 1100 pTemplateNode ? pTemplateNode->GetFirstChildByClass(XFA_Element::Bind) |
1101 : NULL; | 1101 : NULL; |
1102 XFA_ATTRIBUTEENUM eMatch = | 1102 XFA_ATTRIBUTEENUM eMatch = |
1103 pTemplateNodeBind ? pTemplateNodeBind->GetEnum(XFA_ATTRIBUTE_Match) | 1103 pTemplateNodeBind ? pTemplateNodeBind->GetEnum(XFA_ATTRIBUTE_Match) |
1104 : XFA_ATTRIBUTEENUM_Once; | 1104 : XFA_ATTRIBUTEENUM_Once; |
1105 switch (eMatch) { | 1105 switch (eMatch) { |
1106 case XFA_ATTRIBUTEENUM_None: | 1106 case XFA_ATTRIBUTEENUM_None: |
1107 if (!bDataRef || bParentDataRef) { | 1107 if (!bDataRef || bParentDataRef) { |
1108 XFA_DataMerge_FormValueNode_MatchNoneCreateChild(pFormNode); | 1108 XFA_DataMerge_FormValueNode_MatchNoneCreateChild(pFormNode); |
1109 } | 1109 } |
1110 break; | 1110 break; |
1111 case XFA_ATTRIBUTEENUM_Once: | 1111 case XFA_ATTRIBUTEENUM_Once: |
1112 if (!bDataRef || bParentDataRef) { | 1112 if (!bDataRef || bParentDataRef) { |
1113 if (!pDataNode) { | 1113 if (!pDataNode) { |
1114 if (pFormNode->GetNameHash() != 0 && | 1114 if (pFormNode->GetNameHash() != 0 && |
1115 pFormNode->GetEnum(XFA_ATTRIBUTE_Scope) != | 1115 pFormNode->GetEnum(XFA_ATTRIBUTE_Scope) != |
1116 XFA_ATTRIBUTEENUM_None) { | 1116 XFA_ATTRIBUTEENUM_None) { |
1117 XFA_Element eDataNodeType = (eClassID == XFA_Element::Subform || | 1117 XFA_Element eDataNodeType = (eType == XFA_Element::Subform || |
1118 XFA_FieldIsMultiListBox(pFormNode)) | 1118 XFA_FieldIsMultiListBox(pFormNode)) |
1119 ? XFA_Element::DataGroup | 1119 ? XFA_Element::DataGroup |
1120 : XFA_Element::DataValue; | 1120 : XFA_Element::DataValue; |
1121 pDataNode = XFA_DataDescription_MaybeCreateDataNode( | 1121 pDataNode = XFA_DataDescription_MaybeCreateDataNode( |
1122 pDocument, pDataScope, eDataNodeType, | 1122 pDocument, pDataScope, eDataNodeType, |
1123 CFX_WideString(pFormNode->GetCData(XFA_ATTRIBUTE_Name))); | 1123 CFX_WideString(pFormNode->GetCData(XFA_ATTRIBUTE_Name))); |
1124 if (pDataNode) { | 1124 if (pDataNode) { |
1125 XFA_DataMerge_CreateDataBinding(pFormNode, pDataNode, FALSE); | 1125 XFA_DataMerge_CreateDataBinding(pFormNode, pDataNode, FALSE); |
1126 } | 1126 } |
1127 } | 1127 } |
(...skipping 10 matching lines...) Expand all Loading... | |
1138 } | 1138 } |
1139 } | 1139 } |
1140 } | 1140 } |
1141 break; | 1141 break; |
1142 case XFA_ATTRIBUTEENUM_Global: | 1142 case XFA_ATTRIBUTEENUM_Global: |
1143 if (!bDataRef || bParentDataRef) { | 1143 if (!bDataRef || bParentDataRef) { |
1144 uint32_t dwNameHash = pFormNode->GetNameHash(); | 1144 uint32_t dwNameHash = pFormNode->GetNameHash(); |
1145 if (dwNameHash != 0 && !pDataNode) { | 1145 if (dwNameHash != 0 && !pDataNode) { |
1146 pDataNode = XFA_DataMerge_GetGlobalBinding(pDocument, dwNameHash); | 1146 pDataNode = XFA_DataMerge_GetGlobalBinding(pDocument, dwNameHash); |
1147 if (!pDataNode) { | 1147 if (!pDataNode) { |
1148 XFA_Element eDataNodeType = (eClassID == XFA_Element::Subform || | 1148 XFA_Element eDataNodeType = (eType == XFA_Element::Subform || |
1149 XFA_FieldIsMultiListBox(pFormNode)) | 1149 XFA_FieldIsMultiListBox(pFormNode)) |
1150 ? XFA_Element::DataGroup | 1150 ? XFA_Element::DataGroup |
1151 : XFA_Element::DataValue; | 1151 : XFA_Element::DataValue; |
1152 CXFA_Node* pRecordNode = | 1152 CXFA_Node* pRecordNode = |
1153 ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record)); | 1153 ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Record)); |
1154 pDataNode = XFA_DataDescription_MaybeCreateDataNode( | 1154 pDataNode = XFA_DataDescription_MaybeCreateDataNode( |
1155 pDocument, pRecordNode, eDataNodeType, | 1155 pDocument, pRecordNode, eDataNodeType, |
1156 CFX_WideString(pFormNode->GetCData(XFA_ATTRIBUTE_Name))); | 1156 CFX_WideString(pFormNode->GetCData(XFA_ATTRIBUTE_Name))); |
1157 if (pDataNode) { | 1157 if (pDataNode) { |
1158 XFA_DataMerge_CreateDataBinding(pFormNode, pDataNode, FALSE); | 1158 XFA_DataMerge_CreateDataBinding(pFormNode, pDataNode, FALSE); |
(...skipping 29 matching lines...) Expand all Loading... | |
1188 } else { | 1188 } else { |
1189 XFA_DataMerge_FormValueNode_MatchNoneCreateChild(pFormNode); | 1189 XFA_DataMerge_FormValueNode_MatchNoneCreateChild(pFormNode); |
1190 } | 1190 } |
1191 } | 1191 } |
1192 } break; | 1192 } break; |
1193 default: | 1193 default: |
1194 break; | 1194 break; |
1195 } | 1195 } |
1196 } | 1196 } |
1197 if (bMatchRef && | 1197 if (bMatchRef && |
1198 (eClassID == XFA_Element::Subform || | 1198 (eType == XFA_Element::Subform || eType == XFA_Element::SubformSet || |
1199 eClassID == XFA_Element::SubformSet || eClassID == XFA_Element::Area || | 1199 eType == XFA_Element::Area || eType == XFA_Element::PageArea || |
1200 eClassID == XFA_Element::PageArea || eClassID == XFA_Element::PageSet)) { | 1200 eType == XFA_Element::PageSet)) { |
1201 for (CXFA_Node* pFormChild = | 1201 for (CXFA_Node* pFormChild = |
1202 pFormNode->GetNodeItem(XFA_NODEITEM_FirstChild); | 1202 pFormNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
1203 pFormChild; | 1203 pFormChild; |
1204 pFormChild = pFormChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { | 1204 pFormChild = pFormChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
1205 if (!pFormChild->IsContainerNode()) | 1205 if (!pFormChild->IsContainerNode()) |
1206 continue; | 1206 continue; |
1207 if (pFormChild->IsUnusedNode()) | 1207 if (pFormChild->IsUnusedNode()) |
1208 continue; | 1208 continue; |
1209 | 1209 |
1210 XFA_DataMerge_UpdateBindingRelations(pDocument, pFormChild, | 1210 XFA_DataMerge_UpdateBindingRelations(pDocument, pFormChild, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1401 } | 1401 } |
1402 pFormRoot->SetObject(XFA_ATTRIBUTE_BindingNode, NULL); | 1402 pFormRoot->SetObject(XFA_ATTRIBUTE_BindingNode, NULL); |
1403 } | 1403 } |
1404 XFA_DataMerge_ClearGlobalBinding(this); | 1404 XFA_DataMerge_ClearGlobalBinding(this); |
1405 if (bDoDataMerge) { | 1405 if (bDoDataMerge) { |
1406 DoDataMerge(); | 1406 DoDataMerge(); |
1407 } | 1407 } |
1408 CXFA_LayoutProcessor* pLayoutProcessor = GetLayoutProcessor(); | 1408 CXFA_LayoutProcessor* pLayoutProcessor = GetLayoutProcessor(); |
1409 pLayoutProcessor->SetForceReLayout(TRUE); | 1409 pLayoutProcessor->SetForceReLayout(TRUE); |
1410 } | 1410 } |
OLD | NEW |