summaryrefslogtreecommitdiff
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
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>
-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
-rw-r--r--fpdfsdk/cpdfsdk_interform.cpp10
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp25
-rw-r--r--fpdfsdk/cpdfsdk_widget.h8
-rw-r--r--fpdfsdk/formfiller/cffl_checkbox.cpp5
-rw-r--r--fpdfsdk/formfiller/cffl_combobox.cpp10
-rw-r--r--fpdfsdk/formfiller/cffl_listbox.cpp15
-rw-r--r--fpdfsdk/formfiller/cffl_radiobutton.cpp9
-rw-r--r--fpdfsdk/formfiller/cffl_textfield.cpp7
-rw-r--r--fxjs/cjs_document.cpp4
-rw-r--r--fxjs/cjs_field.cpp20
14 files changed, 151 insertions, 133 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;
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index b9256aac35..0e44268b39 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -327,7 +327,7 @@ void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) {
Optional<IJS_Runtime::JS_Error> err = pContext->RunScript(csJS);
if (!err && bRC && sValue.Compare(sOldValue) != 0)
- pField->SetValue(sValue, true);
+ pField->SetValue(sValue, NotificationOption::kNotify);
}
}
@@ -557,19 +557,17 @@ ByteString CPDFSDK_InterForm::ExportFormToFDFTextBuf() {
void CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) {
ASSERT(action.GetDict());
-
const CPDF_Dictionary* pActionDict = action.GetDict();
if (!pActionDict->KeyExist("Fields")) {
- m_pInterForm->ResetForm(true);
+ m_pInterForm->ResetForm(NotificationOption::kNotify);
return;
}
-
CPDF_ActionFields af(&action);
uint32_t dwFlags = action.GetFlags();
-
std::vector<const CPDF_Object*> fieldObjects = af.GetAllFields();
std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects);
- m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), true);
+ m_pInterForm->ResetForm(fields, !(dwFlags & 0x01),
+ NotificationOption::kNotify);
}
std::vector<CPDF_FormField*> CPDFSDK_InterForm::GetFieldFromObjects(
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index f9fdef829b..8bd1f10177 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -526,44 +526,45 @@ int CPDFSDK_Widget::GetMaxLen() const {
return pFormField->GetMaxLen();
}
-void CPDFSDK_Widget::SetCheck(bool bChecked, bool bNotify) {
+void CPDFSDK_Widget::SetCheck(bool bChecked, NotificationOption notify) {
CPDF_FormControl* pFormCtrl = GetFormControl();
CPDF_FormField* pFormField = pFormCtrl->GetField();
pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
- bNotify);
+ notify);
#ifdef PDF_ENABLE_XFA
if (!IsWidgetAppearanceValid(CPDF_Annot::Normal))
ResetAppearance(true);
- if (!bNotify)
+ if (notify == NotificationOption::kDoNotNotify)
Synchronize(true);
#endif // PDF_ENABLE_XFA
}
-void CPDFSDK_Widget::SetValue(const WideString& sValue, bool bNotify) {
+void CPDFSDK_Widget::SetValue(const WideString& sValue,
+ NotificationOption notify) {
CPDF_FormField* pFormField = GetFormField();
- pFormField->SetValue(sValue, bNotify);
+ pFormField->SetValue(sValue, notify);
#ifdef PDF_ENABLE_XFA
- if (!bNotify)
+ if (notify == NotificationOption::kDoNotNotify)
Synchronize(true);
#endif // PDF_ENABLE_XFA
}
void CPDFSDK_Widget::SetOptionSelection(int index,
bool bSelected,
- bool bNotify) {
+ NotificationOption notify) {
CPDF_FormField* pFormField = GetFormField();
- pFormField->SetItemSelection(index, bSelected, bNotify);
+ pFormField->SetItemSelection(index, bSelected, notify);
#ifdef PDF_ENABLE_XFA
- if (!bNotify)
+ if (notify == NotificationOption::kDoNotNotify)
Synchronize(true);
#endif // PDF_ENABLE_XFA
}
-void CPDFSDK_Widget::ClearSelection(bool bNotify) {
+void CPDFSDK_Widget::ClearSelection(NotificationOption notify) {
CPDF_FormField* pFormField = GetFormField();
- pFormField->ClearSelection(bNotify);
+ pFormField->ClearSelection(notify);
#ifdef PDF_ENABLE_XFA
- if (!bNotify)
+ if (notify == NotificationOption::kDoNotNotify)
Synchronize(true);
#endif // PDF_ENABLE_XFA
}
diff --git a/fpdfsdk/cpdfsdk_widget.h b/fpdfsdk/cpdfsdk_widget.h
index 1349981293..f3bdc54944 100644
--- a/fpdfsdk/cpdfsdk_widget.h
+++ b/fpdfsdk/cpdfsdk_widget.h
@@ -81,10 +81,10 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot {
int GetMaxLen() const;
WideString GetAlternateName() const;
- void SetCheck(bool bChecked, bool bNotify);
- void SetValue(const WideString& sValue, bool bNotify);
- void SetOptionSelection(int index, bool bSelected, bool bNotify);
- void ClearSelection(bool bNotify);
+ void SetCheck(bool bChecked, NotificationOption notify);
+ void SetValue(const WideString& sValue, NotificationOption notify);
+ void SetOptionSelection(int index, bool bSelected, NotificationOption notify);
+ void ClearSelection(NotificationOption notify);
void SetTopVisibleIndex(int index);
#ifdef PDF_ENABLE_XFA
diff --git a/fpdfsdk/formfiller/cffl_checkbox.cpp b/fpdfsdk/formfiller/cffl_checkbox.cpp
index 57119c5c31..4308c1a1a5 100644
--- a/fpdfsdk/formfiller/cffl_checkbox.cpp
+++ b/fpdfsdk/formfiller/cffl_checkbox.cpp
@@ -113,13 +113,14 @@ void CFFL_CheckBox::SaveData(CPDFSDK_PageView* pPageView) {
}
CPDFSDK_Widget::ObservedPtr observed_widget(m_pWidget.Get());
CFFL_CheckBox::ObservedPtr observed_this(this);
-
- m_pWidget->SetCheck(bNewChecked, false);
+ m_pWidget->SetCheck(bNewChecked, NotificationOption::kDoNotNotify);
if (!observed_widget)
return;
+
m_pWidget->UpdateField();
if (!observed_widget || !observed_this)
return;
+
SetChangeMark();
}
diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp
index 8aa656b856..e0f0f3fbe5 100644
--- a/fpdfsdk/formfiller/cffl_combobox.cpp
+++ b/fpdfsdk/formfiller/cffl_combobox.cpp
@@ -96,27 +96,27 @@ void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView) {
WideString swText = pWnd->GetText();
int32_t nCurSel = pWnd->GetSelect();
-
bool bSetValue = false;
-
if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)
bSetValue = (nCurSel < 0) || (swText != m_pWidget->GetOptionLabel(nCurSel));
if (bSetValue) {
- m_pWidget->SetValue(swText, false);
+ m_pWidget->SetValue(swText, NotificationOption::kDoNotNotify);
} else {
m_pWidget->GetSelectedIndex(0);
- m_pWidget->SetOptionSelection(nCurSel, true, false);
+ m_pWidget->SetOptionSelection(nCurSel, true,
+ NotificationOption::kDoNotNotify);
}
CPDFSDK_Widget::ObservedPtr observed_widget(m_pWidget.Get());
CFFL_ComboBox::ObservedPtr observed_this(this);
-
m_pWidget->ResetFieldAppearance(true);
if (!observed_widget)
return;
+
m_pWidget->UpdateField();
if (!observed_widget || !observed_this)
return;
+
SetChangeMark();
m_pWidget->GetPDFPage();
}
diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp
index bf24e116e5..c05400d13c 100644
--- a/fpdfsdk/formfiller/cffl_listbox.cpp
+++ b/fpdfsdk/formfiller/cffl_listbox.cpp
@@ -108,27 +108,32 @@ void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView) {
return;
int32_t nNewTopIndex = pListBox->GetTopVisibleIndex();
- m_pWidget->ClearSelection(false);
+ m_pWidget->ClearSelection(NotificationOption::kDoNotNotify);
if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) {
for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; i++) {
- if (pListBox->IsItemSelected(i))
- m_pWidget->SetOptionSelection(i, true, false);
+ if (pListBox->IsItemSelected(i)) {
+ m_pWidget->SetOptionSelection(i, true,
+ NotificationOption::kDoNotNotify);
+ }
}
} else {
- m_pWidget->SetOptionSelection(pListBox->GetCurSel(), true, false);
+ m_pWidget->SetOptionSelection(pListBox->GetCurSel(), true,
+ NotificationOption::kDoNotNotify);
}
CPDFSDK_Widget::ObservedPtr observed_widget(m_pWidget.Get());
CFFL_ListBox::ObservedPtr observed_this(this);
-
m_pWidget->SetTopVisibleIndex(nNewTopIndex);
if (!observed_widget)
return;
+
m_pWidget->ResetFieldAppearance(true);
if (!observed_widget)
return;
+
m_pWidget->UpdateField();
if (!observed_widget || !observed_this)
return;
+
SetChangeMark();
}
diff --git a/fpdfsdk/formfiller/cffl_radiobutton.cpp b/fpdfsdk/formfiller/cffl_radiobutton.cpp
index 73ac44de46..8105b0cdea 100644
--- a/fpdfsdk/formfiller/cffl_radiobutton.cpp
+++ b/fpdfsdk/formfiller/cffl_radiobutton.cpp
@@ -91,26 +91,25 @@ void CFFL_RadioButton::SaveData(CPDFSDK_PageView* pPageView) {
return;
bool bNewChecked = pWnd->IsChecked();
-
if (bNewChecked) {
CPDF_FormField* pField = m_pWidget->GetFormField();
for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) {
if (CPDF_FormControl* pCtrl = pField->GetControl(i)) {
- if (pCtrl->IsChecked()) {
+ if (pCtrl->IsChecked())
break;
- }
}
}
}
CPDFSDK_Widget::ObservedPtr observed_widget(m_pWidget.Get());
CFFL_RadioButton::ObservedPtr observed_this(this);
-
- m_pWidget->SetCheck(bNewChecked, false);
+ m_pWidget->SetCheck(bNewChecked, NotificationOption::kDoNotNotify);
if (!observed_widget)
return;
+
m_pWidget->UpdateField();
if (!observed_widget || !observed_this)
return;
+
SetChangeMark();
}
diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp
index da011e40ab..7293d426bc 100644
--- a/fpdfsdk/formfiller/cffl_textfield.cpp
+++ b/fpdfsdk/formfiller/cffl_textfield.cpp
@@ -138,19 +138,20 @@ void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) {
WideString sOldValue = m_pWidget->GetValue();
WideString sNewValue = pWnd->GetText();
-
CPDFSDK_Widget::ObservedPtr observed_widget(m_pWidget.Get());
CFFL_TextField::ObservedPtr observed_this(this);
-
- m_pWidget->SetValue(sNewValue, false);
+ m_pWidget->SetValue(sNewValue, NotificationOption::kDoNotNotify);
if (!observed_widget)
return;
+
m_pWidget->ResetFieldAppearance(true);
if (!observed_widget)
return;
+
m_pWidget->UpdateField();
if (!observed_widget || !observed_this)
return;
+
SetChangeMark();
}
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 7e89e40230..a6d68c8d29 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -465,7 +465,7 @@ CJS_Return CJS_Document::resetForm(
CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
if (params.empty()) {
- pPDFForm->ResetForm(true);
+ pPDFForm->ResetForm(NotificationOption::kNotify);
m_pFormFillEnv->SetChangeMark();
return CJS_Return();
}
@@ -487,7 +487,7 @@ CJS_Return CJS_Document::resetForm(
}
if (!aFields.empty()) {
- pPDFForm->ResetForm(aFields, true, true);
+ pPDFForm->ResetForm(aFields, true, NotificationOption::kNotify);
m_pFormFillEnv->SetChangeMark();
}
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index 45715e22a0..a14e16828a 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -254,13 +254,14 @@ void SetCurrentValueIndices(CPDFSDK_FormFillEnvironment* pFormFillEnv,
continue;
uint32_t dwFieldFlags = pFormField->GetFieldFlags();
- pFormField->ClearSelection(true);
+ pFormField->ClearSelection(NotificationOption::kNotify);
for (size_t i = 0; i < array.size(); ++i) {
if (i != 0 && !(dwFieldFlags & (1 << 21)))
break;
if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) &&
!pFormField->IsItemSelected(array[i])) {
- pFormField->SetItemSelection(array[i], true);
+ pFormField->SetItemSelection(array[i], true,
+ NotificationOption::kDoNotNotify);
}
}
UpdateFormField(pFormFillEnv, pFormField, true, true, true);
@@ -427,14 +428,14 @@ void SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
case FormFieldType::kTextField:
case FormFieldType::kComboBox:
if (pFormField->GetValue() != strArray[0]) {
- pFormField->SetValue(strArray[0], true);
+ pFormField->SetValue(strArray[0], NotificationOption::kNotify);
UpdateFormField(pFormFillEnv, pFormField, true, false, true);
}
break;
case FormFieldType::kCheckBox:
case FormFieldType::kRadioButton:
if (pFormField->GetValue() != strArray[0]) {
- pFormField->SetValue(strArray[0], true);
+ pFormField->SetValue(strArray[0], NotificationOption::kNotify);
UpdateFormField(pFormFillEnv, pFormField, true, false, true);
}
break;
@@ -447,11 +448,12 @@ void SetValue(CPDFSDK_FormFillEnvironment* pFormFillEnv,
}
}
if (bModified) {
- pFormField->ClearSelection(true);
+ pFormField->ClearSelection(NotificationOption::kNotify);
for (const auto& str : strArray) {
int index = pFormField->FindOption(str);
if (!pFormField->IsItemSelected(index))
- pFormField->SetItemSelection(index, true, true);
+ pFormField->SetItemSelection(index, true,
+ NotificationOption::kNotify);
}
UpdateFormField(pFormFillEnv, pFormField, true, false, true);
}
@@ -2212,7 +2214,7 @@ CJS_Return CJS_Field::browseForFileToSubmit(
(pFormField->GetFieldType() == FormFieldType::kTextField)) {
WideString wsFileName = m_pFormFillEnv->JS_fieldBrowse();
if (!wsFileName.IsEmpty()) {
- pFormField->SetValue(wsFileName);
+ pFormField->SetValue(wsFileName, NotificationOption::kDoNotNotify);
UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
}
return CJS_Return();
@@ -2323,13 +2325,13 @@ CJS_Return CJS_Field::checkThisBox(
if (!IsCheckBoxOrRadioButton(pFormField))
return CJS_Return(JSMessage::kObjectTypeError);
+
if (nWidget < 0 || nWidget >= pFormField->CountControls())
return CJS_Return(JSMessage::kValueError);
// TODO(weili): Check whether anything special needed for radio button.
// (When pFormField->GetFieldType() == FormFieldType::kRadioButton.)
- pFormField->CheckControl(nWidget, bCheckit, true);
-
+ pFormField->CheckControl(nWidget, bCheckit, NotificationOption::kNotify);
UpdateFormField(m_pFormFillEnv.Get(), pFormField, true, true, true);
return CJS_Return();
}