summaryrefslogtreecommitdiff
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
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>
-rw-r--r--fpdfsdk/cpdfsdk_formfillenvironment.cpp105
-rw-r--r--fpdfsdk/cpdfsdk_pageview.cpp16
-rw-r--r--fpdfsdk/formfiller/cffl_interactiveformfiller.cpp605
-rw-r--r--fpdfsdk/javascript/app.cpp7
4 files changed, 369 insertions, 364 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 {
diff --git a/fpdfsdk/cpdfsdk_pageview.cpp b/fpdfsdk/cpdfsdk_pageview.cpp
index aae245e298..c12673491c 100644
--- a/fpdfsdk/cpdfsdk_pageview.cpp
+++ b/fpdfsdk/cpdfsdk_pageview.cpp
@@ -43,16 +43,12 @@ CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv,
m_bLocked(false),
m_bBeingDestroyed(false) {
CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
- if (pInterForm) {
- CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
+ CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
#ifdef PDF_ENABLE_XFA
- if (page->GetPDFPage())
- pPDFInterForm->FixPageFields(page->GetPDFPage());
+ if (page->GetPDFPage())
+ pPDFInterForm->FixPageFields(page->GetPDFPage());
#else // PDF_ENABLE_XFA
- pPDFInterForm->FixPageFields(page);
-#endif // PDF_ENABLE_XFA
- }
-#ifndef PDF_ENABLE_XFA
+ pPDFInterForm->FixPageFields(page);
m_page->SetView(this);
#endif // PDF_ENABLE_XFA
}
@@ -358,8 +354,8 @@ bool CPDFSDK_PageView::OnMouseWheel(double deltaX,
CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr =
m_pFormFillEnv->GetAnnotHandlerMgr();
- return pAnnotHandlerMgr->Annot_OnMouseWheel(this, &pAnnot, nFlag, (int)deltaY,
- point);
+ return pAnnotHandlerMgr->Annot_OnMouseWheel(this, &pAnnot, nFlag,
+ static_cast<int>(deltaY), point);
}
bool CPDFSDK_PageView::OnChar(int nChar, uint32_t nFlag) {
diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
index 69c74bc587..682d41cabf 100644
--- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
@@ -25,8 +25,6 @@
#include "fpdfsdk/pdfwindow/cpwl_utils.h"
#include "third_party/base/stl_util.h"
-#define FFL_MAXLISTBOXHEIGHT 140.0f
-
CFFL_InteractiveFormFiller::CFFL_InteractiveFormFiller(
CPDFSDK_FormFillEnvironment* pFormFillEnv)
: m_pFormFillEnv(pFormFillEnv), m_bNotifying(false) {}
@@ -56,49 +54,49 @@ void CFFL_InteractiveFormFiller::OnDraw(CPDFSDK_PageView* pPageView,
CFX_RenderDevice* pDevice,
CFX_Matrix* pUser2Device) {
ASSERT(pPageView);
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
-
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
if (!IsVisible(pWidget))
return;
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false)) {
- if (pFormFiller->IsValid()) {
- pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device);
- pAnnot->GetPDFPage();
-
- if (m_pFormFillEnv->GetFocusAnnot() == pAnnot) {
- CFX_FloatRect rcFocus = pFormFiller->GetFocusBox(pPageView);
- if (!rcFocus.IsEmpty()) {
- CFX_PathData path;
- path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.top),
- FXPT_TYPE::MoveTo, false);
- path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.bottom),
- FXPT_TYPE::LineTo, false);
- path.AppendPoint(CFX_PointF(rcFocus.right, rcFocus.bottom),
- FXPT_TYPE::LineTo, false);
- path.AppendPoint(CFX_PointF(rcFocus.right, rcFocus.top),
- FXPT_TYPE::LineTo, false);
- path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.top),
- FXPT_TYPE::LineTo, false);
-
- CFX_GraphStateData gsd;
- gsd.SetDashCount(1);
- gsd.m_DashArray[0] = 1.0f;
- gsd.m_DashPhase = 0;
- gsd.m_LineWidth = 1.0f;
- pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
- ArgbEncode(255, 0, 0, 0), FXFILL_ALTERNATE);
- }
- }
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false);
+ if (pFormFiller && pFormFiller->IsValid()) {
+ pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device);
+ pAnnot->GetPDFPage();
+
+ if (m_pFormFillEnv->GetFocusAnnot() != pAnnot)
return;
- }
+
+ CFX_FloatRect rcFocus = pFormFiller->GetFocusBox(pPageView);
+ if (rcFocus.IsEmpty())
+ return;
+
+ CFX_PathData path;
+ path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.top), FXPT_TYPE::MoveTo,
+ false);
+ path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.bottom),
+ FXPT_TYPE::LineTo, false);
+ path.AppendPoint(CFX_PointF(rcFocus.right, rcFocus.bottom),
+ FXPT_TYPE::LineTo, false);
+ path.AppendPoint(CFX_PointF(rcFocus.right, rcFocus.top), FXPT_TYPE::LineTo,
+ false);
+ path.AppendPoint(CFX_PointF(rcFocus.left, rcFocus.top), FXPT_TYPE::LineTo,
+ false);
+
+ CFX_GraphStateData gsd;
+ gsd.SetDashCount(1);
+ gsd.m_DashArray[0] = 1.0f;
+ gsd.m_DashPhase = 0;
+ gsd.m_LineWidth = 1.0f;
+ pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255, 0, 0, 0),
+ FXFILL_ALTERNATE);
+ return;
}
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false)) {
+ pFormFiller = GetFormFiller(pAnnot, false);
+ if (pFormFiller)
pFormFiller->OnDrawDeactive(pPageView, pAnnot, pDevice, pUser2Device);
- } else {
+ else
pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
- }
if (!IsReadOnly(pWidget) && IsFillingAllowed(pWidget))
pWidget->DrawShadow(pDevice, pPageView);
@@ -212,10 +210,9 @@ bool CFFL_InteractiveFormFiller::OnLButtonDown(
}
}
}
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false))
- return pFormFiller->OnLButtonDown(pPageView, pAnnot->Get(), nFlags, point);
-
- return false;
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false);
+ return pFormFiller &&
+ pFormFiller->OnLButtonDown(pPageView, pAnnot->Get(), nFlags, point);
}
bool CFFL_InteractiveFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView,
@@ -225,35 +222,39 @@ bool CFFL_InteractiveFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView,
ASSERT((*pAnnot)->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET);
CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+ bool bSetFocus;
switch (pWidget->GetFieldType()) {
case FIELDTYPE_PUSHBUTTON:
case FIELDTYPE_CHECKBOX:
- case FIELDTYPE_RADIOBUTTON:
- if (GetViewBBox(pPageView, pAnnot->Get())
- .Contains((int)point.x, (int)point.y))
- m_pFormFillEnv->SetFocusAnnot(pAnnot);
+ case FIELDTYPE_RADIOBUTTON: {
+ FX_RECT bbox = GetViewBBox(pPageView, pAnnot->Get());
+ bSetFocus =
+ bbox.Contains(static_cast<int>(point.x), static_cast<int>(point.y));
break;
+ }
default:
- m_pFormFillEnv->SetFocusAnnot(pAnnot);
+ bSetFocus = true;
break;
}
+ if (bSetFocus)
+ m_pFormFillEnv->SetFocusAnnot(pAnnot);
- bool bRet = false;
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false))
- bRet = pFormFiller->OnLButtonUp(pPageView, pAnnot->Get(), nFlags, point);
-
- if (m_pFormFillEnv->GetFocusAnnot() == pAnnot->Get()) {
- bool bExit = false;
- bool bReset = false;
- OnButtonUp(pAnnot, pPageView, bReset, bExit, nFlags);
- if (!pAnnot || bExit)
- return true;
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false);
+ bool bRet = pFormFiller &&
+ pFormFiller->OnLButtonUp(pPageView, pAnnot->Get(), nFlags, point);
+ if (m_pFormFillEnv->GetFocusAnnot() != pAnnot->Get())
+ return bRet;
+
+ bool bExit = false;
+ bool bReset = false;
+ OnButtonUp(pAnnot, pPageView, bReset, bExit, nFlags);
+ if (!pAnnot || bExit)
+ return true;
#ifdef PDF_ENABLE_XFA
- OnClick(pAnnot, pPageView, bReset, bExit, nFlags);
- if (!pAnnot || bExit)
- return true;
+ OnClick(pAnnot, pPageView, bReset, bExit, nFlags);
+ if (!pAnnot || bExit)
+ return true;
#endif // PDF_ENABLE_XFA
- }
return bRet;
}
@@ -262,33 +263,35 @@ void CFFL_InteractiveFormFiller::OnButtonUp(CPDFSDK_Annot::ObservedPtr* pAnnot,
bool& bReset,
bool& bExit,
uint32_t nFlag) {
- if (!m_bNotifying) {
- CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
- if (pWidget->GetAAction(CPDF_AAction::ButtonUp).GetDict()) {
- m_bNotifying = true;
+ if (m_bNotifying)
+ return;
- int nAge = pWidget->GetAppearanceAge();
- int nValueAge = pWidget->GetValueAge();
- ASSERT(pPageView);
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+ if (!pWidget->GetAAction(CPDF_AAction::ButtonUp).GetDict())
+ return;
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
- fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
- pWidget->OnAAction(CPDF_AAction::ButtonUp, fa, pPageView);
- m_bNotifying = false;
- if (!(*pAnnot) || !IsValidAnnot(pPageView, pWidget)) {
- bExit = true;
- return;
- }
- if (nAge != pWidget->GetAppearanceAge()) {
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) {
- pFormFiller->ResetPDFWindow(pPageView,
- nValueAge == pWidget->GetValueAge());
- }
- bReset = true;
- }
- }
+ m_bNotifying = true;
+
+ int nAge = pWidget->GetAppearanceAge();
+ int nValueAge = pWidget->GetValueAge();
+ ASSERT(pPageView);
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
+ pWidget->OnAAction(CPDF_AAction::ButtonUp, fa, pPageView);
+ m_bNotifying = false;
+ if (!(*pAnnot) || !IsValidAnnot(pPageView, pWidget)) {
+ bExit = true;
+ return;
}
+ if (nAge == pWidget->GetAppearanceAge())
+ return;
+
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false);
+ if (pFormFiller)
+ pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
+ bReset = true;
}
bool CFFL_InteractiveFormFiller::OnLButtonDblClk(
@@ -351,11 +354,8 @@ bool CFFL_InteractiveFormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot,
uint32_t nFlags) {
ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET);
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false)) {
- return pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlags);
- }
-
- return false;
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false);
+ return pFormFiller && pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlags);
}
bool CFFL_InteractiveFormFiller::OnChar(CPDFSDK_Annot* pAnnot,
@@ -365,10 +365,8 @@ bool CFFL_InteractiveFormFiller::OnChar(CPDFSDK_Annot* pAnnot,
if (nChar == FWL_VKEY_Tab)
return true;
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false))
- return pFormFiller->OnChar(pAnnot, nChar, nFlags);
-
- return false;
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, false);
+ return pFormFiller && pFormFiller->OnChar(pAnnot, nChar, nFlags);
}
bool CFFL_InteractiveFormFiller::OnSetFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
@@ -423,32 +421,34 @@ bool CFFL_InteractiveFormFiller::OnKillFocus(CPDFSDK_Annot::ObservedPtr* pAnnot,
return false;
ASSERT((*pAnnot)->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET);
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false)) {
- pFormFiller->KillFocusForAnnot(pAnnot->Get(), nFlag);
- if (!(*pAnnot))
- return false;
-
- if (!m_bNotifying) {
- CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
- if (pWidget->GetAAction(CPDF_AAction::LoseFocus).GetDict()) {
- m_bNotifying = true;
- pWidget->ClearAppModified();
-
- CPDFSDK_PageView* pPageView = pWidget->GetPageView();
- ASSERT(pPageView);
-
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
- fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
- pFormFiller->GetActionData(pPageView, CPDF_AAction::LoseFocus, fa);
- pWidget->OnAAction(CPDF_AAction::LoseFocus, fa, pPageView);
- m_bNotifying = false;
- if (!(*pAnnot))
- return false;
- }
- }
- }
- return true;
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot->Get(), false);
+ if (!pFormFiller)
+ return true;
+
+ pFormFiller->KillFocusForAnnot(pAnnot->Get(), nFlag);
+ if (!(*pAnnot))
+ return false;
+
+ if (m_bNotifying)
+ return true;
+
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+ if (!pWidget->GetAAction(CPDF_AAction::LoseFocus).GetDict())
+ return true;
+
+ m_bNotifying = true;
+ pWidget->ClearAppModified();
+
+ CPDFSDK_PageView* pPageView = pWidget->GetPageView();
+ ASSERT(pPageView);
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
+ pFormFiller->GetActionData(pPageView, CPDF_AAction::LoseFocus, fa);
+ pWidget->OnAAction(CPDF_AAction::LoseFocus, fa, pPageView);
+ m_bNotifying = false;
+ return !!(*pAnnot);
}
bool CFFL_InteractiveFormFiller::IsVisible(CPDFSDK_Widget* pWidget) {
@@ -572,8 +572,9 @@ void CFFL_InteractiveFormFiller::QueryWherePopup(void* pPrivateData,
break;
}
+ constexpr float kMaxListBoxHeight = 140;
const float fMaxListBoxHeight =
- pdfium::clamp(FFL_MAXLISTBOXHEIGHT, fPopupMin, fPopupMax);
+ pdfium::clamp(kMaxListBoxHeight, fPopupMin, fPopupMax);
if (fBottom > fMaxListBoxHeight) {
*fPopupRet = fMaxListBoxHeight;
@@ -602,31 +603,33 @@ void CFFL_InteractiveFormFiller::OnKeyStrokeCommit(
bool& bRC,
bool& bExit,
uint32_t nFlag) {
- if (!m_bNotifying) {
- CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
- if (pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) {
- ASSERT(pPageView);
- m_bNotifying = true;
- pWidget->ClearAppModified();
+ if (m_bNotifying)
+ return;
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
- fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
- fa.bWillCommit = true;
- fa.bKeyDown = true;
- fa.bRC = true;
-
- CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false);
- pFormFiller->GetActionData(pPageView, CPDF_AAction::KeyStroke, fa);
- pFormFiller->SaveState(pPageView);
- pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pPageView);
- if (!(*pAnnot))
- return;
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+ if (!pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict())
+ return;
- bRC = fa.bRC;
- m_bNotifying = false;
- }
- }
+ ASSERT(pPageView);
+ m_bNotifying = true;
+ pWidget->ClearAppModified();
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
+ fa.bWillCommit = true;
+ fa.bKeyDown = true;
+ fa.bRC = true;
+
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false);
+ pFormFiller->GetActionData(pPageView, CPDF_AAction::KeyStroke, fa);
+ pFormFiller->SaveState(pPageView);
+ pWidget->OnAAction(CPDF_AAction::KeyStroke, fa, pPageView);
+ if (!(*pAnnot))
+ return;
+
+ bRC = fa.bRC;
+ m_bNotifying = false;
}
void CFFL_InteractiveFormFiller::OnValidate(CPDFSDK_Annot::ObservedPtr* pAnnot,
@@ -634,69 +637,73 @@ void CFFL_InteractiveFormFiller::OnValidate(CPDFSDK_Annot::ObservedPtr* pAnnot,
bool& bRC,
bool& bExit,
uint32_t nFlag) {
- if (!m_bNotifying) {
- CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
- if (pWidget->GetAAction(CPDF_AAction::Validate).GetDict()) {
- ASSERT(pPageView);
- m_bNotifying = true;
- pWidget->ClearAppModified();
+ if (m_bNotifying)
+ return;
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
- fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
- fa.bKeyDown = true;
- fa.bRC = true;
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+ if (!pWidget->GetAAction(CPDF_AAction::Validate).GetDict())
+ return;
- CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false);
- pFormFiller->GetActionData(pPageView, CPDF_AAction::Validate, fa);
- pFormFiller->SaveState(pPageView);
- pWidget->OnAAction(CPDF_AAction::Validate, fa, pPageView);
- if (!(*pAnnot))
- return;
+ ASSERT(pPageView);
+ m_bNotifying = true;
+ pWidget->ClearAppModified();
- bRC = fa.bRC;
- m_bNotifying = false;
- }
- }
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
+ fa.bKeyDown = true;
+ fa.bRC = true;
+
+ CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false);
+ pFormFiller->GetActionData(pPageView, CPDF_AAction::Validate, fa);
+ pFormFiller->SaveState(pPageView);
+ pWidget->OnAAction(CPDF_AAction::Validate, fa, pPageView);
+ if (!(*pAnnot))
+ return;
+
+ bRC = fa.bRC;
+ m_bNotifying = false;
}
void CFFL_InteractiveFormFiller::OnCalculate(CPDFSDK_Annot::ObservedPtr* pAnnot,
CPDFSDK_PageView* pPageView,
bool& bExit,
uint32_t nFlag) {
- if (!m_bNotifying) {
- CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
- ASSERT(pWidget);
- CPDFSDK_InterForm* pInterForm = pPageView->GetFormFillEnv()->GetInterForm();
- pInterForm->OnCalculate(pWidget->GetFormField());
- m_bNotifying = false;
- }
+ if (m_bNotifying)
+ return;
+
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+ ASSERT(pWidget);
+ CPDFSDK_InterForm* pInterForm = pPageView->GetFormFillEnv()->GetInterForm();
+ pInterForm->OnCalculate(pWidget->GetFormField());
+ m_bNotifying = false;
}
void CFFL_InteractiveFormFiller::OnFormat(CPDFSDK_Annot::ObservedPtr* pAnnot,
CPDFSDK_PageView* pPageView,
bool& bExit,
uint32_t nFlag) {
- if (!m_bNotifying) {
- CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
- ASSERT(pWidget);
- CPDFSDK_InterForm* pInterForm = pPageView->GetFormFillEnv()->GetInterForm();
+ if (m_bNotifying)
+ return;
- bool bFormatted = false;
- CFX_WideString sValue =
- pInterForm->OnFormat(pWidget->GetFormField(), bFormatted);
- if (!(*pAnnot))
- return;
- if (bExit)
- return;
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+ ASSERT(pWidget);
+ CPDFSDK_InterForm* pInterForm = pPageView->GetFormFillEnv()->GetInterForm();
- if (bFormatted) {
- pInterForm->ResetFieldAppearance(pWidget->GetFormField(), &sValue, true);
- pInterForm->UpdateField(pWidget->GetFormField());
- }
+ bool bFormatted = false;
+ CFX_WideString sValue =
+ pInterForm->OnFormat(pWidget->GetFormField(), bFormatted);
+ if (!(*pAnnot))
+ return;
+ if (bExit)
+ return;
- m_bNotifying = false;
+ if (bFormatted) {
+ pInterForm->ResetFieldAppearance(pWidget->GetFormField(), &sValue, true);
+ pInterForm->UpdateField(pWidget->GetFormField());
}
+
+ m_bNotifying = false;
}
#ifdef PDF_ENABLE_XFA
@@ -705,39 +712,41 @@ void CFFL_InteractiveFormFiller::OnClick(CPDFSDK_Annot::ObservedPtr* pAnnot,
bool& bReset,
bool& bExit,
uint32_t nFlag) {
- if (!m_bNotifying) {
- CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
- if (pWidget->HasXFAAAction(PDFSDK_XFA_Click)) {
- m_bNotifying = true;
- int nAge = pWidget->GetAppearanceAge();
- int nValueAge = pWidget->GetValueAge();
+ if (m_bNotifying)
+ return;
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
- fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+ if (!pWidget->HasXFAAAction(PDFSDK_XFA_Click))
+ return;
- pWidget->OnXFAAAction(PDFSDK_XFA_Click, fa, pPageView);
- m_bNotifying = false;
- if (!(*pAnnot)) {
- bExit = true;
- return;
- }
+ m_bNotifying = true;
+ int nAge = pWidget->GetAppearanceAge();
+ int nValueAge = pWidget->GetValueAge();
- if (!IsValidAnnot(pPageView, pWidget)) {
- bExit = true;
- return;
- }
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
- if (nAge != pWidget->GetAppearanceAge()) {
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) {
- pFormFiller->ResetPDFWindow(pPageView,
- nValueAge == pWidget->GetValueAge());
- }
+ pWidget->OnXFAAAction(PDFSDK_XFA_Click, fa, pPageView);
+ m_bNotifying = false;
+ if (!(*pAnnot)) {
+ bExit = true;
+ return;
+ }
- bReset = true;
- }
- }
+ if (!IsValidAnnot(pPageView, pWidget)) {
+ bExit = true;
+ return;
+ }
+
+ if (nAge == pWidget->GetAppearanceAge())
+ return;
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) {
+ pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
}
+
+ bReset = true;
}
void CFFL_InteractiveFormFiller::OnFull(CPDFSDK_Annot::ObservedPtr* pAnnot,
@@ -745,39 +754,41 @@ void CFFL_InteractiveFormFiller::OnFull(CPDFSDK_Annot::ObservedPtr* pAnnot,
bool& bReset,
bool& bExit,
uint32_t nFlag) {
- if (!m_bNotifying) {
- CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
- if (pWidget->HasXFAAAction(PDFSDK_XFA_Full)) {
- m_bNotifying = true;
- int nAge = pWidget->GetAppearanceAge();
- int nValueAge = pWidget->GetValueAge();
+ if (m_bNotifying)
+ return;
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
- fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+ if (!pWidget->HasXFAAAction(PDFSDK_XFA_Full))
+ return;
- pWidget->OnXFAAAction(PDFSDK_XFA_Full, fa, pPageView);
- m_bNotifying = false;
- if (!(*pAnnot)) {
- bExit = true;
- return;
- }
+ m_bNotifying = true;
+ int nAge = pWidget->GetAppearanceAge();
+ int nValueAge = pWidget->GetValueAge();
- if (!IsValidAnnot(pPageView, pWidget)) {
- bExit = true;
- return;
- }
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
- if (nAge != pWidget->GetAppearanceAge()) {
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) {
- pFormFiller->ResetPDFWindow(pPageView,
- nValueAge == pWidget->GetValueAge());
- }
+ pWidget->OnXFAAAction(PDFSDK_XFA_Full, fa, pPageView);
+ m_bNotifying = false;
+ if (!(*pAnnot)) {
+ bExit = true;
+ return;
+ }
- bReset = true;
- }
- }
+ if (!IsValidAnnot(pPageView, pWidget)) {
+ bExit = true;
+ return;
}
+
+ if (nAge == pWidget->GetAppearanceAge())
+ return;
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) {
+ pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
+ }
+
+ bReset = true;
}
void CFFL_InteractiveFormFiller::OnPopupPreOpen(void* pPrivateData,
@@ -815,39 +826,41 @@ void CFFL_InteractiveFormFiller::OnPreOpen(CPDFSDK_Annot::ObservedPtr* pAnnot,
bool& bReset,
bool& bExit,
uint32_t nFlag) {
- if (!m_bNotifying) {
- CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
- if (pWidget->HasXFAAAction(PDFSDK_XFA_PreOpen)) {
- m_bNotifying = true;
- int nAge = pWidget->GetAppearanceAge();
- int nValueAge = pWidget->GetValueAge();
+ if (m_bNotifying)
+ return;
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
- fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+ if (!pWidget->HasXFAAAction(PDFSDK_XFA_PreOpen))
+ return;
- pWidget->OnXFAAAction(PDFSDK_XFA_PreOpen, fa, pPageView);
- m_bNotifying = false;
- if (!(*pAnnot)) {
- bExit = true;
- return;
- }
+ m_bNotifying = true;
+ int nAge = pWidget->GetAppearanceAge();
+ int nValueAge = pWidget->GetValueAge();
- if (!IsValidAnnot(pPageView, pWidget)) {
- bExit = true;
- return;
- }
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
- if (nAge != pWidget->GetAppearanceAge()) {
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) {
- pFormFiller->ResetPDFWindow(pPageView,
- nValueAge == pWidget->GetValueAge());
- }
+ pWidget->OnXFAAAction(PDFSDK_XFA_PreOpen, fa, pPageView);
+ m_bNotifying = false;
+ if (!(*pAnnot)) {
+ bExit = true;
+ return;
+ }
- bReset = true;
- }
- }
+ if (!IsValidAnnot(pPageView, pWidget)) {
+ bExit = true;
+ return;
+ }
+
+ if (nAge == pWidget->GetAppearanceAge())
+ return;
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) {
+ pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
}
+
+ bReset = true;
}
void CFFL_InteractiveFormFiller::OnPostOpen(CPDFSDK_Annot::ObservedPtr* pAnnot,
@@ -855,39 +868,41 @@ void CFFL_InteractiveFormFiller::OnPostOpen(CPDFSDK_Annot::ObservedPtr* pAnnot,
bool& bReset,
bool& bExit,
uint32_t nFlag) {
- if (!m_bNotifying) {
- CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
- if (pWidget->HasXFAAAction(PDFSDK_XFA_PostOpen)) {
- m_bNotifying = true;
- int nAge = pWidget->GetAppearanceAge();
- int nValueAge = pWidget->GetValueAge();
+ if (m_bNotifying)
+ return;
- PDFSDK_FieldAction fa;
- fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
- fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot->Get());
+ if (!pWidget->HasXFAAAction(PDFSDK_XFA_PostOpen))
+ return;
- pWidget->OnXFAAAction(PDFSDK_XFA_PostOpen, fa, pPageView);
- m_bNotifying = false;
- if (!(*pAnnot)) {
- bExit = true;
- return;
- }
+ m_bNotifying = true;
+ int nAge = pWidget->GetAppearanceAge();
+ int nValueAge = pWidget->GetValueAge();
- if (!IsValidAnnot(pPageView, pWidget)) {
- bExit = true;
- return;
- }
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(nFlag);
- if (nAge != pWidget->GetAppearanceAge()) {
- if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) {
- pFormFiller->ResetPDFWindow(pPageView,
- nValueAge == pWidget->GetValueAge());
- }
+ pWidget->OnXFAAAction(PDFSDK_XFA_PostOpen, fa, pPageView);
+ m_bNotifying = false;
+ if (!(*pAnnot)) {
+ bExit = true;
+ return;
+ }
- bReset = true;
- }
- }
+ if (!IsValidAnnot(pPageView, pWidget)) {
+ bExit = true;
+ return;
}
+
+ if (nAge == pWidget->GetAppearanceAge())
+ return;
+
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, false)) {
+ pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
+ }
+
+ bReset = true;
}
#endif // PDF_ENABLE_XFA
diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp
index c9d7c3fd50..246db66234 100644
--- a/fpdfsdk/javascript/app.cpp
+++ b/fpdfsdk/javascript/app.cpp
@@ -234,11 +234,10 @@ bool app::calculate(CJS_Runtime* pRuntime,
if (vp.IsSetting()) {
bool bVP;
vp >> bVP;
- m_bCalculate = (bool)bVP;
- pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(
- (bool)m_bCalculate);
+ m_bCalculate = bVP;
+ pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(m_bCalculate);
} else {
- vp << (bool)m_bCalculate;
+ vp << m_bCalculate;
}
return true;
}