summaryrefslogtreecommitdiff
path: root/xfa/fwl/core
diff options
context:
space:
mode:
authorweili <weili@chromium.org>2016-08-04 16:37:48 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-04 16:37:48 -0700
commit1b4f6b36b3ed8d1f6cea96bc32c1b376f4a499bc (patch)
treeaa3ba6730495096411f2a3555c74e83f5d1fca11 /xfa/fwl/core
parent52a5005c453a9e08384e375ae51c5f1ad628fe86 (diff)
downloadpdfium-1b4f6b36b3ed8d1f6cea96bc32c1b376f4a499bc.tar.xz
Use smart pointers for class owned pointers
For classes under xfa/fgas, xfa/fwl/basewidget, and xfa/fwl/core, use smart pointers instead of raw pointer to make memory management easier. BUG=pdfium:518 Review-Url: https://codereview.chromium.org/2207093005
Diffstat (limited to 'xfa/fwl/core')
-rw-r--r--xfa/fwl/core/fwl_formimp.cpp15
-rw-r--r--xfa/fwl/core/fwl_formimp.h4
-rw-r--r--xfa/fwl/core/fwl_noteimp.cpp21
-rw-r--r--xfa/fwl/core/fwl_noteimp.h5
-rw-r--r--xfa/fwl/core/fwl_widgetimp.cpp9
-rw-r--r--xfa/fwl/core/fwl_widgetimp.h6
6 files changed, 31 insertions, 29 deletions
diff --git a/xfa/fwl/core/fwl_formimp.cpp b/xfa/fwl/core/fwl_formimp.cpp
index a3fc6be816..1b82ff59f8 100644
--- a/xfa/fwl/core/fwl_formimp.cpp
+++ b/xfa/fwl/core/fwl_formimp.cpp
@@ -75,7 +75,6 @@ CFWL_FormImp::CFWL_FormImp(const CFWL_WidgetImpProperties& properties,
m_pMinBox(nullptr),
m_pMaxBox(nullptr),
m_pCaptionBox(nullptr),
- m_pNoteLoop(nullptr),
m_pSubFocus(nullptr),
m_fCXBorder(0),
m_fCYBorder(0),
@@ -100,7 +99,6 @@ CFWL_FormImp::CFWL_FormImp(const CFWL_WidgetImpProperties& properties,
CFWL_FormImp::~CFWL_FormImp() {
RemoveSysButtons();
- delete m_pNoteLoop;
}
FWL_Error CFWL_FormImp::GetClassName(CFX_WideString& wsClass) const {
@@ -371,13 +369,16 @@ FWL_Error CFWL_FormImp::DrawWidget(CFX_Graphics* pGraphics,
#endif
return FWL_Error::Succeeded;
}
+
FWL_FORMSIZE CFWL_FormImp::GetFormSize() {
return m_eFormSize;
}
+
FWL_Error CFWL_FormImp::SetFormSize(FWL_FORMSIZE eFormSize) {
m_eFormSize = eFormSize;
return FWL_Error::Succeeded;
}
+
IFWL_Widget* CFWL_FormImp::DoModal() {
IFWL_App* pApp = GetOwnerApp();
if (!pApp)
@@ -387,8 +388,8 @@ IFWL_Widget* CFWL_FormImp::DoModal() {
if (!pDriver)
return nullptr;
- m_pNoteLoop = new CFWL_NoteLoop(this);
- pDriver->PushNoteLoop(m_pNoteLoop);
+ m_pNoteLoop.reset(new CFWL_NoteLoop(this));
+ pDriver->PushNoteLoop(m_pNoteLoop.get());
m_bDoModalFlag = TRUE;
SetStates(FWL_WGTSTATE_Invisible, FALSE);
pDriver->Run();
@@ -396,13 +397,14 @@ IFWL_Widget* CFWL_FormImp::DoModal() {
#else
pDriver->PopNoteLoop();
#endif
- delete m_pNoteLoop;
- m_pNoteLoop = nullptr;
+ m_pNoteLoop.reset();
return nullptr;
}
+
IFWL_Widget* CFWL_FormImp::DoModal(uint32_t& dwCommandID) {
return DoModal();
}
+
FWL_Error CFWL_FormImp::EndDoModal() {
if (!m_pNoteLoop)
return FWL_Error::Indefinite;
@@ -426,6 +428,7 @@ FWL_Error CFWL_FormImp::EndDoModal() {
return m_pNoteLoop->EndModalLoop();
#endif
}
+
FWL_Error CFWL_FormImp::SetBorderRegion(CFX_Path* pPath) {
return FWL_Error::Succeeded;
}
diff --git a/xfa/fwl/core/fwl_formimp.h b/xfa/fwl/core/fwl_formimp.h
index ee1507d17e..c88b5e683b 100644
--- a/xfa/fwl/core/fwl_formimp.h
+++ b/xfa/fwl/core/fwl_formimp.h
@@ -7,6 +7,8 @@
#ifndef XFA_FWL_CORE_FWL_FORMIMP_H_
#define XFA_FWL_CORE_FWL_FORMIMP_H_
+#include <memory>
+
#include "xfa/fwl/core/fwl_widgetimp.h"
#include "xfa/fwl/core/ifwl_form.h"
@@ -134,7 +136,7 @@ class CFWL_FormImp : public CFWL_WidgetImp {
CFWL_SysBtn* m_pMinBox;
CFWL_SysBtn* m_pMaxBox;
CFWL_SysBtn* m_pCaptionBox;
- CFWL_NoteLoop* m_pNoteLoop;
+ std::unique_ptr<CFWL_NoteLoop> m_pNoteLoop;
CFWL_WidgetImp* m_pSubFocus;
RestoreInfo m_InfoStart;
FX_FLOAT m_fCXBorder;
diff --git a/xfa/fwl/core/fwl_noteimp.cpp b/xfa/fwl/core/fwl_noteimp.cpp
index f115e2fd1b..8ecec2df65 100644
--- a/xfa/fwl/core/fwl_noteimp.cpp
+++ b/xfa/fwl/core/fwl_noteimp.cpp
@@ -70,10 +70,9 @@ CFWL_NoteDriver::CFWL_NoteDriver()
m_pFocus(nullptr),
m_pGrab(nullptr),
m_pNoteLoop(new CFWL_NoteLoop) {
- PushNoteLoop(m_pNoteLoop);
+ PushNoteLoop(m_pNoteLoop.get());
}
CFWL_NoteDriver::~CFWL_NoteDriver() {
- delete m_pNoteLoop;
ClearInvalidEventTargets(TRUE);
}
@@ -655,6 +654,8 @@ void CFWL_NoteDriver::ClearInvalidEventTargets(FX_BOOL bRemoveAll) {
class CFWL_CoreToolTipDP : public IFWL_ToolTipDP {
public:
+ CFWL_CoreToolTipDP(int32_t iInitDelayTime, int32_t iAutoDelayTime);
+
// IFWL_ToolTipDP
FWL_Error GetCaption(IFWL_Widget* pWidget,
CFX_WideString& wsCaption) override;
@@ -664,7 +665,6 @@ class CFWL_CoreToolTipDP : public IFWL_ToolTipDP {
CFX_SizeF GetToolTipIconSize(IFWL_Widget* pWidget) override;
CFX_RectF GetAnchor();
- CFWL_CoreToolTipDP();
CFX_WideString m_wsCaption;
int32_t m_nInitDelayTime;
@@ -672,9 +672,9 @@ class CFWL_CoreToolTipDP : public IFWL_ToolTipDP {
CFX_RectF m_fAnchor;
};
-CFWL_CoreToolTipDP::CFWL_CoreToolTipDP() {
- m_nInitDelayTime = 500;
- m_nAutoPopDelayTime = 50000;
+CFWL_CoreToolTipDP::CFWL_CoreToolTipDP(int32_t iInitDelayTime,
+ int32_t iAutoDelayTime)
+ : m_nInitDelayTime(iInitDelayTime), m_nAutoPopDelayTime(iAutoDelayTime) {
m_fAnchor.Set(0.0, 0.0, 0.0, 0.0);
}
@@ -773,11 +773,9 @@ FX_BOOL CFWL_EventTarget::IsFilterEvent(CFWL_Event* pEvent, uint32_t dwFilter) {
CFWL_ToolTipContainer* CFWL_ToolTipContainer::s_pInstance = nullptr;
-CFWL_ToolTipContainer::CFWL_ToolTipContainer() : m_pToolTipImp(nullptr) {
- m_ToolTipDp = new CFWL_CoreToolTipDP;
- m_ToolTipDp->m_nInitDelayTime = 0;
- m_ToolTipDp->m_nAutoPopDelayTime = 2000;
-}
+CFWL_ToolTipContainer::CFWL_ToolTipContainer()
+ : m_pToolTipImp(nullptr), m_pToolTipDp(new CFWL_CoreToolTipDP(0, 2000)) {}
+
CFWL_ToolTipContainer::~CFWL_ToolTipContainer() {
if (m_pToolTipImp) {
IFWL_ToolTip* pToolTip =
@@ -785,7 +783,6 @@ CFWL_ToolTipContainer::~CFWL_ToolTipContainer() {
pToolTip->Finalize();
delete pToolTip;
}
- delete m_ToolTipDp;
}
// static
diff --git a/xfa/fwl/core/fwl_noteimp.h b/xfa/fwl/core/fwl_noteimp.h
index c92395a13a..f923c395d5 100644
--- a/xfa/fwl/core/fwl_noteimp.h
+++ b/xfa/fwl/core/fwl_noteimp.h
@@ -7,6 +7,7 @@
#ifndef XFA_FWL_CORE_FWL_NOTEIMP_H_
#define XFA_FWL_CORE_FWL_NOTEIMP_H_
+#include <memory>
#include <unordered_map>
#include "xfa/fwl/core/cfwl_event.h"
@@ -115,7 +116,7 @@ class CFWL_NoteDriver {
IFWL_Widget* m_pHover;
IFWL_Widget* m_pFocus;
IFWL_Widget* m_pGrab;
- CFWL_NoteLoop* m_pNoteLoop;
+ std::unique_ptr<CFWL_NoteLoop> m_pNoteLoop;
};
class CFWL_EventTarget {
@@ -147,7 +148,7 @@ class CFWL_ToolTipContainer final {
~CFWL_ToolTipContainer();
CFWL_ToolTipImp* m_pToolTipImp;
- CFWL_CoreToolTipDP* m_ToolTipDp;
+ std::unique_ptr<CFWL_CoreToolTipDP> m_pToolTipDp;
private:
static CFWL_ToolTipContainer* s_pInstance;
diff --git a/xfa/fwl/core/fwl_widgetimp.cpp b/xfa/fwl/core/fwl_widgetimp.cpp
index 52a2978908..3aa6233ae5 100644
--- a/xfa/fwl/core/fwl_widgetimp.cpp
+++ b/xfa/fwl/core/fwl_widgetimp.cpp
@@ -531,7 +531,8 @@ void CFWL_WidgetImp::SetAssociateWidget(void* pAssociate) {
CFWL_WidgetImp::CFWL_WidgetImp(const CFWL_WidgetImpProperties& properties,
IFWL_Widget* pOuter)
- : m_pProperties(new CFWL_WidgetImpProperties),
+ : m_pWidgetMgr(CFWL_WidgetMgr::GetInstance()),
+ m_pProperties(new CFWL_WidgetImpProperties(properties)),
m_pDelegate(nullptr),
m_pCurDelegate(nullptr),
m_pOuter(pOuter),
@@ -540,14 +541,10 @@ CFWL_WidgetImp::CFWL_WidgetImp(const CFWL_WidgetImpProperties& properties,
m_pAssociate(nullptr),
m_iLock(0),
m_nEventKey(0) {
- *m_pProperties = properties;
- m_pWidgetMgr = CFWL_WidgetMgr::GetInstance();
ASSERT(m_pWidgetMgr);
}
-CFWL_WidgetImp::~CFWL_WidgetImp() {
- delete m_pProperties;
-}
+CFWL_WidgetImp::~CFWL_WidgetImp() {}
FX_BOOL CFWL_WidgetImp::IsEnabled() const {
return (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == 0;
diff --git a/xfa/fwl/core/fwl_widgetimp.h b/xfa/fwl/core/fwl_widgetimp.h
index d8c4fe6eb6..cbc89b9a8b 100644
--- a/xfa/fwl/core/fwl_widgetimp.h
+++ b/xfa/fwl/core/fwl_widgetimp.h
@@ -7,6 +7,8 @@
#ifndef XFA_FWL_CORE_FWL_WIDGETIMP_H_
#define XFA_FWL_CORE_FWL_WIDGETIMP_H_
+#include <memory>
+
#include "core/fxcrt/include/fx_coordinates.h"
#include "core/fxcrt/include/fx_system.h"
#include "xfa/fwl/core/cfwl_event.h"
@@ -154,9 +156,9 @@ class CFWL_WidgetImp {
FX_BOOL IsParent(IFWL_Widget* pParent);
- CFWL_WidgetMgr* m_pWidgetMgr;
+ CFWL_WidgetMgr* const m_pWidgetMgr;
CFWL_AppImp* m_pOwnerApp;
- CFWL_WidgetImpProperties* m_pProperties;
+ std::unique_ptr<CFWL_WidgetImpProperties> m_pProperties;
IFWL_WidgetDelegate* m_pDelegate;
IFWL_WidgetDelegate* m_pCurDelegate;
IFWL_Widget* m_pOuter;