diff options
author | tsepez <tsepez@chromium.org> | 2016-05-11 10:26:05 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-11 10:26:05 -0700 |
commit | f74ad998d2e8d2636fb25e94823946a3b151e34e (patch) | |
tree | 0b18e0a29fdc4bf1cce66ea437d8a4841b3daf4a /xfa/fwl/theme | |
parent | 2c3a16a7698ba15476173e849f82c97ea3da9939 (diff) | |
download | pdfium-f74ad998d2e8d2636fb25e94823946a3b151e34e.tar.xz |
Replace some calls to Release() with direct delete, part 1.
Searching for the anti-pattern:
void Release() { delete this; }
We must be explicit on the ownership model.
Add unique_ptrs as a result.
Review-Url: https://codereview.chromium.org/1960673003
Diffstat (limited to 'xfa/fwl/theme')
-rw-r--r-- | xfa/fwl/theme/cfwl_widgettp.cpp | 31 | ||||
-rw-r--r-- | xfa/fwl/theme/cfwl_widgettp.h | 2 |
2 files changed, 16 insertions, 17 deletions
diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp index fb1132beef..764c86e314 100644 --- a/xfa/fwl/theme/cfwl_widgettp.cpp +++ b/xfa/fwl/theme/cfwl_widgettp.cpp @@ -83,9 +83,9 @@ FX_BOOL CFWL_WidgetTP::DrawBackground(CFWL_ThemeBackground* pParams) { return TRUE; } FX_BOOL CFWL_WidgetTP::DrawText(CFWL_ThemeText* pParams) { - if (!m_pTextOut) { + if (!m_pTextOut) InitTTO(); - } + int32_t iLen = pParams->m_wsText.GetLength(); if (iLen <= 0) return FALSE; @@ -183,9 +183,8 @@ FWL_Error CFWL_WidgetTP::Initialize() { return FWL_Error::Succeeded; } FWL_Error CFWL_WidgetTP::Finalize() { - if (!m_pTextOut) { + if (!m_pTextOut) FinalizeTTO(); - } return FWL_Error::Succeeded; } CFWL_WidgetTP::~CFWL_WidgetTP() {} @@ -193,9 +192,9 @@ FWL_Error CFWL_WidgetTP::SetFont(IFWL_Widget* pWidget, const FX_WCHAR* strFont, FX_FLOAT fFontSize, FX_ARGB rgbFont) { - if (!m_pTextOut) { + if (!m_pTextOut) return FWL_Error::Succeeded; - } + m_pFDEFont = CFWL_FontManager::GetInstance()->FindFont(strFont, 0, 0); m_pTextOut->SetFont(m_pFDEFont); m_pTextOut->SetFontSize(fFontSize); @@ -206,9 +205,9 @@ FWL_Error CFWL_WidgetTP::SetFont(IFWL_Widget* pWidget, IFX_Font* pFont, FX_FLOAT fFontSize, FX_ARGB rgbFont) { - if (!m_pTextOut) { + if (!m_pTextOut) return FWL_Error::Succeeded; - } + m_pTextOut->SetFont(pFont); m_pTextOut->SetFontSize(fFontSize); m_pTextOut->SetTextColor(rgbFont); @@ -217,26 +216,26 @@ FWL_Error CFWL_WidgetTP::SetFont(IFWL_Widget* pWidget, IFX_Font* CFWL_WidgetTP::GetFont(IFWL_Widget* pWidget) { return m_pFDEFont; } + CFWL_WidgetTP::CFWL_WidgetTP() - : m_dwRefCount(1), m_pTextOut(NULL), m_pFDEFont(NULL), m_dwThemeID(0) {} + : m_dwRefCount(1), m_pFDEFont(nullptr), m_dwThemeID(0) {} + FWL_Error CFWL_WidgetTP::InitTTO() { - if (m_pTextOut) { + if (m_pTextOut) return FWL_Error::Succeeded; - } + m_pFDEFont = CFWL_FontManager::GetInstance()->FindFont(FX_WSTRC(L"Helvetica"), 0, 0); - m_pTextOut = new CFDE_TextOut; + m_pTextOut.reset(new CFDE_TextOut); m_pTextOut->SetFont(m_pFDEFont); m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize); m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor); m_pTextOut->SetEllipsisString(L"..."); return FWL_Error::Succeeded; } + FWL_Error CFWL_WidgetTP::FinalizeTTO() { - if (m_pTextOut) { - m_pTextOut->Release(); - m_pTextOut = NULL; - } + m_pTextOut.reset(); return FWL_Error::Succeeded; } diff --git a/xfa/fwl/theme/cfwl_widgettp.h b/xfa/fwl/theme/cfwl_widgettp.h index edb793def9..b66e19344e 100644 --- a/xfa/fwl/theme/cfwl_widgettp.h +++ b/xfa/fwl/theme/cfwl_widgettp.h @@ -220,7 +220,7 @@ class CFWL_WidgetTP { FWLTHEME_STATE eState, CFX_Matrix* pMatrix = NULL); uint32_t m_dwRefCount; - CFDE_TextOut* m_pTextOut; + std::unique_ptr<CFDE_TextOut> m_pTextOut; IFX_Font* m_pFDEFont; FX_FLOAT m_fValue; uint32_t m_dwValue; |