summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-08-16 20:53:58 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-16 20:53:58 +0000
commitb2e6b4c44a38ea2ca9e021df31cd27eb67a45e35 (patch)
tree8e9392c73c3905d38d9e9e636adf8df9c7af072e /core/fpdfdoc
parentaa987a9a895d42749c0f5e4092618fe7ded6667e (diff)
downloadpdfium-b2e6b4c44a38ea2ca9e021df31cd27eb67a45e35.tar.xz
Replace optional bool bNotify with enum type.
Adds clarity to the call sites. Change-Id: Id4deed9adda2ad79f0847d618792429044d4f7d6 Reviewed-on: https://pdfium-review.googlesource.com/40351 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpdf_formfield.cpp119
-rw-r--r--core/fpdfdoc/cpdf_formfield.h32
-rw-r--r--core/fpdfdoc/cpdf_interform.cpp12
-rw-r--r--core/fpdfdoc/cpdf_interform.h8
4 files changed, 91 insertions, 80 deletions
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index 678a66acaf..e99c745cc9 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -171,34 +171,34 @@ WideString CPDF_FormField::GetFullName() const {
return FPDF_GetFullName(m_pDict.Get());
}
-bool CPDF_FormField::ResetField(bool bNotify) {
+bool CPDF_FormField::ResetField(NotificationOption notify) {
switch (m_Type) {
case CPDF_FormField::CheckBox:
case CPDF_FormField::RadioButton: {
int iCount = CountControls();
- if (iCount) {
- // TODO(weili): Check whether anything special needs to be done for
- // unison field. (When IsUnison(this) returns true/false.)
- for (int i = 0; i < iCount; i++)
- CheckControl(i, GetControl(i)->IsDefaultChecked(), false);
+ // TODO(weili): Check whether anything special needs to be done for
+ // unison field. (When IsUnison(this) returns true/false.)
+ for (int i = 0; i < iCount; i++) {
+ CheckControl(i, GetControl(i)->IsDefaultChecked(),
+ NotificationOption::kDoNotNotify);
}
- if (bNotify && m_pForm->GetFormNotify())
+ if (notify == NotificationOption::kNotify && m_pForm->GetFormNotify())
m_pForm->GetFormNotify()->AfterCheckedStatusChange(this);
break;
}
case CPDF_FormField::ComboBox:
case CPDF_FormField::ListBox: {
+ ClearSelection(NotificationOption::kDoNotNotify);
WideString csValue;
- ClearSelection();
int iIndex = GetDefaultSelectedItem();
if (iIndex >= 0)
csValue = GetOptionLabel(iIndex);
-
- if (bNotify && !NotifyListOrComboBoxBeforeChange(csValue))
+ if (notify == NotificationOption::kNotify &&
+ !NotifyListOrComboBoxBeforeChange(csValue)) {
return false;
-
- SetItemSelection(iIndex, true);
- if (bNotify)
+ }
+ SetItemSelection(iIndex, true, NotificationOption::kDoNotNotify);
+ if (notify == NotificationOption::kNotify)
NotifyListOrComboBoxAfterChange();
break;
}
@@ -220,9 +220,10 @@ bool CPDF_FormField::ResetField(bool bNotify) {
if (!pRV && (csDValue == csValue))
return false;
- if (bNotify && !NotifyBeforeValueChange(csDValue))
+ if (notify == NotificationOption::kNotify &&
+ !NotifyBeforeValueChange(csDValue)) {
return false;
-
+ }
if (pDV) {
std::unique_ptr<CPDF_Object> pClone = pDV->Clone();
if (!pClone)
@@ -235,7 +236,7 @@ bool CPDF_FormField::ResetField(bool bNotify) {
m_pDict->RemoveFor("V");
m_pDict->RemoveFor("RV");
}
- if (bNotify)
+ if (notify == NotificationOption::kNotify)
NotifyAfterValueChange();
break;
}
@@ -341,11 +342,11 @@ WideString CPDF_FormField::GetDefaultValue() const {
bool CPDF_FormField::SetValue(const WideString& value,
bool bDefault,
- bool bNotify) {
+ NotificationOption notify) {
switch (m_Type) {
case CheckBox:
case RadioButton: {
- SetCheckValue(value, bDefault, bNotify);
+ SetCheckValue(value, bDefault, notify);
return true;
}
case File:
@@ -353,9 +354,10 @@ bool CPDF_FormField::SetValue(const WideString& value,
case Text:
case ComboBox: {
WideString csValue = value;
- if (bNotify && !NotifyBeforeValueChange(csValue))
+ if (notify == NotificationOption::kNotify &&
+ !NotifyBeforeValueChange(csValue)) {
return false;
-
+ }
ByteString key(bDefault ? "DV" : "V");
int iIndex = FindOptionValue(csValue);
if (iIndex < 0) {
@@ -367,11 +369,11 @@ bool CPDF_FormField::SetValue(const WideString& value,
} else {
m_pDict->SetNewFor<CPDF_String>(key, PDF_EncodeText(csValue), false);
if (!bDefault) {
- ClearSelection();
- SetItemSelection(iIndex, true);
+ ClearSelection(NotificationOption::kDoNotNotify);
+ SetItemSelection(iIndex, true, NotificationOption::kDoNotNotify);
}
}
- if (bNotify)
+ if (notify == NotificationOption::kNotify)
NotifyAfterValueChange();
break;
}
@@ -383,14 +385,15 @@ bool CPDF_FormField::SetValue(const WideString& value,
if (bDefault && iIndex == GetDefaultSelectedItem())
return false;
- if (bNotify && !NotifyBeforeSelectionChange(value))
+ if (notify == NotificationOption::kNotify &&
+ !NotifyBeforeSelectionChange(value)) {
return false;
-
+ }
if (!bDefault) {
- ClearSelection();
- SetItemSelection(iIndex, true);
+ ClearSelection(NotificationOption::kDoNotNotify);
+ SetItemSelection(iIndex, true, NotificationOption::kDoNotNotify);
}
- if (bNotify)
+ if (notify == NotificationOption::kNotify)
NotifyAfterSelectionChange();
break;
}
@@ -400,8 +403,9 @@ bool CPDF_FormField::SetValue(const WideString& value,
return true;
}
-bool CPDF_FormField::SetValue(const WideString& value, bool bNotify) {
- return SetValue(value, false, bNotify);
+bool CPDF_FormField::SetValue(const WideString& value,
+ NotificationOption notify) {
+ return SetValue(value, false, notify);
}
int CPDF_FormField::GetMaxLen() const {
@@ -468,19 +472,18 @@ int CPDF_FormField::GetSelectedIndex(int index) const {
return -1;
}
-bool CPDF_FormField::ClearSelection(bool bNotify) {
- if (bNotify && m_pForm->GetFormNotify()) {
+bool CPDF_FormField::ClearSelection(NotificationOption notify) {
+ if (notify == NotificationOption::kNotify && m_pForm->GetFormNotify()) {
WideString csValue;
int iIndex = GetSelectedIndex(0);
if (iIndex >= 0)
csValue = GetOptionLabel(iIndex);
-
if (!NotifyListOrComboBoxBeforeChange(csValue))
return false;
}
m_pDict->RemoveFor("V");
m_pDict->RemoveFor("I");
- if (bNotify)
+ if (notify == NotificationOption::kNotify)
NotifyListOrComboBoxAfterChange();
return true;
}
@@ -528,18 +531,21 @@ bool CPDF_FormField::IsItemSelected(int index) const {
return false;
}
-bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) {
+bool CPDF_FormField::SetItemSelection(int index,
+ bool bSelected,
+ NotificationOption notify) {
ASSERT(GetType() == ComboBox || GetType() == ListBox);
if (index < 0 || index >= CountOptions())
return false;
WideString opt_value = GetOptionValue(index);
- if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value))
+ if (notify == NotificationOption::kNotify &&
+ !NotifyListOrComboBoxBeforeChange(opt_value)) {
return false;
-
+ }
if (bSelected) {
if (GetType() == ListBox) {
- SelectOption(index, true);
+ SelectOption(index, true, NotificationOption::kDoNotNotify);
if (!(m_Flags & kFormListMultiSelect)) {
m_pDict->SetNewFor<CPDF_String>("V", PDF_EncodeText(opt_value), false);
} else {
@@ -560,7 +566,7 @@ bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) {
const CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict.Get(), "V");
if (pValue) {
if (GetType() == ListBox) {
- SelectOption(index, false);
+ SelectOption(index, false, NotificationOption::kDoNotNotify);
if (pValue->IsString()) {
if (pValue->GetUnicodeText() == opt_value)
m_pDict->RemoveFor("V");
@@ -581,7 +587,7 @@ bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) {
}
}
}
- if (bNotify)
+ if (notify == NotificationOption::kNotify)
NotifyListOrComboBoxAfterChange();
return true;
}
@@ -655,7 +661,7 @@ int CPDF_FormField::FindOptionValue(const WideString& csOptValue) const {
bool CPDF_FormField::CheckControl(int iControlIndex,
bool bChecked,
- bool bNotify) {
+ NotificationOption notify) {
ASSERT(GetType() == CheckBox || GetType() == RadioButton);
CPDF_FormControl* pControl = GetControl(iControlIndex);
if (!pControl)
@@ -702,7 +708,7 @@ bool CPDF_FormField::CheckControl(int iControlIndex,
} else if (bChecked) {
m_pDict->SetNewFor<CPDF_Name>("V", ByteString::Format("%d", iControlIndex));
}
- if (bNotify && m_pForm->GetFormNotify())
+ if (notify == NotificationOption::kNotify && m_pForm->GetFormNotify())
m_pForm->GetFormNotify()->AfterCheckedStatusChange(this);
return true;
}
@@ -725,19 +731,21 @@ WideString CPDF_FormField::GetCheckValue(bool bDefault) const {
bool CPDF_FormField::SetCheckValue(const WideString& value,
bool bDefault,
- bool bNotify) {
+ NotificationOption notify) {
ASSERT(GetType() == CheckBox || GetType() == RadioButton);
int iCount = CountControls();
for (int i = 0; i < iCount; i++) {
CPDF_FormControl* pControl = GetControl(i);
WideString csExport = pControl->GetExportValue();
bool val = csExport == value;
- if (!bDefault)
- CheckControl(GetControlIndex(pControl), val);
+ if (!bDefault) {
+ CheckControl(GetControlIndex(pControl), val,
+ NotificationOption::kDoNotNotify);
+ }
if (val)
break;
}
- if (bNotify && m_pForm->GetFormNotify())
+ if (notify == NotificationOption::kNotify && m_pForm->GetFormNotify())
m_pForm->GetFormNotify()->AfterCheckedStatusChange(this);
return true;
}
@@ -775,7 +783,9 @@ bool CPDF_FormField::IsOptionSelected(int iOptIndex) const {
return false;
}
-bool CPDF_FormField::SelectOption(int iOptIndex, bool bSelected, bool bNotify) {
+bool CPDF_FormField::SelectOption(int iOptIndex,
+ bool bSelected,
+ NotificationOption notify) {
CPDF_Array* pArray = m_pDict->GetArrayFor("I");
if (!pArray) {
if (!bSelected)
@@ -791,7 +801,7 @@ bool CPDF_FormField::SelectOption(int iOptIndex, bool bSelected, bool bNotify) {
if (bSelected)
return true;
- if (bNotify && m_pForm->GetFormNotify()) {
+ if (notify == NotificationOption::kNotify && m_pForm->GetFormNotify()) {
WideString csValue = GetOptionLabel(iOptIndex);
if (!NotifyListOrComboBoxBeforeChange(csValue))
return false;
@@ -805,7 +815,7 @@ bool CPDF_FormField::SelectOption(int iOptIndex, bool bSelected, bool bNotify) {
if (!bSelected)
continue;
- if (bNotify && m_pForm->GetFormNotify()) {
+ if (notify == NotificationOption::kNotify && m_pForm->GetFormNotify()) {
WideString csValue = GetOptionLabel(iOptIndex);
if (!NotifyListOrComboBoxBeforeChange(csValue))
return false;
@@ -818,30 +828,27 @@ bool CPDF_FormField::SelectOption(int iOptIndex, bool bSelected, bool bNotify) {
if (!bReturn) {
if (bSelected)
pArray->AddNew<CPDF_Number>(iOptIndex);
-
if (pArray->IsEmpty())
m_pDict->RemoveFor("I");
}
- if (bNotify)
+ if (notify == NotificationOption::kNotify)
NotifyListOrComboBoxAfterChange();
return true;
}
-bool CPDF_FormField::ClearSelectedOptions(bool bNotify) {
- if (bNotify && m_pForm->GetFormNotify()) {
+bool CPDF_FormField::ClearSelectedOptions(NotificationOption notify) {
+ if (notify == NotificationOption::kNotify && m_pForm->GetFormNotify()) {
WideString csValue;
int iIndex = GetSelectedIndex(0);
if (iIndex >= 0)
csValue = GetOptionLabel(iIndex);
-
if (!NotifyListOrComboBoxBeforeChange(csValue))
return false;
}
m_pDict->RemoveFor("I");
- if (bNotify)
+ if (notify == NotificationOption::kNotify)
NotifyListOrComboBoxAfterChange();
-
return true;
}
diff --git a/core/fpdfdoc/cpdf_formfield.h b/core/fpdfdoc/cpdf_formfield.h
index 6f0006506f..7dc95e5809 100644
--- a/core/fpdfdoc/cpdf_formfield.h
+++ b/core/fpdfdoc/cpdf_formfield.h
@@ -12,12 +12,13 @@
#include <vector>
#include "core/fpdfdoc/cpdf_aaction.h"
-#include "core/fpdfdoc/cpdf_formfield.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/unowned_ptr.h"
#include "third_party/base/stl_util.h"
+enum class NotificationOption { kDoNotNotify = 0, kNotify };
+
enum class FormFieldType : uint8_t {
kUnknown = 0,
kPushButton = 1,
@@ -111,7 +112,7 @@ class CPDF_FormField {
CPDF_Dictionary* GetFieldDict() const { return m_pDict.Get(); }
void SetFieldDict(CPDF_Dictionary* pDict) { m_pDict = pDict; }
- bool ResetField(bool bNotify);
+ bool ResetField(NotificationOption notify);
int CountControls() const {
return pdfium::CollectionSize<int>(m_ControlList);
@@ -133,15 +134,15 @@ class CPDF_FormField {
WideString GetValue() const;
WideString GetDefaultValue() const;
- bool SetValue(const WideString& value, bool bNotify = false);
+ bool SetValue(const WideString& value, NotificationOption notify);
int GetMaxLen() const;
int CountSelectedItems() const;
int GetSelectedIndex(int index) const;
- bool ClearSelection(bool bNotify = false);
+ bool ClearSelection(NotificationOption notify);
bool IsItemSelected(int index) const;
- bool SetItemSelection(int index, bool bSelected, bool bNotify = false);
+ bool SetItemSelection(int index, bool bSelected, NotificationOption notify);
bool IsItemDefaultSelected(int index) const;
@@ -154,15 +155,17 @@ class CPDF_FormField {
int FindOption(WideString csOptLabel) const;
int FindOptionValue(const WideString& csOptValue) const;
- bool CheckControl(int iControlIndex, bool bChecked, bool bNotify = false);
+ bool CheckControl(int iControlIndex,
+ bool bChecked,
+ NotificationOption notify);
int GetTopVisibleIndex() const;
int CountSelectedOptions() const;
int GetSelectedOptionIndex(int index) const;
bool IsOptionSelected(int iOptIndex) const;
- bool SelectOption(int iOptIndex, bool bSelected, bool bNotify = false);
- bool ClearSelectedOptions(bool bNotify);
+ bool SelectOption(int iOptIndex, bool bSelected, NotificationOption notify);
+ bool ClearSelectedOptions(NotificationOption notify);
float GetFontSize() const { return m_FontSize; }
CPDF_Font* GetFont() const { return m_pFont.Get(); }
@@ -182,21 +185,20 @@ class CPDF_FormField {
private:
WideString GetValue(bool bDefault) const;
- bool SetValue(const WideString& value, bool bDefault, bool bNotify);
-
+ bool SetValue(const WideString& value,
+ bool bDefault,
+ NotificationOption notify);
void SyncFieldFlags();
int FindListSel(CPDF_String* str);
WideString GetOptionText(int index, int sub_index) const;
-
void LoadDA();
- bool SetCheckValue(const WideString& value, bool bDefault, bool bNotify);
-
+ bool SetCheckValue(const WideString& value,
+ bool bDefault,
+ NotificationOption notify);
bool NotifyBeforeSelectionChange(const WideString& value);
void NotifyAfterSelectionChange();
-
bool NotifyBeforeValueChange(const WideString& value);
void NotifyAfterValueChange();
-
bool NotifyListOrComboBoxBeforeChange(const WideString& value);
void NotifyListOrComboBoxAfterChange();
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp
index 953c96234c..97d22a2a93 100644
--- a/core/fpdfdoc/cpdf_interform.cpp
+++ b/core/fpdfdoc/cpdf_interform.cpp
@@ -815,7 +815,7 @@ int CPDF_InterForm::GetFormAlignment() const {
void CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields,
bool bIncludeOrExclude,
- bool bNotify) {
+ NotificationOption notify) {
size_t nCount = m_pFieldTree->m_Root.CountFields();
for (size_t i = 0; i < nCount; ++i) {
CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i);
@@ -823,22 +823,22 @@ void CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields,
continue;
if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField))
- pField->ResetField(bNotify);
+ pField->ResetField(notify);
}
- if (bNotify && m_pFormNotify)
+ if (notify == NotificationOption::kNotify && m_pFormNotify)
m_pFormNotify->AfterFormReset(this);
}
-void CPDF_InterForm::ResetForm(bool bNotify) {
+void CPDF_InterForm::ResetForm(NotificationOption notify) {
size_t nCount = m_pFieldTree->m_Root.CountFields();
for (size_t i = 0; i < nCount; ++i) {
CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i);
if (!pField)
continue;
- pField->ResetField(bNotify);
+ pField->ResetField(notify);
}
- if (bNotify && m_pFormNotify)
+ if (notify == NotificationOption::kNotify && m_pFormNotify)
m_pFormNotify->AfterFormReset(this);
}
diff --git a/core/fpdfdoc/cpdf_interform.h b/core/fpdfdoc/cpdf_interform.h
index 12c840f5f8..c5da15d48a 100644
--- a/core/fpdfdoc/cpdf_interform.h
+++ b/core/fpdfdoc/cpdf_interform.h
@@ -13,6 +13,7 @@
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fpdfdoc/cpdf_defaultappearance.h"
+#include "core/fpdfdoc/cpdf_formfield.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/unowned_ptr.h"
@@ -23,7 +24,6 @@ class CPDF_Document;
class CPDF_Dictionary;
class CPDF_Font;
class CPDF_FormControl;
-class CPDF_FormField;
class CPDF_Object;
class CPDF_Page;
class IPDF_FormNotify;
@@ -80,10 +80,12 @@ class CPDF_InterForm {
bool bIncludeOrExclude,
bool bSimpleFileSpec) const;
+ void ResetForm(NotificationOption notify);
+
+ // TODO(tsepez): Use a span.
void ResetForm(const std::vector<CPDF_FormField*>& fields,
bool bIncludeOrExclude,
- bool bNotify);
- void ResetForm(bool bNotify);
+ NotificationOption notify);
void SetFormNotify(IPDF_FormNotify* pNotify);
bool HasXFAForm() const;