Expose FORM_OnRButton{Down,Up} to non-XFA builds

In turn, this allows the syntax of .evt files to be independent
of whether XFA is enabled, presumably facilitating testing down
the road.

- fewer #ifdefs remain (and deeper down into the code).
- Call from embedder test for coverage.

Change-Id: I3013452d899310f8adae6b308b9c0372a4fd5e3d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/62730
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp
index 376e542..5aeb2df 100644
--- a/fpdfsdk/cpdfsdk_pageview.cpp
+++ b/fpdfsdk/cpdfsdk_pageview.cpp
@@ -335,8 +335,8 @@
   return true;
 }
 
-#ifdef PDF_ENABLE_XFA
 bool CPDFSDK_PageView::OnRButtonDown(const CFX_PointF& point, uint32_t nFlag) {
+#ifdef PDF_ENABLE_XFA
   ObservedPtr<CPDFSDK_Annot> pAnnot(GetFXWidgetAtPoint(point));
   if (!pAnnot)
     return false;
@@ -349,11 +349,13 @@
 
   if (ok)
     m_pFormFillEnv->SetFocusAnnot(&pAnnot);
+#endif  // PDF_ENABLE_XFA
 
   return true;
 }
 
 bool CPDFSDK_PageView::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) {
+#ifdef PDF_ENABLE_XFA
   CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr =
       m_pFormFillEnv->GetAnnotHandlerMgr();
   ObservedPtr<CPDFSDK_Annot> pFXAnnot(GetFXWidgetAtPoint(point));
@@ -362,10 +364,10 @@
 
   if (pAnnotHandlerMgr->Annot_OnRButtonUp(this, &pFXAnnot, nFlag, point))
     m_pFormFillEnv->SetFocusAnnot(&pFXAnnot);
+#endif  // PDF_ENABLE_XFA
 
   return true;
 }
-#endif  // PDF_ENABLE_XFA
 
 bool CPDFSDK_PageView::OnMouseMove(const CFX_PointF& point, int nFlag) {
   CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr =
diff --git a/fpdfsdk/cpdfsdk_pageview.h b/fpdfsdk/cpdfsdk_pageview.h
index 1c47503..9b040db 100644
--- a/fpdfsdk/cpdfsdk_pageview.h
+++ b/fpdfsdk/cpdfsdk_pageview.h
@@ -67,16 +67,11 @@
   bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag);
   bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag);
   bool OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag);
-
-#ifdef PDF_ENABLE_XFA
   bool OnRButtonDown(const CFX_PointF& point, uint32_t nFlag);
   bool OnRButtonUp(const CFX_PointF& point, uint32_t nFlag);
-#endif  // PDF_ENABLE_XFA
-
   bool OnChar(int nChar, uint32_t nFlag);
   bool OnKeyDown(int nKeyCode, int nFlag);
   bool OnKeyUp(int nKeyCode, int nFlag);
-
   bool OnMouseMove(const CFX_PointF& point, int nFlag);
   bool OnMouseWheel(double deltaX,
                     double deltaY,
diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp
index 35685c8..90ac589 100644
--- a/fpdfsdk/fpdf_formfill.cpp
+++ b/fpdfsdk/fpdf_formfill.cpp
@@ -417,7 +417,6 @@
   return pPageView->OnLButtonDblClk(CFX_PointF(page_x, page_y), modifier);
 }
 
-#ifdef PDF_ENABLE_XFA
 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle,
                                                        FPDF_PAGE page,
                                                        int modifier,
@@ -447,7 +446,6 @@
 #endif  // PDF_ENABLE_CLICK_LOGGING
   return pPageView->OnRButtonUp(CFX_PointF(page_x, page_y), modifier);
 }
