Merge to XFA: Clean up CPDF_AnnotList.

- Remove dead code
- Stop using CFX_PtrArray
- Mark more things const
- Fix style nits

TBR=tsepez@chromium.org

Review URL: https://codereview.chromium.org/1425093003 .

(cherry picked from commit c88c42f317c0e94c4c7b98949bfe1a495aef07a9)

Review URL: https://codereview.chromium.org/1430803003 .
diff --git a/fpdfsdk/include/fsdk_baseform.h b/fpdfsdk/include/fsdk_baseform.h
index 14c8fef..bcba4c8 100644
--- a/fpdfsdk/include/fsdk_baseform.h
+++ b/fpdfsdk/include/fsdk_baseform.h
@@ -155,7 +155,7 @@
   CPDF_FormField* GetFormField() const;
   CPDF_FormControl* GetFormControl() const;
   static CPDF_FormControl* GetFormControl(CPDF_InterForm* pInterForm,
-                                          CPDF_Dictionary* pAnnotDict);
+                                          const CPDF_Dictionary* pAnnotDict);
 
   void DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView);
 
diff --git a/fpdfsdk/include/fsdk_define.h b/fpdfsdk/include/fsdk_define.h
index 2faaf01..f62234a 100644
--- a/fpdfsdk/include/fsdk_define.h
+++ b/fpdfsdk/include/fsdk_define.h
@@ -108,7 +108,7 @@
                             IFSDK_PAUSE_Adapter* pause);
 
 void CheckUnSupportError(CPDF_Document* pDoc, FX_DWORD err_code);
-void CheckUnSupportAnnot(CPDF_Document* pDoc, CPDF_Annot* pPDFAnnot);
+void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot);
 void ProcessParseError(FX_DWORD err_code);
 
 #endif  // FPDFSDK_INCLUDE_FSDK_DEFINE_H_
diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h
index bfbbd63..615b585 100644
--- a/fpdfsdk/include/fsdk_mgr.h
+++ b/fpdfsdk/include/fsdk_mgr.h
@@ -538,9 +538,9 @@
                        CPDF_Matrix* pUser2Device,
                        CPDF_RenderOptions* pOptions,
                        FX_RECT* pClip = NULL);
-  CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
+  const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
   CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
-  CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
+  const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
   CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
   CPDFSDK_Annot* GetFocusAnnot();
   void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot, FX_UINT nFlag = 0) {
@@ -578,7 +578,7 @@
                        double deltaY,
                        const CPDF_Point& point,
                        int nFlag);
-  FX_BOOL IsValidAnnot(CPDF_Annot* p) const;
+  bool IsValidAnnot(const CPDF_Annot* p) const;
   void GetCurrentMatrix(CPDF_Matrix& matrix) { matrix = m_curMatrix; }
   void UpdateRects(CFX_RectArray& rects);
   void UpdateView(CPDFSDK_Annot* pAnnot);
diff --git a/fpdfsdk/src/fpdf_ext.cpp b/fpdfsdk/src/fpdf_ext.cpp
index 196ac99..aead361 100644
--- a/fpdfsdk/src/fpdf_ext.cpp
+++ b/fpdfsdk/src/fpdf_ext.cpp
@@ -58,12 +58,12 @@
   return TRUE;
 }
 
