Cover CPDFXFA_DocEnvironment::PopupMenu()

Right-clicking on a combobox should be sufficient.

- Add pdfium_test callback to log invocation.
- Remove passing one nullptr arg while at it.

Change-Id: Ic59325c2095333e4851038e5916ce06933e293e6
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/68152
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index 9ac7f86..d36d628 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -459,11 +459,10 @@
 }
 
 bool CPDFSDK_FormFillEnvironment::PopupMenu(IPDF_Page* page,
-                                            FPDF_WIDGET hWidget,
                                             int menuFlag,
                                             const CFX_PointF& pt) {
   return m_pInfo && m_pInfo->version >= 2 && m_pInfo->FFI_PopupMenu &&
-         m_pInfo->FFI_PopupMenu(m_pInfo, FPDFPageFromIPDFPage(page), hWidget,
+         m_pInfo->FFI_PopupMenu(m_pInfo, FPDFPageFromIPDFPage(page), nullptr,
                                 menuFlag, pt.x, pt.y);
 }
 
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h
index b7da081..c047f22 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.h
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.h
@@ -164,7 +164,6 @@
   void GotoURL(const WideString& wsURL);
   FS_RECTF GetPageViewRect(IPDF_Page* page);
   bool PopupMenu(IPDF_Page* page,
-                 FPDF_WIDGET hWidget,
                  int menuFlag,
                  const CFX_PointF& pt);
   void EmailTo(FPDF_FILEHANDLER* fileHandler,
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index b7ee561..e6ae514 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -266,7 +266,7 @@
   if (hWidget->CanSelectAll())
     menuFlag |= FXFA_MENU_SELECTALL;
 
-  return pFormFillEnv->PopupMenu(pPage.Get(), nullptr, menuFlag, ptPopup);
+  return pFormFillEnv->PopupMenu(pPage.Get(), menuFlag, ptPopup);
 }
 
 void CPDFXFA_DocEnvironment::PageViewEvent(CXFA_FFPageView* pPageView,
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index dc539dd..4f0ab7e 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -328,6 +328,18 @@
 }
 #endif  // PDF_ENABLE_V8
 
+#ifdef PDF_ENABLE_XFA
+FPDF_BOOL ExamplePopupMenu(FPDF_FORMFILLINFO* pInfo,
+                           FPDF_PAGE page,
+                           FPDF_WIDGET always_null,
+                           int flags,
+                           float x,
+                           float y) {
+  printf("Popup: x=%2.1f, y=%2.1f, flags=0x%x\n", x, y, flags);
+  return true;
+}
+#endif  // PDF_ENABLE_XFA
+
 void ExampleUnsupportedHandler(UNSUPPORT_INFO*, int type) {
   std::string feature = "Unknown";
   switch (type) {
@@ -905,6 +917,7 @@
   form_callbacks.version = 2;
   form_callbacks.xfa_disabled =
       options.disable_xfa || options.disable_javascript;
+  form_callbacks.FFI_PopupMenu = ExamplePopupMenu;
 #else   // PDF_ENABLE_XFA
   form_callbacks.version = 1;
 #endif  // PDF_ENABLE_XFA
diff --git a/testing/resources/javascript/xfa_specific/popup_menu.evt b/testing/resources/javascript/xfa_specific/popup_menu.evt
new file mode 100644
index 0000000..7820426
--- /dev/null
+++ b/testing/resources/javascript/xfa_specific/popup_menu.evt
@@ -0,0 +1,5 @@
+mousemove,20,20
+mousedown,left,20,20
+mouseup,left,20,20
+mousedown,right,20,20
+mouseup,right,20,20
diff --git a/testing/resources/javascript/xfa_specific/popup_menu.in b/testing/resources/javascript/xfa_specific/popup_menu.in
new file mode 100644
index 0000000..52f7a45
--- /dev/null
+++ b/testing/resources/javascript/xfa_specific/popup_menu.in
@@ -0,0 +1,40 @@
+{{header}}
+{{include ../../xfa_catalog_1_0.fragment}}
+{{include ../../xfa_object_2_0.fragment}}
+{{include ../../xfa_preamble_3_0.fragment}}
+{{include ../../xfa_config_4_0.fragment}}
+{{object 5 0}} <<
+  {{streamlen}}
+>>
+stream
+<template xmlns="http://www.xfa.org/schema/xfa-template/3.3/">
+  <subform name="form1" layout="tb" locale="en_US" restoreState="auto">
+    <pageSet>
+      <pageArea name="Page1" id="Page1">
+        <contentArea x="18pt" y="18pt" w="612pt" h="792pt"/>
+        <medium stock="default" short="612pt" long="792pt"/>
+      </pageArea>
+    </pageSet>
+    <subform w="576pt" h="756pt" name="Page1">
+      <field name="ImageField1" y="0pt" x="0pt" w="425pt" h="80pt">
+        <ui>
+          <choiceList open="userControl"/>
+        </ui>
+        <items save="1">
+          <text>clams</text>
+          <text>oysters</text>
+          <text>crabs</text>
+        </items>
+      </field>
+    </subform>
+  </subform>
+</template>
+endstream
+endobj
+{{include ../../xfa_locale_6_0.fragment}}
+{{include ../../xfa_postamble_7_0.fragment}}
+{{include ../../xfa_pages_8_0.fragment}}
+{{xref}}
+{{trailer}}
+{{startxref}}
+%%EOF
diff --git a/testing/resources/javascript/xfa_specific/popup_menu_expected.txt b/testing/resources/javascript/xfa_specific/popup_menu_expected.txt
new file mode 100644
index 0000000..dc856e9
--- /dev/null
+++ b/testing/resources/javascript/xfa_specific/popup_menu_expected.txt
@@ -0,0 +1 @@
+Popup: x=20.0, y=20.0, flags=0x0