From 8584902d81ffabc06bb4895f558e375e5429fe72 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Sat, 28 Jul 2018 00:00:33 +0000 Subject: Remove CXFA_TraverseStrategy_ContentLayoutItem. It makes illegal casts and requires its callers to double-check the type validity of results before use. Instead, use the parent class iterator and perform checked casts. No functional difference, since it looks like the requisite checks were being made in all places. Make one "using" visible to other files to save some verbosity. Change-Id: I894ca15b4bdddd4723b787663950a58bc58b7f06 Reviewed-on: https://pdfium-review.googlesource.com/39030 Reviewed-by: Lei Zhang Commit-Queue: Lei Zhang --- fxjs/xfa/cjx_layoutpseudomodel.cpp | 51 ++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'fxjs/xfa') diff --git a/fxjs/xfa/cjx_layoutpseudomodel.cpp b/fxjs/xfa/cjx_layoutpseudomodel.cpp index 4918349111..ea842c78e0 100644 --- a/fxjs/xfa/cjx_layoutpseudomodel.cpp +++ b/fxjs/xfa/cjx_layoutpseudomodel.cpp @@ -24,7 +24,7 @@ #include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_nodeiteratortemplate.h" -#include "xfa/fxfa/parser/cxfa_traversestrategy_contentlayoutitem.h" +#include "xfa/fxfa/parser/cxfa_traversestrategy_layoutitem.h" const CJX_MethodSpec CJX_LayoutPseudoModel::MethodSpecs[] = { {"absPage", absPage_static}, @@ -244,14 +244,13 @@ std::vector CJX_LayoutPseudoModel::GetObjArray( if (pItem->GetFormNode()->GetElementType() == XFA_Element::ContentArea) { retArray.push_back(pItem->GetFormNode()); if (!bOnPageArea) { - CXFA_NodeIteratorTemplate - iterator(static_cast(pItem->m_pFirstChild)); - for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); - pItemChild; pItemChild = iterator.MoveToNext()) { - if (!pItemChild->IsContentLayoutItem()) { + CXFA_LayoutItemIterator iterator(pItem->m_pFirstChild); + for (CXFA_LayoutItem* pChild = iterator.GetCurrent(); pChild; + pChild = iterator.MoveToNext()) { + CXFA_ContentLayoutItem* pItemChild = pChild->AsContentLayoutItem(); + if (!pItemChild) continue; - } + XFA_Element eType = pItemChild->GetFormNode()->GetElementType(); if (eType != XFA_Element::Field && eType != XFA_Element::Draw && eType != XFA_Element::Subform && eType != XFA_Element::Area) { @@ -266,14 +265,13 @@ std::vector CJX_LayoutPseudoModel::GetObjArray( } } else { if (bOnPageArea) { - CXFA_NodeIteratorTemplate - iterator(static_cast(pItem)); - for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); - pItemChild; pItemChild = iterator.MoveToNext()) { - if (!pItemChild->IsContentLayoutItem()) { + CXFA_LayoutItemIterator iterator(pItem); + for (CXFA_LayoutItem* pChild = iterator.GetCurrent(); pChild; + pChild = iterator.MoveToNext()) { + CXFA_ContentLayoutItem* pItemChild = pChild->AsContentLayoutItem(); + if (!pItemChild) continue; - } + XFA_Element eType = pItemChild->GetFormNode()->GetElementType(); if (eType != XFA_Element::Field && eType != XFA_Element::Draw && eType != XFA_Element::Subform && eType != XFA_Element::Area) { @@ -281,6 +279,7 @@ std::vector CJX_LayoutPseudoModel::GetObjArray( } if (pdfium::ContainsValue(formItems, pItemChild->GetFormNode())) continue; + formItems.insert(pItemChild->GetFormNode()); retArray.push_back(pItemChild->GetFormNode()); } @@ -305,12 +304,11 @@ std::vector CJX_LayoutPseudoModel::GetObjArray( pItem = pItem->m_pNextSibling) { if (pItem->GetFormNode()->GetElementType() == XFA_Element::ContentArea) { if (!bOnPageArea) { - CXFA_NodeIteratorTemplate - iterator(static_cast(pItem->m_pFirstChild)); - for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); - pItemChild; pItemChild = iterator.MoveToNext()) { - if (!pItemChild->IsContentLayoutItem()) + CXFA_LayoutItemIterator iterator(pItem->m_pFirstChild); + for (CXFA_LayoutItem* pChild = iterator.GetCurrent(); pChild; + pChild = iterator.MoveToNext()) { + CXFA_ContentLayoutItem* pItemChild = pChild->AsContentLayoutItem(); + if (!pItemChild) continue; if (pItemChild->GetFormNode()->GetElementType() != eType) continue; @@ -323,12 +321,11 @@ std::vector CJX_LayoutPseudoModel::GetObjArray( } } else { if (bOnPageArea) { - CXFA_NodeIteratorTemplate - iterator(static_cast(pItem)); - for (CXFA_ContentLayoutItem* pItemChild = iterator.GetCurrent(); - pItemChild; pItemChild = iterator.MoveToNext()) { - if (!pItemChild->IsContentLayoutItem()) + CXFA_LayoutItemIterator iterator(pItem); + for (CXFA_LayoutItem* pChild = iterator.GetCurrent(); pChild; + pChild = iterator.MoveToNext()) { + CXFA_ContentLayoutItem* pItemChild = pChild->AsContentLayoutItem(); + if (!pItemChild) continue; if (pItemChild->GetFormNode()->GetElementType() != eType) continue; -- cgit v1.2.3