| 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(nullptr), |
| 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(nullptr) {} |
| 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, |
| 31 const FX_WCHAR* pwsName, | 31 const FX_WCHAR* pwsName, |
| 32 FX_BOOL bIsClassName) { | 32 FX_BOOL bIsClassName) { |
| 33 if (parent == NULL) { | 33 if (!parent) { |
| 34 return NULL; | 34 return nullptr; |
| 35 } | 35 } |
| 36 CXFA_NodeArray siblings; | 36 CXFA_NodeArray siblings; |
| 37 uint32_t uNameHash = FX_HashCode_GetW(CFX_WideStringC(pwsName), false); | 37 uint32_t uNameHash = FX_HashCode_GetW(CFX_WideStringC(pwsName), false); |
| 38 XFA_NodeAcc_TraverseAnySiblings(parent, uNameHash, &siblings, bIsClassName); | 38 XFA_NodeAcc_TraverseAnySiblings(parent, uNameHash, &siblings, bIsClassName); |
| 39 if (siblings.GetSize() == 0) { | 39 if (siblings.GetSize() == 0) { |
| 40 return NULL; | 40 return nullptr; |
| 41 } | 41 } |
| 42 return siblings[0]; | 42 return siblings[0]; |
| 43 } | 43 } |
| 44 | 44 |
| 45 int32_t CXFA_NodeHelper::XFA_CountSiblings(CXFA_Node* pNode, | 45 int32_t CXFA_NodeHelper::XFA_CountSiblings(CXFA_Node* pNode, |
| 46 XFA_LOGIC_TYPE eLogicType, | 46 XFA_LOGIC_TYPE eLogicType, |
| 47 CXFA_NodeArray* pSiblings, | 47 CXFA_NodeArray* pSiblings, |
| 48 FX_BOOL bIsClassName) { | 48 FX_BOOL bIsClassName) { |
| 49 if (!pNode) | 49 if (!pNode) |
| 50 return 0; | 50 return 0; |
| 51 CXFA_Node* parent = | 51 CXFA_Node* parent = |
| 52 XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); | 52 XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); |
| 53 if (!parent) | 53 if (!parent) |
| 54 return 0; | 54 return 0; |
| 55 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( | 55 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
| 56 parent->GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); | 56 parent->GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); |
| 57 if (!pProperty && eLogicType == XFA_LOGIC_Transparent) { | 57 if (!pProperty && eLogicType == XFA_LOGIC_Transparent) { |
| 58 parent = XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); | 58 parent = XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); |
| 59 if (parent == NULL) { | 59 if (!parent) { |
| 60 return 0; | 60 return 0; |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 if (bIsClassName) { | 63 if (bIsClassName) { |
| 64 return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetClassHashCode(), | 64 return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetClassHashCode(), |
| 65 pSiblings, eLogicType, bIsClassName); | 65 pSiblings, eLogicType, bIsClassName); |
| 66 } else { | 66 } else { |
| 67 return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetNameHash(), pSiblings, | 67 return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetNameHash(), pSiblings, |
| 68 eLogicType, bIsClassName); | 68 eLogicType, bIsClassName); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 int32_t CXFA_NodeHelper::XFA_NodeAcc_TraverseAnySiblings( | 72 int32_t CXFA_NodeHelper::XFA_NodeAcc_TraverseAnySiblings( |
| 73 CXFA_Node* parent, | 73 CXFA_Node* parent, |
| 74 uint32_t dNameHash, | 74 uint32_t dNameHash, |
| 75 CXFA_NodeArray* pSiblings, | 75 CXFA_NodeArray* pSiblings, |
| 76 FX_BOOL bIsClassName) { | 76 FX_BOOL bIsClassName) { |
| 77 if (parent == NULL || pSiblings == NULL) { | 77 if (!parent || !pSiblings) { |
| 78 return 0; | 78 return 0; |
| 79 } | 79 } |
| 80 int32_t nCount = 0; | 80 int32_t nCount = 0; |
| 81 int32_t i = 0; | 81 int32_t i = 0; |
| 82 CXFA_NodeArray properties; | 82 CXFA_NodeArray properties; |
| 83 parent->GetNodeList(properties, XFA_NODEFILTER_Properties); | 83 parent->GetNodeList(properties, XFA_NODEFILTER_Properties); |
| 84 int32_t nProperties = properties.GetSize(); | 84 int32_t nProperties = properties.GetSize(); |
| 85 for (i = 0; i < nProperties; ++i) { | 85 for (i = 0; i < nProperties; ++i) { |
| 86 CXFA_Node* child = properties[i]; | 86 CXFA_Node* child = properties[i]; |
| 87 if (bIsClassName) { | 87 if (bIsClassName) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 129 } |
| 130 return nCount; | 130 return nCount; |
| 131 } | 131 } |
| 132 | 132 |
| 133 int32_t CXFA_NodeHelper::XFA_NodeAcc_TraverseSiblings(CXFA_Node* parent, | 133 int32_t CXFA_NodeHelper::XFA_NodeAcc_TraverseSiblings(CXFA_Node* parent, |
| 134 uint32_t dNameHash, | 134 uint32_t dNameHash, |
| 135 CXFA_NodeArray* pSiblings, | 135 CXFA_NodeArray* pSiblings, |
| 136 XFA_LOGIC_TYPE eLogicType, | 136 XFA_LOGIC_TYPE eLogicType, |
| 137 FX_BOOL bIsClassName, | 137 FX_BOOL bIsClassName, |
| 138 FX_BOOL bIsFindProperty) { | 138 FX_BOOL bIsFindProperty) { |
| 139 if (parent == NULL || pSiblings == NULL) { | 139 if (!parent || !pSiblings) { |
| 140 return 0; | 140 return 0; |
| 141 } | 141 } |
| 142 int32_t nCount = 0; | 142 int32_t nCount = 0; |
| 143 int32_t i = 0; | 143 int32_t i = 0; |
| 144 if (bIsFindProperty) { | 144 if (bIsFindProperty) { |
| 145 CXFA_NodeArray properties; | 145 CXFA_NodeArray properties; |
| 146 parent->GetNodeList(properties, XFA_NODEFILTER_Properties); | 146 parent->GetNodeList(properties, XFA_NODEFILTER_Properties); |
| 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]; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 eLogicType, bIsClassName, FALSE); | 204 eLogicType, bIsClassName, FALSE); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 return nCount; | 207 return nCount; |
| 208 } | 208 } |
| 209 | 209 |
| 210 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetParent( | 210 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetParent( |
| 211 CXFA_Node* pNode, | 211 CXFA_Node* pNode, |
| 212 XFA_LOGIC_TYPE eLogicType) { | 212 XFA_LOGIC_TYPE eLogicType) { |
| 213 if (!pNode) { | 213 if (!pNode) { |
| 214 return NULL; | 214 return nullptr; |
| 215 } | 215 } |
| 216 if (eLogicType == XFA_LOGIC_NoTransparent) { | 216 if (eLogicType == XFA_LOGIC_NoTransparent) { |
| 217 return pNode->GetNodeItem(XFA_NODEITEM_Parent); | 217 return pNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 218 } | 218 } |
| 219 CXFA_Node* parent; | 219 CXFA_Node* parent; |
| 220 CXFA_Node* node = pNode; | 220 CXFA_Node* node = pNode; |
| 221 while (TRUE) { | 221 while (TRUE) { |
| 222 parent = XFA_ResolveNodes_GetParent(node); | 222 parent = XFA_ResolveNodes_GetParent(node); |
| 223 if (parent == NULL) { | 223 if (!parent) { |
| 224 break; | 224 break; |
| 225 } | 225 } |
| 226 XFA_Element parentType = parent->GetElementType(); | 226 XFA_Element parentType = parent->GetElementType(); |
| 227 if ((!parent->IsUnnamed() && parentType != XFA_Element::SubformSet) || | 227 if ((!parent->IsUnnamed() && parentType != XFA_Element::SubformSet) || |
| 228 parentType == XFA_Element::Variables) { | 228 parentType == XFA_Element::Variables) { |
| 229 break; | 229 break; |
| 230 } | 230 } |
| 231 node = parent; | 231 node = parent; |
| 232 } | 232 } |
| 233 return parent; | 233 return parent; |
| 234 } | 234 } |
| 235 | 235 |
| 236 int32_t CXFA_NodeHelper::XFA_GetIndex(CXFA_Node* pNode, | 236 int32_t CXFA_NodeHelper::XFA_GetIndex(CXFA_Node* pNode, |
| 237 XFA_LOGIC_TYPE eLogicType, | 237 XFA_LOGIC_TYPE eLogicType, |
| 238 FX_BOOL bIsProperty, | 238 FX_BOOL bIsProperty, |
| 239 FX_BOOL bIsClassIndex) { | 239 FX_BOOL bIsClassIndex) { |
| 240 CXFA_Node* parent = | 240 CXFA_Node* parent = |
| 241 XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); | 241 XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); |
| 242 if (parent == NULL) { | 242 if (!parent) { |
| 243 return 0; | 243 return 0; |
| 244 } | 244 } |
| 245 if (!bIsProperty && eLogicType == XFA_LOGIC_Transparent) { | 245 if (!bIsProperty && eLogicType == XFA_LOGIC_Transparent) { |
| 246 parent = XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); | 246 parent = XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); |
| 247 if (parent == NULL) { | 247 if (!parent) { |
| 248 return 0; | 248 return 0; |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 uint32_t dwHashName = pNode->GetNameHash(); | 251 uint32_t dwHashName = pNode->GetNameHash(); |
| 252 if (bIsClassIndex) { | 252 if (bIsClassIndex) { |
| 253 dwHashName = pNode->GetClassHashCode(); | 253 dwHashName = pNode->GetClassHashCode(); |
| 254 } | 254 } |
| 255 CXFA_NodeArray siblings; | 255 CXFA_NodeArray siblings; |
| 256 int32_t iSize = XFA_NodeAcc_TraverseSiblings(parent, dwHashName, &siblings, | 256 int32_t iSize = XFA_NodeAcc_TraverseSiblings(parent, dwHashName, &siblings, |
| 257 eLogicType, bIsClassIndex); | 257 eLogicType, bIsClassIndex); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 XFA_GetIndex(refNode, eLogicType, bIsProperty, TRUE)); | 295 XFA_GetIndex(refNode, eLogicType, bIsProperty, TRUE)); |
| 296 return; | 296 return; |
| 297 } | 297 } |
| 298 ws = refNode->GetCData(XFA_ATTRIBUTE_Name); | 298 ws = refNode->GetCData(XFA_ATTRIBUTE_Name); |
| 299 ws.Replace(L".", L"\\."); | 299 ws.Replace(L".", L"\\."); |
| 300 wsName.Format(L"%s[%d]", ws.c_str(), | 300 wsName.Format(L"%s[%d]", ws.c_str(), |
| 301 XFA_GetIndex(refNode, eLogicType, bIsProperty, FALSE)); | 301 XFA_GetIndex(refNode, eLogicType, bIsProperty, FALSE)); |
| 302 } | 302 } |
| 303 | 303 |
| 304 FX_BOOL CXFA_NodeHelper::XFA_NodeIsTransparent(CXFA_Node* refNode) { | 304 FX_BOOL CXFA_NodeHelper::XFA_NodeIsTransparent(CXFA_Node* refNode) { |
| 305 if (refNode == NULL) { | 305 if (!refNode) { |
| 306 return FALSE; | 306 return FALSE; |
| 307 } | 307 } |
| 308 XFA_Element refNodeType = refNode->GetElementType(); | 308 XFA_Element refNodeType = refNode->GetElementType(); |
| 309 if ((refNode->IsUnnamed() && refNode->IsContainerNode()) || | 309 if ((refNode->IsUnnamed() && refNode->IsContainerNode()) || |
| 310 refNodeType == XFA_Element::SubformSet || | 310 refNodeType == XFA_Element::SubformSet || |
| 311 refNodeType == XFA_Element::Area || refNodeType == XFA_Element::Proto) { | 311 refNodeType == XFA_Element::Area || refNodeType == XFA_Element::Proto) { |
| 312 return TRUE; | 312 return TRUE; |
| 313 } | 313 } |
| 314 return FALSE; | 314 return FALSE; |
| 315 } | 315 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 return TRUE; | 351 return TRUE; |
| 352 } | 352 } |
| 353 return FALSE; | 353 return FALSE; |
| 354 } | 354 } |
| 355 | 355 |
| 356 FX_BOOL CXFA_NodeHelper::XFA_ResolveNodes_CreateNode( | 356 FX_BOOL CXFA_NodeHelper::XFA_ResolveNodes_CreateNode( |
| 357 CFX_WideString wsName, | 357 CFX_WideString wsName, |
| 358 CFX_WideString wsCondition, | 358 CFX_WideString wsCondition, |
| 359 FX_BOOL bLastNode, | 359 FX_BOOL bLastNode, |
| 360 CXFA_ScriptContext* pScriptContext) { | 360 CXFA_ScriptContext* pScriptContext) { |
| 361 if (m_pCreateParent == NULL) { | 361 if (!m_pCreateParent) { |
| 362 return FALSE; | 362 return FALSE; |
| 363 } | 363 } |
| 364 FX_BOOL bIsClassName = FALSE; | 364 FX_BOOL bIsClassName = FALSE; |
| 365 FX_BOOL bResult = FALSE; | 365 FX_BOOL bResult = FALSE; |
| 366 if (wsName.GetAt(0) == '!') { | 366 if (wsName.GetAt(0) == '!') { |
| 367 wsName = wsName.Right(wsName.GetLength() - 1); | 367 wsName = wsName.Right(wsName.GetLength() - 1); |
| 368 m_pCreateParent = ToNode( | 368 m_pCreateParent = ToNode( |
| 369 pScriptContext->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets)); | 369 pScriptContext->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets)); |
| 370 } | 370 } |
| 371 if (wsName.GetAt(0) == '#') { | 371 if (wsName.GetAt(0) == '#') { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 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 = nullptr; |
| 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) { |
| 419 return; | 419 return; |
| 420 } | 420 } |
| 421 if (refNode->GetElementType() == XFA_Element::Subform) { | 421 if (refNode->GetElementType() == XFA_Element::Subform) { |
| 422 m_eLastCreateType = XFA_Element::DataGroup; | 422 m_eLastCreateType = XFA_Element::DataGroup; |
| 423 } else if (refNode->GetElementType() == XFA_Element::Field) { | 423 } else if (refNode->GetElementType() == 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->GetElementType() == XFA_Element::ExclGroup) { | 427 } else if (refNode->GetElementType() == 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->GetElementType(), | 436 XFA_GetPropertyOfElement(parent->GetElementType(), |
| 437 refNode->GetElementType(), | 437 refNode->GetElementType(), |
| 438 XFA_XDPPACKET_UNKNOWN); | 438 XFA_XDPPACKET_UNKNOWN); |
| 439 } | 439 } |
| OLD | NEW |