From 9baf31f8c38e1c5266609e184cc07e369b744760 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 12 Jan 2018 18:36:30 +0000 Subject: 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 Reviewed-by: Henrique Nakashima --- fpdfsdk/fpdfformfill.cpp | 57 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 8 deletions(-) (limited to 'fpdfsdk/fpdfformfill.cpp') 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(FormType::kXFAForeground) == "XFA foreground form types must match"); #endif // PDF_ENABLE_XFA +static_assert(static_cast(FormFieldType::kUnknown) == + FPDF_FORMFIELD_UNKNOWN, + "Unknown form field types must match"); +static_assert(static_cast(FormFieldType::kPushButton) == + FPDF_FORMFIELD_PUSHBUTTON, + "PushButton form field types must match"); +static_assert(static_cast(FormFieldType::kCheckBox) == + FPDF_FORMFIELD_CHECKBOX, + "CheckBox form field types must match"); +static_assert(static_cast(FormFieldType::kRadioButton) == + FPDF_FORMFIELD_RADIOBUTTON, + "RadioButton form field types must match"); +static_assert(static_cast(FormFieldType::kComboBox) == + FPDF_FORMFIELD_COMBOBOX, + "ComboBox form field types must match"); +static_assert(static_cast(FormFieldType::kListBox) == + FPDF_FORMFIELD_LISTBOX, + "ListBox form field types must match"); +static_assert(static_cast(FormFieldType::kTextField) == + FPDF_FORMFIELD_TEXTFIELD, + "TextField form field types must match"); +static_assert(static_cast(FormFieldType::kSignature) == + FPDF_FORMFIELD_SIGNATURE, + "Signature form field types must match"); +#ifdef PDF_ENABLE_XFA +static_assert(static_cast(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(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(page_x), static_cast(page_y)))) { - return FPDF_FORMFIELD_XFA; + return static_cast(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 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, -- cgit v1.2.3