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

Side by Side Diff: xfa/fxfa/app/xfa_ffapp.cpp

Issue 2571913002: Avoid the ptr.reset(new XXX()) anti-pattern (Closed)
Patch Set: rebase Created 4 years 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/fxbarcode/pdf417/BC_PDF417.cpp ('k') | xfa/fxfa/app/xfa_ffdoc.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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/xfa_ffapp.h" 7 #include "xfa/fxfa/xfa_ffapp.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "third_party/base/ptr_util.h"
14 #include "third_party/base/stl_util.h" 15 #include "third_party/base/stl_util.h"
15 #include "xfa/fgas/font/cfgas_fontmgr.h" 16 #include "xfa/fgas/font/cfgas_fontmgr.h"
16 #include "xfa/fwl/cfwl_notedriver.h" 17 #include "xfa/fwl/cfwl_notedriver.h"
17 #include "xfa/fwl/cfwl_widgetmgr.h" 18 #include "xfa/fwl/cfwl_widgetmgr.h"
18 #include "xfa/fxfa/app/xfa_fwladapter.h" 19 #include "xfa/fxfa/app/xfa_fwladapter.h"
19 #include "xfa/fxfa/app/xfa_fwltheme.h" 20 #include "xfa/fxfa/app/xfa_fwltheme.h"
20 #include "xfa/fxfa/xfa_ffdoc.h" 21 #include "xfa/fxfa/xfa_ffdoc.h"
21 #include "xfa/fxfa/xfa_ffdochandler.h" 22 #include "xfa/fxfa/xfa_ffdochandler.h"
22 #include "xfa/fxfa/xfa_ffwidgethandler.h" 23 #include "xfa/fxfa/xfa_ffwidgethandler.h"
23 #include "xfa/fxfa/xfa_fontmgr.h" 24 #include "xfa/fxfa/xfa_fontmgr.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 91
91 CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider) 92 CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider)
92 : m_pProvider(pProvider), 93 : m_pProvider(pProvider),
93 m_pWidgetMgrDelegate(nullptr), 94 m_pWidgetMgrDelegate(nullptr),
94 m_pFWLApp(new CFWL_App(this)) {} 95 m_pFWLApp(new CFWL_App(this)) {}
95 96
96 CXFA_FFApp::~CXFA_FFApp() {} 97 CXFA_FFApp::~CXFA_FFApp() {}
97 98
98 CXFA_FFDocHandler* CXFA_FFApp::GetDocHandler() { 99 CXFA_FFDocHandler* CXFA_FFApp::GetDocHandler() {
99 if (!m_pDocHandler) 100 if (!m_pDocHandler)
100 m_pDocHandler.reset(new CXFA_FFDocHandler); 101 m_pDocHandler = pdfium::MakeUnique<CXFA_FFDocHandler>();
101 return m_pDocHandler.get(); 102 return m_pDocHandler.get();
102 } 103 }
103 104
104 CXFA_FFDoc* CXFA_FFApp::CreateDoc( 105 CXFA_FFDoc* CXFA_FFApp::CreateDoc(
105 IXFA_DocEnvironment* pDocEnvironment, 106 IXFA_DocEnvironment* pDocEnvironment,
106 const CFX_RetainPtr<IFX_SeekableReadStream>& pStream) { 107 const CFX_RetainPtr<IFX_SeekableReadStream>& pStream) {
107 auto pDoc = pdfium::MakeUnique<CXFA_FFDoc>(this, pDocEnvironment); 108 auto pDoc = pdfium::MakeUnique<CXFA_FFDoc>(this, pDocEnvironment);
108 return pDoc->OpenDoc(pStream) ? pDoc.release() : nullptr; 109 return pDoc->OpenDoc(pStream) ? pDoc.release() : nullptr;
109 } 110 }
110 111
111 CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocEnvironment* pDocEnvironment, 112 CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocEnvironment* pDocEnvironment,
112 CPDF_Document* pPDFDoc) { 113 CPDF_Document* pPDFDoc) {
113 if (!pPDFDoc) 114 if (!pPDFDoc)
114 return nullptr; 115 return nullptr;
115 116
116 std::unique_ptr<CXFA_FFDoc> pDoc(new CXFA_FFDoc(this, pDocEnvironment)); 117 std::unique_ptr<CXFA_FFDoc> pDoc(new CXFA_FFDoc(this, pDocEnvironment));
117 bool bSuccess = pDoc->OpenDoc(pPDFDoc); 118 bool bSuccess = pDoc->OpenDoc(pPDFDoc);
118 return bSuccess ? pDoc.release() : nullptr; 119 return bSuccess ? pDoc.release() : nullptr;
119 } 120 }
120 121
121 void CXFA_FFApp::SetDefaultFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr) { 122 void CXFA_FFApp::SetDefaultFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr) {
122 if (!m_pFontMgr) 123 if (!m_pFontMgr)
123 m_pFontMgr.reset(new CXFA_FontMgr()); 124 m_pFontMgr = pdfium::MakeUnique<CXFA_FontMgr>();
124 m_pFontMgr->SetDefFontMgr(std::move(pFontMgr)); 125 m_pFontMgr->SetDefFontMgr(std::move(pFontMgr));
125 } 126 }
126 127
127 CXFA_FontMgr* CXFA_FFApp::GetXFAFontMgr() const { 128 CXFA_FontMgr* CXFA_FFApp::GetXFAFontMgr() const {
128 return m_pFontMgr.get(); 129 return m_pFontMgr.get();
129 } 130 }
130 131
131 CFGAS_FontMgr* CXFA_FFApp::GetFDEFontMgr() { 132 CFGAS_FontMgr* CXFA_FFApp::GetFDEFontMgr() {
132 if (!m_pFDEFontMgr) { 133 if (!m_pFDEFontMgr) {
133 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 134 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
134 m_pFDEFontMgr = CFGAS_FontMgr::Create(FX_GetDefFontEnumerator()); 135 m_pFDEFontMgr = CFGAS_FontMgr::Create(FX_GetDefFontEnumerator());
135 #else 136 #else
136 m_pFontSource.reset(new CFX_FontSourceEnum_File); 137 m_pFontSource = pdfium::MakeUnique<CFX_FontSourceEnum_File>();
137 m_pFDEFontMgr = CFGAS_FontMgr::Create(m_pFontSource.get()); 138 m_pFDEFontMgr = CFGAS_FontMgr::Create(m_pFontSource.get());
138 #endif 139 #endif
139 } 140 }
140 return m_pFDEFontMgr.get(); 141 return m_pFDEFontMgr.get();
141 } 142 }
142 143
143 CXFA_FWLTheme* CXFA_FFApp::GetFWLTheme() { 144 CXFA_FWLTheme* CXFA_FFApp::GetFWLTheme() {
144 if (!m_pFWLTheme) 145 if (!m_pFWLTheme)
145 m_pFWLTheme.reset(new CXFA_FWLTheme(this)); 146 m_pFWLTheme = pdfium::MakeUnique<CXFA_FWLTheme>(this);
146 return m_pFWLTheme.get(); 147 return m_pFWLTheme.get();
147 } 148 }
148 149
149 CXFA_FWLAdapterWidgetMgr* CXFA_FFApp::GetWidgetMgr( 150 CXFA_FWLAdapterWidgetMgr* CXFA_FFApp::GetWidgetMgr(
150 CFWL_WidgetMgrDelegate* pDelegate) { 151 CFWL_WidgetMgrDelegate* pDelegate) {
151 if (!m_pAdapterWidgetMgr) { 152 if (!m_pAdapterWidgetMgr) {
152 m_pAdapterWidgetMgr.reset(new CXFA_FWLAdapterWidgetMgr); 153 m_pAdapterWidgetMgr = pdfium::MakeUnique<CXFA_FWLAdapterWidgetMgr>();
153 pDelegate->OnSetCapability(FWL_WGTMGR_DisableForm); 154 pDelegate->OnSetCapability(FWL_WGTMGR_DisableForm);
154 m_pWidgetMgrDelegate = pDelegate; 155 m_pWidgetMgrDelegate = pDelegate;
155 } 156 }
156 return m_pAdapterWidgetMgr.get(); 157 return m_pAdapterWidgetMgr.get();
157 } 158 }
158 159
159 IFWL_AdapterTimerMgr* CXFA_FFApp::GetTimerMgr() const { 160 IFWL_AdapterTimerMgr* CXFA_FFApp::GetTimerMgr() const {
160 return m_pProvider->GetTimerMgr(); 161 return m_pProvider->GetTimerMgr();
161 } 162 }
162 163
163 void CXFA_FFApp::ClearEventTargets() { 164 void CXFA_FFApp::ClearEventTargets() {
164 m_pFWLApp->GetNoteDriver()->ClearEventTargets(false); 165 m_pFWLApp->GetNoteDriver()->ClearEventTargets(false);
165 } 166 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/pdf417/BC_PDF417.cpp ('k') | xfa/fxfa/app/xfa_ffdoc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698