-#endif  // PDF_ENABLE_XFA
 
 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnKeyDown(FPDF_FORMHANDLE hHandle,
                                                    FPDF_PAGE page,
diff --git a/fpdfsdk/fpdf_formfill_embeddertest.cpp b/fpdfsdk/fpdf_formfill_embeddertest.cpp
index 5b56a3c..a4436b8 100644
--- a/fpdfsdk/fpdf_formfill_embeddertest.cpp
+++ b/fpdfsdk/fpdf_formfill_embeddertest.cpp
@@ -927,12 +927,19 @@
     ScopedFPDFBitmap bitmap2 = RenderLoadedPage(page);
     CompareBitmap(bitmap2.get(), 300, 300, md5_2);
 
+    // Focus remains despite right clicking out of the textfield
+    FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0);
+    FORM_OnRButtonDown(form_handle(), page, 0, 15.0, 15.0);
+    FORM_OnRButtonUp(form_handle(), page, 0, 15.0, 15.0);
+    ScopedFPDFBitmap bitmap3 = RenderLoadedPage(page);
+    CompareBitmap(bitmap3.get(), 300, 300, md5_2);
+
     // Take out focus by clicking out of the textfield
     FORM_OnMouseMove(form_handle(), page, 0, 15.0, 15.0);
     FORM_OnLButtonDown(form_handle(), page, 0, 15.0, 15.0);
     FORM_OnLButtonUp(form_handle(), page, 0, 15.0, 15.0);
-    ScopedFPDFBitmap bitmap3 = RenderLoadedPage(page);
-    CompareBitmap(bitmap3.get(), 300, 300, md5_3);
+    ScopedFPDFBitmap bitmap4 = RenderLoadedPage(page);
+    CompareBitmap(bitmap4.get(), 300, 300, md5_3);
 
     EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
 
diff --git a/public/fpdf_formfill.h b/public/fpdf_formfill.h
index fb2a1fa..1146a9f 100644
--- a/public/fpdf_formfill.h
+++ b/public/fpdf_formfill.h
@@ -1293,6 +1293,18 @@
                                                        double page_y);
 
 /**
+ * Function: FORM_OnRButtonDown
+ *          Same as above, execpt for the right mouse button.
+ * Comments:
+ *          At the present time, has no effect except in XFA builds, but is
+ *          included for the sake of symmetry.
+ */
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle,
+                                                       FPDF_PAGE page,
+                                                       int modifier,
+                                                       double page_x,
+                                                       double page_y);
+/**
  * Function: FORM_OnLButtonUp
  *          You can call this member function when the user releases the left
  *          mouse button.
@@ -1314,6 +1326,19 @@
                                                      double page_y);
 
 /**
+ * Function: FORM_OnRButtonUp
+ *          Same as above, execpt for the right mouse button.
+ * Comments:
+ *          At the present time, has no effect except in XFA builds, but is
+ *          included for the sake of symmetry.
+ */
+FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle,
+                                                     FPDF_PAGE page,
+                                                     int modifier,
+                                                     double page_x,
+                                                     double page_y);
+
+/**
  * Function: FORM_OnLButtonDoubleClick
  *          You can call this member function when the user double clicks the
  *          left mouse button.
@@ -1337,19 +1362,6 @@
                           double page_x,
                           double page_y);
 
-#ifdef PDF_ENABLE_XFA
-FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle,
-                                                       FPDF_PAGE page,
-                                                       int modifier,
-                                                       double page_x,
-                                                       double page_y);
-FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle,
-                                                     FPDF_PAGE page,
-                                                     int modifier,
-                                                     double page_x,
-                                                     double page_y);
-#endif  // PDF_ENABLE_XFA
-
 /**
  * Function: FORM_OnKeyDown
  *          You can call this member function when a nonsystem key is pressed.
diff --git a/samples/pdfium_test_event_helper.cc b/samples/pdfium_test_event_helper.cc
index 1db9a8c..3e6f0ca 100644
--- a/samples/pdfium_test_event_helper.cc
+++ b/samples/pdfium_test_event_helper.cc
@@ -65,10 +65,8 @@
 
   if (tokens[1] == "left")
     FORM_OnLButtonDown(form, page, modifiers, x, y);
-#ifdef PDF_ENABLE_XFA
   else if (tokens[1] == "right")
     FORM_OnRButtonDown(form, page, modifiers, x, y);
-#endif
   else
     fprintf(stderr, "mousedown: bad button name\n");
 }
@@ -86,10 +84,8 @@
   int modifiers = tokens.size() >= 5 ? GetModifiers(tokens[4]) : 0;
   if (tokens[1] == "left")
     FORM_OnLButtonUp(form, page, modifiers, x, y);
-#ifdef PDF_ENABLE_XFA
   else if (tokens[1] == "right")
     FORM_OnRButtonUp(form, page, modifiers, x, y);
-#endif
   else
     fprintf(stderr, "mouseup: bad button name\n");
 }