-void CheckUnSupportAnnot(CPDF_Document* pDoc, CPDF_Annot* pPDFAnnot) {
+void CheckUnSupportAnnot(CPDF_Document* pDoc, const CPDF_Annot* pPDFAnnot) {
   CFX_ByteString cbSubType = pPDFAnnot->GetSubType();
   if (cbSubType.Compare("3D") == 0) {
     FPDF_UnSupportError(FPDF_UNSP_ANNOT_3DANNOT);
   } else if (cbSubType.Compare("Screen") == 0) {
-    CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict();
+    const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict();
     CFX_ByteString cbString;
     if (pAnnotDict->KeyExist("IT"))
       cbString = pAnnotDict->GetString("IT");
@@ -78,7 +78,7 @@
   } else if (cbSubType.Compare("FileAttachment") == 0) {
     FPDF_UnSupportError(FPDF_UNSP_ANNOT_ATTACHMENT);
   } else if (cbSubType.Compare("Widget") == 0) {
-    CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict();
+    const CPDF_Dictionary* pAnnotDict = pPDFAnnot->GetAnnotDict();
     CFX_ByteString cbString;
     if (pAnnotDict->KeyExist("FT")) {
       cbString = pAnnotDict->GetString("FT");
diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp
index 8b4168f..531d372 100644
--- a/fpdfsdk/src/fpdfeditpage.cpp
+++ b/fpdfsdk/src/fpdfeditpage.cpp
@@ -280,7 +280,7 @@
   if (!pPage)
     return;
   CPDF_AnnotList AnnotList(pPage);
-  for (int i = 0; i < AnnotList.Count(); i++) {
+  for (size_t i = 0; i < AnnotList.Count(); ++i) {
     CPDF_Annot* pAnnot = AnnotList.GetAt(i);
     // transformAnnots Rectangle
     CPDF_Rect rect;
diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp
index 54b607a..e486310 100644
--- a/fpdfsdk/src/fsdk_baseform.cpp
+++ b/fpdfsdk/src/fsdk_baseform.cpp
@@ -566,37 +566,23 @@
 }
 
 CPDF_FormField* CPDFSDK_Widget::GetFormField() const {
-  ASSERT(m_pInterForm != NULL);
-
-  CPDF_FormControl* pCtrl = GetFormControl();
-  ASSERT(pCtrl != NULL);
-
-  return pCtrl->GetField();
+  return GetFormControl()->GetField();
 }
 
 CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const {
-  ASSERT(m_pInterForm != NULL);
-
   CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
-  ASSERT(pPDFInterForm != NULL);
-
   return pPDFInterForm->GetControlByDict(GetAnnotDict());
 }
 
-CPDF_FormControl* CPDFSDK_Widget::GetFormControl(CPDF_InterForm* pInterForm,
-                                                 CPDF_Dictionary* pAnnotDict) {
-  ASSERT(pInterForm != NULL);
+CPDF_FormControl* CPDFSDK_Widget::GetFormControl(
+    CPDF_InterForm* pInterForm,
+    const CPDF_Dictionary* pAnnotDict) {
   ASSERT(pAnnotDict != NULL);
-
-  CPDF_FormControl* pControl = pInterForm->GetControlByDict(pAnnotDict);
-
-  return pControl;
+  return pInterForm->GetControlByDict(pAnnotDict);
 }
 
 int CPDFSDK_Widget::GetRotate() const {
   CPDF_FormControl* pCtrl = GetFormControl();
-  ASSERT(pCtrl != NULL);
-
   return pCtrl->GetRotation() % 360;
 }
 
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index 9bb603d..f12e8fb 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -696,11 +696,9 @@
   }
 }
 
-CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX,
-                                                 FX_FLOAT pageY) {
-  const int nCount = m_pAnnotList->Count();
-  for (int i = 0; i < nCount; ++i) {
-    CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
+const CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX,
+                                                       FX_FLOAT pageY) {
+  for (const CPDF_Annot* pAnnot : m_pAnnotList->All()) {
     CFX_FloatRect annotRect;
     pAnnot->GetRect(annotRect);
     if (annotRect.Contains(pageX, pageY))
@@ -709,11 +707,9 @@
   return nullptr;
 }
 
-CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX,
-                                                  FX_FLOAT pageY) {
-  const int nCount = m_pAnnotList->Count();
-  for (int i = 0; i < nCount; ++i) {
-    CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
+const CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX,
+                                                        FX_FLOAT pageY) {
+  for (const CPDF_Annot* pAnnot : m_pAnnotList->All()) {
     if (pAnnot->GetSubType() == "Widget") {
       CFX_FloatRect annotRect;
       pAnnot->GetRect(annotRect);
@@ -1051,8 +1047,8 @@
     m_pAnnotList.reset(new CPDF_AnnotList(pPage));
     CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
 
-    const int nCount = m_pAnnotList->Count();
-    for (int i = 0; i < nCount; i++) {
+    const size_t nCount = m_pAnnotList->Count();
+    for (size_t i = 0; i < nCount; ++i) {
       CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
       CheckUnSupportAnnot(GetPDFDocument(), pPDFAnnot);
 
@@ -1094,16 +1090,12 @@
   return -1;
 }
 
-FX_BOOL CPDFSDK_PageView::IsValidAnnot(CPDF_Annot* p) const {
+bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const {
   if (!p)
-    return FALSE;
+    return false;
 
-  const int nCount = m_pAnnotList->Count();
-  for (int i = 0; i < nCount; ++i) {
-    if (m_pAnnotList->GetAt(i) == p)
-      return TRUE;
-  }
-  return FALSE;
+  const auto& annots = m_pAnnotList->All();
+  return std::find(annots.begin(), annots.end(), p) != annots.end();
 }
 
 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() {