Convert OnBeforeKeyStoke to remove in-out param
This CL removes the in-out params from OnBeforeKeyStroke and instead
returns a std::pair<bool, bool>.
Change-Id: I246cf51652da7e05ea71f582b523aa428cbbd3b8
Reviewed-on: https://pdfium-review.googlesource.com/7337
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
index d318111..d718e7c 100644
--- a/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.cpp
@@ -839,16 +839,16 @@
return pPageView && pPageView->IsValidAnnot(pAnnot->GetPDFAnnot());
}
-void CFFL_InteractiveFormFiller::OnBeforeKeyStroke(
+std::pair<bool, bool> CFFL_InteractiveFormFiller::OnBeforeKeyStroke(
void* pPrivateData,
CFX_WideString& strChange,
const CFX_WideString& strChangeEx,
int nSelStart,
int nSelEnd,
bool bKeyDown,
- bool& bRC,
- bool& bExit,
uint32_t nFlag) {
+ bool bRC = true;
+ bool bExit = false;
CFFL_PrivateData* pData = reinterpret_cast<CFFL_PrivateData*>(pPrivateData);
ASSERT(pData->pWidget);
@@ -857,18 +857,15 @@
#ifdef PDF_ENABLE_XFA
if (pFormFiller->IsFieldFull(pData->pPageView)) {
CPDFSDK_Annot::ObservedPtr pObserved(pData->pWidget);
- if (OnFull(&pObserved, pData->pPageView, nFlag) || !pObserved) {
- bExit = true;
- return;
- }
+ if (OnFull(&pObserved, pData->pPageView, nFlag) || !pObserved)
+ return {bRC, true};
}
#endif // PDF_ENABLE_XFA
- if (m_bNotifying)
- return;
-
- if (!pData->pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict())
- return;
+ if (m_bNotifying ||
+ !pData->pWidget->GetAAction(CPDF_AAction::KeyStroke).GetDict()) {
+ return {bRC, bExit};
+ }
CFX_AutoRestorer<bool> restorer(&m_bNotifying);
m_bNotifying = true;
@@ -897,13 +894,11 @@
pData->pPageView)) {
if (!IsValidAnnot(pData->pPageView, pData->pWidget))
bExit = true;
- return;
+ return {bRC, bExit};
}
- if (!pObserved || !IsValidAnnot(pData->pPageView, pData->pWidget)) {
- bExit = true;
- return;
- }
+ if (!pObserved || !IsValidAnnot(pData->pPageView, pData->pWidget))
+ return {bRC, true};
if (nAge != pData->pWidget->GetAppearanceAge()) {
CPWL_Wnd* pWnd = pFormFiller->ResetPDFWindow(
@@ -919,8 +914,8 @@
bRC = false;
if (pFormFillEnv->GetFocusAnnot() == pData->pWidget)
- return;
+ return {bRC, bExit};
pFormFiller->CommitData(pData->pPageView, nFlag);
- bExit = true;
+ return {bRC, true};
}
diff --git a/fpdfsdk/formfiller/cffl_interactiveformfiller.h b/fpdfsdk/formfiller/cffl_interactiveformfiller.h
index 05fdf0d..fb141e1 100644
--- a/fpdfsdk/formfiller/cffl_interactiveformfiller.h
+++ b/fpdfsdk/formfiller/cffl_interactiveformfiller.h
@@ -9,6 +9,7 @@
#include <map>
#include <memory>
+#include <utility>
#include "core/fxcrt/cfx_unowned_ptr.h"
#include "fpdfsdk/cpdfsdk_annot.h"
@@ -129,15 +130,14 @@
float fPopupMax,
bool* bBottom,
float* fPopupRet) override;
- void OnBeforeKeyStroke(void* pPrivateData,
- CFX_WideString& strChange,
- const CFX_WideString& strChangeEx,
- int nSelStart,
- int nSelEnd,
- bool bKeyDown,
- bool& bRC,
- bool& bExit,
- uint32_t nFlag) override;
+ // Returns {bRC, bExit}.
+ std::pair<bool, bool> OnBeforeKeyStroke(void* pPrivateData,
+ CFX_WideString& strChange,
+ const CFX_WideString& strChangeEx,
+ int nSelStart,
+ int nSelEnd,
+ bool bKeyDown,
+ uint32_t nFlag) override;
#ifdef PDF_ENABLE_XFA
bool OnPopupPreOpen(void* pPrivateData, uint32_t nFlag) override;
bool OnPopupPostOpen(void* pPrivateData, uint32_t nFlag) override;
diff --git a/fpdfsdk/pdfwindow/cpwl_edit.cpp b/fpdfsdk/pdfwindow/cpwl_edit.cpp
index de21dac..a378156 100644
--- a/fpdfsdk/pdfwindow/cpwl_edit.cpp
+++ b/fpdfsdk/pdfwindow/cpwl_edit.cpp
@@ -586,8 +586,6 @@
if (nChar == FWL_VKEY_Delete) {
if (m_pFillerNotify) {
- bool bRC = true;
- bool bExit = false;
CFX_WideString strChange;
CFX_WideString strChangeEx;
@@ -597,9 +595,12 @@
if (nSelStart == nSelEnd)
nSelEnd = nSelStart + 1;
- m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange,
- strChangeEx, nSelStart, nSelEnd, true,
- bRC, bExit, nFlag);
+
+ bool bRC;
+ bool bExit;
+ std::tie(bRC, bExit) = m_pFillerNotify->OnBeforeKeyStroke(
+ GetAttachedData(), strChange, strChangeEx, nSelStart, nSelEnd, true,
+ nFlag);
if (!bRC)
return false;
if (bExit)
@@ -677,9 +678,9 @@
}
CFX_WideString strChangeEx;
- m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange,
- strChangeEx, nSelStart, nSelEnd, true,
- bRC, bExit, nFlag);
+ std::tie(bRC, bExit) = m_pFillerNotify->OnBeforeKeyStroke(
+ GetAttachedData(), swChange, strChangeEx, nSelStart, nSelEnd, true,
+ nFlag);
}
}
diff --git a/fpdfsdk/pdfwindow/cpwl_edit.h b/fpdfsdk/pdfwindow/cpwl_edit.h
index 038aba9..ebf556a 100644
--- a/fpdfsdk/pdfwindow/cpwl_edit.h
+++ b/fpdfsdk/pdfwindow/cpwl_edit.h
@@ -7,6 +7,8 @@
#ifndef FPDFSDK_PDFWINDOW_CPWL_EDIT_H_
#define FPDFSDK_PDFWINDOW_CPWL_EDIT_H_
+#include <utility>
+
#include "core/fpdfdoc/cpvt_wordrange.h"
#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_basic.h"
@@ -22,15 +24,14 @@
float fPopupMax,
bool* bBottom,
float* fPopupRet) = 0;
- virtual void OnBeforeKeyStroke(void* pPrivateData,
- CFX_WideString& strChange,
- const CFX_WideString& strChangeEx,
- int nSelStart,
- int nSelEnd,
- bool bKeyDown,
- bool& bRC,
- bool& bExit,
- uint32_t nFlag) = 0;
+ virtual std::pair<bool, bool> OnBeforeKeyStroke(
+ void* pPrivateData,
+ CFX_WideString& strChange,
+ const CFX_WideString& strChangeEx,
+ int nSelStart,
+ int nSelEnd,
+ bool bKeyDown,
+ uint32_t nFlag) = 0;
#ifdef PDF_ENABLE_XFA
virtual bool OnPopupPreOpen(void* pPrivateData, uint32_t nFlag) = 0;
virtual bool OnPopupPostOpen(void* pPrivateData, uint32_t nFlag) = 0;
diff --git a/fpdfsdk/pdfwindow/cpwl_list_box.cpp b/fpdfsdk/pdfwindow/cpwl_list_box.cpp
index bd2bdb5..e3a2e77 100644
--- a/fpdfsdk/pdfwindow/cpwl_list_box.cpp
+++ b/fpdfsdk/pdfwindow/cpwl_list_box.cpp
@@ -305,15 +305,15 @@
if (!m_pFillerNotify)
return false;
- bool bRC = true;
- bool bExit = false;
CFX_WideString swChange = GetText();
CFX_WideString strChangeEx;
int nSelStart = 0;
int nSelEnd = swChange.GetLength();
- m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange, strChangeEx,
- nSelStart, nSelEnd, bKeyDown, bRC, bExit,
- nFlag);
+ bool bRC;
+ bool bExit;
+ std::tie(bRC, bExit) = m_pFillerNotify->OnBeforeKeyStroke(
+ GetAttachedData(), swChange, strChangeEx, nSelStart, nSelEnd, bKeyDown,
+ nFlag);
return bExit;
}