Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: xfa/fxfa/parser/cxfa_layoutprocessor.cpp

Issue 2617483005: use unique_ptr in cxfa_layoutprocessor.h (Closed)
Patch Set: Unused method Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fxfa/parser/cxfa_layoutprocessor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" 7 #include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
8 8
9 #include "third_party/base/ptr_util.h"
9 #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" 10 #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h"
10 #include "xfa/fxfa/parser/cxfa_document.h" 11 #include "xfa/fxfa/parser/cxfa_document.h"
11 #include "xfa/fxfa/parser/cxfa_layoutpagemgr.h" 12 #include "xfa/fxfa/parser/cxfa_layoutpagemgr.h"
12 #include "xfa/fxfa/parser/cxfa_measurement.h" 13 #include "xfa/fxfa/parser/cxfa_measurement.h"
13 #include "xfa/fxfa/parser/xfa_document_datamerger_imp.h" 14 #include "xfa/fxfa/parser/xfa_document_datamerger_imp.h"
14 #include "xfa/fxfa/parser/xfa_layout_itemlayout.h" 15 #include "xfa/fxfa/parser/xfa_layout_itemlayout.h"
15 #include "xfa/fxfa/parser/xfa_localemgr.h" 16 #include "xfa/fxfa/parser/xfa_localemgr.h"
16 #include "xfa/fxfa/parser/xfa_object.h" 17 #include "xfa/fxfa/parser/xfa_object.h"
17 #include "xfa/fxfa/parser/xfa_utils.h" 18 #include "xfa/fxfa/parser/xfa_utils.h"
18 19
19 CXFA_LayoutProcessor* CXFA_Document::GetLayoutProcessor() { 20 CXFA_LayoutProcessor* CXFA_Document::GetLayoutProcessor() {
20 if (!m_pLayoutProcessor) { 21 if (!m_pLayoutProcessor) {
21 m_pLayoutProcessor = new CXFA_LayoutProcessor(this); 22 m_pLayoutProcessor = new CXFA_LayoutProcessor(this);
22 ASSERT(m_pLayoutProcessor); 23 ASSERT(m_pLayoutProcessor);
23 } 24 }
24 return m_pLayoutProcessor; 25 return m_pLayoutProcessor;
25 } 26 }
26 27
27 CXFA_LayoutProcessor* CXFA_Document::GetDocLayout() { 28 CXFA_LayoutProcessor* CXFA_Document::GetDocLayout() {
28 return GetLayoutProcessor(); 29 return GetLayoutProcessor();
29 } 30 }
30 31
31 CXFA_LayoutProcessor::CXFA_LayoutProcessor(CXFA_Document* pDocument) 32 CXFA_LayoutProcessor::CXFA_LayoutProcessor(CXFA_Document* pDocument)
32 : m_pDocument(pDocument), 33 : m_pDocument(pDocument),
33 m_pRootItemLayoutProcessor(nullptr),
34 m_pLayoutPageMgr(nullptr),
35 m_nProgressCounter(0), 34 m_nProgressCounter(0),
36 m_bNeeLayout(true) {} 35 m_bNeeLayout(true) {}
37 36
38 CXFA_LayoutProcessor::~CXFA_LayoutProcessor() { 37 CXFA_LayoutProcessor::~CXFA_LayoutProcessor() {}
39 ClearLayoutData();
40 }
41 38
42 CXFA_Document* CXFA_LayoutProcessor::GetDocument() const { 39 CXFA_Document* CXFA_LayoutProcessor::GetDocument() const {
43 return m_pDocument; 40 return m_pDocument;
44 } 41 }
45 42
46 int32_t CXFA_LayoutProcessor::StartLayout(bool bForceRestart) { 43 int32_t CXFA_LayoutProcessor::StartLayout(bool bForceRestart) {
47 if (!bForceRestart && !IsNeedLayout()) 44 if (!bForceRestart && !IsNeedLayout())
48 return 100; 45 return 100;
49 46
50 delete m_pRootItemLayoutProcessor; 47 m_pRootItemLayoutProcessor.reset();
51 m_pRootItemLayoutProcessor = nullptr;
52 m_nProgressCounter = 0; 48 m_nProgressCounter = 0;
53 CXFA_Node* pFormPacketNode = 49 CXFA_Node* pFormPacketNode =
54 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)); 50 ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form));
55 if (!pFormPacketNode) 51 if (!pFormPacketNode)
56 return -1; 52 return -1;
57 53
58 CXFA_Node* pFormRoot = 54 CXFA_Node* pFormRoot =
59 pFormPacketNode->GetFirstChildByClass(XFA_Element::Subform); 55 pFormPacketNode->GetFirstChildByClass(XFA_Element::Subform);
60 if (!pFormRoot) 56 if (!pFormRoot)
61 return -1; 57 return -1;
58
62 if (!m_pLayoutPageMgr) 59 if (!m_pLayoutPageMgr)
63 m_pLayoutPageMgr = new CXFA_LayoutPageMgr(this); 60 m_pLayoutPageMgr = pdfium::MakeUnique<CXFA_LayoutPageMgr>(this);
64 if (!m_pLayoutPageMgr->InitLayoutPage(pFormRoot)) 61 if (!m_pLayoutPageMgr->InitLayoutPage(pFormRoot))
65 return -1; 62 return -1;
63
66 if (!m_pLayoutPageMgr->PrepareFirstPage(pFormRoot)) 64 if (!m_pLayoutPageMgr->PrepareFirstPage(pFormRoot))
67 return -1; 65 return -1;
68 m_pRootItemLayoutProcessor = 66
69 new CXFA_ItemLayoutProcessor(pFormRoot, m_pLayoutPageMgr); 67 m_pRootItemLayoutProcessor = pdfium::MakeUnique<CXFA_ItemLayoutProcessor>(
68 pFormRoot, m_pLayoutPageMgr.get());
70 m_nProgressCounter = 1; 69 m_nProgressCounter = 1;
71 return 0; 70 return 0;
72 } 71 }
73 72
74 int32_t CXFA_LayoutProcessor::DoLayout(IFX_Pause* pPause) { 73 int32_t CXFA_LayoutProcessor::DoLayout(IFX_Pause* pPause) {
75 if (m_nProgressCounter < 1) 74 if (m_nProgressCounter < 1)
76 return -1; 75 return -1;
77 76
78 XFA_ItemLayoutProcessorResult eStatus; 77 XFA_ItemLayoutProcessorResult eStatus;
79 CXFA_Node* pFormNode = m_pRootItemLayoutProcessor->GetFormNode(); 78 CXFA_Node* pFormNode = m_pRootItemLayoutProcessor->GetFormNode();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 142
144 void CXFA_LayoutProcessor::AddChangedContainer(CXFA_Node* pContainer) { 143 void CXFA_LayoutProcessor::AddChangedContainer(CXFA_Node* pContainer) {
145 if (m_rgChangedContainers.Find(pContainer) < 0) 144 if (m_rgChangedContainers.Find(pContainer) < 0)
146 m_rgChangedContainers.Add(pContainer); 145 m_rgChangedContainers.Add(pContainer);
147 } 146 }
148 147
149 CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetRootLayoutItem() const { 148 CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetRootLayoutItem() const {
150 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetRootLayoutItem() : nullptr; 149 return m_pLayoutPageMgr ? m_pLayoutPageMgr->GetRootLayoutItem() : nullptr;
151 } 150 }
152 151
153 void CXFA_LayoutProcessor::ClearLayoutData() {
154 delete m_pLayoutPageMgr;
155 m_pLayoutPageMgr = nullptr;
156 delete m_pRootItemLayoutProcessor;
157 m_pRootItemLayoutProcessor = nullptr;
158 m_nProgressCounter = 0;
159 }
160
161 bool CXFA_LayoutProcessor::IsNeedLayout() { 152 bool CXFA_LayoutProcessor::IsNeedLayout() {
162 return m_bNeeLayout || m_rgChangedContainers.GetSize() > 0; 153 return m_bNeeLayout || m_rgChangedContainers.GetSize() > 0;
163 } 154 }
OLDNEW
« no previous file with comments | « xfa/fxfa/parser/cxfa_layoutprocessor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698