summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfformfill.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 /fpdfsdk/fpdfformfill.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 'fpdfsdk/fpdfformfill.cpp')
-rw-r--r--fpdfsdk/fpdfformfill.cpp57
1 files changed, 49 insertions, 8 deletions
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp
index 3d61336d13..cc2861f7f2 100644
--- a/fpdfsdk/fpdfformfill.cpp
+++ b/fpdfsdk/fpdfformfill.cpp
@@ -44,6 +44,37 @@ static_assert(static_cast<int>(FormType::kXFAForeground) ==
"XFA foreground form types must match");
#endif // PDF_ENABLE_XFA
+static_assert(static_cast<int>(FormFieldType::kUnknown) ==
+ FPDF_FORMFIELD_UNKNOWN,
+ "Unknown form field types must match");
+static_assert(static_cast<int>(FormFieldType::kPushButton) ==
+ FPDF_FORMFIELD_PUSHBUTTON,
+ "PushButton form field types must match");
+static_assert(static_cast<int>(FormFieldType::kCheckBox) ==
+ FPDF_FORMFIELD_CHECKBOX,
+ "CheckBox form field types must match");
+static_assert(static_cast<int>(FormFieldType::kRadioButton) ==
+ FPDF_FORMFIELD_RADIOBUTTON,
+ "RadioButton form field types must match");
+static_assert(static_cast<int>(FormFieldType::kComboBox) ==
+ FPDF_FORMFIELD_COMBOBOX,
+ "ComboBox form field types must match");
+static_assert(static_cast<int>(FormFieldType::kListBox) ==
+ FPDF_FORMFIELD_LISTBOX,
+ "ListBox form field types must match");
+static_assert(static_cast<int>(FormFieldType::kTextField) ==
+ FPDF_FORMFIELD_TEXTFIELD,
+ "TextField form field types must match");
+static_assert(static_cast<int>(FormFieldType::kSignature) ==
+ FPDF_FORMFIELD_SIGNATURE,
+ "Signature form field types must match");
+#ifdef PDF_ENABLE_XFA
+static_assert(static_cast<int>(FormFieldType::kXFA) == FPDF_FORMFIELD_XFA,
+ "XFA form field types must match");
+#endif // PDF_ENABLE_XFA
+static_assert(kFormFieldTypeCount == FPDF_FORMFIELD_COUNT,
+ "Number of form field types must match");
+
namespace {
CPDFSDK_FormFillEnvironment* HandleToCPDFSDKEnvironment(
@@ -173,7 +204,7 @@ FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
if (!pFormCtrl)
return -1;
CPDF_FormField* pFormField = pFormCtrl->GetField();
- return pFormField ? pFormField->GetFieldType() : -1;
+ return pFormField ? static_cast<int>(pFormField->GetFieldType()) : -1;
}
#ifdef PDF_ENABLE_XFA
@@ -199,17 +230,16 @@ FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle,
if (!pWidgetIterator)
return -1;
- CXFA_FFWidget* pXFAAnnot = pWidgetIterator->MoveToNext();
- while (pXFAAnnot) {
+ CXFA_FFWidget* pXFAAnnot;
+ while ((pXFAAnnot = pWidgetIterator->MoveToNext()) != nullptr) {
CFX_RectF rcBBox = pXFAAnnot->GetBBox(0);
CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width,
rcBBox.top + rcBBox.height);
rcWidget.Inflate(1.0f, 1.0f);
if (rcWidget.Contains(CFX_PointF(static_cast<float>(page_x),
static_cast<float>(page_y)))) {
- return FPDF_FORMFIELD_XFA;
+ return static_cast<int>(FormFieldType::kXFA);
}
- pXFAAnnot = pWidgetIterator->MoveToNext();
}
#endif // PDF_ENABLE_XFA
return -1;
@@ -663,8 +693,19 @@ FPDF_EXPORT void FPDF_CALLCONV
FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle,
int fieldType,
unsigned long color) {
- if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
- pInterForm->SetHighlightColor(color, fieldType);
+ CPDFSDK_InterForm* interForm = FormHandleToInterForm(hHandle);
+ if (!interForm)
+ return;
+
+ Optional<FormFieldType> cast_input = IntToFormFieldType(fieldType);
+ if (!cast_input.has_value())
+ return;
+
+ if (cast_input.value() == FormFieldType::kUnknown) {
+ interForm->SetAllHighlightColors(color);
+ } else {
+ interForm->SetHighlightColor(color, cast_input.value());
+ }
}
FPDF_EXPORT void FPDF_CALLCONV
@@ -676,7 +717,7 @@ FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, unsigned char alpha) {
FPDF_EXPORT void FPDF_CALLCONV
FPDF_RemoveFormFieldHighlight(FPDF_FORMHANDLE hHandle) {
if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle))
- pInterForm->RemoveAllHighLight();
+ pInterForm->RemoveAllHighLights();
}
FPDF_EXPORT void FPDF_CALLCONV FORM_OnAfterLoadPage(FPDF_PAGE page,