diff options
author | Ryan Harrison <rharrison@chromium.org> | 2018-06-21 21:09:54 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-06-21 21:09:54 +0000 |
commit | c3cc2ab66d3d8f52dea8083abb6775115e17af7d (patch) | |
tree | 227eb764e7ee1f674f9ac992ec6620e4e57e2b01 /fpdfsdk/fpdfxfa | |
parent | aaaf9877478d7add8a74b4db74d97ca19ce1c47e (diff) | |
download | pdfium-c3cc2ab66d3d8f52dea8083abb6775115e17af7d.tar.xz |
Clean up constant values for JS alert and beep
Define constant values in the public API for the valid values of alert
button type, alert icon type, and beep type. Replace various magic
numbers through out the code base using these values. Also replace the
XFA specific versions with an enum class that is guaranteed to have the
same values, instead of #defines that just happen to.
This CL does not attempt to add error checking on these values, since
it currently doesn't exist so adding it may cause regressions.
Change-Id: Ief3aee2a4ad419691c18fc1dba8b984ad222141b
Reviewed-on: https://pdfium-review.googlesource.com/35730
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfxfa')
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | 64 | ||||
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp | 6 |
2 files changed, 24 insertions, 46 deletions
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp index 385bbe7074..d7b3bed849 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp @@ -36,6 +36,19 @@ extern void SetLastError(int err); extern int GetLastError(); #endif +#define IS_VALID_ALERT_BUTTON(type) \ + ((type) == JSPLATFORM_ALERT_BUTTON_OK || \ + (type) == JSPLATFORM_ALERT_BUTTON_OKCANCEL || \ + (type) == JSPLATFORM_ALERT_BUTTON_YESNO || \ + (type) == JSPLATFORM_ALERT_BUTTON_YESNOCANCEL) + +#define IS_VALID_ALERT_ICON(type) \ + ((type) == JSPLATFORM_ALERT_ICON_ERROR || \ + (type) == JSPLATFORM_ALERT_ICON_WARNING || \ + (type) == JSPLATFORM_ALERT_ICON_QUESTION || \ + (type) == JSPLATFORM_ALERT_ICON_STATUS || \ + (type) == JSPLATFORM_ALERT_ICON_ASTERISK) + CPDFXFA_Context::CPDFXFA_Context(CPDF_Document* pPDFDoc) : m_pPDFDoc(pPDFDoc), m_pXFAApp(pdfium::MakeUnique<CXFA_FFApp>(this)), @@ -247,50 +260,13 @@ int32_t CPDFXFA_Context::MsgBox(const WideString& wsMessage, if (!m_pFormFillEnv || m_nLoadStatus != FXFA_LOADSTATUS_LOADED) return -1; - uint32_t iconType = 0; - int iButtonType = 0; - switch (dwIconType) { - case XFA_MBICON_Error: - iconType |= 0; - break; - case XFA_MBICON_Warning: - iconType |= 1; - break; - case XFA_MBICON_Question: - iconType |= 2; - break; - case XFA_MBICON_Status: - iconType |= 3; - break; - } - switch (dwButtonType) { - case XFA_MB_OK: - iButtonType |= 0; - break; - case XFA_MB_OKCancel: - iButtonType |= 1; - break; - case XFA_MB_YesNo: - iButtonType |= 2; - break; - case XFA_MB_YesNoCancel: - iButtonType |= 3; - break; - } - int32_t iRet = - m_pFormFillEnv->JS_appAlert(wsMessage, wsTitle, iButtonType, iconType); - - switch (iRet) { - case 1: - return XFA_IDOK; - case 2: - return XFA_IDCancel; - case 3: - return XFA_IDNo; - case 4: - return XFA_IDYes; - } - return XFA_IDYes; + int iconType = IS_VALID_ALERT_ICON(dwIconType) + ? dwIconType + : JSPLATFORM_ALERT_ICON_DEFAULT; + int iButtonType = IS_VALID_ALERT_BUTTON(dwButtonType) + ? dwButtonType + : JSPLATFORM_ALERT_BUTTON_DEFAULT; + return m_pFormFillEnv->JS_appAlert(wsMessage, wsTitle, iButtonType, iconType); } WideString CPDFXFA_Context::Response(const WideString& wsQuestion, diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index f3fe89c1e2..9d1ceacf02 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp @@ -656,7 +656,8 @@ bool CPDFXFA_DocEnvironment::OnBeforeNotifySubmit() { return false; pFormFillEnv->JS_appAlert(WideString::FromLocal(IDS_XFA_Validate_Input), - L"", 0, 1); + L"", JSPLATFORM_ALERT_BUTTON_OK, + JSPLATFORM_ALERT_ICON_WARNING); return false; } pNode = it->MoveToNext(); @@ -909,7 +910,8 @@ bool CPDFXFA_DocEnvironment::SubmitInternal(CXFA_FFDoc* hDoc, WideString csURL = submit->GetSubmitTarget(); if (csURL.IsEmpty()) { pFormFillEnv->JS_appAlert(WideString::FromLocal("Submit cancelled."), L"", - 0, 4); + JSPLATFORM_ALERT_BUTTON_OK, + JSPLATFORM_ALERT_ICON_ASTERISK); return false; } |