Reuse existing CPDF_InteractiveForm in two APIs.
In FPDFPage_HasFormFieldAtPoint(), the implementation creates a new
CPDF_InteractiveForm object and then examine its form controls.
Constructing CPDF_InteractiveForm objects can be expensive, since
interactive form fields can have hierarchies and inheritance. Meanwhile,
there is a FPDF_FORMHANDLE being passed in and its almost unused. Put it
to use by getting the CPDFSDK_InteractiveForm from the handle. The
CPDFSDK_InteractiveForm then has a pointer to an existing
CPDF_InteractiveForm. Use that instead.
FPDFPage_FormFieldZOrderAtPoint() started out as a sibling of
FPDFPage_HasFormFieldAtPoint(), and has a similar issue.
Change-Id: Ic8928a7354e5fcd8c260d8f4ac824fbc66a18dbe
Reviewed-on: https://pdfium-review.googlesource.com/c/50710
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp
index 4bbc392..41ce671 100644
--- a/fpdfsdk/fpdf_formfill.cpp
+++ b/fpdfsdk/fpdf_formfill.cpp
@@ -238,12 +238,14 @@
FPDF_PAGE page,
double page_x,
double page_y) {
- if (!hHandle)
- return -1;
CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (pPage) {
- CPDF_InteractiveForm interactive_form(pPage->GetDocument());
- CPDF_FormControl* pFormCtrl = interactive_form.GetControlAtPoint(
+ CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle);
+ if (!pForm)
+ return -1;
+
+ CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm();
+ CPDF_FormControl* pFormCtrl = pPDFForm->GetControlAtPoint(
pPage,
CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)),
nullptr);
@@ -253,6 +255,9 @@
return pFormField ? static_cast<int>(pFormField->GetFieldType()) : -1;
}
+ if (!hHandle)
+ return -1;
+
#ifdef PDF_ENABLE_XFA
CPDFXFA_Page* pXFAPage = ToXFAPage(IPDFPageFromFPDFPage(page));
if (!pXFAPage)
@@ -299,14 +304,17 @@
FPDF_PAGE page,
double page_x,
double page_y) {
- if (!hHandle)
+ CPDFSDK_InteractiveForm* pForm = FormHandleToInteractiveForm(hHandle);
+ if (!pForm)
return -1;
+
CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return -1;
- CPDF_InteractiveForm interactive_form(pPage->GetDocument());
+
+ CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm();
int z_order = -1;
- (void)interactive_form.GetControlAtPoint(
+ pPDFForm->GetControlAtPoint(
pPage, CFX_PointF(static_cast<float>(page_x), static_cast<float>(page_y)),
&z_order);
return z_order;