Define behaviors of FPDF_RenderPageBitmap_Retail and FPDF_FFLDraw.

Previously, PDFium only supported widget annotations to draw forms. As
we've implemented other annotations, the behavior of
FPDF_RenderPageBitmap_Retail and FPDF_FFLDraw changed. So, this CL
clearly defines what needs to be done in FPDF_RenderPageBitmap_Retail
and FPDF_FFLDraw.

This CL first assumes that PDFium users will always call
FPDF_RenderPageBitmap_Retail and FPDF_FFLDraw to render PDF pages,
because otherwise they are not able to support PDF forms.

FPDF_RenderPageBitmap_Retail should only deal with non-widget
annotations, such as highlight, underline, text, etc. If
FPDF_ANNOT flag is passed, non-widget annotations are drawn. Otherwise,
they are hidden.

FPDF_FFLDraw should only deal with annotations that requires
user-interaction, such as widget annotations and popup annotation. Since
popup annotation is associated with non-widget annotation, they should
not be drawn if the associated annotation is hidden. Thus, if FPDF_ANNOT
flag is passed, popup annotations are drawn. Otherwise, they are hidden.
Widget annotations should be always drawn regardless of FPDF_ANNOT flag
since they need to be always displayed for PDF forms.

Also, roll DEPS for testing/corpus to 8485b30.

BUG=pdfium:594

Review-Url: https://codereview.chromium.org/2323203002
diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
index 12362e3..0fd48d2 100644
--- a/fpdfsdk/cpdfsdk_annothandlermgr.cpp
+++ b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
@@ -93,9 +93,11 @@
 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
                                            CPDFSDK_Annot* pAnnot,
                                            CFX_RenderDevice* pDevice,
-                                           CFX_Matrix* pUser2Device) {
+                                           CFX_Matrix* pUser2Device,
+                                           bool bDrawAnnots) {
   ASSERT(pAnnot);
-  GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, pUser2Device);
+  GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, pUser2Device,
+                                  bDrawAnnots);
 }
 
 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
diff --git a/fpdfsdk/cpdfsdk_baannothandler.cpp b/fpdfsdk/cpdfsdk_baannothandler.cpp
index 1007104..f0d67f4 100644
--- a/fpdfsdk/cpdfsdk_baannothandler.cpp
+++ b/fpdfsdk/cpdfsdk_baannothandler.cpp
@@ -62,13 +62,16 @@
 void CPDFSDK_BAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
                                     CPDFSDK_Annot* pAnnot,
                                     CFX_RenderDevice* pDevice,
-                                    CFX_Matrix* pUser2Device) {
+                                    CFX_Matrix* pUser2Device,
+                                    bool bDrawAnnots) {
 #ifdef PDF_ENABLE_XFA
   if (pAnnot->IsXFAField())
     return;
 #endif  // PDF_ENABLE_XFA
-  static_cast<CPDFSDK_BAAnnot*>(pAnnot)->DrawAppearance(
-      pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
+  if (bDrawAnnots && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) {
+    static_cast<CPDFSDK_BAAnnot*>(pAnnot)->DrawAppearance(
+        pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
+  }
 }
 
 void CPDFSDK_BAAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {}
diff --git a/fpdfsdk/cpdfsdk_widgethandler.cpp b/fpdfsdk/cpdfsdk_widgethandler.cpp
index b490daa..8a061e5 100644
--- a/fpdfsdk/cpdfsdk_widgethandler.cpp
+++ b/fpdfsdk/cpdfsdk_widgethandler.cpp
@@ -92,7 +92,8 @@
 void CPDFSDK_WidgetHandler::OnDraw(CPDFSDK_PageView* pPageView,
                                    CPDFSDK_Annot* pAnnot,
                                    CFX_RenderDevice* pDevice,
-                                   CFX_Matrix* pUser2Device) {
+                                   CFX_Matrix* pUser2Device,
+                                   bool bDrawAnnots) {
   if (pAnnot->IsSignatureWidget()) {
     static_cast<CPDFSDK_BAAnnot*>(pAnnot)->DrawAppearance(
         pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
diff --git a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp
index 7422011..8621f77 100644
--- a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp
+++ b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp
@@ -46,7 +46,8 @@
 void CPDFSDK_XFAWidgetHandler::OnDraw(CPDFSDK_PageView* pPageView,
                                       CPDFSDK_Annot* pAnnot,
                                       CFX_RenderDevice* pDevice,
-                                      CFX_Matrix* pUser2Device) {
+                                      CFX_Matrix* pUser2Device,
+                                      bool bDrawAnnots) {
   ASSERT(pPageView);
   ASSERT(pAnnot);
 
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp
index 449eac0..2ac6c60 100644
--- a/fpdfsdk/fpdfformfill.cpp
+++ b/fpdfsdk/fpdfformfill.cpp
@@ -114,6 +114,7 @@
     options.m_BackColor = 0xffffff;
   }
   options.m_AddFlags = flags >> 8;
+  options.m_bDrawAnnots = flags & FPDF_ANNOT;
 
 #ifdef PDF_ENABLE_XFA
   options.m_pOCContext = new CPDF_OCContext(pPDFDoc, CPDF_OCContext::View);
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 1c0af1d..4e20751 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -896,7 +896,7 @@
     pContext->m_pAnnots.reset(new CPDF_AnnotList(pPage));
     FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY;
     pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext.get(),
-                                       bPrinting, &matrix, TRUE, nullptr);
+                                       bPrinting, &matrix, FALSE, nullptr);
   }
 
   pContext->m_pRenderer.reset(new CPDF_ProgressiveRenderer(
diff --git a/fpdfsdk/fsdk_mgr.cpp b/fpdfsdk/fsdk_mgr.cpp
index 694e315..c8f387e 100644
--- a/fpdfsdk/fsdk_mgr.cpp
+++ b/fpdfsdk/fsdk_mgr.cpp
@@ -12,6 +12,7 @@
 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
+#include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h"
 #include "core/fpdfdoc/include/cpdf_docjsactions.h"
 #include "core/fpdfdoc/include/cpdf_interform.h"
 #include "core/fxcrt/include/cfx_retain_ptr.h"
@@ -581,7 +582,8 @@
   CPDFSDK_AnnotIterator annotIterator(this, true);
   while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) {
     CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
-    pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device);
+    pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device,
+                                   pOptions->m_bDrawAnnots);
   }
 }
 
