Remove arguments from CPDF_FormField::SelectOption() that never change
Callers always pass bSelected as true and notify as kDoNotNotify. Then
simplify the resulting logic, and change return value as it is ignored
(and always true).
Change-Id: I446002b2c2e19faf3e7ff16dbbbe626ddd6c4830
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/80932
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index 31b7f7d..40f52aa 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -512,7 +512,7 @@
return;
}
- SelectOption(index, true, NotificationOption::kDoNotNotify);
+ SelectOption(index);
if (!m_bIsMultiSelectListBox) {
m_pDict->SetNewFor<CPDF_String>(pdfium::form_fields::kV, opt_value);
return;
@@ -732,58 +732,22 @@
pSelectedIndicesObject->GetInteger() == iOptIndex;
}
-bool CPDF_FormField::SelectOption(int iOptIndex,
- bool bSelected,
- NotificationOption notify) {
+void CPDF_FormField::SelectOption(int iOptIndex) {
CPDF_Array* pArray = m_pDict->GetArrayFor("I");
- if (!pArray) {
- if (!bSelected)
- return true;
-
+ if (!pArray)
pArray = m_pDict->SetNewFor<CPDF_Array>("I");
- }
- bool bReturn = false;
for (size_t i = 0; i < pArray->size(); i++) {
int iFind = pArray->GetIntegerAt(i);
- if (iFind == iOptIndex) {
- if (bSelected)
- return true;
-
- if (notify == NotificationOption::kNotify && m_pForm->GetFormNotify()) {
- WideString csValue = GetOptionLabel(iOptIndex);
- if (!NotifyListOrComboBoxBeforeChange(csValue))
- return false;
- }
- pArray->RemoveAt(i);
- bReturn = true;
- break;
- }
+ if (iFind == iOptIndex)
+ return;
if (iFind > iOptIndex) {
- if (!bSelected)
- continue;
-
- if (notify == NotificationOption::kNotify && m_pForm->GetFormNotify()) {
- WideString csValue = GetOptionLabel(iOptIndex);
- if (!NotifyListOrComboBoxBeforeChange(csValue))
- return false;
- }
pArray->InsertNewAt<CPDF_Number>(i, iOptIndex);
- bReturn = true;
- break;
+ return;
}
}
- if (!bReturn) {
- if (bSelected)
- pArray->AppendNew<CPDF_Number>(iOptIndex);
- if (pArray->IsEmpty())
- m_pDict->RemoveFor("I");
- }
- if (notify == NotificationOption::kNotify)
- NotifyListOrComboBoxAfterChange();
-
- return true;
+ pArray->AppendNew<CPDF_Number>(iOptIndex);
}
bool CPDF_FormField::UseSelectedIndicesObject() const {
diff --git a/core/fpdfdoc/cpdf_formfield.h b/core/fpdfdoc/cpdf_formfield.h
index 727c556..37a52cf 100644
--- a/core/fpdfdoc/cpdf_formfield.h
+++ b/core/fpdfdoc/cpdf_formfield.h
@@ -132,7 +132,7 @@
int GetSelectedOptionIndex(int index) const;
bool IsSelectedOption(const WideString& wsOptValue) const;
bool IsSelectedIndex(int iOptIndex) const;
- bool SelectOption(int iOptIndex, bool bSelected, NotificationOption notify);
+ void SelectOption(int iOptIndex);
// Verifies if there is a valid selected indicies (/I) object and whether its
// entries are consistent with the value (/V) object.