summaryrefslogtreecommitdiff
path: root/fpdfsdk/cpdfsdk_formfillenvironment.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-06-20 14:47:00 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-06-20 22:26:03 +0000
commit222e1a425e2d2199a842883dcc330a549f400630 (patch)
tree4d28a4fbf3856143ebebbe8b430062a25538bacf /fpdfsdk/cpdfsdk_formfillenvironment.cpp
parent995a601c50874729ac40e2cc444b8894cf2aea96 (diff)
downloadpdfium-222e1a425e2d2199a842883dcc330a549f400630.tar.xz
Use early returns in more CPDFSDK_FormFillEnvironment code.
Same for CFFL_InteractiveFormFiller. Fix other nits in both classes and in related code. Change-Id: I9901c48794358889cc20638455ffd7fcb3344574 Reviewed-on: https://pdfium-review.googlesource.com/6652 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fpdfsdk/cpdfsdk_formfillenvironment.cpp')
-rw-r--r--fpdfsdk/cpdfsdk_formfillenvironment.cpp105
1 files changed, 50 insertions, 55 deletions
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index def57d625f..56eb367408 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -408,10 +408,12 @@ void CPDFSDK_FormFillEnvironment::GetPageViewRect(CPDFXFA_Page* page,
double right;
double bottom;
m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
+ if (top < bottom)
+ std::swap(top, bottom);
dstRect.left = static_cast<float>(left);
- dstRect.top = static_cast<float>(top < bottom ? bottom : top);
- dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
+ dstRect.top = static_cast<float>(top);
+ dstRect.bottom = static_cast<float>(bottom);
dstRect.right = static_cast<float>(right);
}
@@ -600,15 +602,11 @@ void CPDFSDK_FormFillEnvironment::ProcJavascriptFun() {
CPDF_Document* pPDFDoc = GetPDFDocument();
CPDF_DocJSActions docJS(pPDFDoc);
int iCount = docJS.CountJSActions();
- if (iCount < 1)
- return;
for (int i = 0; i < iCount; i++) {
CFX_ByteString csJSName;
CPDF_Action jsAction = docJS.GetJSActionAndName(i, &csJSName);
- if (GetActionHander()) {
- GetActionHander()->DoAction_JavaScript(
- jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this);
- }
+ GetActionHander()->DoAction_JavaScript(
+ jsAction, CFX_WideString::FromLocal(csJSName.AsStringC()), this);
}
}
@@ -623,20 +621,19 @@ bool CPDFSDK_FormFillEnvironment::ProcOpenAction() {
CPDF_Object* pOpenAction = pRoot->GetDictFor("OpenAction");
if (!pOpenAction)
pOpenAction = pRoot->GetArrayFor("OpenAction");
-
if (!pOpenAction)
return false;
if (pOpenAction->IsArray())
return true;
- if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) {
- CPDF_Action action(pDict);
- if (GetActionHander())
- GetActionHander()->DoAction_DocOpen(action, this);
- return true;
- }
- return false;
+ CPDF_Dictionary* pDict = pOpenAction->AsDictionary();
+ if (!pDict)
+ return false;
+
+ CPDF_Action action(pDict);
+ GetActionHander()->DoAction_DocOpen(action, this);
+ return true;
}
void CPDFSDK_FormFillEnvironment::RemovePageView(
@@ -696,57 +693,55 @@ bool CPDFSDK_FormFillEnvironment::SetFocusAnnot(
if (!*pAnnot)
return false;
-#ifdef PDF_ENABLE_XFA
- CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get());
-#endif // PDF_ENABLE_XFA
CPDFSDK_PageView* pPageView = (*pAnnot)->GetPageView();
- if (pPageView && pPageView->IsValid()) {
- CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr();
- if (!m_pFocusAnnot) {
+ if (!pPageView || !pPageView->IsValid())
+ return false;
+
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr();
+ if (m_pFocusAnnot)
+ return false;
+
#ifdef PDF_ENABLE_XFA
- if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, &pLastFocusAnnot))
- return false;
+ CPDFSDK_Annot::ObservedPtr pLastFocusAnnot(m_pFocusAnnot.Get());
+ if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot, &pLastFocusAnnot))
+ return false;
#endif // PDF_ENABLE_XFA
- if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, 0))
- return false;
- if (!m_pFocusAnnot) {
- m_pFocusAnnot.Reset(pAnnot->Get());
- return true;
- }
- }
- }
- return false;
+ if (!pAnnotHandler->Annot_OnSetFocus(pAnnot, 0))
+ return false;
+ if (m_pFocusAnnot)
+ return false;
+
+ m_pFocusAnnot.Reset(pAnnot->Get());
+ return true;
}
bool CPDFSDK_FormFillEnvironment::KillFocusAnnot(uint32_t nFlag) {
- if (m_pFocusAnnot) {
- CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr();
- CPDFSDK_Annot::ObservedPtr pFocusAnnot(m_pFocusAnnot.Get());
- m_pFocusAnnot.Reset();
+ if (!m_pFocusAnnot)
+ return false;
+
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandler = GetAnnotHandlerMgr();
+ CPDFSDK_Annot::ObservedPtr pFocusAnnot(m_pFocusAnnot.Get());
+ m_pFocusAnnot.Reset();
#ifdef PDF_ENABLE_XFA
- CPDFSDK_Annot::ObservedPtr pNull;
- if (!pAnnotHandler->Annot_OnChangeFocus(&pNull, &pFocusAnnot))
- return false;
+ CPDFSDK_Annot::ObservedPtr pNull;
+ if (!pAnnotHandler->Annot_OnChangeFocus(&pNull, &pFocusAnnot))
+ return false;
#endif // PDF_ENABLE_XFA
- if (pAnnotHandler->Annot_OnKillFocus(&pFocusAnnot, nFlag)) {
- if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) {
- CPDFSDK_Widget* pWidget =
- static_cast<CPDFSDK_Widget*>(pFocusAnnot.Get());
- int nFieldType = pWidget->GetFieldType();
- if (FIELDTYPE_TEXTFIELD == nFieldType ||
- FIELDTYPE_COMBOBOX == nFieldType) {
- OnSetFieldInputFocus(nullptr, 0, false);
- }
- }
- if (!m_pFocusAnnot)
- return true;
- } else {
- m_pFocusAnnot.Reset(pFocusAnnot.Get());
+ if (!pAnnotHandler->Annot_OnKillFocus(&pFocusAnnot, nFlag)) {
+ m_pFocusAnnot.Reset(pFocusAnnot.Get());
+ return false;
+ }
+
+ if (pFocusAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::WIDGET) {
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pFocusAnnot.Get());
+ int nFieldType = pWidget->GetFieldType();
+ if (FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType) {
+ OnSetFieldInputFocus(nullptr, 0, false);
}
}
- return false;
+ return !m_pFocusAnnot;
}
bool CPDFSDK_FormFillEnvironment::GetPermissions(int nFlag) const {