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_resolveprocessor.h" | 7 #include "xfa/fxfa/parser/xfa_script_resolveprocessor.h" |
8 | 8 |
9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
10 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" | 10 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 delete m_pNodeHelper; | 28 delete m_pNodeHelper; |
29 m_pNodeHelper = NULL; | 29 m_pNodeHelper = NULL; |
30 } | 30 } |
31 } | 31 } |
32 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes(CXFA_ResolveNodesData& rnd) { | 32 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes(CXFA_ResolveNodesData& rnd) { |
33 if (rnd.m_CurNode == NULL) { | 33 if (rnd.m_CurNode == NULL) { |
34 return -1; | 34 return -1; |
35 } | 35 } |
36 if (!rnd.m_CurNode->IsNode()) { | 36 if (!rnd.m_CurNode->IsNode()) { |
37 if (rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) { | 37 if (rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) { |
38 return XFA_ResolveNodes_ForAttributeRs(rnd.m_CurNode, rnd, rnd.m_wsName); | 38 return XFA_ResolveNodes_ForAttributeRs(rnd.m_CurNode, rnd, |
| 39 rnd.m_wsName.AsWideStringC()); |
39 } | 40 } |
40 return 0; | 41 return 0; |
41 } | 42 } |
42 if (rnd.m_dwStyles & XFA_RESOLVENODE_AnyChild) { | 43 if (rnd.m_dwStyles & XFA_RESOLVENODE_AnyChild) { |
43 return XFA_ResolveNodes_AnyChild(rnd); | 44 return XFA_ResolveNodes_AnyChild(rnd); |
44 } | 45 } |
45 FX_WCHAR wch = rnd.m_wsName.GetAt(0); | 46 FX_WCHAR wch = rnd.m_wsName.GetAt(0); |
46 switch (wch) { | 47 switch (wch) { |
47 case '$': | 48 case '$': |
48 return XFA_ResolveNodes_Dollar(rnd); | 49 return XFA_ResolveNodes_Dollar(rnd); |
(...skipping 14 matching lines...) Expand all Loading... |
63 return 1; | 64 return 1; |
64 } else if (rnd.m_CurNode->GetClassID() == XFA_ELEMENT_Xfa) { | 65 } else if (rnd.m_CurNode->GetClassID() == XFA_ELEMENT_Xfa) { |
65 CXFA_Object* pObjNode = | 66 CXFA_Object* pObjNode = |
66 rnd.m_pSC->GetDocument()->GetXFAObject(rnd.m_uHashName); | 67 rnd.m_pSC->GetDocument()->GetXFAObject(rnd.m_uHashName); |
67 if (pObjNode) { | 68 if (pObjNode) { |
68 rnd.m_Nodes.Add(pObjNode); | 69 rnd.m_Nodes.Add(pObjNode); |
69 } else if (rnd.m_uHashName == XFA_HASHCODE_Xfa) { | 70 } else if (rnd.m_uHashName == XFA_HASHCODE_Xfa) { |
70 rnd.m_Nodes.Add(rnd.m_CurNode); | 71 rnd.m_Nodes.Add(rnd.m_CurNode); |
71 } else if ((rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) && | 72 } else if ((rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) && |
72 XFA_ResolveNodes_ForAttributeRs(rnd.m_CurNode, rnd, | 73 XFA_ResolveNodes_ForAttributeRs(rnd.m_CurNode, rnd, |
73 rnd.m_wsName)) { | 74 rnd.m_wsName.AsWideStringC())) { |
74 return 1; | 75 return 1; |
75 } | 76 } |
76 if (rnd.m_Nodes.GetSize() > 0) { | 77 if (rnd.m_Nodes.GetSize() > 0) { |
77 XFA_ResolveNode_FilterCondition(rnd, rnd.m_wsCondition); | 78 XFA_ResolveNode_FilterCondition(rnd, rnd.m_wsCondition); |
78 } | 79 } |
79 return rnd.m_Nodes.GetSize(); | 80 return rnd.m_Nodes.GetSize(); |
80 } | 81 } |
81 int32_t nRet = XFA_ResolveNodes_Normal(rnd); | 82 int32_t nRet = XFA_ResolveNodes_Normal(rnd); |
82 if (nRet < 1 && rnd.m_uHashName == XFA_HASHCODE_Xfa) { | 83 if (nRet < 1 && rnd.m_uHashName == XFA_HASHCODE_Xfa) { |
83 rnd.m_Nodes.Add(rnd.m_pSC->GetDocument()->GetRoot()); | 84 rnd.m_Nodes.Add(rnd.m_pSC->GetDocument()->GetRoot()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 rnd.m_Nodes.Append(rndFind.m_Nodes); | 162 rnd.m_Nodes.Append(rndFind.m_Nodes); |
162 rndFind.m_Nodes.RemoveAll(); | 163 rndFind.m_Nodes.RemoveAll(); |
163 } | 164 } |
164 return rnd.m_Nodes.GetSize(); | 165 return rnd.m_Nodes.GetSize(); |
165 } | 166 } |
166 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_NumberSign( | 167 int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_NumberSign( |
167 CXFA_ResolveNodesData& rnd) { | 168 CXFA_ResolveNodesData& rnd) { |
168 CFX_WideString wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); | 169 CFX_WideString wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); |
169 CFX_WideString wsCondition = rnd.m_wsCondition; | 170 CFX_WideString wsCondition = rnd.m_wsCondition; |
170 CXFA_Node* curNode = ToNode(rnd.m_CurNode); | 171 CXFA_Node* curNode = ToNode(rnd.m_CurNode); |
171 if (XFA_ResolveNodes_ForAttributeRs(curNode, rnd, wsName)) { | 172 if (XFA_ResolveNodes_ForAttributeRs(curNode, rnd, wsName.AsWideStringC())) { |
172 return 1; | 173 return 1; |
173 } | 174 } |
174 CXFA_ResolveNodesData rndFind; | 175 CXFA_ResolveNodesData rndFind; |
175 rndFind.m_pSC = rnd.m_pSC; | 176 rndFind.m_pSC = rnd.m_pSC; |
176 rndFind.m_nLevel = rnd.m_nLevel + 1; | 177 rndFind.m_nLevel = rnd.m_nLevel + 1; |
177 rndFind.m_dwStyles = rnd.m_dwStyles; | 178 rndFind.m_dwStyles = rnd.m_dwStyles; |
178 rndFind.m_dwStyles |= XFA_RESOLVENODE_TagName; | 179 rndFind.m_dwStyles |= XFA_RESOLVENODE_TagName; |
179 rndFind.m_dwStyles &= ~XFA_RESOLVENODE_Attributes; | 180 rndFind.m_dwStyles &= ~XFA_RESOLVENODE_Attributes; |
180 rndFind.m_wsName = wsName; | 181 rndFind.m_wsName = wsName; |
181 rndFind.m_uHashName = | 182 rndFind.m_uHashName = |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 325 } |
325 } | 326 } |
326 XFA_ResolveNode_FilterCondition(rnd, wsCondition); | 327 XFA_ResolveNode_FilterCondition(rnd, wsCondition); |
327 if (nodes.GetSize() > 0) { | 328 if (nodes.GetSize() > 0) { |
328 return 1; | 329 return 1; |
329 } | 330 } |
330 return 0; | 331 return 0; |
331 } | 332 } |
332 } | 333 } |
333 if (dwStyles & XFA_RESOLVENODE_Attributes) { | 334 if (dwStyles & XFA_RESOLVENODE_Attributes) { |
334 if (XFA_ResolveNodes_ForAttributeRs(curNode, rnd, wsName)) { | 335 if (XFA_ResolveNodes_ForAttributeRs(curNode, rnd, wsName.AsWideStringC())) { |
335 return 1; | 336 return 1; |
336 } | 337 } |
337 } | 338 } |
338 if (dwStyles & XFA_RESOLVENODE_Properties) { | 339 if (dwStyles & XFA_RESOLVENODE_Properties) { |
339 for (int32_t i = 0; i < properties.GetSize(); i++) { | 340 for (int32_t i = 0; i < properties.GetSize(); i++) { |
340 CXFA_Node* childProperty = properties[i]; | 341 CXFA_Node* childProperty = properties[i]; |
341 if (childProperty->IsUnnamed()) { | 342 if (childProperty->IsUnnamed()) { |
342 uint32_t uPropHash = childProperty->GetClassHashCode(); | 343 uint32_t uPropHash = childProperty->GetClassHashCode(); |
343 if (uPropHash == uNameHash) { | 344 if (uPropHash == uNameHash) { |
344 nodes.Add(childProperty); | 345 nodes.Add(childProperty); |
(...skipping 13 matching lines...) Expand all Loading... |
358 } | 359 } |
359 CXFA_Node* pProp = NULL; | 360 CXFA_Node* pProp = NULL; |
360 if (XFA_ELEMENT_Subform == curNode->GetClassID() && | 361 if (XFA_ELEMENT_Subform == curNode->GetClassID() && |
361 XFA_HASHCODE_Occur == uNameHash) { | 362 XFA_HASHCODE_Occur == uNameHash) { |
362 CXFA_Node* pInstanceManager = | 363 CXFA_Node* pInstanceManager = |
363 curNode->AsNode()->GetInstanceMgrOfSubform(); | 364 curNode->AsNode()->GetInstanceMgrOfSubform(); |
364 if (pInstanceManager) { | 365 if (pInstanceManager) { |
365 pProp = pInstanceManager->GetProperty(0, XFA_ELEMENT_Occur, TRUE); | 366 pProp = pInstanceManager->GetProperty(0, XFA_ELEMENT_Occur, TRUE); |
366 } | 367 } |
367 } else { | 368 } else { |
368 const XFA_ELEMENTINFO* pElement = XFA_GetElementByName(wsName); | 369 const XFA_ELEMENTINFO* pElement = |
| 370 XFA_GetElementByName(wsName.AsWideStringC()); |
369 if (pElement) { | 371 if (pElement) { |
370 pProp = curNode->AsNode()->GetProperty( | 372 pProp = curNode->AsNode()->GetProperty( |
371 0, pElement->eName, pElement->eName != XFA_ELEMENT_PageSet); | 373 0, pElement->eName, pElement->eName != XFA_ELEMENT_PageSet); |
372 } | 374 } |
373 } | 375 } |
374 if (pProp) { | 376 if (pProp) { |
375 nodes.Add(pProp); | 377 nodes.Add(pProp); |
376 return nodes.GetSize(); | 378 return nodes.GetSize(); |
377 } | 379 } |
378 } | 380 } |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 } else { | 706 } else { |
705 return; | 707 return; |
706 } | 708 } |
707 | 709 |
708 CXFA_ScriptContext* pContext = rnd.m_pSC; | 710 CXFA_ScriptContext* pContext = rnd.m_pSC; |
709 wsExpression = wsCondition.Mid(2, wsCondition.GetLength() - 3); | 711 wsExpression = wsCondition.Mid(2, wsCondition.GetLength() - 3); |
710 for (int32_t i = iFoundCount - 1; i >= 0; i--) { | 712 for (int32_t i = iFoundCount - 1; i >= 0; i--) { |
711 CXFA_Object* node = findNodes[i]; | 713 CXFA_Object* node = findNodes[i]; |
712 FX_BOOL bRet = FALSE; | 714 FX_BOOL bRet = FALSE; |
713 FXJSE_HVALUE pRetValue = FXJSE_Value_Create(rnd.m_pSC->GetRuntime()); | 715 FXJSE_HVALUE pRetValue = FXJSE_Value_Create(rnd.m_pSC->GetRuntime()); |
714 bRet = pContext->RunScript(eLangType, wsExpression, pRetValue, node); | 716 bRet = pContext->RunScript(eLangType, wsExpression.AsWideStringC(), |
| 717 pRetValue, node); |
715 if (!bRet || !FXJSE_Value_ToBoolean(pRetValue)) { | 718 if (!bRet || !FXJSE_Value_ToBoolean(pRetValue)) { |
716 findNodes.RemoveAt(i); | 719 findNodes.RemoveAt(i); |
717 } | 720 } |
718 FXJSE_Value_Release(pRetValue); | 721 FXJSE_Value_Release(pRetValue); |
719 } | 722 } |
720 } | 723 } |
721 | 724 |
722 void CXFA_ResolveProcessor::XFA_ResolveNode_FilterCondition( | 725 void CXFA_ResolveProcessor::XFA_ResolveNode_FilterCondition( |
723 CXFA_ResolveNodesData& rnd, | 726 CXFA_ResolveNodesData& rnd, |
724 CFX_WideString wsCondition) { | 727 CFX_WideString wsCondition) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 if (m_pNodeHelper->XFA_CreateNode_ForCondition(wsNextCondition)) { | 820 if (m_pNodeHelper->XFA_CreateNode_ForCondition(wsNextCondition)) { |
818 if (m_pNodeHelper->m_eLastCreateType == XFA_ELEMENT_DataGroup) { | 821 if (m_pNodeHelper->m_eLastCreateType == XFA_ELEMENT_DataGroup) { |
819 iIndex = 0; | 822 iIndex = 0; |
820 } else { | 823 } else { |
821 iIndex = iCount - 1; | 824 iIndex = iCount - 1; |
822 } | 825 } |
823 } else { | 826 } else { |
824 iIndex = iCount - 1; | 827 iIndex = iCount - 1; |
825 } | 828 } |
826 } | 829 } |
OLD | NEW |