Remove bool arg from CFFL_FormField::GetPWLWindow()
Split into a const GetPWLWindow() method and a non-const
CreateOrUpdatePWLWindow() method.
Change-Id: Ic52fc594c4e505cba785674b4c42a4a0593b45f7
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/81230
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/formfiller/cffl_checkbox.cpp b/fpdfsdk/formfiller/cffl_checkbox.cpp
index c37e452..ff280eb 100644
--- a/fpdfsdk/formfiller/cffl_checkbox.cpp
+++ b/fpdfsdk/formfiller/cffl_checkbox.cpp
@@ -63,7 +63,7 @@
CFFL_FormField::OnChar(pAnnot, nChar, nFlags);
- CPWL_CheckBox* pWnd = GetCheckBox(pPageView, true);
+ CPWL_CheckBox* pWnd = CreateOrUpdateCheckBox(pPageView);
if (pWnd && !pWnd->IsReadOnly()) {
CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot);
pWnd->SetCheck(!pWidget->IsChecked());
@@ -85,7 +85,7 @@
if (!IsValid())
return true;
- CPWL_CheckBox* pWnd = GetCheckBox(pPageView, true);
+ CPWL_CheckBox* pWnd = CreateOrUpdateCheckBox(pPageView);
if (pWnd) {
CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot);
pWnd->SetCheck(!pWidget->IsChecked());
@@ -95,12 +95,12 @@
}
bool CFFL_CheckBox::IsDataChanged(CPDFSDK_PageView* pPageView) {
- CPWL_CheckBox* pWnd = GetCheckBox(pPageView, false);
+ CPWL_CheckBox* pWnd = GetCheckBox(pPageView);
return pWnd && pWnd->IsChecked() != m_pWidget->IsChecked();
}
void CFFL_CheckBox::SaveData(CPDFSDK_PageView* pPageView) {
- CPWL_CheckBox* pWnd = GetCheckBox(pPageView, false);
+ CPWL_CheckBox* pWnd = GetCheckBox(pPageView);
if (!pWnd)
return;
@@ -128,7 +128,11 @@
SetChangeMark();
}
-CPWL_CheckBox* CFFL_CheckBox::GetCheckBox(CPDFSDK_PageView* pPageView,
- bool bNew) {
- return static_cast<CPWL_CheckBox*>(GetPWLWindow(pPageView, bNew));
+CPWL_CheckBox* CFFL_CheckBox::GetCheckBox(CPDFSDK_PageView* pPageView) const {
+ return static_cast<CPWL_CheckBox*>(GetPWLWindow(pPageView));
+}
+
+CPWL_CheckBox* CFFL_CheckBox::CreateOrUpdateCheckBox(
+ CPDFSDK_PageView* pPageView) {
+ return static_cast<CPWL_CheckBox*>(CreateOrUpdatePWLWindow(pPageView));
}
diff --git a/fpdfsdk/formfiller/cffl_checkbox.h b/fpdfsdk/formfiller/cffl_checkbox.h
index aff2762..fbf4a9a 100644
--- a/fpdfsdk/formfiller/cffl_checkbox.h
+++ b/fpdfsdk/formfiller/cffl_checkbox.h
@@ -33,7 +33,8 @@
void SaveData(CPDFSDK_PageView* pPageView) override;
private:
- CPWL_CheckBox* GetCheckBox(CPDFSDK_PageView* pPageView, bool bNew);
+ CPWL_CheckBox* GetCheckBox(CPDFSDK_PageView* pPageView) const;
+ CPWL_CheckBox* CreateOrUpdateCheckBox(CPDFSDK_PageView* pPageView);
};
#endif // FPDFSDK_FORMFILLER_CFFL_CHECKBOX_H_
diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp
index e4e0867..77f3685 100644
--- a/fpdfsdk/formfiller/cffl_combobox.cpp
+++ b/fpdfsdk/formfiller/cffl_combobox.cpp
@@ -70,7 +70,7 @@
}
bool CFFL_ComboBox::IsDataChanged(CPDFSDK_PageView* pPageView) {
- auto* pWnd = GetComboBox(pPageView, false);
+ auto* pWnd = GetComboBox(pPageView);
if (!pWnd)
return false;
@@ -85,7 +85,7 @@
}
void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView) {
- CPWL_ComboBox* pWnd = GetComboBox(pPageView, false);
+ CPWL_ComboBox* pWnd = GetComboBox(pPageView);
if (!pWnd)
return;
@@ -119,7 +119,7 @@
CPDFSDK_FieldAction& fa) {
switch (type) {
case CPDF_AAction::kKeyStroke:
- if (CPWL_ComboBox* pComboBox = GetComboBox(pPageView, false)) {
+ if (CPWL_ComboBox* pComboBox = GetComboBox(pPageView)) {
if (CPWL_Edit* pEdit = pComboBox->GetEdit()) {
fa.bFieldFull = pEdit->IsTextFull();
std::tie(fa.nSelStart, fa.nSelEnd) = pEdit->GetSelection();
@@ -134,7 +134,7 @@
}
break;
case CPDF_AAction::kValidate:
- if (CPWL_ComboBox* pComboBox = GetComboBox(pPageView, false)) {
+ if (CPWL_ComboBox* pComboBox = GetComboBox(pPageView)) {
if (CPWL_Edit* pEdit = pComboBox->GetEdit()) {
fa.sValue = pEdit->GetText();
}
@@ -154,7 +154,7 @@
const CPDFSDK_FieldAction& fa) {
switch (type) {
case CPDF_AAction::kKeyStroke:
- if (CPWL_ComboBox* pComboBox = GetComboBox(pPageView, false)) {
+ if (CPWL_ComboBox* pComboBox = GetComboBox(pPageView)) {
if (CPWL_Edit* pEdit = pComboBox->GetEdit()) {
pEdit->SetSelection(fa.nSelStart, fa.nSelEnd);
pEdit->ReplaceSelection(fa.sChange);
@@ -167,7 +167,7 @@
}
void CFFL_ComboBox::SaveState(CPDFSDK_PageView* pPageView) {
- CPWL_ComboBox* pComboBox = GetComboBox(pPageView, false);
+ CPWL_ComboBox* pComboBox = GetComboBox(pPageView);
if (!pComboBox)
return;
@@ -182,7 +182,7 @@
}
void CFFL_ComboBox::RestoreState(CPDFSDK_PageView* pPageView) {
- CPWL_ComboBox* pComboBox = GetComboBox(pPageView, true);
+ CPWL_ComboBox* pComboBox = CreateOrUpdateComboBox(pPageView);
if (!pComboBox)
return;
@@ -206,7 +206,7 @@
if (index < 0 || index >= m_pWidget->CountOptions())
return false;
- CPWL_ComboBox* pWnd = GetComboBox(GetCurPageView(), false);
+ CPWL_ComboBox* pWnd = GetComboBox(GetCurPageView());
if (!pWnd)
return false;
@@ -221,13 +221,13 @@
if (index < 0 || index >= m_pWidget->CountOptions())
return false;
- CPWL_ComboBox* pWnd = GetComboBox(GetCurPageView(), false);
+ CPWL_ComboBox* pWnd = GetComboBox(GetCurPageView());
return pWnd && index == pWnd->GetSelect();
}
#ifdef PDF_ENABLE_XFA
bool CFFL_ComboBox::IsFieldFull(CPDFSDK_PageView* pPageView) {
- CPWL_ComboBox* pComboBox = GetComboBox(pPageView, false);
+ CPWL_ComboBox* pComboBox = GetComboBox(pPageView);
if (!pComboBox)
return false;
@@ -250,7 +250,7 @@
WideString CFFL_ComboBox::GetSelectExportText() {
WideString swRet;
- CPWL_ComboBox* pComboBox = GetComboBox(GetCurPageView(), false);
+ CPWL_ComboBox* pComboBox = GetComboBox(GetCurPageView());
int nExport = pComboBox ? pComboBox->GetSelect() : -1;
if (nExport >= 0) {
@@ -264,7 +264,11 @@
return swRet;
}
-CPWL_ComboBox* CFFL_ComboBox::GetComboBox(CPDFSDK_PageView* pPageView,
- bool bNew) {
- return static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView, bNew));
+CPWL_ComboBox* CFFL_ComboBox::GetComboBox(CPDFSDK_PageView* pPageView) const {
+ return static_cast<CPWL_ComboBox*>(GetPWLWindow(pPageView));
+}
+
+CPWL_ComboBox* CFFL_ComboBox::CreateOrUpdateComboBox(
+ CPDFSDK_PageView* pPageView) {
+ return static_cast<CPWL_ComboBox*>(CreateOrUpdatePWLWindow(pPageView));
}
diff --git a/fpdfsdk/formfiller/cffl_combobox.h b/fpdfsdk/formfiller/cffl_combobox.h
index 250dba7..02ba37c 100644
--- a/fpdfsdk/formfiller/cffl_combobox.h
+++ b/fpdfsdk/formfiller/cffl_combobox.h
@@ -55,7 +55,8 @@
private:
WideString GetSelectExportText();
- CPWL_ComboBox* GetComboBox(CPDFSDK_PageView* pPageView, bool bNew);
+ CPWL_ComboBox* GetComboBox(CPDFSDK_PageView* pPageView) const;
+ CPWL_ComboBox* CreateOrUpdateComboBox(CPDFSDK_PageView* pPageView);
FFL_ComboBoxState m_State;
};
diff --git a/fpdfsdk/formfiller/cffl_formfield.cpp b/fpdfsdk/formfiller/cffl_formfield.cpp
index 3db3e8b..90ba187 100644
--- a/fpdfsdk/formfiller/cffl_formfield.cpp
+++ b/fpdfsdk/formfiller/cffl_formfield.cpp
@@ -38,7 +38,7 @@
}
FX_RECT CFFL_FormField::GetViewBBox(CPDFSDK_PageView* pPageView) {
- CPWL_Wnd* pWnd = GetPWLWindow(pPageView, false);
+ CPWL_Wnd* pWnd = GetPWLWindow(pPageView);
CFX_FloatRect rcAnnot =
pWnd ? PWLtoFFL(pWnd->GetWindowRect()) : m_pWidget->GetRect();
CFX_FloatRect rcFocus = GetFocusBox(pPageView);
@@ -58,7 +58,7 @@
CPDFSDK_Annot* pAnnot,
CFX_RenderDevice* pDevice,
const CFX_Matrix& mtUser2Device) {
- CPWL_Wnd* pWnd = GetPWLWindow(pPageView, false);
+ CPWL_Wnd* pWnd = GetPWLWindow(pPageView);
if (pWnd) {
pWnd->DrawAppearance(pDevice, GetCurMatrix() * mtUser2Device);
return;
@@ -90,7 +90,7 @@
CPDFSDK_Annot* pAnnot,
uint32_t nFlags,
const CFX_PointF& point) {
- CPWL_Wnd* pWnd = GetPWLWindow(pPageView, true);
+ CPWL_Wnd* pWnd = CreateOrUpdatePWLWindow(pPageView);
if (!pWnd)
return false;
@@ -106,7 +106,7 @@
CPDFSDK_Annot* pAnnot,
uint32_t nFlags,
const CFX_PointF& point) {
- CPWL_Wnd* pWnd = GetPWLWindow(pPageView, false);
+ CPWL_Wnd* pWnd = GetPWLWindow(pPageView);
if (!pWnd)
return false;
@@ -118,7 +118,7 @@
bool CFFL_FormField::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
uint32_t nFlags,
const CFX_PointF& point) {
- CPWL_Wnd* pWnd = GetPWLWindow(pPageView, false);
+ CPWL_Wnd* pWnd = GetPWLWindow(pPageView);
if (!pWnd)
return false;
@@ -129,7 +129,7 @@
bool CFFL_FormField::OnMouseMove(CPDFSDK_PageView* pPageView,
uint32_t nFlags,
const CFX_PointF& point) {
- CPWL_Wnd* pWnd = GetPWLWindow(pPageView, false);
+ CPWL_Wnd* pWnd = GetPWLWindow(pPageView);
if (!pWnd)
return false;
@@ -144,21 +144,21 @@
if (!IsValid())
return false;
- CPWL_Wnd* pWnd = GetPWLWindow(pPageView, true);
+ CPWL_Wnd* pWnd = CreateOrUpdatePWLWindow(pPageView);
return pWnd && pWnd->OnMouseWheel(nFlags, FFLtoPWL(point), delta);
}
bool CFFL_FormField::OnRButtonDown(CPDFSDK_PageView* pPageView,
uint32_t nFlags,
const CFX_PointF& point) {
- CPWL_Wnd* pWnd = GetPWLWindow(pPageView, true);
+ CPWL_Wnd* pWnd = CreateOrUpdatePWLWindow(pPageView);
return pWnd && pWnd->OnRButtonDown(nFlags, FFLtoPWL(point));
}
bool CFFL_FormField::OnRButtonUp(CPDFSDK_PageView* pPageView,
uint32_t nFlags,
const CFX_PointF& point) {
- CPWL_Wnd* pWnd = GetPWLWindow(pPageView, false);
+ CPWL_Wnd* pWnd = GetPWLWindow(pPageView);
return pWnd && pWnd->OnRButtonUp(nFlags, FFLtoPWL(point));
}
@@ -166,7 +166,7 @@
if (!IsValid())
return false;
- CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView(), false);
+ CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView());
return pWnd && pWnd->OnKeyDown(nKeyCode, nFlags);
}
@@ -176,7 +176,7 @@
if (!IsValid())
return false;
- CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView(), false);
+ CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView());
return pWnd && pWnd->OnChar(nChar, nFlags);
}
@@ -192,7 +192,7 @@
if (!IsValid())
return WideString();
- CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView(), false);
+ CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView());
return pWnd ? pWnd->GetText() : WideString();
}
@@ -200,7 +200,7 @@
if (!IsValid())
return WideString();
- CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView(), false);
+ CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView());
return pWnd ? pWnd->GetSelectedText() : WideString();
}
@@ -208,7 +208,7 @@
if (!IsValid())
return;
- CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView(), false);
+ CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView());
if (!pWnd)
return;
@@ -219,7 +219,7 @@
if (!IsValid())
return false;
- CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView(), false);
+ CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView());
return pWnd && pWnd->SelectAllText();
}
@@ -227,7 +227,7 @@
if (!IsValid())
return false;
- CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView(), false);
+ CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView());
return pWnd && pWnd->CanUndo();
}
@@ -235,7 +235,7 @@
if (!IsValid())
return false;
- CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView(), false);
+ CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView());
return pWnd && pWnd->CanRedo();
}
@@ -243,7 +243,7 @@
if (!IsValid())
return false;
- CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView(), false);
+ CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView());
return pWnd && pWnd->Undo();
}
@@ -251,7 +251,7 @@
if (!IsValid())
return false;
- CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView(), false);
+ CPWL_Wnd* pWnd = GetPWLWindow(GetCurPageView());
return pWnd && pWnd->Redo();
}
@@ -259,7 +259,7 @@
CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pAnnot);
IPDF_Page* pPage = pWidget->GetPage();
CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, true);
- if (CPWL_Wnd* pWnd = GetPWLWindow(pPageView, true))
+ if (CPWL_Wnd* pWnd = CreateOrUpdatePWLWindow(pPageView))
pWnd->SetFocus();
m_bValid = true;
@@ -274,7 +274,7 @@
m_pFormFillEnv->GetPageView(m_pWidget->GetPage(), false);
if (!pPageView || !CommitData(pPageView, nFlag))
return;
- if (CPWL_Wnd* pWnd = GetPWLWindow(pPageView, false))
+ if (CPWL_Wnd* pWnd = GetPWLWindow(pPageView))
pWnd->KillFocus();
bool bDestroyPWLWindow;
@@ -343,13 +343,16 @@
return cp;
}
-CPWL_Wnd* CFFL_FormField::GetPWLWindow(CPDFSDK_PageView* pPageView, bool bNew) {
+CPWL_Wnd* CFFL_FormField::GetPWLWindow(CPDFSDK_PageView* pPageView) const {
DCHECK(pPageView);
auto it = m_Maps.find(pPageView);
- if (it == m_Maps.end()) {
- if (!bNew)
- return nullptr;
+ return it != m_Maps.end() ? it->second.get() : nullptr;
+}
+CPWL_Wnd* CFFL_FormField::CreateOrUpdatePWLWindow(CPDFSDK_PageView* pPageView) {
+ DCHECK(pPageView);
+ CPWL_Wnd* pWnd = GetPWLWindow(pPageView);
+ if (!pWnd) {
CPWL_Wnd::CreateParams cp = GetCreateParam();
// TODO(tsepez): maybe pass widget's value age as 4th arg.
auto pPrivateData = std::make_unique<CFFL_PrivateData>(
@@ -357,11 +360,6 @@
m_Maps[pPageView] = NewPWLWindow(cp, std::move(pPrivateData));
return m_Maps[pPageView].get();
}
-
- CPWL_Wnd* pWnd = it->second.get();
- if (!bNew)
- return pWnd;
-
const auto* pPrivateData =
static_cast<const CFFL_PrivateData*>(pWnd->GetAttachedData());
if (pPrivateData->AppearanceAgeEquals(m_pWidget->GetAppearanceAge()))
@@ -434,7 +432,7 @@
}
CFX_FloatRect CFFL_FormField::GetFocusBox(CPDFSDK_PageView* pPageView) {
- CPWL_Wnd* pWnd = GetPWLWindow(pPageView, false);
+ CPWL_Wnd* pWnd = GetPWLWindow(pPageView);
if (!pWnd)
return CFX_FloatRect();
@@ -533,7 +531,7 @@
CPWL_Wnd* CFFL_FormField::ResetPWLWindow(CPDFSDK_PageView* pPageView,
bool bRestoreValue) {
- return GetPWLWindow(pPageView, false);
+ return GetPWLWindow(pPageView);
}
void CFFL_FormField::OnTimerFired() {}
diff --git a/fpdfsdk/formfiller/cffl_formfield.h b/fpdfsdk/formfiller/cffl_formfield.h
index aa8dae3..2359970 100644
--- a/fpdfsdk/formfiller/cffl_formfield.h
+++ b/fpdfsdk/formfiller/cffl_formfield.h
@@ -123,7 +123,8 @@
virtual bool IsFieldFull(CPDFSDK_PageView* pPageView);
#endif // PDF_ENABLE_XFA
- CPWL_Wnd* GetPWLWindow(CPDFSDK_PageView* pPageView, bool bNew);
+ CPWL_Wnd* GetPWLWindow(CPDFSDK_PageView* pPageView) const;
+ CPWL_Wnd* CreateOrUpdatePWLWindow(CPDFSDK_PageView* pPageView);
void DestroyPWLWindow(CPDFSDK_PageView* pPageView);
void EscapeFiller(CPDFSDK_PageView* pPageView, bool bDestroyPWLWindow);
diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp
index ef60ab1..546eb3c 100644
--- a/fpdfsdk/formfiller/cffl_listbox.cpp
+++ b/fpdfsdk/formfiller/cffl_listbox.cpp
@@ -220,6 +220,6 @@
return pListBox && pListBox->IsItemSelected(index);
}
-CPWL_ListBox* CFFL_ListBox::GetListBox(CPDFSDK_PageView* pPageView) {
- return static_cast<CPWL_ListBox*>(GetPWLWindow(pPageView, /*bNew=*/false));
+CPWL_ListBox* CFFL_ListBox::GetListBox(CPDFSDK_PageView* pPageView) const {
+ return static_cast<CPWL_ListBox*>(GetPWLWindow(pPageView));
}
diff --git a/fpdfsdk/formfiller/cffl_listbox.h b/fpdfsdk/formfiller/cffl_listbox.h
index 7f39f5a..7553de4 100644
--- a/fpdfsdk/formfiller/cffl_listbox.h
+++ b/fpdfsdk/formfiller/cffl_listbox.h
@@ -38,7 +38,7 @@
bool IsIndexSelected(int index) override;
private:
- CPWL_ListBox* GetListBox(CPDFSDK_PageView* pPageView);
+ CPWL_ListBox* GetListBox(CPDFSDK_PageView* pPageView) const;
std::set<int> m_OriginSelections;
std::vector<int> m_State;
diff --git a/fpdfsdk/formfiller/cffl_radiobutton.cpp b/fpdfsdk/formfiller/cffl_radiobutton.cpp
index cd283e0..52fc5ec 100644
--- a/fpdfsdk/formfiller/cffl_radiobutton.cpp
+++ b/fpdfsdk/formfiller/cffl_radiobutton.cpp
@@ -58,7 +58,7 @@
}
CFFL_FormField::OnChar(pAnnot, nChar, nFlags);
- CPWL_RadioButton* pWnd = GetRadioButton(pPageView, true);
+ CPWL_RadioButton* pWnd = CreateOrUpdateRadioButton(pPageView);
if (pWnd && !pWnd->IsReadOnly())
pWnd->SetCheck(true);
return CommitData(pPageView, nFlags);
@@ -77,7 +77,7 @@
if (!IsValid())
return true;
- CPWL_RadioButton* pWnd = GetRadioButton(pPageView, true);
+ CPWL_RadioButton* pWnd = CreateOrUpdateRadioButton(pPageView);
if (pWnd)
pWnd->SetCheck(true);
@@ -85,12 +85,12 @@
}
bool CFFL_RadioButton::IsDataChanged(CPDFSDK_PageView* pPageView) {
- CPWL_RadioButton* pWnd = GetRadioButton(pPageView, false);
+ CPWL_RadioButton* pWnd = GetRadioButton(pPageView);
return pWnd && pWnd->IsChecked() != m_pWidget->IsChecked();
}
void CFFL_RadioButton::SaveData(CPDFSDK_PageView* pPageView) {
- CPWL_RadioButton* pWnd = GetRadioButton(pPageView, false);
+ CPWL_RadioButton* pWnd = GetRadioButton(pPageView);
if (!pWnd)
return;
@@ -117,7 +117,12 @@
SetChangeMark();
}
-CPWL_RadioButton* CFFL_RadioButton::GetRadioButton(CPDFSDK_PageView* pPageView,
- bool bNew) {
- return static_cast<CPWL_RadioButton*>(GetPWLWindow(pPageView, bNew));
+CPWL_RadioButton* CFFL_RadioButton::GetRadioButton(
+ CPDFSDK_PageView* pPageView) const {
+ return static_cast<CPWL_RadioButton*>(GetPWLWindow(pPageView));
+}
+
+CPWL_RadioButton* CFFL_RadioButton::CreateOrUpdateRadioButton(
+ CPDFSDK_PageView* pPageView) {
+ return static_cast<CPWL_RadioButton*>(CreateOrUpdatePWLWindow(pPageView));
}
diff --git a/fpdfsdk/formfiller/cffl_radiobutton.h b/fpdfsdk/formfiller/cffl_radiobutton.h
index 8ba2f28..c077208 100644
--- a/fpdfsdk/formfiller/cffl_radiobutton.h
+++ b/fpdfsdk/formfiller/cffl_radiobutton.h
@@ -33,7 +33,8 @@
void SaveData(CPDFSDK_PageView* pPageView) override;
private:
- CPWL_RadioButton* GetRadioButton(CPDFSDK_PageView* pPageView, bool bNew);
+ CPWL_RadioButton* GetRadioButton(CPDFSDK_PageView* pPageView) const;
+ CPWL_RadioButton* CreateOrUpdateRadioButton(CPDFSDK_PageView* pPageView);
};
#endif // FPDFSDK_FORMFILLER_CFFL_RADIOBUTTON_H_
diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp
index 2a223d6..28236ce 100644
--- a/fpdfsdk/formfiller/cffl_textfield.cpp
+++ b/fpdfsdk/formfiller/cffl_textfield.cpp
@@ -119,7 +119,7 @@
pAnnot->GetRect().GetOuterRect());
if (m_bValid) {
- if (CPWL_Wnd* pWnd = GetPWLWindow(pPageView, true))
+ if (CPWL_Wnd* pWnd = CreateOrUpdatePWLWindow(pPageView))
pWnd->SetFocus();
break;
}
@@ -142,12 +142,12 @@
}
bool CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) {
- CPWL_Edit* pEdit = GetEdit(pPageView, false);
+ CPWL_Edit* pEdit = GetEdit(pPageView);
return pEdit && pEdit->GetText() != m_pWidget->GetValue();
}
void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) {
- CPWL_Edit* pWnd = GetEdit(pPageView, false);
+ CPWL_Edit* pWnd = GetEdit(pPageView);
if (!pWnd)
return;
@@ -175,7 +175,7 @@
CPDFSDK_FieldAction& fa) {
switch (type) {
case CPDF_AAction::kKeyStroke:
- if (CPWL_Edit* pWnd = GetEdit(pPageView, false)) {
+ if (CPWL_Edit* pWnd = GetEdit(pPageView)) {
fa.bFieldFull = pWnd->IsTextFull();
fa.sValue = pWnd->GetText();
@@ -187,7 +187,7 @@
}
break;
case CPDF_AAction::kValidate:
- if (CPWL_Edit* pWnd = GetEdit(pPageView, false)) {
+ if (CPWL_Edit* pWnd = GetEdit(pPageView)) {
fa.sValue = pWnd->GetText();
}
break;
@@ -205,7 +205,7 @@
const CPDFSDK_FieldAction& fa) {
switch (type) {
case CPDF_AAction::kKeyStroke:
- if (CPWL_Edit* pEdit = GetEdit(pPageView, false)) {
+ if (CPWL_Edit* pEdit = GetEdit(pPageView)) {
pEdit->SetFocus();
pEdit->SetSelection(fa.nSelStart, fa.nSelEnd);
pEdit->ReplaceSelection(fa.sChange);
@@ -217,7 +217,7 @@
}
void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) {
- CPWL_Edit* pWnd = GetEdit(pPageView, false);
+ CPWL_Edit* pWnd = GetEdit(pPageView);
if (!pWnd)
return;
@@ -226,7 +226,7 @@
}
void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) {
- CPWL_Edit* pWnd = GetEdit(pPageView, true);
+ CPWL_Edit* pWnd = CreateOrUpdateEdit(pPageView);
if (!pWnd)
return;
@@ -236,7 +236,7 @@
#ifdef PDF_ENABLE_XFA
bool CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView) {
- CPWL_Edit* pWnd = GetEdit(pPageView, false);
+ CPWL_Edit* pWnd = GetEdit(pPageView);
return pWnd && pWnd->IsTextFull();
}
#endif // PDF_ENABLE_XFA
@@ -252,6 +252,10 @@
m_pFormFillEnv->OnSetFieldInputFocus(pBuffer, nCharacters, true);
}
-CPWL_Edit* CFFL_TextField::GetEdit(CPDFSDK_PageView* pPageView, bool bNew) {
- return static_cast<CPWL_Edit*>(GetPWLWindow(pPageView, bNew));
+CPWL_Edit* CFFL_TextField::GetEdit(CPDFSDK_PageView* pPageView) const {
+ return static_cast<CPWL_Edit*>(GetPWLWindow(pPageView));
+}
+
+CPWL_Edit* CFFL_TextField::CreateOrUpdateEdit(CPDFSDK_PageView* pPageView) {
+ return static_cast<CPWL_Edit*>(CreateOrUpdatePWLWindow(pPageView));
}
diff --git a/fpdfsdk/formfiller/cffl_textfield.h b/fpdfsdk/formfiller/cffl_textfield.h
index 5941b42..4ae5b2a 100644
--- a/fpdfsdk/formfiller/cffl_textfield.h
+++ b/fpdfsdk/formfiller/cffl_textfield.h
@@ -50,7 +50,8 @@
void OnSetFocus(CPWL_Edit* pEdit) override;
private:
- CPWL_Edit* GetEdit(CPDFSDK_PageView* pPageView, bool bNew);
+ CPWL_Edit* GetEdit(CPDFSDK_PageView* pPageView) const;
+ CPWL_Edit* CreateOrUpdateEdit(CPDFSDK_PageView* pPageView);
FFL_TextFieldState m_State;
};
diff --git a/fpdfsdk/formfiller/cffl_textobject.cpp b/fpdfsdk/formfiller/cffl_textobject.cpp
index 7d5f293..d4f5430 100644
--- a/fpdfsdk/formfiller/cffl_textobject.cpp
+++ b/fpdfsdk/formfiller/cffl_textobject.cpp
@@ -18,7 +18,9 @@
if (bRestoreValue)
RestoreState(pPageView);
- ObservedPtr<CPWL_Wnd> pRet(GetPWLWindow(pPageView, !bRestoreValue));
+ ObservedPtr<CPWL_Wnd> pRet(bRestoreValue
+ ? GetPWLWindow(pPageView)
+ : CreateOrUpdatePWLWindow(pPageView));
m_pWidget->UpdateField(); // May invoke JS, invalidating |pRet|.
return pRet.Get();
}
diff --git a/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp b/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp
index 33ac34f..f5e10b8 100644
--- a/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp
+++ b/fpdfsdk/pwl/cpwl_combo_box_embeddertest.cpp
@@ -64,8 +64,8 @@
pInteractiveFormFiller->GetFormFieldForTesting(pAnnotCombobox);
ASSERT_TRUE(m_pFormFiller);
- CPWL_Wnd* pWindow = m_pFormFiller->GetPWLWindow(
- m_pFormFillEnv->GetPageViewAtIndex(0), false);
+ CPWL_Wnd* pWindow =
+ m_pFormFiller->GetPWLWindow(m_pFormFillEnv->GetPageViewAtIndex(0));
ASSERT_TRUE(pWindow);
m_pComboBox = static_cast<CPWL_ComboBox*>(pWindow);
}
diff --git a/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp b/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp
index 8f566ea..ac217ce 100644
--- a/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp
+++ b/fpdfsdk/pwl/cpwl_edit_embeddertest.cpp
@@ -70,8 +70,8 @@
pInteractiveFormFiller->GetFormFieldForTesting(pAnnotTextField);
ASSERT_TRUE(m_pFormFiller);
- CPWL_Wnd* pWindow = m_pFormFiller->GetPWLWindow(
- m_pFormFillEnv->GetPageViewAtIndex(0), false);
+ CPWL_Wnd* pWindow =
+ m_pFormFiller->GetPWLWindow(m_pFormFillEnv->GetPageViewAtIndex(0));
ASSERT_TRUE(pWindow);
m_pEdit = static_cast<CPWL_Edit*>(pWindow);
}
diff --git a/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp b/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp
index 55238df..ed2ab15 100644
--- a/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp
+++ b/fpdfsdk/pwl/cpwl_special_button_embeddertest.cpp
@@ -74,8 +74,8 @@
form_filler_ = interactive_formfiller->GetFormFieldForTesting(annot);
ASSERT_TRUE(form_filler_);
- window_ =
- form_filler_->GetPWLWindow(formfill_env_->GetPageViewAtIndex(0), true);
+ window_ = form_filler_->CreateOrUpdatePWLWindow(
+ formfill_env_->GetPageViewAtIndex(0));
ASSERT_TRUE(window_);
}