summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/cpdfsdk_interform.cpp6
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp7
-rw-r--r--fpdfsdk/cpdfsdk_widgethandler.cpp108
-rw-r--r--fpdfsdk/cpdfsdk_widgethandler.h4
-rw-r--r--fpdfsdk/fpdf_formfill.cpp6
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp14
-rw-r--r--fxjs/cjs_field.cpp20
7 files changed, 59 insertions, 106 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,
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index ef2a252b42..cffefeb8c7 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -142,13 +142,6 @@ std::vector<CPDF_FormField*> GetFormFieldsForName(
return fields;
}
-CPDFSDK_Widget* GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv,
- CPDF_FormControl* pFormControl) {
- CPDFSDK_InterForm* pInterForm =
- static_cast<CPDFSDK_InterForm*>(pFormFillEnv->GetInterForm());
- return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr;
-}
-
bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) {
if (!pWidget)
return false;
@@ -209,12 +202,14 @@ void SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
std::vector<CPDF_FormField*> FieldArray =
GetFormFieldsForName(pFormFillEnv, swFieldName);
+ auto* pInterForm = pFormFillEnv->GetInterForm();
for (CPDF_FormField* pFormField : FieldArray) {
if (nControlIndex < 0) {
bool bSet = false;
for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) {
- if (CPDFSDK_Widget* pWidget =
- GetWidget(pFormFillEnv, pFormField->GetControl(i))) {
+ CPDFSDK_Widget* pWidget =
+ pInterForm->GetWidget(pFormField->GetControl(i));
+ if (pWidget) {
if (pWidget->GetBorderStyle() != nBorderStyle) {
pWidget->SetBorderStyle(nBorderStyle);
bSet = true;
@@ -228,7 +223,8 @@ void SetBorderStyle(CPDFSDK_FormFillEnvironment* pFormFillEnv,
return;
if (CPDF_FormControl* pFormControl =
pFormField->GetControl(nControlIndex)) {
- if (CPDFSDK_Widget* pWidget = GetWidget(pFormFillEnv, pFormControl)) {
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
+ if (pWidget) {
if (pWidget->GetBorderStyle() != nBorderStyle) {
pWidget->SetBorderStyle(nBorderStyle);
UpdateFormControl(pFormFillEnv, pFormControl, true, true, true);
@@ -704,8 +700,8 @@ CJS_Result CJS_Field::get_border_style(CJS_Runtime* pRuntime) {
if (!pFormField)
return CJS_Result::Failure(JSMessage::kBadObjectError);
- CPDFSDK_Widget* pWidget =
- GetWidget(m_pFormFillEnv.Get(), GetSmartFieldControl(pFormField));
+ CPDFSDK_Widget* pWidget = m_pFormFillEnv->GetInterForm()->GetWidget(
+ GetSmartFieldControl(pFormField));
if (!pWidget)
return CJS_Result::Failure(JSMessage::kBadObjectError);