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 /xfa | |
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 'xfa')
-rw-r--r-- | xfa/fxfa/cxfa_ffdocview.cpp | 5 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fffield.cpp | 9 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_fftextedit.cpp | 5 | ||||
-rw-r--r-- | xfa/fxfa/fxfa.h | 39 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 39 |
5 files changed, 66 insertions, 31 deletions
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp index 51277c91ae..400be36e76 100644 --- a/xfa/fxfa/cxfa_ffdocview.cpp +++ b/xfa/fxfa/cxfa_ffdocview.cpp @@ -156,8 +156,9 @@ void CXFA_FFDocView::ShowNullTestMsg() { L"validation errors not reported.", iRemain); } - pAppProvider->MsgBox(wsMsg, pAppProvider->GetAppTitle(), XFA_MBICON_Status, - XFA_MB_OK); + pAppProvider->MsgBox(wsMsg, pAppProvider->GetAppTitle(), + static_cast<uint32_t>(AlertIcon::kStatus), + static_cast<uint32_t>(AlertButton::kOK)); } m_arrNullTestMsg.clear(); } diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp index f1b8cffa8f..fe53da1a46 100644 --- a/xfa/fxfa/cxfa_fffield.cpp +++ b/xfa/fxfa/cxfa_fffield.cpp @@ -665,8 +665,9 @@ int32_t CXFA_FFField::CalculateNode(CXFA_Node* pNode) { IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); if (pAppProvider) { pAppProvider->MsgBox(L"You are not allowed to modify this field.", - L"Calculate Override", XFA_MBICON_Warning, - XFA_MB_OK); + L"Calculate Override", + static_cast<uint32_t>(AlertIcon::kWarning), + static_cast<uint32_t>(AlertButton::kOK)); } return 0; } @@ -692,7 +693,9 @@ int32_t CXFA_FFField::CalculateNode(CXFA_Node* pNode) { wsMessage += L"Are you sure you want to modify this field?"; if (pAppProvider->MsgBox(wsMessage, L"Calculate Override", - XFA_MBICON_Warning, XFA_MB_YesNo) == XFA_IDYes) { + static_cast<uint32_t>(AlertIcon::kWarning), + static_cast<uint32_t>(AlertButton::kYesNo)) == + static_cast<uint32_t>(AlertReturn::kYes)) { pNode->SetFlag(XFA_NodeFlag_UserInteractive); return 1; } diff --git a/xfa/fxfa/cxfa_fftextedit.cpp b/xfa/fxfa/cxfa_fftextedit.cpp index 81bc9b3816..e18b099401 100644 --- a/xfa/fxfa/cxfa_fftextedit.cpp +++ b/xfa/fxfa/cxfa_fftextedit.cpp @@ -205,8 +205,9 @@ void CXFA_FFTextEdit::ValidateNumberField(const WideString& wsText) { WideString wsSomField = GetNode()->GetSOMExpression(); pAppProvider->MsgBox(WideString::Format(L"%ls can not contain %ls", wsText.c_str(), wsSomField.c_str()), - pAppProvider->GetAppTitle(), XFA_MBICON_Error, - XFA_MB_OK); + pAppProvider->GetAppTitle(), + static_cast<uint32_t>(AlertIcon::kError), + static_cast<uint32_t>(AlertButton::kOK)); } bool CXFA_FFTextEdit::IsDataChanged() { diff --git a/xfa/fxfa/fxfa.h b/xfa/fxfa/fxfa.h index 1b0c76f584..c1fdd2bcb7 100644 --- a/xfa/fxfa/fxfa.h +++ b/xfa/fxfa/fxfa.h @@ -23,18 +23,32 @@ class CXFA_Submit; class IFWL_AdapterTimerMgr; class IFX_SeekableReadStream; -#define XFA_MBICON_Error 0 -#define XFA_MBICON_Warning 1 -#define XFA_MBICON_Question 2 -#define XFA_MBICON_Status 3 -#define XFA_MB_OK 0 -#define XFA_MB_OKCancel 1 -#define XFA_MB_YesNo 2 -#define XFA_MB_YesNoCancel 3 -#define XFA_IDOK 1 -#define XFA_IDCancel 2 -#define XFA_IDNo 3 -#define XFA_IDYes 4 +// Note, values must match fpdf_formfill.h JSPLATFORM_ALERT_BUTTON_* flags. +enum class AlertButton { + kDefault = 0, + kOK = 0, + kOKCancel = 1, + kYesNo = 2, + kYesNoCancel = 3, +}; + +// Note, values must match fpdf_formfill.h JSPLATFORM_ALERT_ICON_* flags. +enum class AlertIcon { + kDefault = 0, + kError = 0, + kWarning = 1, + kQuestion = 2, + kStatus = 3, + kAsterisk = 4, +}; + +// Note, values must match fpdf_formfill.h JSPLATFORM_ALERT_RETURN_* flags. +enum class AlertReturn { + kOK = 1, + kCancel = 2, + kNo = 3, + kYes = 4, +}; // Note, values must match fpdf_formfill.h FORMTYPE_* flags. enum class FormType { @@ -50,6 +64,7 @@ enum class FormType { #define XFA_PRINTOPT_AsImage 0x00000008 #define XFA_PRINTOPT_ReverseOrder 0x00000010 #define XFA_PRINTOPT_PrintAnnot 0x00000020 + #define XFA_PAGEVIEWEVENT_PostAdded 1 #define XFA_PAGEVIEWEVENT_PostRemoved 3 #define XFA_PAGEVIEWEVENT_StopLayout 4 diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 00ea7b7a1b..86644694ca 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -2046,11 +2046,15 @@ void CXFA_Node::ProcessScriptTestValidate(CXFA_FFDocView* docView, wsScriptMsg = GetValidateMessage(false, bVersionFlag); if (bVersionFlag) { - pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Warning, XFA_MB_OK); + pAppProvider->MsgBox(wsScriptMsg, wsTitle, + static_cast<uint32_t>(AlertIcon::kWarning), + static_cast<uint32_t>(AlertButton::kOK)); return; } - if (pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Warning, - XFA_MB_YesNo) == XFA_IDYes) { + if (pAppProvider->MsgBox(wsScriptMsg, wsTitle, + static_cast<uint32_t>(AlertIcon::kWarning), + static_cast<uint32_t>(AlertButton::kYesNo)) == + static_cast<uint32_t>(AlertReturn::kYes)) { SetFlag(XFA_NodeFlag_UserInteractive); } return; @@ -2058,7 +2062,9 @@ void CXFA_Node::ProcessScriptTestValidate(CXFA_FFDocView* docView, if (wsScriptMsg.IsEmpty()) wsScriptMsg = GetValidateMessage(true, bVersionFlag); - pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); + pAppProvider->MsgBox(wsScriptMsg, wsTitle, + static_cast<uint32_t>(AlertIcon::kError), + static_cast<uint32_t>(AlertButton::kOK)); } int32_t CXFA_Node::ProcessFormatTestValidate(CXFA_FFDocView* docView, @@ -2087,7 +2093,9 @@ int32_t CXFA_Node::ProcessFormatTestValidate(CXFA_FFDocView* docView, if (validate->GetFormatTest() == XFA_AttributeEnum::Error) { if (wsFormatMsg.IsEmpty()) wsFormatMsg = GetValidateMessage(true, bVersionFlag); - pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); + pAppProvider->MsgBox(wsFormatMsg, wsTitle, + static_cast<uint32_t>(AlertIcon::kError), + static_cast<uint32_t>(AlertButton::kOK)); return XFA_EVENTERROR_Success; } if (IsUserInteractive()) @@ -2096,12 +2104,15 @@ int32_t CXFA_Node::ProcessFormatTestValidate(CXFA_FFDocView* docView, wsFormatMsg = GetValidateMessage(false, bVersionFlag); if (bVersionFlag) { - pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Warning, - XFA_MB_OK); + pAppProvider->MsgBox(wsFormatMsg, wsTitle, + static_cast<uint32_t>(AlertIcon::kWarning), + static_cast<uint32_t>(AlertButton::kOK)); return XFA_EVENTERROR_Success; } - if (pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Warning, - XFA_MB_YesNo) == XFA_IDYes) { + if (pAppProvider->MsgBox(wsFormatMsg, wsTitle, + static_cast<uint32_t>(AlertIcon::kWarning), + static_cast<uint32_t>(AlertButton::kYesNo)) == + static_cast<uint32_t>(AlertReturn::kYes)) { SetFlag(XFA_NodeFlag_UserInteractive); } return XFA_EVENTERROR_Success; @@ -2153,7 +2164,9 @@ int32_t CXFA_Node::ProcessNullTestValidate(CXFA_FFDocView* docView, wsNullMsg = WideString::Format(L"%ls cannot be blank.", wsCaptionName.c_str()); } - pAppProvider->MsgBox(wsNullMsg, wsTitle, XFA_MBICON_Status, XFA_MB_OK); + pAppProvider->MsgBox(wsNullMsg, wsTitle, + static_cast<uint32_t>(AlertIcon::kStatus), + static_cast<uint32_t>(AlertButton::kOK)); return XFA_EVENTERROR_Error; } case XFA_AttributeEnum::Warning: { @@ -2167,8 +2180,10 @@ int32_t CXFA_Node::ProcessNullTestValidate(CXFA_FFDocView* docView, L"Ignore.", wsCaptionName.c_str(), wsCaptionName.c_str()); } - if (pAppProvider->MsgBox(wsNullMsg, wsTitle, XFA_MBICON_Warning, - XFA_MB_YesNo) == XFA_IDYes) { + if (pAppProvider->MsgBox(wsNullMsg, wsTitle, + static_cast<uint32_t>(AlertIcon::kWarning), + static_cast<uint32_t>(AlertButton::kYesNo)) == + static_cast<uint32_t>(AlertReturn::kYes)) { SetFlag(XFA_NodeFlag_UserInteractive); } return XFA_EVENTERROR_Error; |