From 469f6da247ffe77d0ae6089e5d93db0b0c0bb37e Mon Sep 17 00:00:00 2001 From: tsepez Date: Thu, 5 Jan 2017 19:21:39 -0800 Subject: use unique_ptr in cxfa_layoutprocessor.h Review-Url: https://codereview.chromium.org/2617483005 --- xfa/fxfa/parser/cxfa_layoutprocessor.cpp | 27 +++++++++------------------ xfa/fxfa/parser/cxfa_layoutprocessor.h | 19 ++++++++++--------- 2 files changed, 19 insertions(+), 27 deletions(-) (limited to 'xfa/fxfa') diff --git a/xfa/fxfa/parser/cxfa_layoutprocessor.cpp b/xfa/fxfa/parser/cxfa_layoutprocessor.cpp index ad1c2a936a..ea1064a4bc 100644 --- a/xfa/fxfa/parser/cxfa_layoutprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_layoutprocessor.cpp @@ -6,6 +6,7 @@ #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" +#include "third_party/base/ptr_util.h" #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_layoutpagemgr.h" @@ -30,14 +31,10 @@ CXFA_LayoutProcessor* CXFA_Document::GetDocLayout() { CXFA_LayoutProcessor::CXFA_LayoutProcessor(CXFA_Document* pDocument) : m_pDocument(pDocument), - m_pRootItemLayoutProcessor(nullptr), - m_pLayoutPageMgr(nullptr), m_nProgressCounter(0), m_bNeeLayout(true) {} -CXFA_LayoutProcessor::~CXFA_LayoutProcessor() { - ClearLayoutData(); -} +CXFA_LayoutProcessor::~CXFA_LayoutProcessor() {} CXFA_Document* CXFA_LayoutProcessor::GetDocument() const { return m_pDocument; @@ -47,8 +44,7 @@ int32_t CXFA_LayoutProcessor::StartLayout(bool bForceRestart) { if (!bForceRestart && !IsNeedLayout()) return 100; - delete m_pRootItemLayoutProcessor; - m_pRootItemLayoutProcessor = nullptr; + m_pRootItemLayoutProcessor.reset(); m_nProgressCounter = 0; CXFA_Node* pFormPacketNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)); @@ -59,14 +55,17 @@ int32_t CXFA_LayoutProcessor::StartLayout(bool bForceRestart) { pFormPacketNode->GetFirstChildByClass(XFA_Element::Subform); if (!pFormRoot) return -1; + if (!m_pLayoutPageMgr) - m_pLayoutPageMgr = new CXFA_LayoutPageMgr(this); + m_pLayoutPageMgr = pdfium::MakeUnique(this); if (!m_pLayoutPageMgr->InitLayoutPage(pFormRoot)) return -1; + if (!m_pLayoutPageMgr->PrepareFirstPage(pFormRoot)) return -1; - m_pRootItemLayoutProcessor = - new CXFA_ItemLayoutProcessor(pFormRoot, m_pLayoutPageMgr); + + m_pRootItemLayoutProcessor = pdfium::MakeUnique( + pFormRoot, m_pLayoutPageMgr.get()); m_nProgressCounter = 1; return 0; } @@ -150,14 +149,6 @@ CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetRootLayoutItem() const { return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetRootLayoutItem() : nullptr; } -void CXFA_LayoutProcessor::ClearLayoutData() { - delete m_pLayoutPageMgr; - m_pLayoutPageMgr = nullptr; - delete m_pRootItemLayoutProcessor; - m_pRootItemLayoutProcessor = nullptr; - m_nProgressCounter = 0; -} - bool CXFA_LayoutProcessor::IsNeedLayout() { return m_bNeeLayout || m_rgChangedContainers.GetSize() > 0; } diff --git a/xfa/fxfa/parser/cxfa_layoutprocessor.h b/xfa/fxfa/parser/cxfa_layoutprocessor.h index cf1b1e83b4..5861bf7048 100644 --- a/xfa/fxfa/parser/cxfa_layoutprocessor.h +++ b/xfa/fxfa/parser/cxfa_layoutprocessor.h @@ -7,6 +7,8 @@ #ifndef XFA_FXFA_PARSER_CXFA_LAYOUTPROCESSOR_H_ #define XFA_FXFA_PARSER_CXFA_LAYOUTPROCESSOR_H_ +#include + #include "core/fxcrt/fx_system.h" #include "xfa/fxfa/parser/xfa_object.h" @@ -30,23 +32,22 @@ class CXFA_LayoutProcessor { int32_t CountPages() const; CXFA_ContainerLayoutItem* GetPage(int32_t index) const; CXFA_LayoutItem* GetLayoutItem(CXFA_Node* pFormItem); - void AddChangedContainer(CXFA_Node* pContainer); void SetForceReLayout(bool bForceRestart) { m_bNeeLayout = bForceRestart; } CXFA_ContainerLayoutItem* GetRootLayoutItem() const; - CXFA_ItemLayoutProcessor* GetRootRootItemLayoutProcessor() { - return m_pRootItemLayoutProcessor; + CXFA_ItemLayoutProcessor* GetRootRootItemLayoutProcessor() const { + return m_pRootItemLayoutProcessor.get(); + } + CXFA_LayoutPageMgr* GetLayoutPageMgr() const { + return m_pLayoutPageMgr.get(); } - CXFA_LayoutPageMgr* GetLayoutPageMgr() { return m_pLayoutPageMgr; } private: - void ClearLayoutData(); - bool IsNeedLayout(); - CXFA_Document* m_pDocument; - CXFA_ItemLayoutProcessor* m_pRootItemLayoutProcessor; - CXFA_LayoutPageMgr* m_pLayoutPageMgr; + CXFA_Document* const m_pDocument; + std::unique_ptr m_pRootItemLayoutProcessor; + std::unique_ptr m_pLayoutPageMgr; CXFA_NodeArray m_rgChangedContainers; uint32_t m_nProgressCounter; bool m_bNeeLayout; -- cgit v1.2.3