Remove always-true boolean options to SetItemSelection()

Change-Id: I555a156de0954f8e96af3c318edad00db23f17bc
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/79430
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 576e3ba..eb58655 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -171,7 +171,7 @@
           !NotifyListOrComboBoxBeforeChange(csValue)) {
         return false;
       }
-      SetItemSelection(iIndex, true, NotificationOption::kDoNotNotify);
+      SetItemSelection(iIndex, NotificationOption::kDoNotNotify);
       if (notify == NotificationOption::kNotify)
         NotifyListOrComboBoxAfterChange();
       break;
@@ -360,7 +360,7 @@
       } else {
         if (!bDefault) {
           ClearSelection(NotificationOption::kDoNotNotify);
-          SetItemSelection(iIndex, true, NotificationOption::kDoNotNotify);
+          SetItemSelection(iIndex, NotificationOption::kDoNotNotify);
         }
       }
       if (notify == NotificationOption::kNotify)
@@ -381,7 +381,7 @@
       }
       if (!bDefault) {
         ClearSelection(NotificationOption::kDoNotNotify);
-        SetItemSelection(iIndex, true, NotificationOption::kDoNotNotify);
+        SetItemSelection(iIndex, NotificationOption::kDoNotNotify);
       }
       if (notify == NotificationOption::kNotify)
         NotifyAfterSelectionChange();
@@ -485,7 +485,6 @@
 }
 
 bool CPDF_FormField::SetItemSelection(int index,
-                                      bool bSelected,
                                       NotificationOption notify) {
   DCHECK(GetType() == kComboBox || GetType() == kListBox);
   if (index < 0 || index >= CountOptions())
@@ -497,10 +496,7 @@
     return false;
   }
 
-  if (bSelected)
-    SetItemSelectionSelected(index, opt_value);
-  else
-    SetItemSelectionUnselected(index, opt_value);
+  SetItemSelectionSelected(index, opt_value);
 
   // UseSelectedIndicesObject() has a non-trivial linearithmic run-time, so run
   // only if necessary.
@@ -534,39 +530,6 @@
   }
 }
 
-void CPDF_FormField::SetItemSelectionUnselected(int index,
-                                                const WideString& opt_value) {
-  const CPDF_Object* pValue = GetValueObject();
-  if (!pValue)
-    return;
-
-  if (GetType() != kListBox) {
-    m_pDict->RemoveFor(pdfium::form_fields::kV);
-    m_pDict->RemoveFor("I");
-    return;
-  }
-
-  SelectOption(index, false, NotificationOption::kDoNotNotify);
-  if (pValue->IsString()) {
-    if (pValue->GetUnicodeText() == opt_value) {
-      m_pDict->RemoveFor(pdfium::form_fields::kV);
-    }
-    return;
-  }
-
-  if (!pValue->IsArray())
-    return;
-
-  auto pArray = pdfium::MakeRetain<CPDF_Array>();
-  for (int i = 0; i < CountOptions(); i++) {
-    if (i != index && IsItemSelected(i))
-      pArray->AppendNew<CPDF_String>(GetOptionValue(i));
-  }
-  if (pArray->size() > 0) {
-    m_pDict->SetFor(pdfium::form_fields::kV, pArray);
-  }
-}
-
 bool CPDF_FormField::IsItemDefaultSelected(int index) const {
   DCHECK(GetType() == kComboBox || GetType() == kListBox);
   if (index < 0 || index >= CountOptions())
diff --git a/core/fpdfdoc/cpdf_formfield.h b/core/fpdfdoc/cpdf_formfield.h
index 826f8ec..cd2c823 100644
--- a/core/fpdfdoc/cpdf_formfield.h
+++ b/core/fpdfdoc/cpdf_formfield.h
@@ -113,7 +113,7 @@
 
   bool ClearSelection(NotificationOption notify);
   bool IsItemSelected(int index) const;
-  bool SetItemSelection(int index, bool bSelected, NotificationOption notify);
+  bool SetItemSelection(int index, NotificationOption notify);
 
   bool IsItemDefaultSelected(int index) const;
 
@@ -161,7 +161,6 @@
                      bool bDefault,
                      NotificationOption notify);
   void SetItemSelectionSelected(int index, const WideString& opt_value);
