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" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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->GetClassID(), pNode->GetClassID(), 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 == NULL) { |
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 { |
(...skipping 80 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->GetElementType() != XFA_Element::PageSet && |
158 child->GetClassID() != XFA_Element::Extras && | 158 child->GetElementType() != XFA_Element::Extras && |
159 child->GetClassID() != XFA_Element::Items) { | 159 child->GetElementType() != 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() && |
| 166 child->GetElementType() == XFA_Element::PageSet) { |
166 nCount += XFA_NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, | 167 nCount += XFA_NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, |
167 eLogicType, bIsClassName, FALSE); | 168 eLogicType, bIsClassName, FALSE); |
168 } | 169 } |
169 } | 170 } |
170 if (nCount > 0) { | 171 if (nCount > 0) { |
171 return nCount; | 172 return nCount; |
172 } | 173 } |
173 } | 174 } |
174 CXFA_NodeArray children; | 175 CXFA_NodeArray children; |
175 parent->GetNodeList(children, XFA_NODEFILTER_Children); | 176 parent->GetNodeList(children, XFA_NODEFILTER_Children); |
176 int32_t nChildren = children.GetSize(); | 177 int32_t nChildren = children.GetSize(); |
177 for (i = 0; i < nChildren; i++) { | 178 for (i = 0; i < nChildren; i++) { |
178 CXFA_Node* child = children[i]; | 179 CXFA_Node* child = children[i]; |
179 if (child->GetClassID() == XFA_Element::Variables) { | 180 if (child->GetElementType() == XFA_Element::Variables) { |
180 continue; | 181 continue; |
181 } | 182 } |
182 if (bIsClassName) { | 183 if (bIsClassName) { |
183 if (child->GetClassHashCode() == dNameHash) { | 184 if (child->GetClassHashCode() == dNameHash) { |
184 if (pSiblings) { | 185 if (pSiblings) { |
185 pSiblings->Add(child); | 186 pSiblings->Add(child); |
186 } | 187 } |
187 nCount++; | 188 nCount++; |
188 } | 189 } |
189 } else { | 190 } else { |
190 if (child->GetNameHash() == dNameHash) { | 191 if (child->GetNameHash() == dNameHash) { |
191 if (pSiblings) { | 192 if (pSiblings) { |
192 pSiblings->Add(child); | 193 pSiblings->Add(child); |
193 } | 194 } |
194 nCount++; | 195 nCount++; |
195 } | 196 } |
196 } | 197 } |
197 if (eLogicType == XFA_LOGIC_NoTransparent) { | 198 if (eLogicType == XFA_LOGIC_NoTransparent) { |
198 continue; | 199 continue; |
199 } | 200 } |
200 if (XFA_NodeIsTransparent(child) && | 201 if (XFA_NodeIsTransparent(child) && |
201 child->GetClassID() != XFA_Element::PageSet) { | 202 child->GetElementType() != XFA_Element::PageSet) { |
202 nCount += XFA_NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, | 203 nCount += XFA_NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, |
203 eLogicType, bIsClassName, FALSE); | 204 eLogicType, bIsClassName, FALSE); |
204 } | 205 } |
205 } | 206 } |
206 return nCount; | 207 return nCount; |
207 } | 208 } |
208 | 209 |
209 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetParent( | 210 CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetParent( |
210 CXFA_Node* pNode, | 211 CXFA_Node* pNode, |
211 XFA_LOGIC_TYPE eLogicType) { | 212 XFA_LOGIC_TYPE eLogicType) { |
212 if (!pNode) { | 213 if (!pNode) { |
213 return NULL; | 214 return NULL; |
214 } | 215 } |
215 if (eLogicType == XFA_LOGIC_NoTransparent) { | 216 if (eLogicType == XFA_LOGIC_NoTransparent) { |
216 return pNode->GetNodeItem(XFA_NODEITEM_Parent); | 217 return pNode->GetNodeItem(XFA_NODEITEM_Parent); |
217 } | 218 } |
218 CXFA_Node* parent; | 219 CXFA_Node* parent; |
219 CXFA_Node* node = pNode; | 220 CXFA_Node* node = pNode; |
220 while (TRUE) { | 221 while (TRUE) { |
221 parent = XFA_ResolveNodes_GetParent(node); | 222 parent = XFA_ResolveNodes_GetParent(node); |
222 if (parent == NULL) { | 223 if (parent == NULL) { |
223 break; | 224 break; |
224 } | 225 } |
225 XFA_Element parentElement = parent->GetClassID(); | 226 XFA_Element parentElement = parent->GetElementType(); |
226 if ((!parent->IsUnnamed() && parentElement != XFA_Element::SubformSet) || | 227 if ((!parent->IsUnnamed() && parentElement != XFA_Element::SubformSet) || |
227 parentElement == XFA_Element::Variables) { | 228 parentElement == XFA_Element::Variables) { |
228 break; | 229 break; |
229 } | 230 } |
230 node = parent; | 231 node = parent; |
231 } | 232 } |
232 return parent; | 233 return parent; |
233 } | 234 } |
234 | 235 |
235 int32_t CXFA_NodeHelper::XFA_GetIndex(CXFA_Node* pNode, | 236 int32_t CXFA_NodeHelper::XFA_GetIndex(CXFA_Node* pNode, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 wsName = wsParent; | 281 wsName = wsParent; |
281 parent = XFA_ResolveNodes_GetParent(parent, XFA_LOGIC_NoTransparent); | 282 parent = XFA_ResolveNodes_GetParent(parent, XFA_LOGIC_NoTransparent); |
282 } | 283 } |
283 return; | 284 return; |
284 } | 285 } |
285 | 286 |
286 CFX_WideStringC wsTagName; | 287 CFX_WideStringC wsTagName; |
287 CFX_WideString ws; | 288 CFX_WideString ws; |
288 FX_BOOL bIsProperty = XFA_NodeIsProperty(refNode); | 289 FX_BOOL bIsProperty = XFA_NodeIsProperty(refNode); |
289 if (refNode->IsUnnamed() || | 290 if (refNode->IsUnnamed() || |
290 (bIsProperty && refNode->GetClassID() != XFA_Element::PageSet)) { | 291 (bIsProperty && refNode->GetElementType() != XFA_Element::PageSet)) { |
291 refNode->GetClassName(wsTagName); | 292 refNode->GetClassName(wsTagName); |
292 ws = wsTagName; | 293 ws = wsTagName; |
293 wsName.Format(L"#%s[%d]", ws.c_str(), | 294 wsName.Format(L"#%s[%d]", ws.c_str(), |
294 XFA_GetIndex(refNode, eLogicType, bIsProperty, TRUE)); | 295 XFA_GetIndex(refNode, eLogicType, bIsProperty, TRUE)); |
295 return; | 296 return; |
296 } | 297 } |
297 ws = refNode->GetCData(XFA_ATTRIBUTE_Name); | 298 ws = refNode->GetCData(XFA_ATTRIBUTE_Name); |
298 ws.Replace(L".", L"\\."); | 299 ws.Replace(L".", L"\\."); |
299 wsName.Format(L"%s[%d]", ws.c_str(), | 300 wsName.Format(L"%s[%d]", ws.c_str(), |
300 XFA_GetIndex(refNode, eLogicType, bIsProperty, FALSE)); | 301 XFA_GetIndex(refNode, eLogicType, bIsProperty, FALSE)); |
301 } | 302 } |
302 | 303 |
303 FX_BOOL CXFA_NodeHelper::XFA_NodeIsTransparent(CXFA_Node* refNode) { | 304 FX_BOOL CXFA_NodeHelper::XFA_NodeIsTransparent(CXFA_Node* refNode) { |
304 if (refNode == NULL) { | 305 if (refNode == NULL) { |
305 return FALSE; | 306 return FALSE; |
306 } | 307 } |
307 XFA_Element eRefNode = refNode->GetClassID(); | 308 XFA_Element eRefNode = refNode->GetElementType(); |
308 if ((refNode->IsUnnamed() && refNode->IsContainerNode()) || | 309 if ((refNode->IsUnnamed() && refNode->IsContainerNode()) || |
309 eRefNode == XFA_Element::SubformSet || eRefNode == XFA_Element::Area || | 310 eRefNode == XFA_Element::SubformSet || eRefNode == XFA_Element::Area || |
310 eRefNode == XFA_Element::Proto) { | 311 eRefNode == XFA_Element::Proto) { |
311 return TRUE; | 312 return TRUE; |
312 } | 313 } |
313 return FALSE; | 314 return FALSE; |
314 } | 315 } |
315 | 316 |
316 FX_BOOL CXFA_NodeHelper::XFA_CreateNode_ForCondition( | 317 FX_BOOL CXFA_NodeHelper::XFA_CreateNode_ForCondition( |
317 CFX_WideString& wsCondition) { | 318 CFX_WideString& wsCondition) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 if (!bResult) { | 412 if (!bResult) { |
412 m_pCreateParent = NULL; | 413 m_pCreateParent = NULL; |
413 } | 414 } |
414 return bResult; | 415 return bResult; |
415 } | 416 } |
416 | 417 |
417 void CXFA_NodeHelper::XFA_SetCreateNodeType(CXFA_Node* refNode) { | 418 void CXFA_NodeHelper::XFA_SetCreateNodeType(CXFA_Node* refNode) { |
418 if (refNode == NULL) { | 419 if (refNode == NULL) { |
419 return; | 420 return; |
420 } | 421 } |
421 if (refNode->GetClassID() == XFA_Element::Subform) { | 422 if (refNode->GetElementType() == XFA_Element::Subform) { |
422 m_eLastCreateType = XFA_Element::DataGroup; | 423 m_eLastCreateType = XFA_Element::DataGroup; |
423 } else if (refNode->GetClassID() == XFA_Element::Field) { | 424 } else if (refNode->GetElementType() == XFA_Element::Field) { |
424 m_eLastCreateType = XFA_FieldIsMultiListBox(refNode) | 425 m_eLastCreateType = XFA_FieldIsMultiListBox(refNode) |
425 ? XFA_Element::DataGroup | 426 ? XFA_Element::DataGroup |
426 : XFA_Element::DataValue; | 427 : XFA_Element::DataValue; |
427 } else if (refNode->GetClassID() == XFA_Element::ExclGroup) { | 428 } else if (refNode->GetElementType() == XFA_Element::ExclGroup) { |
428 m_eLastCreateType = XFA_Element::DataValue; | 429 m_eLastCreateType = XFA_Element::DataValue; |
429 } | 430 } |
430 } | 431 } |
431 | 432 |
432 FX_BOOL CXFA_NodeHelper::XFA_NodeIsProperty(CXFA_Node* refNode) { | 433 FX_BOOL CXFA_NodeHelper::XFA_NodeIsProperty(CXFA_Node* refNode) { |
433 CXFA_Node* parent = | 434 CXFA_Node* parent = |
434 XFA_ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); | 435 XFA_ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); |
435 return parent && refNode && | 436 return parent && refNode && |
436 XFA_GetPropertyOfElement(parent->GetClassID(), refNode->GetClassID(), | 437 XFA_GetPropertyOfElement(parent->GetElementType(), |
| 438 refNode->GetElementType(), |
437 XFA_XDPPACKET_UNKNOWN); | 439 XFA_XDPPACKET_UNKNOWN); |
438 } | 440 } |
OLD | NEW |