summaryrefslogtreecommitdiff
path: root/fpdfsdk/formfiller
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-08-03 11:06:49 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-03 11:06:49 -0700
commit2d5b020304e8a9aa8afeb632c61daa7ece87e36d (patch)
tree4d7f04d4800577fa597b4ca1f1b4d31b87194ef0 /fpdfsdk/formfiller
parentca27127240fbca2184f1c576b15b5212d5b314e6 (diff)
downloadpdfium-2d5b020304e8a9aa8afeb632c61daa7ece87e36d.tar.xz
Use smart pointers for class owned pointers
For all classes under /fpdfsdk, use smart pointer to replace raw pointer type for class owned member variables so that memory management will be easier. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2173253002
Diffstat (limited to 'fpdfsdk/formfiller')
-rw-r--r--fpdfsdk/formfiller/cffl_iformfiller.cpp11
-rw-r--r--fpdfsdk/formfiller/cffl_iformfiller.h6
-rw-r--r--fpdfsdk/formfiller/cffl_listbox.cpp10
-rw-r--r--fpdfsdk/formfiller/cffl_listbox.h3
-rw-r--r--fpdfsdk/formfiller/cffl_textfield.cpp9
-rw-r--r--fpdfsdk/formfiller/cffl_textfield.h6
6 files changed, 21 insertions, 24 deletions
diff --git a/fpdfsdk/formfiller/cffl_iformfiller.cpp b/fpdfsdk/formfiller/cffl_iformfiller.cpp
index 827c44a102..2fd4af1166 100644
--- a/fpdfsdk/formfiller/cffl_iformfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_iformfiller.cpp
@@ -24,11 +24,7 @@
CFFL_IFormFiller::CFFL_IFormFiller(CPDFDoc_Environment* pApp)
: m_pApp(pApp), m_bNotifying(FALSE) {}
-CFFL_IFormFiller::~CFFL_IFormFiller() {
- for (auto& it : m_Maps)
- delete it.second;
- m_Maps.clear();
-}
+CFFL_IFormFiller::~CFFL_IFormFiller() {}
FX_BOOL CFFL_IFormFiller::Annot_HitTest(CPDFSDK_PageView* pPageView,
CPDFSDK_Annot* pAnnot,
@@ -511,7 +507,7 @@ CFFL_FormFiller* CFFL_IFormFiller::GetFormFiller(CPDFSDK_Annot* pAnnot,
FX_BOOL bRegister) {
auto it = m_Maps.find(pAnnot);
if (it != m_Maps.end())
- return it->second;
+ return it->second.get();
if (!bRegister)
return nullptr;
@@ -547,7 +543,7 @@ CFFL_FormFiller* CFFL_IFormFiller::GetFormFiller(CPDFSDK_Annot* pAnnot,
if (!pFormFiller)
return nullptr;
- m_Maps[pAnnot] = pFormFiller;
+ m_Maps[pAnnot].reset(pFormFiller);
return pFormFiller;
}
@@ -562,7 +558,6 @@ void CFFL_IFormFiller::UnRegisterFormFiller(CPDFSDK_Annot* pAnnot) {
if (it == m_Maps.end())
return;
- delete it->second;
m_Maps.erase(it);
}
diff --git a/fpdfsdk/formfiller/cffl_iformfiller.h b/fpdfsdk/formfiller/cffl_iformfiller.h
index b01159475a..b5b0e4aed6 100644
--- a/fpdfsdk/formfiller/cffl_iformfiller.h
+++ b/fpdfsdk/formfiller/cffl_iformfiller.h
@@ -8,6 +8,7 @@
#define FPDFSDK_FORMFILLER_CFFL_IFORMFILLER_H_
#include <map>
+#include <memory>
#include "fpdfsdk/include/fsdk_define.h"
#include "fpdfsdk/pdfwindow/PWL_Edit.h"
@@ -140,7 +141,8 @@ class CFFL_IFormFiller : public IPWL_Filler_Notify {
#endif // PDF_ENABLE_XFA
private:
- using CFFL_Widget2Filler = std::map<CPDFSDK_Annot*, CFFL_FormFiller*>;
+ using CFFL_Widget2Filler =
+ std::map<CPDFSDK_Annot*, std::unique_ptr<CFFL_FormFiller>>;
// IPWL_Filler_Notify:
void QueryWherePopup(void* pPrivateData,
@@ -170,7 +172,7 @@ class CFFL_IFormFiller : public IPWL_Filler_Notify {
#endif // PDF_ENABLE_XFA
void UnRegisterFormFiller(CPDFSDK_Annot* pAnnot);
- CPDFDoc_Environment* m_pApp;
+ CPDFDoc_Environment* const m_pApp;
CFFL_Widget2Filler m_Maps;
FX_BOOL m_bNotifying;
};
diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp
index cbac83cb55..a70a1f33ff 100644
--- a/fpdfsdk/formfiller/cffl_listbox.cpp
+++ b/fpdfsdk/formfiller/cffl_listbox.cpp
@@ -16,11 +16,9 @@
#define FFL_DEFAULTLISTBOXFONTSIZE 12.0f
CFFL_ListBox::CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget)
- : CFFL_FormFiller(pApp, pWidget), m_pFontMap(nullptr) {}
+ : CFFL_FormFiller(pApp, pWidget) {}
-CFFL_ListBox::~CFFL_ListBox() {
- delete m_pFontMap;
-}
+CFFL_ListBox::~CFFL_ListBox() {}
PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() {
PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
@@ -37,8 +35,8 @@ PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() {
cp.fFontSize = FFL_DEFAULTLISTBOXFONTSIZE;
if (!m_pFontMap)
- m_pFontMap = new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler());
- cp.pFontMap = m_pFontMap;
+ m_pFontMap.reset(new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler()));
+ cp.pFontMap = m_pFontMap.get();
return cp;
}
diff --git a/fpdfsdk/formfiller/cffl_listbox.h b/fpdfsdk/formfiller/cffl_listbox.h
index 43fbab6642..4d1f64f113 100644
--- a/fpdfsdk/formfiller/cffl_listbox.h
+++ b/fpdfsdk/formfiller/cffl_listbox.h
@@ -7,6 +7,7 @@
#ifndef FPDFSDK_FORMFILLER_CFFL_LISTBOX_H_
#define FPDFSDK_FORMFILLER_CFFL_LISTBOX_H_
+#include <memory>
#include <set>
#include "fpdfsdk/formfiller/cffl_formfiller.h"
@@ -37,7 +38,7 @@ class CFFL_ListBox : public CFFL_FormFiller {
FX_BOOL bRestoreValue) override;
private:
- CBA_FontMap* m_pFontMap;
+ std::unique_ptr<CBA_FontMap> m_pFontMap;
std::set<int> m_OriginSelections;
CFX_ArrayTemplate<int> m_State;
};
diff --git a/fpdfsdk/formfiller/cffl_textfield.cpp b/fpdfsdk/formfiller/cffl_textfield.cpp
index d24452fd45..76f4b7414d 100644
--- a/fpdfsdk/formfiller/cffl_textfield.cpp
+++ b/fpdfsdk/formfiller/cffl_textfield.cpp
@@ -11,14 +11,11 @@
#include "fpdfsdk/include/fsdk_mgr.h"
CFFL_TextField::CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot)
- : CFFL_FormFiller(pApp, pAnnot), m_pFontMap(nullptr) {
- m_State.nStart = m_State.nEnd = 0;
-}
+ : CFFL_FormFiller(pApp, pAnnot) {}
CFFL_TextField::~CFFL_TextField() {
for (const auto& it : m_Maps)
it.second->InvalidateFocusHandler(this);
- delete m_pFontMap;
}
PWL_CREATEPARAM CFFL_TextField::GetCreateParam() {
@@ -68,8 +65,8 @@ PWL_CREATEPARAM CFFL_TextField::GetCreateParam() {
}
if (!m_pFontMap)
- m_pFontMap = new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler());
- cp.pFontMap = m_pFontMap;
+ m_pFontMap.reset(new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler()));
+ cp.pFontMap = m_pFontMap.get();
cp.pFocusHandler = this;
return cp;
diff --git a/fpdfsdk/formfiller/cffl_textfield.h b/fpdfsdk/formfiller/cffl_textfield.h
index 34968e8fc3..5f9fc5d3bc 100644
--- a/fpdfsdk/formfiller/cffl_textfield.h
+++ b/fpdfsdk/formfiller/cffl_textfield.h
@@ -7,6 +7,8 @@
#ifndef FPDFSDK_FORMFILLER_CFFL_TEXTFIELD_H_
#define FPDFSDK_FORMFILLER_CFFL_TEXTFIELD_H_
+#include <memory>
+
#include "fpdfsdk/formfiller/cffl_formfiller.h"
#define BF_ALIGN_LEFT 0
@@ -16,6 +18,8 @@
class CBA_FontMap;
struct FFL_TextFieldState {
+ FFL_TextFieldState() : nStart(0), nEnd(0) {}
+
int nStart;
int nEnd;
CFX_WideString sValue;
@@ -56,7 +60,7 @@ class CFFL_TextField : public CFFL_FormFiller, public IPWL_FocusHandler {
#endif // PDF_ENABLE_XFA
private:
- CBA_FontMap* m_pFontMap;
+ std::unique_ptr<CBA_FontMap> m_pFontMap;
FFL_TextFieldState m_State;
};