summaryrefslogtreecommitdiff
path: root/core/src/fpdfdoc
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-12-09 16:39:40 -0800
committerTom Sepez <tsepez@chromium.org>2015-12-09 16:39:40 -0800
commitbd573f126f93acc2034be2df1c6f571670f76c35 (patch)
treebeeea3b9370bb7490ed5933dadbef857cb8df23d /core/src/fpdfdoc
parente021e084717b8cc43f8a0667ad9d1a807dfe381c (diff)
downloadpdfium-bd573f126f93acc2034be2df1c6f571670f76c35.tar.xz
Merge to XFA: Get rid of most uses of CFX_PtrArray.
Original Review URL: https://codereview.chromium.org/1518593002 . (cherry picked from commit 035359cd8ddb555fa33b6133db4fd405e4660712) R=thestig@chromium.org TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1513103002 .
Diffstat (limited to 'core/src/fpdfdoc')
-rw-r--r--core/src/fpdfdoc/doc_form.cpp41
-rw-r--r--core/src/fpdfdoc/doc_formfield.cpp36
-rw-r--r--core/src/fpdfdoc/tagged_int.h2
3 files changed, 30 insertions, 49 deletions
diff --git a/core/src/fpdfdoc/doc_form.cpp b/core/src/fpdfdoc/doc_form.cpp
index c73b3e199e..9417ffe1a9 100644
--- a/core/src/fpdfdoc/doc_form.cpp
+++ b/core/src/fpdfdoc/doc_form.cpp
@@ -36,7 +36,7 @@ class CFieldTree {
public:
struct _Node {
_Node* parent;
- CFX_PtrArray children;
+ CFX_ArrayTemplate<_Node*> children;
CFX_WideString short_name;
CPDF_FormField* field_ptr;
int CountFields(int nLevel = 0) {
@@ -48,7 +48,7 @@ class CFieldTree {
}
int count = 0;
for (int i = 0; i < children.GetSize(); i++) {
- count += ((_Node*)children.GetAt(i))->CountFields(nLevel + 1);
+ count += children.GetAt(i)->CountFields(nLevel + 1);
}
return count;
}
@@ -61,11 +61,8 @@ class CFieldTree {
return NULL;
}
for (int i = 0; i < children.GetSize(); i++) {
- _Node* pNode = (_Node*)children.GetAt(i);
- CPDF_FormField* pField = pNode->GetField(fields_to_go);
- if (pField) {
+ if (CPDF_FormField* pField = children.GetAt(i)->GetField(fields_to_go))
return pField;
- }
}
return NULL;
}
@@ -109,17 +106,13 @@ CFieldTree::_Node* CFieldTree::AddChild(_Node* pParent,
return pNode;
}
void CFieldTree::RemoveNode(_Node* pNode, int nLevel) {
- if (pNode == NULL) {
+ if (!pNode) {
return;
}
- if (nLevel > nMaxRecursion) {
- delete pNode;
- return;
- }
- CFX_PtrArray& ptr_array = pNode->children;
- for (int i = 0; i < ptr_array.GetSize(); i++) {
- _Node* pChild = (_Node*)ptr_array[i];
- RemoveNode(pChild, nLevel + 1);
+ if (nLevel <= nMaxRecursion) {
+ for (int i = 0; i < pNode->children.GetSize(); i++) {
+ RemoveNode(pNode->children[i], nLevel + 1);
+ }
}
delete pNode;
}
@@ -128,9 +121,8 @@ CFieldTree::_Node* CFieldTree::_Lookup(_Node* pParent,
if (pParent == NULL) {
return NULL;
}
- CFX_PtrArray& ptr_array = pParent->children;
- for (int i = 0; i < ptr_array.GetSize(); i++) {
- _Node* pNode = (_Node*)ptr_array[i];
+ for (int i = 0; i < pParent->children.GetSize(); i++) {
+ _Node* pNode = pParent->children[i];
if (pNode->short_name.GetLength() == short_name.GetLength() &&
FXSYS_memcmp(pNode->short_name.c_str(), short_name.c_str(),
short_name.GetLength() * sizeof(FX_WCHAR)) == 0) {
@@ -140,10 +132,8 @@ CFieldTree::_Node* CFieldTree::_Lookup(_Node* pParent,
return NULL;
}
void CFieldTree::RemoveAll() {
- CFX_PtrArray& ptr_array = m_Root.children;
- for (int i = 0; i < ptr_array.GetSize(); i++) {
- _Node* pNode = (_Node*)ptr_array[i];
- RemoveNode(pNode);
+ for (int i = 0; i < m_Root.children.GetSize(); i++) {
+ RemoveNode(m_Root.children[i]);
}
}
void CFieldTree::SetField(const CFX_WideString& full_name,
@@ -202,10 +192,9 @@ CPDF_FormField* CFieldTree::RemoveField(const CFX_WideString& full_name) {
name_extractor.GetNext(pName, nLength);
}
if (pNode && pNode != &m_Root) {
- CFX_PtrArray& ptr_array = pLast->children;
- for (int i = 0; i < ptr_array.GetSize(); i++) {
- if (pNode == (_Node*)ptr_array[i]) {
- ptr_array.RemoveAt(i);
+ for (int i = 0; i < pLast->children.GetSize(); i++) {
+ if (pNode == pLast->children[i]) {
+ pLast->children.RemoveAt(i);
break;
}
}
diff --git a/core/src/fpdfdoc/doc_formfield.cpp b/core/src/fpdfdoc/doc_formfield.cpp
index c5d789a4e4..ca2fe05476 100644
--- a/core/src/fpdfdoc/doc_formfield.cpp
+++ b/core/src/fpdfdoc/doc_formfield.cpp
@@ -207,15 +207,12 @@ FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) {
return TRUE;
}
int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) {
- if (pControl == NULL) {
+ if (!pControl) {
return -1;
}
- int iCount = m_ControlList.GetSize();
- for (int i = 0; i < iCount; i++) {
- CPDF_FormControl* pFind = (CPDF_FormControl*)m_ControlList.GetAt(i);
- if (pFind == pControl) {
+ for (int i = 0; i < m_ControlList.GetSize(); i++) {
+ if (m_ControlList.GetAt(i) == pControl)
return i;
- }
}
return -1;
}
@@ -399,22 +396,19 @@ FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bNotify) {
return SetValue(value, FALSE, bNotify);
}
int CPDF_FormField::GetMaxLen() {
- CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen");
- if (pObj == NULL) {
- int iCount = m_ControlList.GetSize();
- for (int i = 0; i < iCount; i++) {
- CPDF_FormControl* pControl = (CPDF_FormControl*)m_ControlList.GetAt(i);
- if (pControl == NULL) {
- continue;
- }
- CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict;
- if (pWidgetDict->KeyExist("MaxLen")) {
- return pWidgetDict->GetInteger("MaxLen");
- }
- }
- return 0;
+ if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen"))
+ return pObj->GetInteger();
+
+ for (int i = 0; i < m_ControlList.GetSize(); i++) {
+ CPDF_FormControl* pControl = m_ControlList.GetAt(i);
+ if (!pControl)
+ continue;
+
+ CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict;
+ if (pWidgetDict->KeyExist("MaxLen"))
+ return pWidgetDict->GetInteger("MaxLen");
}
- return pObj->GetInteger();
+ return 0;
}
int CPDF_FormField::CountSelectedItems() {
CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
diff --git a/core/src/fpdfdoc/tagged_int.h b/core/src/fpdfdoc/tagged_int.h
index b7f18bd177..b9ae86bc6a 100644
--- a/core/src/fpdfdoc/tagged_int.h
+++ b/core/src/fpdfdoc/tagged_int.h
@@ -53,7 +53,6 @@ class CPDF_StructElementImpl final : public CPDF_StructElement {
const CPDF_StructKid& GetKid(int index) const override {
return m_Kids.GetData()[index];
}
- CFX_PtrArray* GetObjectArray() override { return &m_ObjectArray; }
CPDF_Object* GetAttr(const CFX_ByteStringC& owner,
const CFX_ByteStringC& name,
FX_BOOL bInheritable = FALSE,
@@ -79,7 +78,6 @@ class CPDF_StructElementImpl final : public CPDF_StructElement {
FX_BOOL bInheritable = FALSE,
int subindex = -1) override;
- CFX_PtrArray m_ObjectArray;
void LoadKids(CPDF_Dictionary* pDict);
void LoadKid(FX_DWORD PageObjNum, CPDF_Object* pObj, CPDF_StructKid* pKid);
CPDF_Object* GetAttr(const CFX_ByteStringC& owner,