Fix some nits in XFA widget code.

- Document CXFA_FFDoc::WidgetPostAdd() and WidgetPreRemove() should
  never receive a nullptr for the widget argument. Remove the
  corresponding nullptr check in the implementation.
- For consistency rename several related methods in CPDFSDK_PageView:
  AddAnnot()             -> AddAnnotForFFWidget()
  DeleteAnnotForWidget() -> DeleteAnnotForFFWidget()
  GetAnnotByXFAWidget()  -> GetAnnotForFFWidget()

Change-Id: I644d35cdbf741c93e84cc2a458105e77dd8b123e
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/92133
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp
index 08ce6a3..144f6c4 100644
--- a/fpdfsdk/cpdfsdk_pageview.cpp
+++ b/fpdfsdk/cpdfsdk_pageview.cpp
@@ -120,22 +120,22 @@
 }
 
 #ifdef PDF_ENABLE_XFA
-CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CXFA_FFWidget* pPDFAnnot) {
-  CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
+CPDFSDK_Annot* CPDFSDK_PageView::AddAnnotForFFWidget(CXFA_FFWidget* pWidget) {
+  CPDFSDK_Annot* pSDKAnnot = GetAnnotForFFWidget(pWidget);
   if (pSDKAnnot)
     return pSDKAnnot;
 
   CPDFSDK_AnnotHandlerMgr* pAnnotHandler = m_pFormFillEnv->GetAnnotHandlerMgr();
   std::unique_ptr<CPDFSDK_Annot> pNewAnnot =
-      pAnnotHandler->NewAnnotForXFA(pPDFAnnot, this);
+      pAnnotHandler->NewAnnotForXFA(pWidget, this);
   DCHECK(pNewAnnot);
   pSDKAnnot = pNewAnnot.get();
   m_SDKAnnotArray.push_back(std::move(pNewAnnot));
   return pSDKAnnot;
 }
 
-void CPDFSDK_PageView::DeleteAnnotForWidget(CXFA_FFWidget* pWidget) {
-  CPDFSDK_Annot* pAnnot = GetAnnotByXFAWidget(pWidget);
+void CPDFSDK_PageView::DeleteAnnotForFFWidget(CXFA_FFWidget* pWidget) {
+  CPDFSDK_Annot* pAnnot = GetAnnotForFFWidget(pWidget);
   if (!pAnnot)
     return;
 
@@ -199,7 +199,7 @@
 }
 
 #ifdef PDF_ENABLE_XFA
-CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(CXFA_FFWidget* pWidget) {
+CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotForFFWidget(CXFA_FFWidget* pWidget) {
   if (!pWidget)
     return nullptr;
 
diff --git a/fpdfsdk/cpdfsdk_pageview.h b/fpdfsdk/cpdfsdk_pageview.h
index da1532c..83460ed 100644
--- a/fpdfsdk/cpdfsdk_pageview.h
+++ b/fpdfsdk/cpdfsdk_pageview.h
@@ -53,9 +53,9 @@
   CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
 
 #ifdef PDF_ENABLE_XFA
-  void DeleteAnnotForWidget(CXFA_FFWidget* pWidget);
-  CPDFSDK_Annot* AddAnnot(CXFA_FFWidget* pPDFAnnot);
-  CPDFSDK_Annot* GetAnnotByXFAWidget(CXFA_FFWidget* pWidget);
+  CPDFSDK_Annot* AddAnnotForFFWidget(CXFA_FFWidget* pWidget);
+  void DeleteAnnotForFFWidget(CXFA_FFWidget* pWidget);
+  CPDFSDK_Annot* GetAnnotForFFWidget(CXFA_FFWidget* pWidget);
   IPDF_Page* GetXFAPage();
 #endif  // PDF_ENABLE_XFA
 
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 8189130..34c549d 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -315,7 +315,7 @@
 }
 
 void CPDFXFA_DocEnvironment::WidgetPostAdd(CXFA_FFWidget* hWidget) {
-  if (m_pContext->GetFormType() != FormType::kXFAFull || !hWidget)
+  if (m_pContext->GetFormType() != FormType::kXFAFull)
     return;
 
   CXFA_FFPageView* pPageView = hWidget->GetPageView();
@@ -326,13 +326,12 @@
   if (!pXFAPage)
     return;
 
-  m_pContext->GetFormFillEnv()
-      ->GetOrCreatePageView(pXFAPage.Get())
-      ->AddAnnot(hWidget);
+  auto* formfill = m_pContext->GetFormFillEnv();
+  formfill->GetOrCreatePageView(pXFAPage.Get())->AddAnnotForFFWidget(hWidget);
 }
 
 void CPDFXFA_DocEnvironment::WidgetPreRemove(CXFA_FFWidget* hWidget) {
-  if (m_pContext->GetFormType() != FormType::kXFAFull || !hWidget)
+  if (m_pContext->GetFormType() != FormType::kXFAFull)
     return;
 
   CXFA_FFPageView* pPageView = hWidget->GetPageView();
@@ -345,7 +344,7 @@
 
   CPDFSDK_PageView* pSdkPageView =
       m_pContext->GetFormFillEnv()->GetOrCreatePageView(pXFAPage.Get());
-  pSdkPageView->DeleteAnnotForWidget(hWidget);
+  pSdkPageView->DeleteAnnotForFFWidget(hWidget);
 }
 
 int32_t CPDFXFA_DocEnvironment::CountPages(const CXFA_FFDoc* hDoc) const {
@@ -563,7 +562,7 @@
     if (!pPageView)
       continue;
 
-    ObservedPtr<CPDFSDK_Annot> pAnnot(pPageView->GetAnnotByXFAWidget(hWidget));
+    ObservedPtr<CPDFSDK_Annot> pAnnot(pPageView->GetAnnotForFFWidget(hWidget));
     if (pAnnot) {
       m_pContext->GetFormFillEnv()->SetFocusAnnot(pAnnot);
       break;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
index d5881d9..f5dd962 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
@@ -227,7 +227,7 @@
   if (!pWidgetIterator)
     return nullptr;
 
-  return pSDKAnnot->GetPageView()->GetAnnotByXFAWidget(
+  return pSDKAnnot->GetPageView()->GetAnnotForFFWidget(
       pWidgetIterator->MoveToNext());
 }
 
@@ -237,7 +237,7 @@
   if (!pWidgetIterator)
     return nullptr;
 
-  return pSDKAnnot->GetPageView()->GetAnnotByXFAWidget(
+  return pSDKAnnot->GetPageView()->GetAnnotForFFWidget(
       pWidgetIterator->MoveToPrevious());
 }
 
@@ -248,7 +248,7 @@
   if (!pWidgetIterator)
     return nullptr;
 
-  return page_view->GetAnnotByXFAWidget(pWidgetIterator->MoveToFirst());
+  return page_view->GetAnnotForFFWidget(pWidgetIterator->MoveToFirst());
 }
 
 CPDFSDK_Annot* CPDFXFA_Page::GetLastXFAAnnot(
@@ -258,7 +258,7 @@
   if (!pWidgetIterator)
     return nullptr;
 
-  return page_view->GetAnnotByXFAWidget(pWidgetIterator->MoveToLast());
+  return page_view->GetAnnotForFFWidget(pWidgetIterator->MoveToLast());
 }
 
 int CPDFXFA_Page::HasFormFieldAtPoint(const CFX_PointF& point) const {
diff --git a/xfa/fxfa/cxfa_ffdoc.h b/xfa/fxfa/cxfa_ffdoc.h
index d108cc3..2551562 100644
--- a/xfa/fxfa/cxfa_ffdoc.h
+++ b/xfa/fxfa/cxfa_ffdoc.h
@@ -84,8 +84,10 @@
     virtual void OnPageViewEvent(CXFA_FFPageView* pPageView,
                                  PageViewEvent eEvent) = 0;
 
+    // Caller must not pass in nullptr.
     virtual void WidgetPostAdd(CXFA_FFWidget* hWidget) = 0;
     virtual void WidgetPreRemove(CXFA_FFWidget* hWidget) = 0;
+
     virtual int32_t CountPages(const CXFA_FFDoc* hDoc) const = 0;
     virtual int32_t GetCurrentPage(const CXFA_FFDoc* hDoc) const = 0;
     virtual void SetCurrentPage(CXFA_FFDoc* hDoc, int32_t iCurPage) = 0;