From 29bd35451003e58ef4be06413cce5544c16c395d Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 22 Mar 2017 13:24:18 -0700 Subject: Use unique_ptr in xfa_ffpushbutton.h Change-Id: I605c1219b1090eb13d22237fa1d61d9defe137d5 Reviewed-on: https://pdfium-review.googlesource.com/3151 Commit-Queue: Tom Sepez Commit-Queue: dsinclair Reviewed-by: dsinclair --- xfa/fxfa/app/xfa_ffpushbutton.cpp | 62 ++++++++++++++++++--------------------- xfa/fxfa/app/xfa_ffpushbutton.h | 10 ++++--- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/xfa/fxfa/app/xfa_ffpushbutton.cpp b/xfa/fxfa/app/xfa_ffpushbutton.cpp index 7989e3207d..2233c5a6bb 100644 --- a/xfa/fxfa/app/xfa_ffpushbutton.cpp +++ b/xfa/fxfa/app/xfa_ffpushbutton.cpp @@ -19,12 +19,7 @@ #include "xfa/fxgraphics/cfx_path.h" CXFA_FFPushButton::CXFA_FFPushButton(CXFA_WidgetAcc* pDataAcc) - : CXFA_FFField(pDataAcc), - m_pRolloverTextLayout(nullptr), - m_pDownTextLayout(nullptr), - m_pDownProvider(nullptr), - m_pRollProvider(nullptr), - m_pOldDelegate(nullptr) {} + : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} CXFA_FFPushButton::~CXFA_FFPushButton() { CXFA_FFPushButton::UnloadWidget(); @@ -86,14 +81,10 @@ void CXFA_FFPushButton::UpdateWidgetProperty() { } void CXFA_FFPushButton::UnloadWidget() { - delete m_pRolloverTextLayout; - m_pRolloverTextLayout = nullptr; - delete m_pDownTextLayout; - m_pDownTextLayout = nullptr; - delete m_pDownProvider; - m_pDownProvider = nullptr; - delete m_pRollProvider; - m_pRollProvider = nullptr; + m_pRolloverTextLayout.reset(); + m_pDownTextLayout.reset(); + m_pRollProvider.reset(); + m_pDownProvider.reset(); CXFA_FFField::UnloadWidget(); } @@ -125,36 +116,41 @@ float CXFA_FFPushButton::GetLineWidth() { } return 0; } + FX_ARGB CXFA_FFPushButton::GetLineColor() { return 0xFF000000; } + FX_ARGB CXFA_FFPushButton::GetFillColor() { return 0xFFFFFFFF; } + void CXFA_FFPushButton::LoadHighlightCaption() { CXFA_Caption caption = m_pDataAcc->GetCaption(); - if (caption && caption.GetPresence() != XFA_ATTRIBUTEENUM_Hidden) { - { - CFX_WideString wsRollover; - bool bRichText; - if (m_pDataAcc->GetButtonRollover(wsRollover, bRichText)) { - if (!m_pRollProvider) { - m_pRollProvider = - new CXFA_TextProvider(m_pDataAcc, XFA_TEXTPROVIDERTYPE_Rollover); - } - m_pRolloverTextLayout = new CXFA_TextLayout(m_pRollProvider); - } - CFX_WideString wsDown; - if (m_pDataAcc->GetButtonDown(wsDown, bRichText)) { - if (!m_pDownProvider) { - m_pDownProvider = - new CXFA_TextProvider(m_pDataAcc, XFA_TEXTPROVIDERTYPE_Down); - } - m_pDownTextLayout = new CXFA_TextLayout(m_pDownProvider); - } + if (!caption || caption.GetPresence() == XFA_ATTRIBUTEENUM_Hidden) + return; + + bool bRichText; + CFX_WideString wsRollover; + if (m_pDataAcc->GetButtonRollover(wsRollover, bRichText)) { + if (!m_pRollProvider) { + m_pRollProvider = pdfium::MakeUnique( + m_pDataAcc, XFA_TEXTPROVIDERTYPE_Rollover); + } + m_pRolloverTextLayout = + pdfium::MakeUnique(m_pRollProvider.get()); + } + CFX_WideString wsDown; + if (m_pDataAcc->GetButtonDown(wsDown, bRichText)) { + if (!m_pDownProvider) { + m_pDownProvider = pdfium::MakeUnique( + m_pDataAcc, XFA_TEXTPROVIDERTYPE_Down); } + m_pDownTextLayout = + pdfium::MakeUnique(m_pDownProvider.get()); } } + void CXFA_FFPushButton::LayoutHighlightCaption() { CFX_SizeF sz(m_rtCaption.width, m_rtCaption.height); LayoutCaption(); diff --git a/xfa/fxfa/app/xfa_ffpushbutton.h b/xfa/fxfa/app/xfa_ffpushbutton.h index 70853e8942..7e6e9e57d5 100644 --- a/xfa/fxfa/app/xfa_ffpushbutton.h +++ b/xfa/fxfa/app/xfa_ffpushbutton.h @@ -7,6 +7,8 @@ #ifndef XFA_FXFA_APP_XFA_FFPUSHBUTTON_H_ #define XFA_FXFA_APP_XFA_FFPUSHBUTTON_H_ +#include + #include "xfa/fxfa/app/xfa_fffield.h" #define XFA_FWL_PSBSTYLEEXT_HiliteNone (0L << 0) @@ -42,10 +44,10 @@ class CXFA_FFPushButton : public CXFA_FFField { FX_ARGB GetLineColor(); FX_ARGB GetFillColor(); - CXFA_TextLayout* m_pRolloverTextLayout; - CXFA_TextLayout* m_pDownTextLayout; - CXFA_TextProvider* m_pDownProvider; - CXFA_TextProvider* m_pRollProvider; + std::unique_ptr m_pRolloverTextLayout; + std::unique_ptr m_pDownTextLayout; + std::unique_ptr m_pRollProvider; + std::unique_ptr m_pDownProvider; IFWL_WidgetDelegate* m_pOldDelegate; }; -- cgit v1.2.3