summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-01-30 18:15:02 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-30 18:15:02 +0000
commitce047a637b5abfc5abbea90958f276946b7efdd4 (patch)
tree6b78b2d0dbc826e61bcca91f138d8afd138623ac
parentbb1ee53577418429d2e30180bd941f16eea8b340 (diff)
downloadpdfium-ce047a637b5abfc5abbea90958f276946b7efdd4.tar.xz
Cleanup some SDK code
This CL cleans up nits in some SDK code. Change-Id: Id8dc5face65230e607119a65c821fcde01483ad2 Reviewed-on: https://pdfium-review.googlesource.com/24610 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r--fpdfsdk/cpdfsdk_interform.cpp46
-rw-r--r--fpdfsdk/cpdfsdk_interform.h3
-rw-r--r--fpdfsdk/fsdk_actionhandler.cpp104
-rw-r--r--fpdfsdk/fsdk_actionhandler.h7
4 files changed, 43 insertions, 117 deletions
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index e19d47bb55..21a6d41c43 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -237,12 +237,11 @@ void CPDFSDK_InterForm::XfaSetValidationsEnabled(bool bEnabled) {
m_bXfaValidationsEnabled = bEnabled;
}
-void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField,
- bool bSynchronizeElse) {
+void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField) {
for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
- pWidget->Synchronize(bSynchronizeElse);
+ pWidget->Synchronize(false);
}
}
#endif // PDF_ENABLE_XFA
@@ -608,20 +607,17 @@ bool CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) {
return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), true);
}
-bool CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) {
- return false;
-}
-
std::vector<CPDF_FormField*> CPDFSDK_InterForm::GetFieldFromObjects(
const std::vector<CPDF_Object*>& objects) const {
std::vector<CPDF_FormField*> fields;
for (CPDF_Object* pObject : objects) {
- if (pObject && pObject->IsString()) {
- WideString csName = pObject->GetUnicodeText();
- CPDF_FormField* pField = m_pInterForm->GetField(0, csName);
- if (pField)
- fields.push_back(pField);
- }
+ if (!pObject || !pObject->IsString())
+ continue;
+
+ WideString csName = pObject->GetUnicodeText();
+ CPDF_FormField* pField = m_pInterForm->GetField(0, csName);
+ if (pField)
+ fields.push_back(pField);
}
return fields;
}
@@ -631,41 +627,37 @@ int CPDFSDK_InterForm::BeforeValueChange(CPDF_FormField* pField,
FormFieldType fieldType = pField->GetFieldType();
if (!IsFormFieldTypeComboOrText(fieldType))
return 0;
-
if (!OnKeyStrokeCommit(pField, csValue))
return -1;
-
if (!OnValidate(pField, csValue))
return -1;
-
return 1;
}
void CPDFSDK_InterForm::AfterValueChange(CPDF_FormField* pField) {
#ifdef PDF_ENABLE_XFA
- SynchronizeField(pField, false);
+ SynchronizeField(pField);
#endif // PDF_ENABLE_XFA
+
FormFieldType fieldType = pField->GetFieldType();
- if (IsFormFieldTypeComboOrText(fieldType)) {
- OnCalculate(pField);
- bool bFormatted = false;
- WideString sValue = OnFormat(pField, bFormatted);
- ResetFieldAppearance(pField, bFormatted ? &sValue : nullptr, true);
- UpdateField(pField);
- }
+ if (!IsFormFieldTypeComboOrText(fieldType))
+ return;
+
+ OnCalculate(pField);
+ bool bFormatted = false;
+ WideString sValue = OnFormat(pField, bFormatted);
+ ResetFieldAppearance(pField, bFormatted ? &sValue : nullptr, true);
+ UpdateField(pField);
}
int CPDFSDK_InterForm::BeforeSelectionChange(CPDF_FormField* pField,
const WideString& csValue) {
if (pField->GetFieldType() != FormFieldType::kListBox)
return 0;
-
if (!OnKeyStrokeCommit(pField, csValue))
return -1;
-
if (!OnValidate(pField, csValue))
return -1;
-
return 1;
}
diff --git a/fpdfsdk/cpdfsdk_interform.h b/fpdfsdk/cpdfsdk_interform.h
index ee960ff33c..a412f05689 100644
--- a/fpdfsdk/cpdfsdk_interform.h
+++ b/fpdfsdk/cpdfsdk_interform.h
@@ -62,7 +62,7 @@ class CPDFSDK_InterForm : public IPDF_FormNotify {
bool IsXfaCalculateEnabled() const;
bool IsXfaValidationsEnabled();
void XfaSetValidationsEnabled(bool bEnabled);
- void SynchronizeField(CPDF_FormField* pFormField, bool bSynchronizeElse);
+ void SynchronizeField(CPDF_FormField* pFormField);
#endif // PDF_ENABLE_XFA
bool OnKeyStrokeCommit(CPDF_FormField* pFormField, const WideString& csValue);
@@ -78,7 +78,6 @@ class CPDFSDK_InterForm : public IPDF_FormNotify {
bool DoAction_Hide(const CPDF_Action& action);
bool DoAction_SubmitForm(const CPDF_Action& action);
bool DoAction_ResetForm(const CPDF_Action& action);
- bool DoAction_ImportData(const CPDF_Action& action);
std::vector<CPDF_FormField*> GetFieldFromObjects(
const std::vector<CPDF_Object*>& objects) const;
diff --git a/fpdfsdk/fsdk_actionhandler.cpp b/fpdfsdk/fsdk_actionhandler.cpp
index de5c9313b5..b0bc3f6831 100644
--- a/fpdfsdk/fsdk_actionhandler.cpp
+++ b/fpdfsdk/fsdk_actionhandler.cpp
@@ -126,9 +126,8 @@ bool CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(
if (action.GetType() == CPDF_Action::JavaScript) {
if (pFormFillEnv->IsJSInitiated()) {
WideString swJS = action.GetJavaScript();
- if (!swJS.IsEmpty()) {
+ if (!swJS.IsEmpty())
RunDocumentOpenJavaScript(pFormFillEnv, L"", swJS);
- }
}
} else {
DoAction_NoJs(action, pFormFillEnv);
@@ -163,11 +162,9 @@ bool CPDFSDK_ActionHandler::ExecuteLinkAction(
pContext->OnLink_MouseUp(pFormFillEnv);
WideString csInfo;
- bool bRet = pContext->RunScript(swJS, &csInfo);
+ pContext->RunScript(swJS, &csInfo);
pRuntime->ReleaseEventContext(pContext);
- if (!bRet) {
- // FIXME: return error.
- }
+ // TODO(dsinclair): Return error if RunScript returns false.
}
}
} else {
@@ -198,16 +195,14 @@ bool CPDFSDK_ActionHandler::ExecuteDocumentPageAction(
if (action.GetType() == CPDF_Action::JavaScript) {
if (pFormFillEnv->IsJSInitiated()) {
WideString swJS = action.GetJavaScript();
- if (!swJS.IsEmpty()) {
+ if (!swJS.IsEmpty())
RunDocumentPageJavaScript(pFormFillEnv, type, swJS);
- }
}
} else {
DoAction_NoJs(action, pFormFillEnv);
}
- if (!IsValidDocView(pFormFillEnv))
- return false;
+ ASSERT(pFormFillEnv);
for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
CPDF_Action subaction = action.GetSubAction(i);
@@ -285,11 +280,9 @@ bool CPDFSDK_ActionHandler::ExecuteScreenAction(
IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
IJS_EventContext* pContext = pRuntime->NewEventContext();
WideString csInfo;
- bool bRet = pContext->RunScript(swJS, &csInfo);
+ pContext->RunScript(swJS, &csInfo);
pRuntime->ReleaseEventContext(pContext);
- if (!bRet) {
- // FIXME: return error.
- }
+ // TODO(dsinclair): Return error if RunScript returns false.
}
}
} else {
@@ -326,11 +319,9 @@ bool CPDFSDK_ActionHandler::ExecuteBookMark(
pContext->OnBookmark_MouseUp(pBookmark);
WideString csInfo;
- bool bRet = pContext->RunScript(swJS, &csInfo);
+ pContext->RunScript(swJS, &csInfo);
pRuntime->ReleaseEventContext(pContext);
- if (!bRet) {
- // FIXME: return error.
- }
+ // TODO(dsinclair): Return error if RunScript returns false.
}
}
} else {
@@ -355,23 +346,9 @@ void CPDFSDK_ActionHandler::DoAction_NoJs(
case CPDF_Action::GoTo:
DoAction_GoTo(pFormFillEnv, action);
break;
- case CPDF_Action::GoToR:
- DoAction_GoToR(pFormFillEnv, action);
- break;
- case CPDF_Action::GoToE:
- break;
- case CPDF_Action::Launch:
- DoAction_Launch(pFormFillEnv, action);
- break;
- case CPDF_Action::Thread:
- break;
case CPDF_Action::URI:
DoAction_URI(pFormFillEnv, action);
break;
- case CPDF_Action::Sound:
- break;
- case CPDF_Action::Movie:
- break;
case CPDF_Action::Hide:
DoAction_Hide(action, pFormFillEnv);
break;
@@ -384,32 +361,27 @@ void CPDFSDK_ActionHandler::DoAction_NoJs(
case CPDF_Action::ResetForm:
DoAction_ResetForm(action, pFormFillEnv);
break;
- case CPDF_Action::ImportData:
- DoAction_ImportData(action, pFormFillEnv);
- break;
case CPDF_Action::JavaScript:
NOTREACHED();
break;
case CPDF_Action::SetOCGState:
- DoAction_SetOCGState(pFormFillEnv, action);
- break;
+ case CPDF_Action::Thread:
+ case CPDF_Action::Sound:
+ case CPDF_Action::Movie:
case CPDF_Action::Rendition:
- break;
case CPDF_Action::Trans:
- break;
case CPDF_Action::GoTo3DView:
+ case CPDF_Action::GoToR:
+ case CPDF_Action::GoToE:
+ case CPDF_Action::Launch:
+ case CPDF_Action::ImportData:
+ // Unimplemented
break;
default:
break;
}
}
-bool CPDFSDK_ActionHandler::IsValidDocView(
- CPDFSDK_FormFillEnvironment* pFormFillEnv) {
- ASSERT(pFormFillEnv);
- return true;
-}
-
void CPDFSDK_ActionHandler::DoAction_GoTo(
CPDFSDK_FormFillEnvironment* pFormFillEnv,
const CPDF_Action& action) {
@@ -431,14 +403,6 @@ void CPDFSDK_ActionHandler::DoAction_GoTo(
posArray.size());
}
-void CPDFSDK_ActionHandler::DoAction_GoToR(
- CPDFSDK_FormFillEnvironment* pFormFillEnv,
- const CPDF_Action& action) {}
-
-void CPDFSDK_ActionHandler::DoAction_Launch(
- CPDFSDK_FormFillEnvironment* pFormFillEnv,
- const CPDF_Action& action) {}
-
void CPDFSDK_ActionHandler::DoAction_URI(
CPDFSDK_FormFillEnvironment* pFormFillEnv,
const CPDF_Action& action) {
@@ -457,10 +421,6 @@ void CPDFSDK_ActionHandler::DoAction_Named(
pFormFillEnv->ExecuteNamedAction(csName.c_str());
}
-void CPDFSDK_ActionHandler::DoAction_SetOCGState(
- CPDFSDK_FormFillEnvironment* pFormFillEnv,
- const CPDF_Action& action) {}
-
void CPDFSDK_ActionHandler::RunFieldJavaScript(
CPDFSDK_FormFillEnvironment* pFormFillEnv,
CPDF_FormField* pFormField,
@@ -510,11 +470,9 @@ void CPDFSDK_ActionHandler::RunFieldJavaScript(
}
WideString csInfo;
- bool bRet = pContext->RunScript(script, &csInfo);
+ pContext->RunScript(script, &csInfo);
pRuntime->ReleaseEventContext(pContext);
- if (!bRet) {
- // FIXME: return error.
- }
+ // TODO(dsinclair): Return error if RunScript returns false.
}
void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(
@@ -526,11 +484,9 @@ void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(
pContext->OnDoc_Open(pFormFillEnv, sScriptName);
WideString csInfo;
- bool bRet = pContext->RunScript(script, &csInfo);
+ pContext->RunScript(script, &csInfo);
pRuntime->ReleaseEventContext(pContext);
- if (!bRet) {
- // FIXME: return error.
- }
+ // TODO(dsinclair): Return error if RunScript returns false.
}
void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(
@@ -573,11 +529,9 @@ void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(
}
WideString csInfo;
- bool bRet = pContext->RunScript(script, &csInfo);
+ pContext->RunScript(script, &csInfo);
pRuntime->ReleaseEventContext(pContext);
- if (!bRet) {
- // FIXME: return error.
- }
+ // TODO(dsinclair): Return error if RunScript returns false.
}
bool CPDFSDK_ActionHandler::DoAction_Hide(
@@ -588,7 +542,6 @@ bool CPDFSDK_ActionHandler::DoAction_Hide(
pFormFillEnv->SetChangeMark();
return true;
}
-
return false;
}
@@ -606,14 +559,3 @@ bool CPDFSDK_ActionHandler::DoAction_ResetForm(
return pInterForm->DoAction_ResetForm(action);
}
-bool CPDFSDK_ActionHandler::DoAction_ImportData(
- const CPDF_Action& action,
- CPDFSDK_FormFillEnvironment* pFormFillEnv) {
- CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
- if (pInterForm->DoAction_ImportData(action)) {
- pFormFillEnv->SetChangeMark();
- return true;
- }
-
- return false;
-}
diff --git a/fpdfsdk/fsdk_actionhandler.h b/fpdfsdk/fsdk_actionhandler.h
index 7457b4ed91..006aff3995 100644
--- a/fpdfsdk/fsdk_actionhandler.h
+++ b/fpdfsdk/fsdk_actionhandler.h
@@ -98,20 +98,15 @@ class CPDFSDK_ActionHandler {
bool IsValidField(CPDFSDK_FormFillEnvironment* pFormFillEnv,
CPDF_Dictionary* pFieldDict);
- bool IsValidDocView(CPDFSDK_FormFillEnvironment* pFormFillEnv);
void DoAction_GoTo(CPDFSDK_FormFillEnvironment* pFormFillEnv,
const CPDF_Action& action);
- void DoAction_GoToR(CPDFSDK_FormFillEnvironment* pFormFillEnv,
- const CPDF_Action& action);
void DoAction_Launch(CPDFSDK_FormFillEnvironment* pFormFillEnv,
const CPDF_Action& action);
void DoAction_URI(CPDFSDK_FormFillEnvironment* pFormFillEnv,
const CPDF_Action& action);
void DoAction_Named(CPDFSDK_FormFillEnvironment* pFormFillEnv,
const CPDF_Action& action);
- void DoAction_SetOCGState(CPDFSDK_FormFillEnvironment* pFormFillEnv,
- const CPDF_Action& action);
bool DoAction_Hide(const CPDF_Action& action,
CPDFSDK_FormFillEnvironment* pFormFillEnv);
@@ -119,8 +114,6 @@ class CPDFSDK_ActionHandler {
CPDFSDK_FormFillEnvironment* pFormFillEnv);
bool DoAction_ResetForm(const CPDF_Action& action,
CPDFSDK_FormFillEnvironment* pFormFillEnv);
- bool DoAction_ImportData(const CPDF_Action& action,
- CPDFSDK_FormFillEnvironment* pFormFillEnv);
};
#endif // FPDFSDK_FSDK_ACTIONHANDLER_H_