Replace XFA_PAGEVIEWEVENT_* defines with nested enum class
-- consistently name all methods OnPageViewEvent().
Bug: pdfium:1085
Change-Id: If5973873fbcffe828fabd5935d360d60c5a7dca2
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/80750
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 76dbc33..6776486 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -44,6 +44,17 @@
#define FXFA_PDF 0x10000000
#define FXFA_XFA_ALL 0x01111111
+// Although there isn't direct casting between these types at present,
+// keep the internal and exernal types in sync.
+static_assert(
+ FXFA_PAGEVIEWEVENT_POSTADDED ==
+ static_cast<int>(IXFA_DocEnvironment::PageViewEvent::kPostAdded),
+ "kPostAdded mismatch");
+static_assert(
+ FXFA_PAGEVIEWEVENT_POSTREMOVED ==
+ static_cast<int>(IXFA_DocEnvironment::PageViewEvent::kPostRemoved),
+ "kPostRemoved mismatch");
+
CPDFXFA_DocEnvironment::CPDFXFA_DocEnvironment(CPDFXFA_Context* pContext)
: m_pContext(pContext) {
DCHECK(m_pContext);
@@ -270,17 +281,17 @@
return pFormFillEnv->PopupMenu(pPage.Get(), menuFlag, ptPopup);
}
-void CPDFXFA_DocEnvironment::PageViewEvent(CXFA_FFPageView* pPageView,
- uint32_t dwFlags) {
+void CPDFXFA_DocEnvironment::OnPageViewEvent(CXFA_FFPageView* pPageView,
+ PageViewEvent eEvent) {
CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv();
if (!pFormFillEnv)
return;
if (m_pContext->GetLoadStatus() == FXFA_LOADSTATUS_LOADING ||
m_pContext->GetLoadStatus() == FXFA_LOADSTATUS_CLOSING ||
- XFA_PAGEVIEWEVENT_StopLayout != dwFlags)
+ eEvent != IXFA_DocEnvironment::PageViewEvent::kStopLayout) {
return;
-
+ }
int nNewCount = m_pContext->GetPageCount();
if (nNewCount == m_pContext->GetOriginalPageCount())
return;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h
index f6789bc..7035ce4 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h
@@ -33,7 +33,8 @@
const CFX_RectF& rtAnchor,
CFX_RectF* pPopupRect) override;
bool PopupMenu(CXFA_FFWidget* hWidget, const CFX_PointF& ptPopup) override;
- void PageViewEvent(CXFA_FFPageView* pPageView, uint32_t dwFlags) override;
+ void OnPageViewEvent(CXFA_FFPageView* pPageView,
+ PageViewEvent eEvent) override;
void WidgetPostAdd(CXFA_FFWidget* hWidget) override;
void WidgetPreRemove(CXFA_FFWidget* hWidget) override;
int32_t CountPages(const CXFA_FFDoc* hDoc) const override;
diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp
index 54d17f7..23c7887 100644
--- a/xfa/fxfa/cxfa_ffdoc.cpp
+++ b/xfa/fxfa/cxfa_ffdoc.cpp
@@ -137,8 +137,9 @@
return m_pDocEnvironment->PopupMenu(hWidget, ptPopup);
}
-void CXFA_FFDoc::PageViewEvent(CXFA_FFPageView* pPageView, uint32_t dwFlags) {
- m_pDocEnvironment->PageViewEvent(pPageView, dwFlags);
+void CXFA_FFDoc::OnPageViewEvent(CXFA_FFPageView* pPageView,
+ IXFA_DocEnvironment::PageViewEvent eEvent) {
+ m_pDocEnvironment->OnPageViewEvent(pPageView, eEvent);
}
void CXFA_FFDoc::WidgetPostAdd(CXFA_FFWidget* hWidget) {
diff --git a/xfa/fxfa/cxfa_ffdoc.h b/xfa/fxfa/cxfa_ffdoc.h
index 6601824..19e00e1 100644
--- a/xfa/fxfa/cxfa_ffdoc.h
+++ b/xfa/fxfa/cxfa_ffdoc.h
@@ -71,7 +71,8 @@
const CFX_RectF& rtAnchor,
CFX_RectF* pPopupRect) const;
bool PopupMenu(CXFA_FFWidget* hWidget, const CFX_PointF& ptPopup);
- void PageViewEvent(CXFA_FFPageView* pPageView, uint32_t dwFlags);
+ void OnPageViewEvent(CXFA_FFPageView* pPageView,
+ IXFA_DocEnvironment::PageViewEvent eEvent);
void WidgetPostAdd(CXFA_FFWidget* hWidget);
void WidgetPreRemove(CXFA_FFWidget* hWidget);
int32_t CountPages() const;
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp
index cd68494..53770b3 100644
--- a/xfa/fxfa/cxfa_ffdocview.cpp
+++ b/xfa/fxfa/cxfa_ffdocview.cpp
@@ -454,10 +454,11 @@
return nullptr;
}
-void CXFA_FFDocView::OnPageEvent(CXFA_ViewLayoutItem* pSender,
- uint32_t dwEvent) {
+void CXFA_FFDocView::OnPageViewEvent(
+ CXFA_ViewLayoutItem* pSender,
+ IXFA_DocEnvironment::PageViewEvent eEvent) {
CXFA_FFPageView* pFFPageView = pSender ? pSender->GetPageView() : nullptr;
- m_pDoc->PageViewEvent(pFFPageView, dwEvent);
+ m_pDoc->OnPageViewEvent(pFFPageView, eEvent);
}
void CXFA_FFDocView::InvalidateRect(CXFA_FFPageView* pPageView,
@@ -474,12 +475,14 @@
pProcessor->DoLayout();
UnlockUpdate();
m_bInLayoutStatus = false;
- m_pDoc->PageViewEvent(nullptr, XFA_PAGEVIEWEVENT_StopLayout);
+ m_pDoc->OnPageViewEvent(nullptr,
+ IXFA_DocEnvironment::PageViewEvent::kStopLayout);
return true;
}
m_bInLayoutStatus = false;
- m_pDoc->PageViewEvent(nullptr, XFA_PAGEVIEWEVENT_StopLayout);
+ m_pDoc->OnPageViewEvent(nullptr,
+ IXFA_DocEnvironment::PageViewEvent::kStopLayout);
UnlockUpdate();
return false;
}
diff --git a/xfa/fxfa/cxfa_ffdocview.h b/xfa/fxfa/cxfa_ffdocview.h
index b1e66e3..610b1cd 100644
--- a/xfa/fxfa/cxfa_ffdocview.h
+++ b/xfa/fxfa/cxfa_ffdocview.h
@@ -72,7 +72,8 @@
CXFA_FFWidget* GetWidgetByName(const WideString& wsName,
CXFA_FFWidget* pRefWidget);
CXFA_LayoutProcessor* GetLayoutProcessor() const;
- void OnPageEvent(CXFA_ViewLayoutItem* pSender, uint32_t dwEvent);
+ void OnPageViewEvent(CXFA_ViewLayoutItem* pSender,
+ IXFA_DocEnvironment::PageViewEvent eEvent);
void LockUpdate() { m_iLock++; }
void UnlockUpdate() { m_iLock--; }
void InvalidateRect(CXFA_FFPageView* pPageView,
diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp
index d5238c6..f5354fe 100644
--- a/xfa/fxfa/cxfa_ffnotify.cpp
+++ b/xfa/fxfa/cxfa_ffnotify.cpp
@@ -51,11 +51,11 @@
visitor->Trace(m_pDoc);
}
-void CXFA_FFNotify::OnPageEvent(CXFA_ViewLayoutItem* pSender,
- uint32_t dwEvent) {
+void CXFA_FFNotify::OnPageViewEvent(CXFA_ViewLayoutItem* pSender,
+ IXFA_DocEnvironment::PageViewEvent eEvent) {
CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pSender->GetLayout());
if (pDocView)
- pDocView->OnPageEvent(pSender, dwEvent);
+ pDocView->OnPageViewEvent(pSender, eEvent);
}
void CXFA_FFNotify::OnWidgetListItemAdded(CXFA_Node* pSender,
diff --git a/xfa/fxfa/cxfa_ffnotify.h b/xfa/fxfa/cxfa_ffnotify.h
index a5f8224..167a17a 100644
--- a/xfa/fxfa/cxfa_ffnotify.h
+++ b/xfa/fxfa/cxfa_ffnotify.h
@@ -28,7 +28,8 @@
void Trace(cppgc::Visitor* visitor) const;
- void OnPageEvent(CXFA_ViewLayoutItem* pSender, uint32_t dwEvent);
+ void OnPageViewEvent(CXFA_ViewLayoutItem* pSender,
+ IXFA_DocEnvironment::PageViewEvent eEvent);
void OnWidgetListItemAdded(CXFA_Node* pSender,
const WideString& wsLabel,
diff --git a/xfa/fxfa/fxfa.h b/xfa/fxfa/fxfa.h
index ae21363..7630405 100644
--- a/xfa/fxfa/fxfa.h
+++ b/xfa/fxfa/fxfa.h
@@ -68,10 +68,6 @@
#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
-
enum class XFA_EventError {
kError = -1,
kNotExist = 0,
@@ -201,6 +197,12 @@
// Probably should be called CFXA_FFDoc::CallbackIface in cxfa_ffdoc.h
class IXFA_DocEnvironment {
public:
+ enum class PageViewEvent {
+ kPostAdded = 1,
+ kPostRemoved = 3,
+ kStopLayout = 4,
+ };
+
virtual ~IXFA_DocEnvironment() = default;
virtual void SetChangeMark(CXFA_FFDoc* hDoc) = 0;
@@ -218,8 +220,8 @@
CFX_RectF* pPopupRect) = 0;
virtual bool PopupMenu(CXFA_FFWidget* hWidget, const CFX_PointF& ptPopup) = 0;
- // Specify dwFlags XFA_PAGEVIEWEVENT_Added, XFA_PAGEVIEWEVENT_Removing
- virtual void PageViewEvent(CXFA_FFPageView* pPageView, uint32_t dwFlags) = 0;
+ virtual void OnPageViewEvent(CXFA_FFPageView* pPageView,
+ PageViewEvent eEvent) = 0;
virtual void WidgetPostAdd(CXFA_FFWidget* hWidget) = 0;
virtual void WidgetPreRemove(CXFA_FFWidget* hWidget) = 0;
diff --git a/xfa/fxfa/layout/cxfa_layoutitem.cpp b/xfa/fxfa/layout/cxfa_layoutitem.cpp
index f4ff49c..e60dcb7 100644
--- a/xfa/fxfa/layout/cxfa_layoutitem.cpp
+++ b/xfa/fxfa/layout/cxfa_layoutitem.cpp
@@ -27,8 +27,8 @@
auto* pDocLayout = CXFA_LayoutProcessor::FromDocument(pDocument);
pNotify->OnLayoutItemRemoving(pDocLayout, pLayoutItem);
if (pLayoutItem->GetFormNode()->GetElementType() == XFA_Element::PageArea) {
- pNotify->OnPageEvent(ToViewLayoutItem(pLayoutItem),
- XFA_PAGEVIEWEVENT_PostRemoved);
+ pNotify->OnPageViewEvent(ToViewLayoutItem(pLayoutItem),
+ IXFA_DocEnvironment::PageViewEvent::kPostRemoved);
}
pLayoutItem->RemoveSelfIfParented();
}
diff --git a/xfa/fxfa/layout/cxfa_viewlayoutprocessor.cpp b/xfa/fxfa/layout/cxfa_viewlayoutprocessor.cpp
index 68ca498..41c6338 100644
--- a/xfa/fxfa/layout/cxfa_viewlayoutprocessor.cpp
+++ b/xfa/fxfa/layout/cxfa_viewlayoutprocessor.cpp
@@ -694,7 +694,8 @@
pNotify->OnCreateViewLayoutItem(pNewPageArea));
m_PageArray.push_back(pViewItem);
m_nAvailPages++;
- pNotify->OnPageEvent(pViewItem, XFA_PAGEVIEWEVENT_PostRemoved);
+ pNotify->OnPageViewEvent(pViewItem,
+ IXFA_DocEnvironment::PageViewEvent::kPostRemoved);
pNewPageAreaLayoutItem = pViewItem;
}
pNewRecord->pCurPageSet->AppendLastChild(pNewPageAreaLayoutItem);
@@ -1912,7 +1913,8 @@
for (int32_t i = nPage - 1; i >= m_nAvailPages; i--) {
CXFA_ViewLayoutItem* pPage = m_PageArray[i];
m_PageArray.erase(m_PageArray.begin() + i);
- pNotify->OnPageEvent(pPage, XFA_PAGEVIEWEVENT_PostRemoved);
+ pNotify->OnPageViewEvent(pPage,
+ IXFA_DocEnvironment::PageViewEvent::kPostRemoved);
}
ClearData();
}