Remove impossible nullptr checks in CPDFSDK_InterForm.
Also remove dead code and move initialization to headers in
CPDFSDK_InterForm.
Change-Id: Ib75864ccfd3f1d0d255d9c7942cc610edce822a3
Reviewed-on: https://pdfium-review.googlesource.com/c/43599
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index bd3c7fa..549caaf 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -122,15 +122,9 @@
CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_FormFillEnvironment* pFormFillEnv)
: m_pFormFillEnv(pFormFillEnv),
- m_pInterForm(
- pdfium::MakeUnique<CPDF_InterForm>(m_pFormFillEnv->GetPDFDocument())),
-#ifdef PDF_ENABLE_XFA
- m_bXfaCalculate(true),
- m_bXfaValidationsEnabled(true),
-#endif // PDF_ENABLE_XFA
- m_bCalculate(true),
- m_bBusy(false),
- m_HighlightAlpha(0) {
+ m_pInterForm(pdfium::MakeUnique<CPDF_InterForm>(
+ m_pFormFillEnv->GetPDFDocument())) {
+ ASSERT(m_pFormFillEnv);
m_pInterForm->SetFormNotify(this);
RemoveAllHighLights();
}
@@ -142,10 +136,6 @@
#endif // PDF_ENABLE_XFA
}
-bool CPDFSDK_InterForm::HighlightWidgets() {
- return false;
-}
-
CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget,
bool bNext) const {
auto pIterator = pdfium::MakeUnique<CPDFSDK_AnnotIterator>(
@@ -156,7 +146,7 @@
}
CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const {
- if (!pControl || !m_pInterForm)
+ if (!pControl)
return nullptr;
CPDFSDK_Widget* pWidget = nullptr;
@@ -527,9 +517,6 @@
if (sDestination.IsEmpty())
return false;
- if (!m_pFormFillEnv || !m_pInterForm)
- return false;
-
std::unique_ptr<CFDF_Document> pFDFDoc =
m_pInterForm->ExportToFDF(m_pFormFillEnv->JS_docGetFilePath(), false);
if (!pFDFDoc)
@@ -642,7 +629,7 @@
OnCalculate(nullptr);
}
-bool CPDFSDK_InterForm::IsNeedHighLight(FormFieldType fieldType) {
+bool CPDFSDK_InterForm::IsNeedHighLight(FormFieldType fieldType) const {
if (fieldType == FormFieldType::kUnknown)
return false;
diff --git a/fpdfsdk/cpdfsdk_interform.h b/fpdfsdk/cpdfsdk_interform.h
index bd1a760..1862fdb 100644
--- a/fpdfsdk/cpdfsdk_interform.h
+++ b/fpdfsdk/cpdfsdk_interform.h
@@ -39,8 +39,6 @@
return m_pFormFillEnv.Get();
}
- bool HighlightWidgets();
-
CPDFSDK_Widget* GetSibling(CPDFSDK_Widget* pWidget, bool bNext) const;
CPDFSDK_Widget* GetWidget(CPDF_FormControl* pControl) const;
void GetWidgets(const WideString& sFieldName,
@@ -92,7 +90,7 @@
const std::vector<CPDF_FormField*>& fields,
bool bIncludeOrExclude);
- bool IsNeedHighLight(FormFieldType fieldType);
+ bool IsNeedHighLight(FormFieldType fieldType) const;
void RemoveAllHighLights();
void SetHighlightAlpha(uint8_t alpha) { m_HighlightAlpha = alpha; }
uint8_t GetHighlightAlpha() { return m_HighlightAlpha; }
@@ -114,20 +112,18 @@
int GetPageIndexByAnnotDict(CPDF_Document* pDocument,
CPDF_Dictionary* pAnnotDict) const;
- using CPDFSDK_WidgetMap = std::map<CPDF_FormControl*, CPDFSDK_Widget*>;
-
- UnownedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv;
- std::unique_ptr<CPDF_InterForm> m_pInterForm;
- CPDFSDK_WidgetMap m_Map;
+ UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
+ std::unique_ptr<CPDF_InterForm> const m_pInterForm;
+ std::map<CPDF_FormControl*, CPDFSDK_Widget*> m_Map;
#ifdef PDF_ENABLE_XFA
std::map<CXFA_FFWidget*, CPDFSDK_XFAWidget*> m_XFAMap;
- bool m_bXfaCalculate;
- bool m_bXfaValidationsEnabled;
+ bool m_bXfaCalculate = true;
+ bool m_bXfaValidationsEnabled = true;
#endif // PDF_ENABLE_XFA
- bool m_bCalculate;
- bool m_bBusy;
+ bool m_bCalculate = true;
+ bool m_bBusy = false;
- uint8_t m_HighlightAlpha;
+ uint8_t m_HighlightAlpha = 0;
FX_COLORREF m_HighlightColor[kFormFieldTypeCount];
bool m_NeedsHighlight[kFormFieldTypeCount];
};
diff --git a/fpdfsdk/cpdfsdk_widgethandler.cpp b/fpdfsdk/cpdfsdk_widgethandler.cpp
index 70d0397..b67a92d 100644
--- a/fpdfsdk/cpdfsdk_widgethandler.cpp
+++ b/fpdfsdk/cpdfsdk_widgethandler.cpp
@@ -62,7 +62,7 @@
CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
pInterForm->AddMap(pCtrl, pWidget);
CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
- if (pPDFInterForm && pPDFInterForm->NeedConstructAP())
+ if (pPDFInterForm->NeedConstructAP())
pWidget->ResetAppearance(nullptr, false);
return pWidget;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
index 2e1abb8..40ccbdc 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -12,7 +12,6 @@
#include "core/fpdfapi/parser/cpdf_document.h"
#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
#include "fpdfsdk/cpdfsdk_helpers.h"
-#include "fpdfsdk/cpdfsdk_interform.h"
#include "fpdfsdk/cpdfsdk_pageview.h"
#include "fpdfsdk/fpdfxfa/cpdfxfa_page.h"
#include "fpdfsdk/fpdfxfa/cxfa_fwladaptertimermgr.h"
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index db58c87..6b617ea 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -380,12 +380,7 @@
bool CPDFXFA_DocEnvironment::IsCalculationsEnabled(CXFA_FFDoc* hDoc) {
if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv())
return false;
- if (m_pContext->GetFormFillEnv()->GetInterForm()) {
- return m_pContext->GetFormFillEnv()
- ->GetInterForm()
- ->IsXfaCalculateEnabled();
- }
- return false;
+ return m_pContext->GetFormFillEnv()->GetInterForm()->IsXfaCalculateEnabled();
}
void CPDFXFA_DocEnvironment::SetCalculationsEnabled(CXFA_FFDoc* hDoc,
@@ -602,9 +597,6 @@
return 0;
CPDFSDK_InterForm* pInterForm = m_pContext->GetFormFillEnv()->GetInterForm();
- if (!pInterForm)
- return 0;
-
return AlphaAndColorRefToArgb(
pInterForm->GetHighlightAlpha(),
pInterForm->GetHighlightColor(FormFieldType::kXFA));