diff --git a/fpdfsdk/include/cpdfsdk_annothandlermgr.h b/fpdfsdk/include/cpdfsdk_annothandlermgr.h
index 540bd98..f4be66a 100644
--- a/fpdfsdk/include/cpdfsdk_annothandlermgr.h
+++ b/fpdfsdk/include/cpdfsdk_annothandlermgr.h
@@ -48,7 +48,8 @@
   virtual void Annot_OnDraw(CPDFSDK_PageView* pPageView,
                             CPDFSDK_Annot* pAnnot,
                             CFX_RenderDevice* pDevice,
-                            CFX_Matrix* pUser2Device);
+                            CFX_Matrix* pUser2Device,
+                            bool bDrawAnnots);
 
   virtual void Annot_OnMouseEnter(CPDFSDK_PageView* pPageView,
                                   CPDFSDK_Annot* pAnnot,
diff --git a/fpdfsdk/include/cpdfsdk_baannothandler.h b/fpdfsdk/include/cpdfsdk_baannothandler.h
index 5425b0b..ba50df3 100644
--- a/fpdfsdk/include/cpdfsdk_baannothandler.h
+++ b/fpdfsdk/include/cpdfsdk_baannothandler.h
@@ -44,7 +44,8 @@
   void OnDraw(CPDFSDK_PageView* pPageView,
               CPDFSDK_Annot* pAnnot,
               CFX_RenderDevice* pDevice,
-              CFX_Matrix* pUser2Device) override;
+              CFX_Matrix* pUser2Device,
+              bool bDrawAnnots) override;
   void OnCreate(CPDFSDK_Annot* pAnnot) override;
   void OnLoad(CPDFSDK_Annot* pAnnot) override;
   void OnDelete(CPDFSDK_Annot* pAnnot) override;
diff --git a/fpdfsdk/include/cpdfsdk_widgethandler.h b/fpdfsdk/include/cpdfsdk_widgethandler.h
index b8cb182..d34510d 100644
--- a/fpdfsdk/include/cpdfsdk_widgethandler.h
+++ b/fpdfsdk/include/cpdfsdk_widgethandler.h
@@ -44,7 +44,8 @@
   void OnDraw(CPDFSDK_PageView* pPageView,
               CPDFSDK_Annot* pAnnot,
               CFX_RenderDevice* pDevice,
-              CFX_Matrix* pUser2Device) override;
+              CFX_Matrix* pUser2Device,
+              bool bDrawAnnots) override;
   void OnCreate(CPDFSDK_Annot* pAnnot) override;
   void OnLoad(CPDFSDK_Annot* pAnnot) override;
   void OnDelete(CPDFSDK_Annot* pAnnot) override;
diff --git a/fpdfsdk/include/cpdfsdk_xfawidgethandler.h b/fpdfsdk/include/cpdfsdk_xfawidgethandler.h
index 10eb1ee..dec2675 100644
--- a/fpdfsdk/include/cpdfsdk_xfawidgethandler.h
+++ b/fpdfsdk/include/cpdfsdk_xfawidgethandler.h
@@ -39,7 +39,8 @@
   void OnDraw(CPDFSDK_PageView* pPageView,
               CPDFSDK_Annot* pAnnot,
               CFX_RenderDevice* pDevice,
-              CFX_Matrix* pUser2Device) override;
+              CFX_Matrix* pUser2Device,
+              bool bDrawAnnots) override;
   void OnCreate(CPDFSDK_Annot* pAnnot) override;
   void OnLoad(CPDFSDK_Annot* pAnnot) override;
   void OnDelete(CPDFSDK_Annot* pAnnot) override;
diff --git a/fpdfsdk/include/ipdfsdk_annothandler.h b/fpdfsdk/include/ipdfsdk_annothandler.h
index 289d480..d2f9010 100644
--- a/fpdfsdk/include/ipdfsdk_annothandler.h
+++ b/fpdfsdk/include/ipdfsdk_annothandler.h
@@ -43,7 +43,8 @@
   virtual void OnDraw(CPDFSDK_PageView* pPageView,
                       CPDFSDK_Annot* pAnnot,
                       CFX_RenderDevice* pDevice,
-                      CFX_Matrix* pUser2Device) = 0;
+                      CFX_Matrix* pUser2Device,
+                      bool bDrawAnnots) = 0;
   virtual void OnCreate(CPDFSDK_Annot* pAnnot) = 0;
   virtual void OnLoad(CPDFSDK_Annot* pAnnot) = 0;
   virtual void OnDelete(CPDFSDK_Annot* pAnnot) = 0;