Use CPDFSDK_BAAnnot::GetAnnotDict() in more places.

Also initialize CPDFSDK_Widget members in the header.

Change-Id: I55cfad3b0393b7d8e897c6ea1b91952b9c5a68d1
Reviewed-on: https://pdfium-review.googlesource.com/c/43598
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp
index 4b16498..e49a200 100644
--- a/fpdfsdk/cpdfsdk_baannot.cpp
+++ b/fpdfsdk/cpdfsdk_baannot.cpp
@@ -42,9 +42,9 @@
 }
 
 CPDF_Dictionary* CPDFSDK_BAAnnot::GetAPDict() const {
-  CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
+  CPDF_Dictionary* pAPDict = GetAnnotDict()->GetDictFor("AP");
   if (!pAPDict)
-    pAPDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("AP");
+    pAPDict = GetAnnotDict()->SetNewFor<CPDF_Dictionary>("AP");
   return pAPDict;
 }
 
@@ -52,7 +52,7 @@
   ASSERT(rect.right - rect.left >= GetMinWidth());
   ASSERT(rect.top - rect.bottom >= GetMinHeight());
 
-  m_pAnnot->GetAnnotDict()->SetRectFor("Rect", rect);
+  GetAnnotDict()->SetRectFor("Rect", rect);
 }
 
 CFX_FloatRect CPDFSDK_BAAnnot::GetRect() const {
@@ -72,11 +72,11 @@
 }
 
 bool CPDFSDK_BAAnnot::IsAppearanceValid() {
-  return !!m_pAnnot->GetAnnotDict()->GetDictFor("AP");
+  return !!GetAnnotDict()->GetDictFor("AP");
 }
 
 bool CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode) {
-  CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
+  CPDF_Dictionary* pAP = GetAnnotDict()->GetDictFor("AP");
   if (!pAP)
     return false;
 
@@ -95,65 +95,62 @@
 }
 
 void CPDFSDK_BAAnnot::SetAnnotName(const WideString& sName) {
-  if (sName.IsEmpty()) {
-    m_pAnnot->GetAnnotDict()->RemoveFor("NM");
-  } else {
-    m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>(
-        "NM", PDF_EncodeText(sName), false);
-  }
+  if (sName.IsEmpty())
+    GetAnnotDict()->RemoveFor("NM");
+  else
+    GetAnnotDict()->SetNewFor<CPDF_String>("NM", PDF_EncodeText(sName), false);
 }
 
 WideString CPDFSDK_BAAnnot::GetAnnotName() const {
-  return m_pAnnot->GetAnnotDict()->GetUnicodeTextFor("NM");
+  return GetAnnotDict()->GetUnicodeTextFor("NM");
 }
 
 void CPDFSDK_BAAnnot::SetFlags(uint32_t nFlags) {
-  m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("F",
-                                                   static_cast<int>(nFlags));
+  GetAnnotDict()->SetNewFor<CPDF_Number>("F", static_cast<int>(nFlags));
 }
 
 uint32_t CPDFSDK_BAAnnot::GetFlags() const {
-  return m_pAnnot->GetAnnotDict()->GetIntegerFor("F");
+  return GetAnnotDict()->GetIntegerFor("F");
 }
 
 void CPDFSDK_BAAnnot::SetAppState(const ByteString& str) {
   if (str.IsEmpty())
-    m_pAnnot->GetAnnotDict()->RemoveFor("AS");
+    GetAnnotDict()->RemoveFor("AS");
   else
-    m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>("AS", str, false);
+    GetAnnotDict()->SetNewFor<CPDF_String>("AS", str, false);
 }
 
 ByteString CPDFSDK_BAAnnot::GetAppState() const {
-  return m_pAnnot->GetAnnotDict()->GetStringFor("AS");
+  return GetAnnotDict()->GetStringFor("AS");
 }
 
 void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
