diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-10 21:34:17 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-10 21:34:17 +0000 |
commit | 7db136abc305630fb9ba9754a2c371c0e7ae8237 (patch) | |
tree | b04ed80e31df6677881d1b0b8901d7669c14d7c2 /fpdfsdk | |
parent | e2210acfff622ac73b0783e1523615753484073b (diff) | |
download | pdfium-7db136abc305630fb9ba9754a2c371c0e7ae8237.tar.xz |
Remove more impossible checks in form filler code.
Also fix some nits and inline some calls.
Change-Id: Ie962f416b8ecd51ce05341e5511129ea0602fa8e
Reviewed-on: https://pdfium-review.googlesource.com/c/43604
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/cpdfsdk_interform.cpp | 6 | ||||
-rw-r--r-- | fpdfsdk/cpdfsdk_widget.cpp | 7 | ||||
-rw-r--r-- | fpdfsdk/cpdfsdk_widgethandler.cpp | 108 | ||||
-rw-r--r-- | fpdfsdk/cpdfsdk_widgethandler.h | 4 | ||||
-rw-r--r-- | fpdfsdk/fpdf_formfill.cpp | 6 | ||||
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp | 14 |
6 files changed, 51 insertions, 94 deletions
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index 2cc20f9d98..66a52b6dee 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -391,12 +391,11 @@ bool CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, if (!action.GetDict()) return true; - CPDFSDK_ActionHandler* pActionHandler = m_pFormFillEnv->GetActionHandler(); CPDFSDK_FieldAction fa; fa.bModifier = false; fa.bShift = false; fa.sValue = csValue; - pActionHandler->DoAction_FieldJavaScript( + m_pFormFillEnv->GetActionHandler()->DoAction_FieldJavaScript( action, CPDF_AAction::KeyStroke, m_pFormFillEnv.Get(), pFormField, &fa); return fa.bRC; } @@ -411,12 +410,11 @@ bool CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, if (!action.GetDict()) return true; - CPDFSDK_ActionHandler* pActionHandler = m_pFormFillEnv->GetActionHandler(); CPDFSDK_FieldAction fa; fa.bModifier = false; fa.bShift = false; fa.sValue = csValue; - pActionHandler->DoAction_FieldJavaScript( + m_pFormFillEnv->GetActionHandler()->DoAction_FieldJavaScript( action, CPDF_AAction::Validate, m_pFormFillEnv.Get(), pFormField, &fa); return fa.bRC; } diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index cbd2c7bbba..727035122d 100644 --- a/fpdfsdk/cpdfsdk_widget.cpp +++ b/fpdfsdk/cpdfsdk_widget.cpp @@ -833,10 +833,9 @@ bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, #endif // PDF_ENABLE_XFA CPDF_Action action = GetAAction(type); - if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) { - CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHandler(); - return pActionHandler->DoAction_Field(action, type, pFormFillEnv, - GetFormField(), data); + if (action.GetType() != CPDF_Action::Unknown) { + pFormFillEnv->GetActionHandler()->DoAction_Field(action, type, pFormFillEnv, + GetFormField(), data); } return false; } diff --git a/fpdfsdk/cpdfsdk_widgethandler.cpp b/fpdfsdk/cpdfsdk_widgethandler.cpp index bf7de5e742..7dfedad2cd 100644 --- a/fpdfsdk/cpdfsdk_widgethandler.cpp +++ b/fpdfsdk/cpdfsdk_widgethandler.cpp @@ -26,9 +26,12 @@ CPDFSDK_WidgetHandler::CPDFSDK_WidgetHandler( CPDFSDK_FormFillEnvironment* pFormFillEnv) : m_pFormFillEnv(pFormFillEnv), - m_pFormFiller(pFormFillEnv->GetInteractiveFormFiller()) {} + m_pFormFiller(pFormFillEnv->GetInteractiveFormFiller()) { + ASSERT(m_pFormFillEnv); + ASSERT(m_pFormFiller); +} -CPDFSDK_WidgetHandler::~CPDFSDK_WidgetHandler() {} +CPDFSDK_WidgetHandler::~CPDFSDK_WidgetHandler() = default; bool CPDFSDK_WidgetHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot); @@ -76,8 +79,7 @@ CPDFSDK_Annot* CPDFSDK_WidgetHandler::NewAnnot(CXFA_FFWidget* hWidget, void CPDFSDK_WidgetHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { ASSERT(pAnnot); - if (m_pFormFiller) - m_pFormFiller->OnDelete(pAnnot); + m_pFormFiller->OnDelete(pAnnot); std::unique_ptr<CPDFSDK_Widget> pWidget(ToCPDFSDKWidget(pAnnot)); CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); @@ -94,22 +96,21 @@ void CPDFSDK_WidgetHandler::OnDraw(CPDFSDK_PageView* pPageView, pAnnot->AsBAAnnot()->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Normal, nullptr); } else { - if (m_pFormFiller) - m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, mtUser2Device); + m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, mtUser2Device); } } void CPDFSDK_WidgetHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlag) { - if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) + if (!(*pAnnot)->IsSignatureWidget()) m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag); } void CPDFSDK_WidgetHandler::OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlag) { - if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) + if (!(*pAnnot)->IsSignatureWidget()) m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag); } @@ -117,40 +118,32 @@ bool CPDFSDK_WidgetHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlags, const CFX_PointF& point) { - if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point); - - return false; + return !(*pAnnot)->IsSignatureWidget() && + m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point); } bool CPDFSDK_WidgetHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlags, const CFX_PointF& point) { - if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point); - - return false; + return !(*pAnnot)->IsSignatureWidget() && + m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point); } bool CPDFSDK_WidgetHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlags, const CFX_PointF& point) { - if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); - - return false; + return !(*pAnnot)->IsSignatureWidget() && + m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); } bool CPDFSDK_WidgetHandler::OnMouseMove(CPDFSDK_PageView* pPageView, CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlags, const CFX_PointF& point) { - if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point); - - return false; + return !(*pAnnot)->IsSignatureWidget() && + m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point); } bool CPDFSDK_WidgetHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, @@ -158,31 +151,24 @@ bool CPDFSDK_WidgetHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, uint32_t nFlags, short zDelta, const CFX_PointF& point) { - if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, - point); - - return false; + return !(*pAnnot)->IsSignatureWidget() && + m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, point); } bool CPDFSDK_WidgetHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlags, const CFX_PointF& point) { - if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point); - - return false; + return !(*pAnnot)->IsSignatureWidget() && + m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point); } bool CPDFSDK_WidgetHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlags, const CFX_PointF& point) { - if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point); - - return false; + return !(*pAnnot)->IsSignatureWidget() && + m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point); } bool CPDFSDK_WidgetHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, @@ -195,19 +181,15 @@ bool CPDFSDK_WidgetHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, bool CPDFSDK_WidgetHandler::OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnChar(pAnnot, nChar, nFlags); - - return false; + return !pAnnot->IsSignatureWidget() && + m_pFormFiller->OnChar(pAnnot, nChar, nFlags); } bool CPDFSDK_WidgetHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag); - - return false; + return !pAnnot->IsSignatureWidget() && + m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag); } bool CPDFSDK_WidgetHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, @@ -248,18 +230,14 @@ void CPDFSDK_WidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) { bool CPDFSDK_WidgetHandler::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlag) { - if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnSetFocus(pAnnot, nFlag); - - return true; + return (*pAnnot)->IsSignatureWidget() || + m_pFormFiller->OnSetFocus(pAnnot, nFlag); } bool CPDFSDK_WidgetHandler::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot, uint32_t nFlag) { - if (!(*pAnnot)->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->OnKillFocus(pAnnot, nFlag); - - return true; + return (*pAnnot)->IsSignatureWidget() || + m_pFormFiller->OnKillFocus(pAnnot, nFlag); } #ifdef PDF_ENABLE_XFA @@ -272,51 +250,43 @@ bool CPDFSDK_WidgetHandler::OnXFAChangedFocus( CFX_FloatRect CPDFSDK_WidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + if (!pAnnot->IsSignatureWidget()) return CFX_FloatRect(m_pFormFiller->GetViewBBox(pPageView, pAnnot)); return CFX_FloatRect(); } WideString CPDFSDK_WidgetHandler::GetText(CPDFSDK_Annot* pAnnot) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + if (!pAnnot->IsSignatureWidget()) return m_pFormFiller->GetText(pAnnot); return WideString(); } WideString CPDFSDK_WidgetHandler::GetSelectedText(CPDFSDK_Annot* pAnnot) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + if (!pAnnot->IsSignatureWidget()) return m_pFormFiller->GetSelectedText(pAnnot); return WideString(); } void CPDFSDK_WidgetHandler::ReplaceSelection(CPDFSDK_Annot* pAnnot, const WideString& text) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) + if (!pAnnot->IsSignatureWidget()) m_pFormFiller->ReplaceSelection(pAnnot, text); } bool CPDFSDK_WidgetHandler::CanUndo(CPDFSDK_Annot* pAnnot) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->CanUndo(pAnnot); - return false; + return !pAnnot->IsSignatureWidget() && m_pFormFiller->CanUndo(pAnnot); } bool CPDFSDK_WidgetHandler::CanRedo(CPDFSDK_Annot* pAnnot) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->CanRedo(pAnnot); - return false; + return !pAnnot->IsSignatureWidget() && m_pFormFiller->CanRedo(pAnnot); } bool CPDFSDK_WidgetHandler::Undo(CPDFSDK_Annot* pAnnot) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->Undo(pAnnot); - return false; + return !pAnnot->IsSignatureWidget() && m_pFormFiller->Undo(pAnnot); } bool CPDFSDK_WidgetHandler::Redo(CPDFSDK_Annot* pAnnot) { - if (!pAnnot->IsSignatureWidget() && m_pFormFiller) - return m_pFormFiller->Redo(pAnnot); - return false; + return !pAnnot->IsSignatureWidget() && m_pFormFiller->Redo(pAnnot); } bool CPDFSDK_WidgetHandler::HitTest(CPDFSDK_PageView* pPageView, diff --git a/fpdfsdk/cpdfsdk_widgethandler.h b/fpdfsdk/cpdfsdk_widgethandler.h index c74869c77c..61b3c540e8 100644 --- a/fpdfsdk/cpdfsdk_widgethandler.h +++ b/fpdfsdk/cpdfsdk_widgethandler.h @@ -103,10 +103,6 @@ class CPDFSDK_WidgetHandler final : public IPDFSDK_AnnotHandler { CPDFSDK_Annot::ObservedPtr* pNewAnnot) override; #endif // PDF_ENABLE_XFA - CFFL_InteractiveFormFiller* GetFormFiller() const { - return m_pFormFiller.Get(); - } - private: UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv; UnownedPtr<CFFL_InteractiveFormFiller> const m_pFormFiller; diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp index 0bd0f5e008..1d3f06fc1e 100644 --- a/fpdfsdk/fpdf_formfill.cpp +++ b/fpdfsdk/fpdf_formfill.cpp @@ -669,10 +669,8 @@ FPDF_EXPORT void FPDF_CALLCONV FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, auto type = static_cast<CPDF_AAction::AActionType>(aaType); if (aa.ActionExist(type)) { CPDF_Action action = aa.GetAction(type); - CPDFSDK_ActionHandler* pActionHandler = - CPDFSDKFormFillEnvironmentFromFPDFFormHandle(hHandle) - ->GetActionHandler(); - pActionHandler->DoAction_Document(action, type, pFormFillEnv); + pFormFillEnv->GetActionHandler()->DoAction_Document(action, type, + pFormFillEnv); } } diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index 6b617eaef0..d95d242c48 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp @@ -387,9 +387,7 @@ void CPDFXFA_DocEnvironment::SetCalculationsEnabled(CXFA_FFDoc* hDoc, bool bEnabled) { if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv()) return; - if (m_pContext->GetFormFillEnv()->GetInterForm()) { - m_pContext->GetFormFillEnv()->GetInterForm()->XfaEnableCalculate(bEnabled); - } + m_pContext->GetFormFillEnv()->GetInterForm()->XfaEnableCalculate(bEnabled); } void CPDFXFA_DocEnvironment::GetTitle(CXFA_FFDoc* hDoc, WideString& wsTitle) { @@ -530,9 +528,8 @@ void CPDFXFA_DocEnvironment::GotoURL(CXFA_FFDoc* hDoc, bool CPDFXFA_DocEnvironment::IsValidationsEnabled(CXFA_FFDoc* hDoc) { if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv()) return false; - - auto* interform = m_pContext->GetFormFillEnv()->GetInterForm(); - return !interform || interform->IsXfaValidationsEnabled(); + auto* pInterform = m_pContext->GetFormFillEnv()->GetInterForm(); + return pInterform->IsXfaValidationsEnabled(); } void CPDFXFA_DocEnvironment::SetValidationsEnabled(CXFA_FFDoc* hDoc, @@ -540,9 +537,8 @@ void CPDFXFA_DocEnvironment::SetValidationsEnabled(CXFA_FFDoc* hDoc, if (hDoc != m_pContext->GetXFADoc() || !m_pContext->GetFormFillEnv()) return; - auto* interform = m_pContext->GetFormFillEnv()->GetInterForm(); - if (interform) - interform->XfaSetValidationsEnabled(bEnabled); + m_pContext->GetFormFillEnv()->GetInterForm()->XfaSetValidationsEnabled( + bEnabled); } void CPDFXFA_DocEnvironment::SetFocusWidget(CXFA_FFDoc* hDoc, |