summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpdf_formfield.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-10-15 18:51:11 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-10-15 18:51:11 +0000
commite4f2f4a3f4fd3e9f372912f4151d7c7843f9556f (patch)
treed88a221b657d7e09bd0fd7460644fd5c048515fb /core/fpdfdoc/cpdf_formfield.cpp
parent98ac76ec09ce72526134ad75f1921a1691804dd1 (diff)
downloadpdfium-e4f2f4a3f4fd3e9f372912f4151d7c7843f9556f.tar.xz
Use more UnownedPtr in CPDF_FormControl.
To make this work, remove an UnownedPtr vector in CPDF_FormField and make CPDF_InteractiveForm manage it instead. Also simplify some code within CPDF_FormControl and CPDF_InteractiveForm. Change-Id: Ifc3a979dcdb992376a48db7a40840d2e76078500 Reviewed-on: https://pdfium-review.googlesource.com/c/43938 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfdoc/cpdf_formfield.cpp')
-rw-r--r--core/fpdfdoc/cpdf_formfield.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index 4cb9496af9..2b06161b06 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -251,15 +251,20 @@ bool CPDF_FormField::ResetField(NotificationOption notify) {
}
int CPDF_FormField::CountControls() const {
- return pdfium::CollectionSize<int>(m_ControlList);
+ return pdfium::CollectionSize<int>(GetControls());
+}
+
+CPDF_FormControl* CPDF_FormField::GetControl(int index) const {
+ return GetControls()[index].Get();
}
int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) const {
if (!pControl)
return -1;
- auto it = std::find(m_ControlList.begin(), m_ControlList.end(), pControl);
- return it != m_ControlList.end() ? it - m_ControlList.begin() : -1;
+ const auto& controls = GetControls();
+ auto it = std::find(controls.begin(), controls.end(), pControl);
+ return it != controls.end() ? it - controls.begin() : -1;
}
FormFieldType CPDF_FormField::GetFieldType() const {
@@ -426,10 +431,11 @@ int CPDF_FormField::GetMaxLen() const {
if (const CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict.Get(), "MaxLen"))
return pObj->GetInteger();
- for (auto& pControl : m_ControlList) {
+ for (auto& pControl : GetControls()) {
if (!pControl)
continue;
- CPDF_Dictionary* pWidgetDict = pControl->GetWidget();
+
+ const CPDF_Dictionary* pWidgetDict = pControl->GetWidget();
if (pWidgetDict->KeyExist("MaxLen"))
return pWidgetDict->GetIntegerFor("MaxLen");
}
@@ -931,3 +937,8 @@ void CPDF_FormField::NotifyListOrComboBoxAfterChange() {
break;
}
}
+
+const std::vector<UnownedPtr<CPDF_FormControl>>& CPDF_FormField::GetControls()
+ const {
+ return m_pForm->GetControlsForField(this);
+}