-  CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border");
+  CPDF_Array* pBorder = GetAnnotDict()->GetArrayFor("Border");
   if (pBorder) {
     pBorder->SetNewAt<CPDF_Number>(2, nWidth);
   } else {
-    CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
+    CPDF_Dictionary* pBSDict = GetAnnotDict()->GetDictFor("BS");
     if (!pBSDict)
-      pBSDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS");
+      pBSDict = GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS");
 
     pBSDict->SetNewFor<CPDF_Number>("W", nWidth);
   }
 }
 
 int CPDFSDK_BAAnnot::GetBorderWidth() const {
-  if (CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border"))
+  if (CPDF_Array* pBorder = GetAnnotDict()->GetArrayFor("Border"))
     return pBorder->GetIntegerAt(2);
 
-  if (CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS"))
+  if (CPDF_Dictionary* pBSDict = GetAnnotDict()->GetDictFor("BS"))
     return pBSDict->GetIntegerFor("W", 1);
 
   return 1;
 }
 
 void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) {
-  CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
+  CPDF_Dictionary* pBSDict = GetAnnotDict()->GetDictFor("BS");
   if (!pBSDict)
-    pBSDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS");
+    pBSDict = GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS");
 
   switch (nStyle) {
     case BorderStyle::SOLID:
@@ -177,7 +174,7 @@
 }
 
 BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const {
-  CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
+  CPDF_Dictionary* pBSDict = GetAnnotDict()->GetDictFor("BS");
   if (pBSDict) {
     ByteString sBorderStyle = pBSDict->GetStringFor("S", "S");
     if (sBorderStyle == "S")
@@ -192,7 +189,7 @@
       return BorderStyle::UNDERLINE;
   }
 
-  CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border");
+  CPDF_Array* pBorder = GetAnnotDict()->GetArrayFor("Border");
   if (pBorder) {
     if (pBorder->GetCount() >= 4) {
       CPDF_Array* pDP = pBorder->GetArrayAt(3);
@@ -211,11 +208,11 @@
 }
 
 CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
-  return CPDF_Action(m_pAnnot->GetAnnotDict()->GetDictFor("A"));
+  return CPDF_Action(GetAnnotDict()->GetDictFor("A"));
 }
 
 CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
-  return CPDF_AAction(m_pAnnot->GetAnnotDict()->GetDictFor("AA"));
+  return CPDF_AAction(GetAnnotDict()->GetDictFor("AA"));
 }
 
 CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index 82776e3..70ad592 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -44,19 +44,9 @@
 CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
                                CPDFSDK_PageView* pPageView,
                                CPDFSDK_InterForm* pInterForm)
-    : CPDFSDK_BAAnnot(pAnnot, pPageView),
-      m_pInterForm(pInterForm),
-      m_nAppearanceAge(0),
-      m_nValueAge(0)
-#ifdef PDF_ENABLE_XFA
-      ,
-      m_hMixXFAWidget(nullptr),
-      m_pWidgetHandler(nullptr)
-#endif  // PDF_ENABLE_XFA
-{
-}
+    : CPDFSDK_BAAnnot(pAnnot, pPageView), m_pInterForm(pInterForm) {}
 
-CPDFSDK_Widget::~CPDFSDK_Widget() {}
+CPDFSDK_Widget::~CPDFSDK_Widget() = default;
 
 #ifdef PDF_ENABLE_XFA
 CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const {
@@ -312,7 +302,7 @@
 #endif  // PDF_ENABLE_XFA
 
 bool CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) {
-  CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
+  CPDF_Dictionary* pAP = GetAnnotDict()->GetDictFor("AP");
   if (!pAP)
     return false;
 
@@ -371,7 +361,7 @@
 int CPDFSDK_Widget::GetFieldFlags() const {
   CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
   CPDF_FormControl* pFormControl =
-      pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict());
+      pPDFInterForm->GetControlByDict(GetAnnotDict());
   CPDF_FormField* pFormField = pFormControl->GetField();
   return pFormField->GetFieldFlags();
 }
diff --git a/fpdfsdk/cpdfsdk_widget.h b/fpdfsdk/cpdfsdk_widget.h
index e7d5f6d..6ccfdfd 100644
--- a/fpdfsdk/cpdfsdk_widget.h
+++ b/fpdfsdk/cpdfsdk_widget.h
@@ -132,9 +132,9 @@
 #endif  // PDF_ENABLE_XFA
 
   UnownedPtr<CPDFSDK_InterForm> const m_pInterForm;
-  bool m_bAppModified;
-  uint32_t m_nAppearanceAge;
-  uint32_t m_nValueAge;
+  bool m_bAppModified = false;
+  uint32_t m_nAppearanceAge = 0;
+  uint32_t m_nValueAge = 0;
 
 #ifdef PDF_ENABLE_XFA
   mutable UnownedPtr<CXFA_FFWidget> m_hMixXFAWidget;