summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp6
-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
6 files changed, 27 insertions, 29 deletions
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index 62364c0a75..f9d9eb3a97 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -986,14 +986,14 @@ bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) {
if (!pArray)
return false;
- CFX_ArrayTemplate<uint32_t> WidthArray;
+ std::vector<uint32_t> WidthArray;
FX_SAFE_UINT32 dwAccWidth = 0;
for (size_t i = 0; i < pArray->GetCount(); ++i) {
- WidthArray.Add(pArray->GetIntegerAt(i));
+ WidthArray.push_back(pArray->GetIntegerAt(i));
dwAccWidth += WidthArray[i];
}
- if (!dwAccWidth.IsValid() || WidthArray.GetSize() < 3)
+ if (!dwAccWidth.IsValid() || WidthArray.size() < 3)
return false;
uint32_t totalWidth = dwAccWidth.ValueOrDie();
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;