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(void) | 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 CXFA_NodeHelper::~CXFA_NodeHelper(void) {} | 26 |
| 27 CXFA_NodeHelper::~CXFA_NodeHelper() {} |
| 28 |
27 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetOneChild( | 29 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetOneChild( |
28 CXFA_Node* parent, | 30 CXFA_Node* parent, |
29 const FX_WCHAR* pwsName, | 31 const FX_WCHAR* pwsName, |
30 FX_BOOL bIsClassName) { | 32 FX_BOOL bIsClassName) { |
31 if (parent == NULL) { | 33 if (parent == NULL) { |
32 return NULL; | 34 return NULL; |
33 } | 35 } |
34 CXFA_NodeArray siblings; | 36 CXFA_NodeArray siblings; |
35 uint32_t uNameHash = FX_HashCode_GetW(CFX_WideStringC(pwsName), false); | 37 uint32_t uNameHash = FX_HashCode_GetW(CFX_WideStringC(pwsName), false); |
36 XFA_NodeAcc_TraverseAnySiblings(parent, uNameHash, &siblings, bIsClassName); | 38 XFA_NodeAcc_TraverseAnySiblings(parent, uNameHash, &siblings, bIsClassName); |
37 if (siblings.GetSize() == 0) { | 39 if (siblings.GetSize() == 0) { |
38 return NULL; | 40 return NULL; |
39 } | 41 } |
40 return siblings[0]; | 42 return siblings[0]; |
41 } | 43 } |
| 44 |
42 int32_t CXFA_NodeHelper::XFA_CountSiblings(CXFA_Node* pNode, | 45 int32_t CXFA_NodeHelper::XFA_CountSiblings(CXFA_Node* pNode, |
43 XFA_LOGIC_TYPE eLogicType, | 46 XFA_LOGIC_TYPE eLogicType, |
44 CXFA_NodeArray* pSiblings, | 47 CXFA_NodeArray* pSiblings, |
45 FX_BOOL bIsClassName) { | 48 FX_BOOL bIsClassName) { |
46 if (!pNode) | 49 if (!pNode) |
47 return 0; | 50 return 0; |
48 CXFA_Node* parent = | 51 CXFA_Node* parent = |
49 XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); | 52 XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); |
50 if (!parent) | 53 if (!parent) |
51 return 0; | 54 return 0; |
52 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( | 55 const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
53 parent->GetClassID(), pNode->GetClassID(), XFA_XDPPACKET_UNKNOWN); | 56 parent->GetClassID(), pNode->GetClassID(), XFA_XDPPACKET_UNKNOWN); |
54 if (!pProperty && eLogicType == XFA_LOGIC_Transparent) { | 57 if (!pProperty && eLogicType == XFA_LOGIC_Transparent) { |
55 parent = XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); | 58 parent = XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); |
56 if (parent == NULL) { | 59 if (parent == NULL) { |
57 return 0; | 60 return 0; |
58 } | 61 } |
59 } | 62 } |
60 if (bIsClassName) { | 63 if (bIsClassName) { |
61 return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetClassHashCode(), | 64 return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetClassHashCode(), |
62 pSiblings, eLogicType, bIsClassName); | 65 pSiblings, eLogicType, bIsClassName); |
63 } else { | 66 } else { |
64 return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetNameHash(), pSiblings, | 67 return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetNameHash(), pSiblings, |
65 eLogicType, bIsClassName); | 68 eLogicType, bIsClassName); |
66 } | 69 } |
67 } | 70 } |
| 71 |
68 int32_t CXFA_NodeHelper::XFA_NodeAcc_TraverseAnySiblings( | 72 int32_t CXFA_NodeHelper::XFA_NodeAcc_TraverseAnySiblings( |
69 CXFA_Node* parent, | 73 CXFA_Node* parent, |
70 uint32_t dNameHash, | 74 uint32_t dNameHash, |
71 CXFA_NodeArray* pSiblings, | 75 CXFA_NodeArray* pSiblings, |
72 FX_BOOL bIsClassName) { | 76 FX_BOOL bIsClassName) { |
73 if (parent == NULL || pSiblings == NULL) { | 77 if (parent == NULL || pSiblings == NULL) { |
74 return 0; | 78 return 0; |
75 } | 79 } |
76 int32_t nCount = 0; | 80 int32_t nCount = 0; |
77 int32_t i = 0; | 81 int32_t i = 0; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 122 } |
119 } | 123 } |
120 if (nCount > 0) { | 124 if (nCount > 0) { |
121 return nCount; | 125 return nCount; |
122 } | 126 } |
123 nCount += XFA_NodeAcc_TraverseAnySiblings(child, dNameHash, pSiblings, | 127 nCount += XFA_NodeAcc_TraverseAnySiblings(child, dNameHash, pSiblings, |
124 bIsClassName); | 128 bIsClassName); |
125 } | 129 } |
126 return nCount; | 130 return nCount; |
127 } | 131 } |
| 132 |
128 int32_t CXFA_NodeHelper::XFA_NodeAcc_TraverseSiblings(CXFA_Node* parent, | 133 int32_t CXFA_NodeHelper::XFA_NodeAcc_TraverseSiblings(CXFA_Node* parent, |
129 uint32_t dNameHash, | 134 uint32_t dNameHash, |
130 CXFA_NodeArray* pSiblings, | 135 CXFA_NodeArray* pSiblings, |
131 XFA_LOGIC_TYPE eLogicType, | 136 XFA_LOGIC_TYPE eLogicType, |
132 FX_BOOL bIsClassName, | 137 FX_BOOL bIsClassName, |
133 FX_BOOL bIsFindProperty) { | 138 FX_BOOL bIsFindProperty) { |
134 if (parent == NULL || pSiblings == NULL) { | 139 if (parent == NULL || pSiblings == NULL) { |
135 return 0; | 140 return 0; |
136 } | 141 } |
137 int32_t nCount = 0; | 142 int32_t nCount = 0; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 continue; | 198 continue; |
194 } | 199 } |
195 if (XFA_NodeIsTransparent(child) && | 200 if (XFA_NodeIsTransparent(child) && |
196 child->GetClassID() != XFA_ELEMENT_PageSet) { | 201 child->GetClassID() != XFA_ELEMENT_PageSet) { |
197 nCount += XFA_NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, | 202 nCount += XFA_NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, |
198 eLogicType, bIsClassName, FALSE); | 203 eLogicType, bIsClassName, FALSE); |
199 } | 204 } |
200 } | 205 } |
201 return nCount; | 206 return nCount; |
202 } | 207 } |
| 208 |
203 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetParent( | 209 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetParent( |
204 CXFA_Node* pNode, | 210 CXFA_Node* pNode, |
205 XFA_LOGIC_TYPE eLogicType) { | 211 XFA_LOGIC_TYPE eLogicType) { |
206 if (!pNode) { | 212 if (!pNode) { |
207 return NULL; | 213 return NULL; |
208 } | 214 } |
209 if (eLogicType == XFA_LOGIC_NoTransparent) { | 215 if (eLogicType == XFA_LOGIC_NoTransparent) { |
210 return pNode->GetNodeItem(XFA_NODEITEM_Parent); | 216 return pNode->GetNodeItem(XFA_NODEITEM_Parent); |
211 } | 217 } |
212 CXFA_Node* parent; | 218 CXFA_Node* parent; |
213 CXFA_Node* node = pNode; | 219 CXFA_Node* node = pNode; |
214 while (TRUE) { | 220 while (TRUE) { |
215 parent = XFA_ResolveNodes_GetParent(node); | 221 parent = XFA_ResolveNodes_GetParent(node); |
216 if (parent == NULL) { | 222 if (parent == NULL) { |
217 break; | 223 break; |
218 } | 224 } |
219 XFA_ELEMENT parentElement = parent->GetClassID(); | 225 XFA_ELEMENT parentElement = parent->GetClassID(); |
220 if ((!parent->IsUnnamed() && parentElement != XFA_ELEMENT_SubformSet) || | 226 if ((!parent->IsUnnamed() && parentElement != XFA_ELEMENT_SubformSet) || |
221 parentElement == XFA_ELEMENT_Variables) { | 227 parentElement == XFA_ELEMENT_Variables) { |
222 break; | 228 break; |
223 } | 229 } |
224 node = parent; | 230 node = parent; |
225 } | 231 } |
226 return parent; | 232 return parent; |
227 } | 233 } |
| 234 |
228 int32_t CXFA_NodeHelper::XFA_GetIndex(CXFA_Node* pNode, | 235 int32_t CXFA_NodeHelper::XFA_GetIndex(CXFA_Node* pNode, |
229 XFA_LOGIC_TYPE eLogicType, | 236 XFA_LOGIC_TYPE eLogicType, |
230 FX_BOOL bIsProperty, | 237 FX_BOOL bIsProperty, |
231 FX_BOOL bIsClassIndex) { | 238 FX_BOOL bIsClassIndex) { |
232 CXFA_Node* parent = | 239 CXFA_Node* parent = |
233 XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); | 240 XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); |
234 if (parent == NULL) { | 241 if (parent == NULL) { |
235 return 0; | 242 return 0; |
236 } | 243 } |
237 if (!bIsProperty && eLogicType == XFA_LOGIC_Transparent) { | 244 if (!bIsProperty && eLogicType == XFA_LOGIC_Transparent) { |
(...skipping 10 matching lines...) Expand all Loading... |
248 int32_t iSize = XFA_NodeAcc_TraverseSiblings(parent, dwHashName, &siblings, | 255 int32_t iSize = XFA_NodeAcc_TraverseSiblings(parent, dwHashName, &siblings, |
249 eLogicType, bIsClassIndex); | 256 eLogicType, bIsClassIndex); |
250 for (int32_t i = 0; i < iSize; ++i) { | 257 for (int32_t i = 0; i < iSize; ++i) { |
251 CXFA_Node* child = siblings[i]; | 258 CXFA_Node* child = siblings[i]; |
252 if (child == pNode) { | 259 if (child == pNode) { |
253 return i; | 260 return i; |
254 } | 261 } |
255 } | 262 } |
256 return 0; | 263 return 0; |
257 } | 264 } |
| 265 |
258 void CXFA_NodeHelper::XFA_GetNameExpression(CXFA_Node* refNode, | 266 void CXFA_NodeHelper::XFA_GetNameExpression(CXFA_Node* refNode, |
259 CFX_WideString& wsName, | 267 CFX_WideString& wsName, |
260 FX_BOOL bIsAllPath, | 268 FX_BOOL bIsAllPath, |
261 XFA_LOGIC_TYPE eLogicType) { | 269 XFA_LOGIC_TYPE eLogicType) { |
262 wsName.clear(); | 270 wsName.clear(); |
263 if (bIsAllPath) { | 271 if (bIsAllPath) { |
264 XFA_GetNameExpression(refNode, wsName, FALSE, eLogicType); | 272 XFA_GetNameExpression(refNode, wsName, FALSE, eLogicType); |
265 CFX_WideString wsParent; | 273 CFX_WideString wsParent; |
266 CXFA_Node* parent = | 274 CXFA_Node* parent = |
267 XFA_ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); | 275 XFA_ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); |
(...skipping 29 matching lines...) Expand all Loading... |
297 return FALSE; | 305 return FALSE; |
298 } | 306 } |
299 XFA_ELEMENT eRefNode = refNode->GetClassID(); | 307 XFA_ELEMENT eRefNode = refNode->GetClassID(); |
300 if ((refNode->IsUnnamed() && refNode->IsContainerNode()) || | 308 if ((refNode->IsUnnamed() && refNode->IsContainerNode()) || |
301 eRefNode == XFA_ELEMENT_SubformSet || eRefNode == XFA_ELEMENT_Area || | 309 eRefNode == XFA_ELEMENT_SubformSet || eRefNode == XFA_ELEMENT_Area || |
302 eRefNode == XFA_ELEMENT_Proto) { | 310 eRefNode == XFA_ELEMENT_Proto) { |
303 return TRUE; | 311 return TRUE; |
304 } | 312 } |
305 return FALSE; | 313 return FALSE; |
306 } | 314 } |
| 315 |
307 FX_BOOL CXFA_NodeHelper::XFA_CreateNode_ForCondition( | 316 FX_BOOL CXFA_NodeHelper::XFA_CreateNode_ForCondition( |
308 CFX_WideString& wsCondition) { | 317 CFX_WideString& wsCondition) { |
309 int32_t iLen = wsCondition.GetLength(); | 318 int32_t iLen = wsCondition.GetLength(); |
310 CFX_WideString wsIndex(L"0"); | 319 CFX_WideString wsIndex(L"0"); |
311 FX_BOOL bAll = FALSE; | 320 FX_BOOL bAll = FALSE; |
312 if (iLen == 0) { | 321 if (iLen == 0) { |
313 m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeOne; | 322 m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeOne; |
314 return FALSE; | 323 return FALSE; |
315 } | 324 } |
316 if (wsCondition.GetAt(0) == '[') { | 325 if (wsCondition.GetAt(0) == '[') { |
(...skipping 18 matching lines...) Expand all Loading... |
335 } else { | 344 } else { |
336 m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeOne; | 345 m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeOne; |
337 wsIndex = wsCondition.Mid(i, iLen - 1 - i); | 346 wsIndex = wsCondition.Mid(i, iLen - 1 - i); |
338 } | 347 } |
339 int32_t iIndex = wsIndex.GetInteger(); | 348 int32_t iIndex = wsIndex.GetInteger(); |
340 m_iCreateCount = iIndex; | 349 m_iCreateCount = iIndex; |
341 return TRUE; | 350 return TRUE; |
342 } | 351 } |
343 return FALSE; | 352 return FALSE; |
344 } | 353 } |
| 354 |
345 FX_BOOL CXFA_NodeHelper::XFA_ResolveNodes_CreateNode( | 355 FX_BOOL CXFA_NodeHelper::XFA_ResolveNodes_CreateNode( |
346 CFX_WideString wsName, | 356 CFX_WideString wsName, |
347 CFX_WideString wsCondition, | 357 CFX_WideString wsCondition, |
348 FX_BOOL bLastNode, | 358 FX_BOOL bLastNode, |
349 CXFA_ScriptContext* pScriptContext) { | 359 CXFA_ScriptContext* pScriptContext) { |
350 if (m_pCreateParent == NULL) { | 360 if (m_pCreateParent == NULL) { |
351 return FALSE; | 361 return FALSE; |
352 } | 362 } |
353 FX_BOOL bIsClassName = FALSE; | 363 FX_BOOL bIsClassName = FALSE; |
354 FX_BOOL bResult = FALSE; | 364 FX_BOOL bResult = FALSE; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 } | 406 } |
397 bResult = TRUE; | 407 bResult = TRUE; |
398 } | 408 } |
399 } | 409 } |
400 } | 410 } |
401 if (!bResult) { | 411 if (!bResult) { |
402 m_pCreateParent = NULL; | 412 m_pCreateParent = NULL; |
403 } | 413 } |
404 return bResult; | 414 return bResult; |
405 } | 415 } |
| 416 |
406 void CXFA_NodeHelper::XFA_SetCreateNodeType(CXFA_Node* refNode) { | 417 void CXFA_NodeHelper::XFA_SetCreateNodeType(CXFA_Node* refNode) { |
407 if (refNode == NULL) { | 418 if (refNode == NULL) { |
408 return; | 419 return; |
409 } | 420 } |
410 if (refNode->GetClassID() == XFA_ELEMENT_Subform) { | 421 if (refNode->GetClassID() == XFA_ELEMENT_Subform) { |
411 m_eLastCreateType = XFA_ELEMENT_DataGroup; | 422 m_eLastCreateType = XFA_ELEMENT_DataGroup; |
412 } else if (refNode->GetClassID() == XFA_ELEMENT_Field) { | 423 } else if (refNode->GetClassID() == XFA_ELEMENT_Field) { |
413 m_eLastCreateType = XFA_FieldIsMultiListBox(refNode) | 424 m_eLastCreateType = XFA_FieldIsMultiListBox(refNode) |
414 ? XFA_ELEMENT_DataGroup | 425 ? XFA_ELEMENT_DataGroup |
415 : XFA_ELEMENT_DataValue; | 426 : XFA_ELEMENT_DataValue; |
416 } else if (refNode->GetClassID() == XFA_ELEMENT_ExclGroup) { | 427 } else if (refNode->GetClassID() == XFA_ELEMENT_ExclGroup) { |
417 m_eLastCreateType = XFA_ELEMENT_DataValue; | 428 m_eLastCreateType = XFA_ELEMENT_DataValue; |
418 } | 429 } |
419 } | 430 } |
| 431 |
420 FX_BOOL CXFA_NodeHelper::XFA_NodeIsProperty(CXFA_Node* refNode) { | 432 FX_BOOL CXFA_NodeHelper::XFA_NodeIsProperty(CXFA_Node* refNode) { |
421 CXFA_Node* parent = | 433 CXFA_Node* parent = |
422 XFA_ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); | 434 XFA_ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); |
423 return parent && refNode && | 435 return parent && refNode && |
424 XFA_GetPropertyOfElement(parent->GetClassID(), refNode->GetClassID(), | 436 XFA_GetPropertyOfElement(parent->GetClassID(), refNode->GetClassID(), |
425 XFA_XDPPACKET_UNKNOWN); | 437 XFA_XDPPACKET_UNKNOWN); |
426 } | 438 } |
OLD | NEW |