| 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_script_nodehelper.h" | 7 #include "xfa/fxfa/parser/xfa_script_nodehelper.h" |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
| 10 #include "xfa/fxfa/parser/xfa_doclayout.h" | 10 #include "xfa/fxfa/parser/xfa_doclayout.h" |
| 11 #include "xfa/fxfa/parser/xfa_document.h" | 11 #include "xfa/fxfa/parser/xfa_document.h" |
| 12 #include "xfa/fxfa/parser/xfa_localemgr.h" | 12 #include "xfa/fxfa/parser/xfa_localemgr.h" |
| 13 #include "xfa/fxfa/parser/xfa_object.h" | 13 #include "xfa/fxfa/parser/xfa_object.h" |
| 14 #include "xfa/fxfa/parser/xfa_parser.h" | 14 #include "xfa/fxfa/parser/xfa_parser.h" |
| 15 #include "xfa/fxfa/parser/xfa_script.h" | 15 #include "xfa/fxfa/parser/xfa_script.h" |
| 16 #include "xfa/fxfa/parser/xfa_script_imp.h" | 16 #include "xfa/fxfa/parser/xfa_script_imp.h" |
| 17 #include "xfa/fxfa/parser/xfa_utils.h" | 17 #include "xfa/fxfa/parser/xfa_utils.h" |
| 18 | 18 |
| 19 CXFA_NodeHelper::CXFA_NodeHelper() | 19 CXFA_NodeHelper::CXFA_NodeHelper() |
| 20 : m_eLastCreateType(XFA_ELEMENT_DataValue), | 20 : m_eLastCreateType(XFA_Element::DataValue), |
| 21 m_pCreateParent(NULL), | 21 m_pCreateParent(NULL), |
| 22 m_iCreateCount(0), | 22 m_iCreateCount(0), |
| 23 m_iCreateFlag(XFA_RESOLVENODE_RSTYPE_CreateNodeOne), | 23 m_iCreateFlag(XFA_RESOLVENODE_RSTYPE_CreateNodeOne), |
| 24 m_iCurAllStart(-1), | 24 m_iCurAllStart(-1), |
| 25 m_pAllStartParent(NULL) {} | 25 m_pAllStartParent(NULL) {} |
| 26 | 26 |
| 27 CXFA_NodeHelper::~CXFA_NodeHelper() {} | 27 CXFA_NodeHelper::~CXFA_NodeHelper() {} |
| 28 | 28 |
| 29 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetOneChild( | 29 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetOneChild( |
| 30 CXFA_Node* parent, | 30 CXFA_Node* parent, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 int32_t nProperties = properties.GetSize(); | 147 int32_t nProperties = properties.GetSize(); |
| 148 for (i = 0; i < nProperties; ++i) { | 148 for (i = 0; i < nProperties; ++i) { |
| 149 CXFA_Node* child = properties[i]; | 149 CXFA_Node* child = properties[i]; |
| 150 if (bIsClassName) { | 150 if (bIsClassName) { |
| 151 if (child->GetClassHashCode() == dNameHash) { | 151 if (child->GetClassHashCode() == dNameHash) { |
| 152 pSiblings->Add(child); | 152 pSiblings->Add(child); |
| 153 nCount++; | 153 nCount++; |
| 154 } | 154 } |
| 155 } else { | 155 } else { |
| 156 if (child->GetNameHash() == dNameHash) { | 156 if (child->GetNameHash() == dNameHash) { |
| 157 if (child->GetClassID() != XFA_ELEMENT_PageSet && | 157 if (child->GetClassID() != XFA_Element::PageSet && |
| 158 child->GetClassID() != XFA_ELEMENT_Extras && | 158 child->GetClassID() != XFA_Element::Extras && |
| 159 child->GetClassID() != XFA_ELEMENT_Items) { | 159 child->GetClassID() != XFA_Element::Items) { |
| 160 pSiblings->Add(child); | 160 pSiblings->Add(child); |
| 161 nCount++; | 161 nCount++; |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 if (child->IsUnnamed() && child->GetClassID() == XFA_ELEMENT_PageSet) { | 165 if (child->IsUnnamed() && child->GetClassID() == XFA_Element::PageSet) { |
| 166 nCount += XFA_NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, | 166 nCount += XFA_NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, |
| 167 eLogicType, bIsClassName, FALSE); | 167 eLogicType, bIsClassName, FALSE); |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 if (nCount > 0) { | 170 if (nCount > 0) { |
| 171 return nCount; | 171 return nCount; |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 CXFA_NodeArray children; | 174 CXFA_NodeArray children; |
| 175 parent->GetNodeList(children, XFA_NODEFILTER_Children); | 175 parent->GetNodeList(children, XFA_NODEFILTER_Children); |
| 176 int32_t nChildren = children.GetSize(); | 176 int32_t nChildren = children.GetSize(); |
| 177 for (i = 0; i < nChildren; i++) { | 177 for (i = 0; i < nChildren; i++) { |
| 178 CXFA_Node* child = children[i]; | 178 CXFA_Node* child = children[i]; |
| 179 if (child->GetClassID() == XFA_ELEMENT_Variables) { | 179 if (child->GetClassID() == XFA_Element::Variables) { |
| 180 continue; | 180 continue; |
| 181 } | 181 } |
| 182 if (bIsClassName) { | 182 if (bIsClassName) { |
| 183 if (child->GetClassHashCode() == dNameHash) { | 183 if (child->GetClassHashCode() == dNameHash) { |
| 184 if (pSiblings) { | 184 if (pSiblings) { |
| 185 pSiblings->Add(child); | 185 pSiblings->Add(child); |
| 186 } | 186 } |
| 187 nCount++; | 187 nCount++; |
| 188 } | 188 } |
| 189 } else { | 189 } else { |
| 190 if (child->GetNameHash() == dNameHash) { | 190 if (child->GetNameHash() == dNameHash) { |
| 191 if (pSiblings) { | 191 if (pSiblings) { |
| 192 pSiblings->Add(child); | 192 pSiblings->Add(child); |
| 193 } | 193 } |
| 194 nCount++; | 194 nCount++; |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 if (eLogicType == XFA_LOGIC_NoTransparent) { | 197 if (eLogicType == XFA_LOGIC_NoTransparent) { |
| 198 continue; | 198 continue; |
| 199 } | 199 } |
| 200 if (XFA_NodeIsTransparent(child) && | 200 if (XFA_NodeIsTransparent(child) && |
| 201 child->GetClassID() != XFA_ELEMENT_PageSet) { | 201 child->GetClassID() != XFA_Element::PageSet) { |
| 202 nCount += XFA_NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, | 202 nCount += XFA_NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, |
| 203 eLogicType, bIsClassName, FALSE); | 203 eLogicType, bIsClassName, FALSE); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 return nCount; | 206 return nCount; |
| 207 } | 207 } |
| 208 | 208 |
| 209 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetParent( | 209 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetParent( |
| 210 CXFA_Node* pNode, | 210 CXFA_Node* pNode, |
| 211 XFA_LOGIC_TYPE eLogicType) { | 211 XFA_LOGIC_TYPE eLogicType) { |
| 212 if (!pNode) { | 212 if (!pNode) { |
| 213 return NULL; | 213 return NULL; |
| 214 } | 214 } |
| 215 if (eLogicType == XFA_LOGIC_NoTransparent) { | 215 if (eLogicType == XFA_LOGIC_NoTransparent) { |
| 216 return pNode->GetNodeItem(XFA_NODEITEM_Parent); | 216 return pNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 217 } | 217 } |
| 218 CXFA_Node* parent; | 218 CXFA_Node* parent; |
| 219 CXFA_Node* node = pNode; | 219 CXFA_Node* node = pNode; |
| 220 while (TRUE) { | 220 while (TRUE) { |
| 221 parent = XFA_ResolveNodes_GetParent(node); | 221 parent = XFA_ResolveNodes_GetParent(node); |
| 222 if (parent == NULL) { | 222 if (parent == NULL) { |
| 223 break; | 223 break; |
| 224 } | 224 } |
| 225 XFA_ELEMENT parentElement = parent->GetClassID(); | 225 XFA_Element parentElement = parent->GetClassID(); |
| 226 if ((!parent->IsUnnamed() && parentElement != XFA_ELEMENT_SubformSet) || | 226 if ((!parent->IsUnnamed() && parentElement != XFA_Element::SubformSet) || |
| 227 parentElement == XFA_ELEMENT_Variables) { | 227 parentElement == XFA_Element::Variables) { |
| 228 break; | 228 break; |
| 229 } | 229 } |
| 230 node = parent; | 230 node = parent; |
| 231 } | 231 } |
| 232 return parent; | 232 return parent; |
| 233 } | 233 } |
| 234 | 234 |
| 235 int32_t CXFA_NodeHelper::XFA_GetIndex(CXFA_Node* pNode, | 235 int32_t CXFA_NodeHelper::XFA_GetIndex(CXFA_Node* pNode, |
| 236 XFA_LOGIC_TYPE eLogicType, | 236 XFA_LOGIC_TYPE eLogicType, |
| 237 FX_BOOL bIsProperty, | 237 FX_BOOL bIsProperty, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 wsName = wsParent; | 280 wsName = wsParent; |
| 281 parent = XFA_ResolveNodes_GetParent(parent, XFA_LOGIC_NoTransparent); | 281 parent = XFA_ResolveNodes_GetParent(parent, XFA_LOGIC_NoTransparent); |
| 282 } | 282 } |
| 283 return; | 283 return; |
| 284 } | 284 } |
| 285 | 285 |
| 286 CFX_WideStringC wsTagName; | 286 CFX_WideStringC wsTagName; |
| 287 CFX_WideString ws; | 287 CFX_WideString ws; |
| 288 FX_BOOL bIsProperty = XFA_NodeIsProperty(refNode); | 288 FX_BOOL bIsProperty = XFA_NodeIsProperty(refNode); |
| 289 if (refNode->IsUnnamed() || | 289 if (refNode->IsUnnamed() || |
| 290 (bIsProperty && refNode->GetClassID() != XFA_ELEMENT_PageSet)) { | 290 (bIsProperty && refNode->GetClassID() != XFA_Element::PageSet)) { |
| 291 refNode->GetClassName(wsTagName); | 291 refNode->GetClassName(wsTagName); |
| 292 ws = wsTagName; | 292 ws = wsTagName; |
| 293 wsName.Format(L"#%s[%d]", ws.c_str(), | 293 wsName.Format(L"#%s[%d]", ws.c_str(), |
| 294 XFA_GetIndex(refNode, eLogicType, bIsProperty, TRUE)); | 294 XFA_GetIndex(refNode, eLogicType, bIsProperty, TRUE)); |
| 295 return; | 295 return; |
| 296 } | 296 } |
| 297 ws = refNode->GetCData(XFA_ATTRIBUTE_Name); | 297 ws = refNode->GetCData(XFA_ATTRIBUTE_Name); |
| 298 ws.Replace(L".", L"\\."); | 298 ws.Replace(L".", L"\\."); |
| 299 wsName.Format(L"%s[%d]", ws.c_str(), | 299 wsName.Format(L"%s[%d]", ws.c_str(), |
| 300 XFA_GetIndex(refNode, eLogicType, bIsProperty, FALSE)); | 300 XFA_GetIndex(refNode, eLogicType, bIsProperty, FALSE)); |
| 301 } | 301 } |
| 302 | 302 |
| 303 FX_BOOL CXFA_NodeHelper::XFA_NodeIsTransparent(CXFA_Node* refNode) { | 303 FX_BOOL CXFA_NodeHelper::XFA_NodeIsTransparent(CXFA_Node* refNode) { |
| 304 if (refNode == NULL) { | 304 if (refNode == NULL) { |
| 305 return FALSE; | 305 return FALSE; |
| 306 } | 306 } |
| 307 XFA_ELEMENT eRefNode = refNode->GetClassID(); | 307 XFA_Element eRefNode = refNode->GetClassID(); |
| 308 if ((refNode->IsUnnamed() && refNode->IsContainerNode()) || | 308 if ((refNode->IsUnnamed() && refNode->IsContainerNode()) || |
| 309 eRefNode == XFA_ELEMENT_SubformSet || eRefNode == XFA_ELEMENT_Area || | 309 eRefNode == XFA_Element::SubformSet || eRefNode == XFA_Element::Area || |
| 310 eRefNode == XFA_ELEMENT_Proto) { | 310 eRefNode == XFA_Element::Proto) { |
| 311 return TRUE; | 311 return TRUE; |
| 312 } | 312 } |
| 313 return FALSE; | 313 return FALSE; |
| 314 } | 314 } |
| 315 | 315 |
| 316 FX_BOOL CXFA_NodeHelper::XFA_CreateNode_ForCondition( | 316 FX_BOOL CXFA_NodeHelper::XFA_CreateNode_ForCondition( |
| 317 CFX_WideString& wsCondition) { | 317 CFX_WideString& wsCondition) { |
| 318 int32_t iLen = wsCondition.GetLength(); | 318 int32_t iLen = wsCondition.GetLength(); |
| 319 CFX_WideString wsIndex(L"0"); | 319 CFX_WideString wsIndex(L"0"); |
| 320 FX_BOOL bAll = FALSE; | 320 FX_BOOL bAll = FALSE; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 m_pCreateParent->CreateSamePacketNode(lpElement->eName); | 384 m_pCreateParent->CreateSamePacketNode(lpElement->eName); |
| 385 if (pNewNode) { | 385 if (pNewNode) { |
| 386 m_pCreateParent->InsertChild(pNewNode); | 386 m_pCreateParent->InsertChild(pNewNode); |
| 387 if (iIndex == m_iCreateCount - 1) { | 387 if (iIndex == m_iCreateCount - 1) { |
| 388 m_pCreateParent = pNewNode; | 388 m_pCreateParent = pNewNode; |
| 389 } | 389 } |
| 390 bResult = TRUE; | 390 bResult = TRUE; |
| 391 } | 391 } |
| 392 } | 392 } |
| 393 } else { | 393 } else { |
| 394 XFA_ELEMENT eClassType = XFA_ELEMENT_DataGroup; | 394 XFA_Element eClassType = XFA_Element::DataGroup; |
| 395 if (bLastNode) { | 395 if (bLastNode) { |
| 396 eClassType = m_eLastCreateType; | 396 eClassType = m_eLastCreateType; |
| 397 } | 397 } |
| 398 for (int32_t iIndex = 0; iIndex < m_iCreateCount; iIndex++) { | 398 for (int32_t iIndex = 0; iIndex < m_iCreateCount; iIndex++) { |
| 399 CXFA_Node* pNewNode = m_pCreateParent->CreateSamePacketNode(eClassType); | 399 CXFA_Node* pNewNode = m_pCreateParent->CreateSamePacketNode(eClassType); |
| 400 if (pNewNode) { | 400 if (pNewNode) { |
| 401 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, wsName.AsStringC()); | 401 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, wsName.AsStringC()); |
| 402 pNewNode->CreateXMLMappingNode(); | 402 pNewNode->CreateXMLMappingNode(); |
| 403 m_pCreateParent->InsertChild(pNewNode); | 403 m_pCreateParent->InsertChild(pNewNode); |
| 404 if (iIndex == m_iCreateCount - 1) { | 404 if (iIndex == m_iCreateCount - 1) { |
| 405 m_pCreateParent = pNewNode; | 405 m_pCreateParent = pNewNode; |
| 406 } | 406 } |
| 407 bResult = TRUE; | 407 bResult = TRUE; |
| 408 } | 408 } |
| 409 } | 409 } |
| 410 } | 410 } |
| 411 if (!bResult) { | 411 if (!bResult) { |
| 412 m_pCreateParent = NULL; | 412 m_pCreateParent = NULL; |
| 413 } | 413 } |
| 414 return bResult; | 414 return bResult; |
| 415 } | 415 } |
| 416 | 416 |
| 417 void CXFA_NodeHelper::XFA_SetCreateNodeType(CXFA_Node* refNode) { | 417 void CXFA_NodeHelper::XFA_SetCreateNodeType(CXFA_Node* refNode) { |
| 418 if (refNode == NULL) { | 418 if (refNode == NULL) { |
| 419 return; | 419 return; |
| 420 } | 420 } |
| 421 if (refNode->GetClassID() == XFA_ELEMENT_Subform) { | 421 if (refNode->GetClassID() == XFA_Element::Subform) { |
| 422 m_eLastCreateType = XFA_ELEMENT_DataGroup; | 422 m_eLastCreateType = XFA_Element::DataGroup; |
| 423 } else if (refNode->GetClassID() == XFA_ELEMENT_Field) { | 423 } else if (refNode->GetClassID() == XFA_Element::Field) { |
| 424 m_eLastCreateType = XFA_FieldIsMultiListBox(refNode) | 424 m_eLastCreateType = XFA_FieldIsMultiListBox(refNode) |
| 425 ? XFA_ELEMENT_DataGroup | 425 ? XFA_Element::DataGroup |
| 426 : XFA_ELEMENT_DataValue; | 426 : XFA_Element::DataValue; |
| 427 } else if (refNode->GetClassID() == XFA_ELEMENT_ExclGroup) { | 427 } else if (refNode->GetClassID() == XFA_Element::ExclGroup) { |
| 428 m_eLastCreateType = XFA_ELEMENT_DataValue; | 428 m_eLastCreateType = XFA_Element::DataValue; |
| 429 } | 429 } |
| 430 } | 430 } |
| 431 | 431 |
| 432 FX_BOOL CXFA_NodeHelper::XFA_NodeIsProperty(CXFA_Node* refNode) { | 432 FX_BOOL CXFA_NodeHelper::XFA_NodeIsProperty(CXFA_Node* refNode) { |
| 433 CXFA_Node* parent = | 433 CXFA_Node* parent = |
| 434 XFA_ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); | 434 XFA_ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); |
| 435 return parent && refNode && | 435 return parent && refNode && |
| 436 XFA_GetPropertyOfElement(parent->GetClassID(), refNode->GetClassID(), | 436 XFA_GetPropertyOfElement(parent->GetClassID(), refNode->GetClassID(), |
| 437 XFA_XDPPACKET_UNKNOWN); | 437 XFA_XDPPACKET_UNKNOWN); |
| 438 } | 438 } |
| OLD | NEW |