-  void SetItemSelectionUnselected(int index, const WideString& opt_value);
   bool NotifyBeforeSelectionChange(const WideString& value);
   void NotifyAfterSelectionChange();
   bool NotifyBeforeValueChange(const WideString& value);
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index c4269fd..d13eaba 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -540,10 +540,9 @@
 }
 
 void CPDFSDK_Widget::SetOptionSelection(int index,
-                                        bool bSelected,
                                         NotificationOption notify) {
   CPDF_FormField* pFormField = GetFormField();
-  pFormField->SetItemSelection(index, bSelected, notify);
+  pFormField->SetItemSelection(index, notify);
 #ifdef PDF_ENABLE_XFA
   if (notify == NotificationOption::kDoNotNotify)
     Synchronize(true);
diff --git a/fpdfsdk/cpdfsdk_widget.h b/fpdfsdk/cpdfsdk_widget.h
index c943727..42d914a 100644
--- a/fpdfsdk/cpdfsdk_widget.h
+++ b/fpdfsdk/cpdfsdk_widget.h
@@ -77,7 +77,7 @@
 
   void SetCheck(bool bChecked, NotificationOption notify);
   void SetValue(const WideString& sValue, NotificationOption notify);
-  void SetOptionSelection(int index, bool bSelected, NotificationOption notify);
+  void SetOptionSelection(int index, NotificationOption notify);
   void ClearSelection(NotificationOption notify);
   void SetTopVisibleIndex(int index);
 
diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp
index db9a7ff..7a8a1e1 100644
--- a/fpdfsdk/formfiller/cffl_combobox.cpp
+++ b/fpdfsdk/formfiller/cffl_combobox.cpp
@@ -102,8 +102,7 @@
     m_pWidget->SetValue(swText, NotificationOption::kDoNotNotify);
   } else {
     m_pWidget->GetSelectedIndex(0);
-    m_pWidget->SetOptionSelection(nCurSel, true,
-                                  NotificationOption::kDoNotNotify);
+    m_pWidget->SetOptionSelection(nCurSel, NotificationOption::kDoNotNotify);
   }
   ObservedPtr<CPDFSDK_Widget> observed_widget(m_pWidget.Get());
   ObservedPtr<CFFL_ComboBox> observed_this(this);
diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp
index 0cbc20a..29cd452 100644
--- a/fpdfsdk/formfiller/cffl_listbox.cpp
+++ b/fpdfsdk/formfiller/cffl_listbox.cpp
@@ -113,13 +113,11 @@
   m_pWidget->ClearSelection(NotificationOption::kDoNotNotify);
   if (m_pWidget->GetFieldFlags() & pdfium::form_flags::kChoiceMultiSelect) {
     for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; i++) {
-      if (pListBox->IsItemSelected(i)) {
-        m_pWidget->SetOptionSelection(i, true,
-                                      NotificationOption::kDoNotNotify);
-      }
+      if (pListBox->IsItemSelected(i))
+        m_pWidget->SetOptionSelection(i, NotificationOption::kDoNotNotify);
     }
   } else {
-    m_pWidget->SetOptionSelection(pListBox->GetCurSel(), true,
+    m_pWidget->SetOptionSelection(pListBox->GetCurSel(),
                                   NotificationOption::kDoNotNotify);
   }
   ObservedPtr<CPDFSDK_Widget> observed_widget(m_pWidget.Get());
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index 130d914..35ff13b 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -290,7 +290,7 @@
         break;
       if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
           !pFormField->IsItemSelected(array[i])) {
-        pFormField->SetItemSelection(array[i], true,
+        pFormField->SetItemSelection(array[i],
                                      NotificationOption::kDoNotNotify);
       }
     }
@@ -482,8 +482,7 @@
           for (const auto& str : strArray) {
             int index = pFormField->FindOption(str);
             if (!pFormField->IsItemSelected(index))
-              pFormField->SetItemSelection(index, true,
-                                           NotificationOption::kNotify);
+              pFormField->SetItemSelection(index, NotificationOption::kNotify);
           }
           UpdateFormField(pFormFillEnv, pFormField, true, false, true);
         }