From 8b8031dc46c892e3cb67535f2540bb863648ed3b Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Fri, 22 Jun 2018 19:15:05 +0000 Subject: Follow up to removing JS alert/beep magic numbers Cleanup CL to address some comments on https://pdfium-review.googlesource.com/c/pdfium/+/35730 that appeared after I sent it to the CQ. Change-Id: I7d5539101547a79d6fc3edf45720b60a1112e2e5 Reviewed-on: https://pdfium-review.googlesource.com/35951 Reviewed-by: Henrique Nakashima Commit-Queue: Ryan Harrison --- fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | 37 +++++++++++++++++++++---------------- public/fpdf_formfill.h | 2 +- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp index d7b3bed849..f2bfff6fa6 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp @@ -36,18 +36,24 @@ 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) +namespace { + +bool IsValidAlertButton(int type) { + return type == JSPLATFORM_ALERT_BUTTON_OK || + type == JSPLATFORM_ALERT_BUTTON_OKCANCEL || + type == JSPLATFORM_ALERT_BUTTON_YESNO || + type == JSPLATFORM_ALERT_BUTTON_YESNOCANCEL; +} + +bool IsValidAlertIcon(int type) { + return 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; +} + +} // namespace CPDFXFA_Context::CPDFXFA_Context(CPDF_Document* pPDFDoc) : m_pPDFDoc(pPDFDoc), @@ -260,10 +266,9 @@ int32_t CPDFXFA_Context::MsgBox(const WideString& wsMessage, if (!m_pFormFillEnv || m_nLoadStatus != FXFA_LOADSTATUS_LOADED) return -1; - int iconType = IS_VALID_ALERT_ICON(dwIconType) - ? dwIconType - : JSPLATFORM_ALERT_ICON_DEFAULT; - int iButtonType = IS_VALID_ALERT_BUTTON(dwButtonType) + int iconType = + IsValidAlertIcon(dwIconType) ? dwIconType : JSPLATFORM_ALERT_ICON_DEFAULT; + int iButtonType = IsValidAlertButton(dwButtonType) ? dwButtonType : JSPLATFORM_ALERT_BUTTON_DEFAULT; return m_pFormFillEnv->JS_appAlert(wsMessage, wsTitle, iButtonType, iconType); diff --git a/public/fpdf_formfill.h b/public/fpdf_formfill.h index 915c07a134..0bc08ec54b 100644 --- a/public/fpdf_formfill.h +++ b/public/fpdf_formfill.h @@ -76,7 +76,7 @@ typedef struct _IPDF_JsPlatform { * JSPLATFORM_ALERT_ICON_* above . * * Return Value: - * Option selected by user in dialogue, see see + * Option selected by user in dialogue, see * JSPLATFORM_ALERT_RETURN_* above. */ int (*app_alert)(struct _IPDF_JsPlatform* pThis, -- cgit v1.2.3