summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpdf_formfield.cpp
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2018-01-12 18:36:30 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-12 18:36:30 +0000
commit9baf31f8c38e1c5266609e184cc07e369b744760 (patch)
tree37002a8148539b21f2562454b4864f0056f2aed2 /core/fpdfdoc/cpdf_formfield.cpp
parent72d34be06324624ee4dcf27b1f001ab573ddec06 (diff)
downloadpdfium-9baf31f8c38e1c5266609e184cc07e369b744760.tar.xz
Use enum for tracking form field types
Within PDFium use enum class for better type safety when working with form field types. These values will still be converted to ints as part of the public API, since that is the existing API. This work is preperation for extending the number of form field types to have more specific entries for XFA. BUG=pdfium:952,chromium:763129,chromium:592758 Change-Id: Ie6c29f02ae22be782ff36eb87d27f1a4bf2c099e Reviewed-on: https://pdfium-review.googlesource.com/22742 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core/fpdfdoc/cpdf_formfield.cpp')
-rw-r--r--core/fpdfdoc/cpdf_formfield.cpp27
1 files changed, 17 insertions, 10 deletions
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index 2502fe6faa..df59369723 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -45,6 +45,14 @@ bool IsUnison(CPDF_FormField* pField) {
} // namespace
+Optional<FormFieldType> IntToFormFieldType(int value) {
+ if (value >= static_cast<int>(FormFieldType::kUnknown) &&
+ value < static_cast<int>(kFormFieldTypeCount)) {
+ return {static_cast<FormFieldType>(value)};
+ }
+ return {};
+}
+
CPDF_Object* FPDF_GetFieldAttr(const CPDF_Dictionary* pFieldDict,
const char* name,
int nLevel) {
@@ -238,28 +246,27 @@ int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl) const {
return it != m_ControlList.end() ? it - m_ControlList.begin() : -1;
}
-int CPDF_FormField::GetFieldType() const {
+FormFieldType CPDF_FormField::GetFieldType() const {
switch (m_Type) {
case PushButton:
- return FIELDTYPE_PUSHBUTTON;
+ return FormFieldType::kPushButton;
case CheckBox:
- return FIELDTYPE_CHECKBOX;
+ return FormFieldType::kCheckBox;
case RadioButton:
- return FIELDTYPE_RADIOBUTTON;
+ return FormFieldType::kRadioButton;
case ComboBox:
- return FIELDTYPE_COMBOBOX;
+ return FormFieldType::kComboBox;
case ListBox:
- return FIELDTYPE_LISTBOX;
+ return FormFieldType::kListBox;
case Text:
case RichText:
case File:
- return FIELDTYPE_TEXTFIELD;
+ return FormFieldType::kTextField;
case Sign:
- return FIELDTYPE_SIGNATURE;
+ return FormFieldType::kSignature;
default:
- break;
+ return FormFieldType::kUnknown;
}
- return FIELDTYPE_UNKNOWN;
}
CPDF_AAction CPDF_FormField::GetAdditionalAction() const {