summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_interform.cpp4
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp68
-rw-r--r--fpdfsdk/cpdfsdk_widget.h4
-rw-r--r--fpdfsdk/formfiller/cffl_interactiveformfiller.cpp26
-rw-r--r--fpdfsdk/fsdk_actionhandler.cpp259
-rw-r--r--fpdfsdk/fsdk_actionhandler.h16
6 files changed, 188 insertions, 189 deletions
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index 21a6d41c43..03a782b15b 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -383,7 +383,7 @@ bool CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField,
fa.bShift = false;
fa.sValue = csValue;
pActionHandler->DoAction_FieldJavaScript(
- action, CPDF_AAction::KeyStroke, m_pFormFillEnv.Get(), pFormField, fa);
+ action, CPDF_AAction::KeyStroke, m_pFormFillEnv.Get(), pFormField, &fa);
return fa.bRC;
}
@@ -403,7 +403,7 @@ bool CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField,
fa.bShift = false;
fa.sValue = csValue;
pActionHandler->DoAction_FieldJavaScript(
- action, CPDF_AAction::Validate, m_pFormFillEnv.Get(), pFormField, fa);
+ 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 fc67059025..d0eaa7adc8 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -221,7 +221,7 @@ bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) {
}
bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
- PDFSDK_FieldAction& data,
+ PDFSDK_FieldAction* data,
CPDFSDK_PageView* pPageView) {
CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
@@ -239,22 +239,22 @@ bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
CXFA_EventParam param;
param.m_eType = eEventType;
- param.m_wsChange = data.sChange;
- param.m_iCommitKey = data.nCommitKey;
- param.m_bShift = data.bShift;
- param.m_iSelStart = data.nSelStart;
- param.m_iSelEnd = data.nSelEnd;
- param.m_wsFullText = data.sValue;
- param.m_bKeyDown = data.bKeyDown;
- param.m_bModifier = data.bModifier;
- param.m_wsNewText = data.sValue;
- if (data.nSelEnd > data.nSelStart)
- param.m_wsNewText.Delete(data.nSelStart, data.nSelEnd - data.nSelStart);
-
- for (const auto& c : data.sChange)
- param.m_wsNewText.Insert(data.nSelStart, c);
-
- param.m_wsPrevText = data.sValue;
+ param.m_wsChange = data->sChange;
+ param.m_iCommitKey = data->nCommitKey;
+ param.m_bShift = data->bShift;
+ param.m_iSelStart = data->nSelStart;
+ param.m_iSelEnd = data->nSelEnd;
+ param.m_wsFullText = data->sValue;
+ param.m_bKeyDown = data->bKeyDown;
+ param.m_bModifier = data->bModifier;
+ param.m_wsNewText = data->sValue;
+ if (data->nSelEnd > data->nSelStart)
+ param.m_wsNewText.Delete(data->nSelStart, data->nSelEnd - data->nSelStart);
+
+ for (const auto& c : data->sChange)
+ param.m_wsNewText.Insert(data->nSelStart, c);
+
+ param.m_wsPrevText = data->sValue;
if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
GetFieldType() == FormFieldType::kRadioButton) {
if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
@@ -831,34 +831,34 @@ CFX_Color CPDFSDK_Widget::GetFillPWLColor() const {
}
bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
- PDFSDK_FieldAction& data,
+ PDFSDK_FieldAction* data,
CPDFSDK_PageView* pPageView) {
CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv();
#ifdef PDF_ENABLE_XFA
CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext();
if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
- XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit);
+ XFA_EVENTTYPE eEventType = GetXFAEventType(type, data->bWillCommit);
if (eEventType != XFA_EVENT_Unknown) {
if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
CXFA_EventParam param;
param.m_eType = eEventType;
- param.m_wsChange = data.sChange;
- param.m_iCommitKey = data.nCommitKey;
- param.m_bShift = data.bShift;
- param.m_iSelStart = data.nSelStart;
- param.m_iSelEnd = data.nSelEnd;
- param.m_wsFullText = data.sValue;
- param.m_bKeyDown = data.bKeyDown;
- param.m_bModifier = data.bModifier;
- param.m_wsNewText = data.sValue;
- if (data.nSelEnd > data.nSelStart)
- param.m_wsNewText.Delete(data.nSelStart,
- data.nSelEnd - data.nSelStart);
- for (int i = data.sChange.GetLength() - 1; i >= 0; i--)
- param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
- param.m_wsPrevText = data.sValue;
+ param.m_wsChange = data->sChange;
+ param.m_iCommitKey = data->nCommitKey;
+ param.m_bShift = data->bShift;
+ param.m_iSelStart = data->nSelStart;
+ param.m_iSelEnd = data->nSelEnd;
+ param.m_wsFullText = data->sValue;
+ param.m_bKeyDown = data->bKeyDown;
+ param.m_bModifier = data->bModifier;
+ param.m_wsNewText = data->sValue;
+ if (data->nSelEnd > data->nSelStart)
+ param.m_wsNewText.Delete(data->nSelStart,
+ data->nSelEnd - data->nSelStart);
+ for (int i = data->sChange.GetLength() - 1; i >= 0; i--)
+ param.m_wsNewText.Insert(data->nSelStart, data->sChange[i]);
+ param.m_wsPrevText = data->sValue;
int32_t nRet = XFA_EVENTERROR_NotExist;
CXFA_Node* node = hWidget->GetNode();
diff --git a/fpdfsdk/cpdfsdk_widget.h b/fpdfsdk/cpdfsdk_widget.h
index 22d0e364c1..c3257325e7 100644
--- a/fpdfsdk/cpdfsdk_widget.h
+++ b/fpdfsdk/cpdfsdk_widget.h
@@ -42,7 +42,7 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot {
bool HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT);
bool OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
- PDFSDK_FieldAction& data,
+ PDFSDK_FieldAction* data,
CPDFSDK_PageView* pPageView);
void Synchronize(bool bSynchronizeElse);
@@ -100,7 +100,7 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot {
WideString OnFormat(bool& bFormatted);
bool OnAAction(CPDF_AAction::AActionType type,
- PDFSDK_FieldAction& data,
+ PDFSDK_FieldAction* data,
CPDFSDK_PageView* pPageView);
CPDFSDK_InterForm* GetInterForm() const { return m_pInterForm.Get(); }
diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
index e74f902bd2..f33bde68cc 100644
--- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
@@ -129,7 +129,7 @@ void CFFL_InteractiveFormFiller::OnMouseEnter(
PDFSDK_FieldAction fa;
fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag);
fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag);
- pWidget->OnAAction(CPDF_AAction::CursorEnter, fa, pPageView);
+ pWidget->OnAAction(CPDF_AAction::CursorEnter, &fa, pPageView);
m_bNotifying = false;
if (!(*pAnnot))
return;
@@ -162,7 +162,7 @@ void CFFL_InteractiveFormFiller::OnMouseExit(CPDFSDK_PageView* pPageView,
PDFSDK_FieldAction fa;
fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag);
fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag);
- pWidget->OnAAction(CPDF_AAction::CursorExit, fa, pPageView);
+ pWidget->OnAAction(CPDF_AAction::CursorExit, &fa, pPageView);
m_bNotifying = false;
if (!(*pAnnot))
return;
@@ -198,7 +198,7 @@ bool CFFL_InteractiveFormFiller::OnLButtonDown(
PDFSDK_FieldAction fa;
fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlags);
fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlags);
- pWidget->OnAAction(CPDF_AAction::ButtonDown, fa, pPageView);
+ pWidget->OnAAction(CPDF_AAction::ButtonDown, &fa, pPageView);
m_bNotifying = false;
if (!(*pAnnot))
return true;
@@ -276,7 +276,7 @@ bool CFFL_InteractiveFormFiller::OnButtonUp(CPDFSDK_Annot::ObservedPtr* pAnnot,
PDFSDK_FieldAction fa;
fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag);
fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag);
- pWidget->OnAAction(CPDF_AAction::ButtonUp, fa, pPageView);
+ pWidget->OnAAction(CPDF_AAction::ButtonUp, &fa, pPageView);
m_bNotifying = false;
if (!(*pAnnot) || !IsValidAnnot(pPageView, pWidget))
return true;
@@ -389,7 +389,7 @@ bool CFFL_InteractiveFormFiller::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag);
fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag);
pFormFiller->GetActionData(pPageView, CPDF_AAction::GetFocus, fa);
- pWidget->OnAAction(CPDF_AAction::GetFocus, fa, pPageView);
+ pWidget->OnAAction(CPDF_AAction::GetFocus, &fa, pPageView);
m_bNotifying = false;
if (!(*pAnnot))
return false;
@@ -440,7 +440,7 @@ bool CFFL_InteractiveFormFiller::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag);
fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag);
pFormFiller->GetActionData(pPageView, CPDF_AAction::LoseFocus, fa);
- pWidget->OnAAction(CPDF_AAction::LoseFocus, fa, pPageView);
+ pWidget->OnAAction(CPDF_AAction::LoseFocus, &fa, pPageView);
m_bNotifying = false;
return !!(*pAnnot);
}
@@ -621,7 +621,7 @@ bool CFFL_InteractiveFormFiller::OnKeyStrokeCommit(
CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false);
pFormFiller->GetActionData(pPageView, CPDF_AAction::KeyStroke, fa);
pFormFiller->SaveState(pPageView);
- pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pPageView);
+ pWidget->OnAAction(CPDF_AAction::KeyStroke, &fa, pPageView);
if (!(*pAnnot))
return true;
@@ -652,7 +652,7 @@ bool CFFL_InteractiveFormFiller::OnValidate(CPDFSDK_Annot::ObservedPtr* pAnnot,
CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false);
pFormFiller->GetActionData(pPageView, CPDF_AAction::Validate, fa);
pFormFiller->SaveState(pPageView);
- pWidget->OnAAction(CPDF_AAction::Validate, fa, pPageView);
+ pWidget->OnAAction(CPDF_AAction::Validate, &fa, pPageView);
if (!(*pAnnot))
return true;
@@ -716,7 +716,7 @@ bool CFFL_InteractiveFormFiller::OnClick(CPDFSDK_Annot::ObservedPtr* pAnnot,
fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag);
fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag);
- pWidget->OnXFAAAction(PDFSDK_XFA_Click, fa, pPageView);
+ pWidget->OnXFAAAction(PDFSDK_XFA_Click, &fa, pPageView);
m_bNotifying = false;
if (!(*pAnnot) || !IsValidAnnot(pPageView, pWidget))
return true;
@@ -746,7 +746,7 @@ bool CFFL_InteractiveFormFiller::OnFull(CPDFSDK_Annot::ObservedPtr* pAnnot,
fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag);
fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag);
- pWidget->OnXFAAAction(PDFSDK_XFA_Full, fa, pPageView);
+ pWidget->OnXFAAAction(PDFSDK_XFA_Full, &fa, pPageView);
m_bNotifying = false;
if (!(*pAnnot) || !IsValidAnnot(pPageView, pWidget))
return true;
@@ -799,7 +799,7 @@ bool CFFL_InteractiveFormFiller::OnPreOpen(CPDFSDK_Annot::ObservedPtr* pAnnot,
fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag);
fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag);
- pWidget->OnXFAAAction(PDFSDK_XFA_PreOpen, fa, pPageView);
+ pWidget->OnXFAAAction(PDFSDK_XFA_PreOpen, &fa, pPageView);
m_bNotifying = false;
if (!(*pAnnot) || !IsValidAnnot(pPageView, pWidget))
return true;
@@ -830,7 +830,7 @@ bool CFFL_InteractiveFormFiller::OnPostOpen(CPDFSDK_Annot::ObservedPtr* pAnnot,
fa.bModifier = CPDFSDK_FormFillEnvironment::IsCTRLKeyDown(nFlag);
fa.bShift = CPDFSDK_FormFillEnvironment::IsSHIFTKeyDown(nFlag);
- pWidget->OnXFAAAction(PDFSDK_XFA_PostOpen, fa, pPageView);
+ pWidget->OnXFAAAction(PDFSDK_XFA_PostOpen, &fa, pPageView);
m_bNotifying = false;
if (!(*pAnnot) || !IsValidAnnot(pPageView, pWidget))
return true;
@@ -900,7 +900,7 @@ std::pair<bool, bool> CFFL_InteractiveFormFiller::OnBeforeKeyStroke(
CPDFSDK_Annot::ObservedPtr pObserved(privateData.pWidget);
bool action_status = privateData.pWidget->OnAAction(
- CPDF_AAction::KeyStroke, fa, privateData.pPageView);
+ CPDF_AAction::KeyStroke, &fa, privateData.pPageView);
if (!pObserved || !IsValidAnnot(privateData.pPageView, privateData.pWidget))
return {true, true};
diff --git a/fpdfsdk/fsdk_actionhandler.cpp b/fpdfsdk/fsdk_actionhandler.cpp
index b0bc3f6831..6fcf9d41c1 100644
--- a/fpdfsdk/fsdk_actionhandler.cpp
+++ b/fpdfsdk/fsdk_actionhandler.cpp
@@ -47,7 +47,7 @@ bool CPDFSDK_ActionHandler::DoAction_FieldJavaScript(
CPDF_AAction::AActionType type,
CPDFSDK_FormFillEnvironment* pFormFillEnv,
CPDF_FormField* pFormField,
- PDFSDK_FieldAction& data) {
+ PDFSDK_FieldAction* data) {
ASSERT(pFormFillEnv);
if (pFormFillEnv->IsJSInitiated() &&
JsAction.GetType() == CPDF_Action::JavaScript) {
@@ -106,7 +106,7 @@ bool CPDFSDK_ActionHandler::DoAction_Field(
CPDF_AAction::AActionType type,
CPDFSDK_FormFillEnvironment* pFormFillEnv,
CPDF_FormField* pFormField,
- PDFSDK_FieldAction& data) {
+ PDFSDK_FieldAction* data) {
std::set<CPDF_Dictionary*> visited;
return ExecuteFieldAction(action, type, pFormFillEnv, pFormField, data,
&visited);
@@ -154,19 +154,10 @@ bool CPDFSDK_ActionHandler::ExecuteLinkAction(
ASSERT(pFormFillEnv);
if (action.GetType() == CPDF_Action::JavaScript) {
- if (pFormFillEnv->IsJSInitiated()) {
- WideString swJS = action.GetJavaScript();
- if (!swJS.IsEmpty()) {
- IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
- IJS_EventContext* pContext = pRuntime->NewEventContext();
- pContext->OnLink_MouseUp(pFormFillEnv);
-
- WideString csInfo;
- pContext->RunScript(swJS, &csInfo);
- pRuntime->ReleaseEventContext(pContext);
- // TODO(dsinclair): Return error if RunScript returns false.
- }
- }
+ RunScriptForAction(action, pFormFillEnv,
+ [pFormFillEnv](IJS_EventContext* context) {
+ context->OnLink_MouseUp(pFormFillEnv);
+ });
} else {
DoAction_NoJs(action, pFormFillEnv);
}
@@ -228,7 +219,7 @@ bool CPDFSDK_ActionHandler::ExecuteFieldAction(
CPDF_AAction::AActionType type,
CPDFSDK_FormFillEnvironment* pFormFillEnv,
CPDF_FormField* pFormField,
- PDFSDK_FieldAction& data,
+ PDFSDK_FieldAction* data,
std::set<CPDF_Dictionary*>* visited) {
CPDF_Dictionary* pDict = action.GetDict();
if (pdfium::ContainsKey(*visited, pDict))
@@ -273,21 +264,10 @@ bool CPDFSDK_ActionHandler::ExecuteScreenAction(
visited->insert(pDict);
ASSERT(pFormFillEnv);
- if (action.GetType() == CPDF_Action::JavaScript) {
- if (pFormFillEnv->IsJSInitiated()) {
- WideString swJS = action.GetJavaScript();
- if (!swJS.IsEmpty()) {
- IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
- IJS_EventContext* pContext = pRuntime->NewEventContext();
- WideString csInfo;
- pContext->RunScript(swJS, &csInfo);
- pRuntime->ReleaseEventContext(pContext);
- // TODO(dsinclair): Return error if RunScript returns false.
- }
- }
- } else {
+ if (action.GetType() == CPDF_Action::JavaScript)
+ RunScriptForAction(action, pFormFillEnv, [](IJS_EventContext*) {});
+ else
DoAction_NoJs(action, pFormFillEnv);
- }
for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
CPDF_Action subaction = action.GetSubAction(i);
@@ -311,19 +291,10 @@ bool CPDFSDK_ActionHandler::ExecuteBookMark(
ASSERT(pFormFillEnv);
if (action.GetType() == CPDF_Action::JavaScript) {
- if (pFormFillEnv->IsJSInitiated()) {
- WideString swJS = action.GetJavaScript();
- if (!swJS.IsEmpty()) {
- IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
- IJS_EventContext* pContext = pRuntime->NewEventContext();
- pContext->OnBookmark_MouseUp(pBookmark);
-
- WideString csInfo;
- pContext->RunScript(swJS, &csInfo);
- pRuntime->ReleaseEventContext(pContext);
- // TODO(dsinclair): Return error if RunScript returns false.
- }
- }
+ RunScriptForAction(action, pFormFillEnv,
+ [pFormFillEnv, pBookmark](IJS_EventContext* context) {
+ context->OnBookmark_MouseUp(pBookmark);
+ });
} else {
DoAction_NoJs(action, pFormFillEnv);
}
@@ -425,113 +396,105 @@ void CPDFSDK_ActionHandler::RunFieldJavaScript(
CPDFSDK_FormFillEnvironment* pFormFillEnv,
CPDF_FormField* pFormField,
CPDF_AAction::AActionType type,
- PDFSDK_FieldAction& data,
+ PDFSDK_FieldAction* data,
const WideString& script) {
ASSERT(type != CPDF_AAction::Calculate);
ASSERT(type != CPDF_AAction::Format);
- IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
- IJS_EventContext* pContext = pRuntime->NewEventContext();
- switch (type) {
- case CPDF_AAction::CursorEnter:
- pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
- break;
- case CPDF_AAction::CursorExit:
- pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
- break;
- case CPDF_AAction::ButtonDown:
- pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
- break;
- case CPDF_AAction::ButtonUp:
- pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField);
- break;
- case CPDF_AAction::GetFocus:
- pContext->OnField_Focus(data.bModifier, data.bShift, pFormField,
- data.sValue);
- break;
- case CPDF_AAction::LoseFocus:
- pContext->OnField_Blur(data.bModifier, data.bShift, pFormField,
- data.sValue);
- break;
- case CPDF_AAction::KeyStroke:
- pContext->OnField_Keystroke(data.sChange, data.sChangeEx, data.bKeyDown,
- data.bModifier, data.nSelEnd, data.nSelStart,
- data.bShift, pFormField, data.sValue,
- data.bWillCommit, data.bFieldFull, data.bRC);
- break;
- case CPDF_AAction::Validate:
- pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown,
- data.bModifier, data.bShift, pFormField,
- data.sValue, data.bRC);
- break;
- default:
- NOTREACHED();
- break;
- }
-
- WideString csInfo;
- pContext->RunScript(script, &csInfo);
- pRuntime->ReleaseEventContext(pContext);
- // TODO(dsinclair): Return error if RunScript returns false.
+ RunScript(
+ pFormFillEnv, script,
+ [type, data, pFormField](IJS_EventContext* context) {
+ switch (type) {
+ case CPDF_AAction::CursorEnter:
+ context->OnField_MouseEnter(data->bModifier, data->bShift,
+ pFormField);
+ break;
+ case CPDF_AAction::CursorExit:
+ context->OnField_MouseExit(data->bModifier, data->bShift,
+ pFormField);
+ break;
+ case CPDF_AAction::ButtonDown:
+ context->OnField_MouseDown(data->bModifier, data->bShift,
+ pFormField);
+ break;
+ case CPDF_AAction::ButtonUp:
+ context->OnField_MouseUp(data->bModifier, data->bShift, pFormField);
+ break;
+ case CPDF_AAction::GetFocus:
+ context->OnField_Focus(data->bModifier, data->bShift, pFormField,
+ data->sValue);
+ break;
+ case CPDF_AAction::LoseFocus:
+ context->OnField_Blur(data->bModifier, data->bShift, pFormField,
+ data->sValue);
+ break;
+ case CPDF_AAction::KeyStroke:
+ context->OnField_Keystroke(
+ data->sChange, data->sChangeEx, data->bKeyDown, data->bModifier,
+ data->nSelEnd, data->nSelStart, data->bShift, pFormField,
+ data->sValue, data->bWillCommit, data->bFieldFull, data->bRC);
+ break;
+ case CPDF_AAction::Validate:
+ context->OnField_Validate(
+ data->sChange, data->sChangeEx, data->bKeyDown, data->bModifier,
+ data->bShift, pFormField, data->sValue, data->bRC);
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ });
}
void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(
CPDFSDK_FormFillEnvironment* pFormFillEnv,
const WideString& sScriptName,
const WideString& script) {
- IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
- IJS_EventContext* pContext = pRuntime->NewEventContext();
- pContext->OnDoc_Open(pFormFillEnv, sScriptName);
-
- WideString csInfo;
- pContext->RunScript(script, &csInfo);
- pRuntime->ReleaseEventContext(pContext);
- // TODO(dsinclair): Return error if RunScript returns false.
+ RunScript(pFormFillEnv, script,
+ [pFormFillEnv, sScriptName](IJS_EventContext* context) {
+ context->OnDoc_Open(pFormFillEnv, sScriptName);
+ });
}
void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(
CPDFSDK_FormFillEnvironment* pFormFillEnv,
CPDF_AAction::AActionType type,
const WideString& script) {
- IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
- IJS_EventContext* pContext = pRuntime->NewEventContext();
- switch (type) {
- case CPDF_AAction::OpenPage:
- pContext->OnPage_Open(pFormFillEnv);
- break;
- case CPDF_AAction::ClosePage:
- pContext->OnPage_Close(pFormFillEnv);
- break;
- case CPDF_AAction::CloseDocument:
- pContext->OnDoc_WillClose(pFormFillEnv);
- break;
- case CPDF_AAction::SaveDocument:
- pContext->OnDoc_WillSave(pFormFillEnv);
- break;
- case CPDF_AAction::DocumentSaved:
- pContext->OnDoc_DidSave(pFormFillEnv);
- break;
- case CPDF_AAction::PrintDocument:
- pContext->OnDoc_WillPrint(pFormFillEnv);
- break;
- case CPDF_AAction::DocumentPrinted:
- pContext->OnDoc_DidPrint(pFormFillEnv);
- break;
- case CPDF_AAction::PageVisible:
- pContext->OnPage_InView(pFormFillEnv);
- break;
- case CPDF_AAction::PageInvisible:
- pContext->OnPage_OutView(pFormFillEnv);
- break;
- default:
- NOTREACHED();
- break;
- }
-
- WideString csInfo;
- pContext->RunScript(script, &csInfo);
- pRuntime->ReleaseEventContext(pContext);
- // TODO(dsinclair): Return error if RunScript returns false.
+ RunScript(pFormFillEnv, script,
+ [type, pFormFillEnv](IJS_EventContext* context) {
+ switch (type) {
+ case CPDF_AAction::OpenPage:
+ context->OnPage_Open(pFormFillEnv);
+ break;
+ case CPDF_AAction::ClosePage:
+ context->OnPage_Close(pFormFillEnv);
+ break;
+ case CPDF_AAction::CloseDocument:
+ context->OnDoc_WillClose(pFormFillEnv);
+ break;
+ case CPDF_AAction::SaveDocument:
+ context->OnDoc_WillSave(pFormFillEnv);
+ break;
+ case CPDF_AAction::DocumentSaved:
+ context->OnDoc_DidSave(pFormFillEnv);
+ break;
+ case CPDF_AAction::PrintDocument:
+ context->OnDoc_WillPrint(pFormFillEnv);
+ break;
+ case CPDF_AAction::DocumentPrinted:
+ context->OnDoc_DidPrint(pFormFillEnv);
+ break;
+ case CPDF_AAction::PageVisible:
+ context->OnPage_InView(pFormFillEnv);
+ break;
+ case CPDF_AAction::PageInvisible:
+ context->OnPage_OutView(pFormFillEnv);
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ });
}
bool CPDFSDK_ActionHandler::DoAction_Hide(
@@ -559,3 +522,31 @@ bool CPDFSDK_ActionHandler::DoAction_ResetForm(
return pInterForm->DoAction_ResetForm(action);
}
+void CPDFSDK_ActionHandler::RunScriptForAction(
+ const CPDF_Action& action,
+ CPDFSDK_FormFillEnvironment* pFormFillEnv,
+ std::function<void(IJS_EventContext* context)> cb) {
+ if (!pFormFillEnv->IsJSInitiated())
+ return;
+
+ WideString swJS = action.GetJavaScript();
+ if (swJS.IsEmpty())
+ return;
+
+ RunScript(pFormFillEnv, swJS, cb);
+}
+
+void CPDFSDK_ActionHandler::RunScript(
+ CPDFSDK_FormFillEnvironment* pFormFillEnv,
+ const WideString& script,
+ std::function<void(IJS_EventContext* context)> cb) {
+ IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
+ IJS_EventContext* pContext = pRuntime->NewEventContext();
+
+ cb(pContext);
+
+ WideString csInfo;
+ pContext->RunScript(script, &csInfo);
+ pRuntime->ReleaseEventContext(pContext);
+ // TODO(dsinclair): Return error if RunScript returns false.
+}
diff --git a/fpdfsdk/fsdk_actionhandler.h b/fpdfsdk/fsdk_actionhandler.h
index 006aff3995..a77ee77296 100644
--- a/fpdfsdk/fsdk_actionhandler.h
+++ b/fpdfsdk/fsdk_actionhandler.h
@@ -20,6 +20,7 @@ class CPDFSDK_FormFillEnvironment;
class CPDF_Bookmark;
class CPDF_Dictionary;
class CPDF_FormField;
+class IJS_EventContext;
class CPDFSDK_ActionHandler {
public:
@@ -48,14 +49,21 @@ class CPDFSDK_ActionHandler {
CPDF_AAction::AActionType type,
CPDFSDK_FormFillEnvironment* pFormFillEnv,
CPDF_FormField* pFormField,
- PDFSDK_FieldAction& data);
+ PDFSDK_FieldAction* data);
bool DoAction_FieldJavaScript(const CPDF_Action& JsAction,
CPDF_AAction::AActionType type,
CPDFSDK_FormFillEnvironment* pFormFillEnv,
CPDF_FormField* pFormField,
- PDFSDK_FieldAction& data);
+ PDFSDK_FieldAction* data);
private:
+ void RunScriptForAction(const CPDF_Action& action,
+ CPDFSDK_FormFillEnvironment* pFormFillEnv,
+ std::function<void(IJS_EventContext* context)> cb);
+ void RunScript(CPDFSDK_FormFillEnvironment* pFormFillEnv,
+ const WideString& script,
+ std::function<void(IJS_EventContext* context)> cb);
+
bool ExecuteDocumentOpenAction(const CPDF_Action& action,
CPDFSDK_FormFillEnvironment* pFormFillEnv,
std::set<CPDF_Dictionary*>* visited);
@@ -67,7 +75,7 @@ class CPDFSDK_ActionHandler {
CPDF_AAction::AActionType type,
CPDFSDK_FormFillEnvironment* pFormFillEnv,
CPDF_FormField* pFormField,
- PDFSDK_FieldAction& data,
+ PDFSDK_FieldAction* data,
std::set<CPDF_Dictionary*>* visited);
bool ExecuteScreenAction(const CPDF_Action& action,
CPDF_AAction::AActionType type,
@@ -93,7 +101,7 @@ class CPDFSDK_ActionHandler {
void RunFieldJavaScript(CPDFSDK_FormFillEnvironment* pFormFillEnv,
CPDF_FormField* pFormField,
CPDF_AAction::AActionType type,
- PDFSDK_FieldAction& data,
+ PDFSDK_FieldAction* data,
const WideString& script);
bool IsValidField(CPDFSDK_FormFillEnvironment* pFormFillEnv,