summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-07-12 19:06:50 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-12 19:06:50 +0000
commitdfa2ac2378dd85459ab2d65c06b68643d97fd355 (patch)
tree9e6b99a7042ab387880264024eb6a1e3873a9c25 /fxjs
parent47aff85a5f80cc3cd3a7c55869ab777c407bbf11 (diff)
downloadpdfium-dfa2ac2378dd85459ab2d65c06b68643d97fd355.tar.xz
Add a IsCheckBoxOrRadioButton() helper for CJS_Field.
Change-Id: I0e06d641d482cbcd2cf33f327d9504e55a772157 Reviewed-on: https://pdfium-review.googlesource.com/37672 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/cjs_field.cpp35
1 files changed, 14 insertions, 21 deletions
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index 6f6455d984..00f1ce23db 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -62,6 +62,11 @@ bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) {
return false;
}
+bool IsCheckBoxOrRadioButton(const CPDF_FormField* pFormField) {
+ return pFormField->GetFieldType() == FormFieldType::kCheckBox ||
+ pFormField->GetFieldType() == FormFieldType::kRadioButton;
+}
+
} // namespace
const JSPropertySpec CJS_Field::PropertySpecs[] = {
@@ -1082,10 +1087,8 @@ CJS_Return CJS_Field::get_export_values(CJS_Runtime* pRuntime) {
return CJS_Return(JSMessage::kBadObjectError);
CPDF_FormField* pFormField = FieldArray[0];
- if (pFormField->GetFieldType() != FormFieldType::kCheckBox &&
- pFormField->GetFieldType() != FormFieldType::kRadioButton) {
+ if (!IsCheckBoxOrRadioButton(pFormField))
return CJS_Return(JSMessage::kObjectTypeError);
- }
v8::Local<v8::Array> ExportValuesArray = pRuntime->NewArray();
if (m_nFormControlIndex < 0) {
@@ -1118,10 +1121,8 @@ CJS_Return CJS_Field::set_export_values(CJS_Runtime* pRuntime,
return CJS_Return(JSMessage::kBadObjectError);
CPDF_FormField* pFormField = FieldArray[0];
- if (pFormField->GetFieldType() != FormFieldType::kCheckBox &&
- pFormField->GetFieldType() != FormFieldType::kRadioButton) {
+ if (!IsCheckBoxOrRadioButton(pFormField))
return CJS_Return(JSMessage::kObjectTypeError);
- }
if (!m_bCanSet)
return CJS_Return(JSMessage::kReadOnlyError);
@@ -1872,10 +1873,8 @@ CJS_Return CJS_Field::get_style(CJS_Runtime* pRuntime) {
return CJS_Return(JSMessage::kBadObjectError);
CPDF_FormField* pFormField = FieldArray[0];
- if (pFormField->GetFieldType() != FormFieldType::kRadioButton &&
- pFormField->GetFieldType() != FormFieldType::kCheckBox) {
+ if (!IsCheckBoxOrRadioButton(pFormField))
return CJS_Return(JSMessage::kObjectTypeError);
- }
CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
if (!pFormControl)
@@ -2389,10 +2388,8 @@ CJS_Return CJS_Field::checkThisBox(
return CJS_Return(JSMessage::kBadObjectError);
CPDF_FormField* pFormField = FieldArray[0];
- if (pFormField->GetFieldType() != FormFieldType::kCheckBox &&
- pFormField->GetFieldType() != FormFieldType::kRadioButton) {
+ if (!IsCheckBoxOrRadioButton(pFormField))
return CJS_Return(JSMessage::kObjectTypeError);
- }
if (nWidget < 0 || nWidget >= pFormField->CountControls())
return CJS_Return(JSMessage::kValueError);
@@ -2429,9 +2426,7 @@ CJS_Return CJS_Field::defaultIsChecked(
if (nWidget < 0 || nWidget >= pFormField->CountControls())
return CJS_Return(JSMessage::kValueError);
- return CJS_Return(pRuntime->NewBoolean(
- pFormField->GetFieldType() == FormFieldType::kCheckBox ||
- pFormField->GetFieldType() == FormFieldType::kRadioButton));
+ return CJS_Return(pRuntime->NewBoolean(IsCheckBoxOrRadioButton(pFormField)));
}
CJS_Return CJS_Field::deleteItemAt(
@@ -2537,10 +2532,9 @@ CJS_Return CJS_Field::isBoxChecked(
if (nIndex < 0 || nIndex >= pFormField->CountControls())
return CJS_Return(JSMessage::kValueError);
- return CJS_Return(pRuntime->NewBoolean(
- ((pFormField->GetFieldType() == FormFieldType::kCheckBox ||
- pFormField->GetFieldType() == FormFieldType::kRadioButton) &&
- pFormField->GetControl(nIndex)->IsChecked() != 0)));
+ return CJS_Return(
+ pRuntime->NewBoolean((IsCheckBoxOrRadioButton(pFormField) &&
+ pFormField->GetControl(nIndex)->IsChecked() != 0)));
}
CJS_Return CJS_Field::isDefaultChecked(
@@ -2559,8 +2553,7 @@ CJS_Return CJS_Field::isDefaultChecked(
return CJS_Return(JSMessage::kValueError);
return CJS_Return(pRuntime->NewBoolean(
- ((pFormField->GetFieldType() == FormFieldType::kCheckBox ||
- pFormField->GetFieldType() == FormFieldType::kRadioButton) &&
+ (IsCheckBoxOrRadioButton(pFormField) &&
pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)));
}