summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpdf_formcontrol.h4
-rw-r--r--core/fpdfdoc/cpdf_formfield.cpp11
-rw-r--r--core/fpdfdoc/cpdf_formfield.h15
-rw-r--r--core/fpdfdoc/cpdf_interform.cpp17
-rw-r--r--core/fpdfdoc/cpdf_interform.h3
5 files changed, 24 insertions, 26 deletions
diff --git a/core/fpdfdoc/cpdf_formcontrol.h b/core/fpdfdoc/cpdf_formcontrol.h
index d24dd04941..c0dad39098 100644
--- a/core/fpdfdoc/cpdf_formcontrol.h
+++ b/core/fpdfdoc/cpdf_formcontrol.h
@@ -46,6 +46,8 @@ class CPDF_FormControl {
public:
enum HighlightingMode { None = 0, Invert, Outline, Push, Toggle };
+ CPDF_FormControl(CPDF_FormField* pField, CPDF_Dictionary* pWidgetDict);
+
CPDF_FormField::Type GetType() const { return m_pField->GetType(); }
CPDF_InterForm* GetInterForm() const { return m_pForm; }
CPDF_FormField* GetField() const { return m_pField; }
@@ -111,8 +113,6 @@ class CPDF_FormControl {
friend class CPDF_InterForm;
friend class CPDF_FormField;
- CPDF_FormControl(CPDF_FormField* pField, CPDF_Dictionary* pWidgetDict);
-
CFX_ByteString GetOnStateName() const;
void SetOnStateName(const CFX_ByteString& csOn);
void CheckControl(bool bChecked);
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index cc7054dfaf..b344327adc 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -245,11 +245,8 @@ int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) const {
if (!pControl)
return -1;
- for (int i = 0; i < m_ControlList.GetSize(); i++) {
- if (m_ControlList.GetAt(i) == pControl)
- return i;
- }
- return -1;
+ auto it = std::find(m_ControlList.begin(), m_ControlList.end(), pControl);
+ return it != m_ControlList.end() ? it - m_ControlList.begin() : -1;
}
int CPDF_FormField::GetFieldType() const {
@@ -414,11 +411,9 @@ int CPDF_FormField::GetMaxLen() const {
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);
+ for (const auto& pControl : m_ControlList) {
if (!pControl)
continue;
-
CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict;
if (pWidgetDict->KeyExist("MaxLen"))
return pWidgetDict->GetIntegerFor("MaxLen");
diff --git a/core/fpdfdoc/cpdf_formfield.h b/core/fpdfdoc/cpdf_formfield.h
index 37f17c3a8a..9a1ddc4599 100644
--- a/core/fpdfdoc/cpdf_formfield.h
+++ b/core/fpdfdoc/cpdf_formfield.h
@@ -7,11 +7,14 @@
#ifndef CORE_FPDFDOC_CPDF_FORMFIELD_H_
#define CORE_FPDFDOC_CPDF_FORMFIELD_H_
+#include <vector>
+
#include "core/fpdfdoc/cpdf_aaction.h"
#include "core/fpdfdoc/cpdf_formfield.h"
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
+#include "third_party/base/stl_util.h"
#define FIELDTYPE_UNKNOWN 0
#define FIELDTYPE_PUSHBUTTON 1
@@ -58,12 +61,12 @@ class CPDF_FormField {
bool ResetField(bool bNotify = false);
- int CountControls() const { return m_ControlList.GetSize(); }
-
- CPDF_FormControl* GetControl(int index) const {
- return m_ControlList.GetAt(index);
+ int CountControls() const {
+ return pdfium::CollectionSize<int>(m_ControlList);
}
+ CPDF_FormControl* GetControl(int index) const { return m_ControlList[index]; }
+
int GetControlIndex(const CPDF_FormControl* pControl) const;
int GetFieldType() const;
@@ -150,9 +153,9 @@ class CPDF_FormField {
CPDF_FormField::Type m_Type;
uint32_t m_Flags;
- CPDF_InterForm* m_pForm;
+ CPDF_InterForm* const m_pForm;
CPDF_Dictionary* m_pDict;
- CFX_ArrayTemplate<CPDF_FormControl*> m_ControlList;
+ std::vector<CPDF_FormControl*> m_ControlList; // Owned by InterForm parent.
FX_FLOAT m_FontSize;
CPDF_Font* m_pFont;
};
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp
index e574e28fe5..6cffea6222 100644
--- a/core/fpdfdoc/cpdf_interform.cpp
+++ b/core/fpdfdoc/cpdf_interform.cpp
@@ -669,9 +669,7 @@ CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument)
}
CPDF_InterForm::~CPDF_InterForm() {
- for (auto it : m_ControlMap)
- delete it.second;
-
+ m_ControlMap.clear();
size_t nCount = m_pFieldTree->m_Root.CountFields();
for (size_t i = 0; i < nCount; ++i)
delete m_pFieldTree->m_Root.GetFieldAtIndex(i);
@@ -919,7 +917,7 @@ CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage,
if (it == m_ControlMap.end())
continue;
- CPDF_FormControl* pControl = it->second;
+ CPDF_FormControl* pControl = it->second.get();
CFX_FloatRect rect = pControl->GetRect();
if (!rect.Contains(pdf_x, pdf_y))
continue;
@@ -934,7 +932,7 @@ CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage,
CPDF_FormControl* CPDF_InterForm::GetControlByDict(
const CPDF_Dictionary* pWidgetDict) const {
const auto it = m_ControlMap.find(pWidgetDict);
- return it != m_ControlMap.end() ? it->second : nullptr;
+ return it != m_ControlMap.end() ? it->second.get() : nullptr;
}
bool CPDF_InterForm::NeedConstructAP() const {
@@ -1150,11 +1148,12 @@ CPDF_FormControl* CPDF_InterForm::AddControl(CPDF_FormField* pField,
CPDF_Dictionary* pWidgetDict) {
const auto it = m_ControlMap.find(pWidgetDict);
if (it != m_ControlMap.end())
- return it->second;
+ return it->second.get();
- CPDF_FormControl* pControl = new CPDF_FormControl(pField, pWidgetDict);
- m_ControlMap[pWidgetDict] = pControl;
- pField->m_ControlList.Add(pControl);
+ auto pNew = pdfium::MakeUnique<CPDF_FormControl>(pField, pWidgetDict);
+ CPDF_FormControl* pControl = pNew.get();
+ m_ControlMap[pWidgetDict] = std::move(pNew);
+ pField->m_ControlList.push_back(pControl);
return pControl;
}
diff --git a/core/fpdfdoc/cpdf_interform.h b/core/fpdfdoc/cpdf_interform.h
index f03ffb1e60..b846973435 100644
--- a/core/fpdfdoc/cpdf_interform.h
+++ b/core/fpdfdoc/cpdf_interform.h
@@ -112,7 +112,8 @@ class CPDF_InterForm {
CPDF_Document* const m_pDocument;
CPDF_Dictionary* m_pFormDict;
- std::map<const CPDF_Dictionary*, CPDF_FormControl*> m_ControlMap;
+ std::map<const CPDF_Dictionary*, std::unique_ptr<CPDF_FormControl>>
+ m_ControlMap;
std::unique_ptr<CFieldTree> m_pFieldTree;
CFX_ByteString m_bsEncoding;
IPDF_FormNotify* m_pFormNotify;