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

Side by Side Diff: xfa/fxfa/app/xfa_ffwidgetacc.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/fxfa/app/xfa_ffdocview.cpp ('k') | xfa/fxfa/app/xfa_fontmgr.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/app/xfa_ffwidgetacc.h" 7 #include "xfa/fxfa/app/xfa_ffwidgetacc.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "fxjs/cfxjse_value.h" 13 #include "fxjs/cfxjse_value.h"
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/fde/tto/fde_textout.h" 16 #include "xfa/fde/tto/fde_textout.h"
16 #include "xfa/fde/xml/fde_xml_imp.h" 17 #include "xfa/fde/xml/fde_xml_imp.h"
17 #include "xfa/fxfa/app/xfa_ffcheckbutton.h" 18 #include "xfa/fxfa/app/xfa_ffcheckbutton.h"
18 #include "xfa/fxfa/app/xfa_ffchoicelist.h" 19 #include "xfa/fxfa/app/xfa_ffchoicelist.h"
19 #include "xfa/fxfa/app/xfa_fffield.h" 20 #include "xfa/fxfa/app/xfa_fffield.h"
20 #include "xfa/fxfa/app/xfa_fwladapter.h" 21 #include "xfa/fxfa/app/xfa_fwladapter.h"
21 #include "xfa/fxfa/app/xfa_textlayout.h" 22 #include "xfa/fxfa/app/xfa_textlayout.h"
22 #include "xfa/fxfa/cxfa_eventparam.h" 23 #include "xfa/fxfa/cxfa_eventparam.h"
23 #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" 24 #include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
(...skipping 29 matching lines...) Expand all
53 CXFA_TextLayoutData() {} 54 CXFA_TextLayoutData() {}
54 ~CXFA_TextLayoutData() override {} 55 ~CXFA_TextLayoutData() override {}
55 56
56 CXFA_TextLayout* GetTextLayout() const { return m_pTextLayout.get(); } 57 CXFA_TextLayout* GetTextLayout() const { return m_pTextLayout.get(); }
57 CXFA_TextProvider* GetTextProvider() const { return m_pTextProvider.get(); } 58 CXFA_TextProvider* GetTextProvider() const { return m_pTextProvider.get(); }
58 59
59 void LoadText(CXFA_WidgetAcc* pAcc) { 60 void LoadText(CXFA_WidgetAcc* pAcc) {
60 if (m_pTextLayout) 61 if (m_pTextLayout)
61 return; 62 return;
62 63
63 m_pTextProvider.reset( 64 m_pTextProvider =
64 new CXFA_TextProvider(pAcc, XFA_TEXTPROVIDERTYPE_Text)); 65 pdfium::MakeUnique<CXFA_TextProvider>(pAcc, XFA_TEXTPROVIDERTYPE_Text);
65 m_pTextLayout.reset(new CXFA_TextLayout(m_pTextProvider.get())); 66 m_pTextLayout = pdfium::MakeUnique<CXFA_TextLayout>(m_pTextProvider.get());
66 } 67 }
67 68
68 private: 69 private:
69 std::unique_ptr<CXFA_TextLayout> m_pTextLayout; 70 std::unique_ptr<CXFA_TextLayout> m_pTextLayout;
70 std::unique_ptr<CXFA_TextProvider> m_pTextProvider; 71 std::unique_ptr<CXFA_TextProvider> m_pTextProvider;
71 }; 72 };
72 73
73 class CXFA_ImageLayoutData : public CXFA_WidgetLayoutData { 74 class CXFA_ImageLayoutData : public CXFA_WidgetLayoutData {
74 public: 75 public:
75 CXFA_ImageLayoutData() 76 CXFA_ImageLayoutData()
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 ~CXFA_FieldLayoutData() override {} 114 ~CXFA_FieldLayoutData() override {}
114 115
115 bool LoadCaption(CXFA_WidgetAcc* pAcc) { 116 bool LoadCaption(CXFA_WidgetAcc* pAcc) {
116 if (m_pCapTextLayout) 117 if (m_pCapTextLayout)
117 return true; 118 return true;
118 CXFA_Caption caption = pAcc->GetCaption(); 119 CXFA_Caption caption = pAcc->GetCaption();
119 if (!caption || caption.GetPresence() == XFA_ATTRIBUTEENUM_Hidden) 120 if (!caption || caption.GetPresence() == XFA_ATTRIBUTEENUM_Hidden)
120 return false; 121 return false;
121 m_pCapTextProvider.reset( 122 m_pCapTextProvider.reset(
122 new CXFA_TextProvider(pAcc, XFA_TEXTPROVIDERTYPE_Caption)); 123 new CXFA_TextProvider(pAcc, XFA_TEXTPROVIDERTYPE_Caption));
123 m_pCapTextLayout.reset(new CXFA_TextLayout(m_pCapTextProvider.get())); 124 m_pCapTextLayout =
125 pdfium::MakeUnique<CXFA_TextLayout>(m_pCapTextProvider.get());
124 return true; 126 return true;
125 } 127 }
126 128
127 std::unique_ptr<CXFA_TextLayout> m_pCapTextLayout; 129 std::unique_ptr<CXFA_TextLayout> m_pCapTextLayout;
128 std::unique_ptr<CXFA_TextProvider> m_pCapTextProvider; 130 std::unique_ptr<CXFA_TextProvider> m_pCapTextProvider;
129 std::unique_ptr<CFDE_TextOut> m_pTextOut; 131 std::unique_ptr<CFDE_TextOut> m_pTextOut;
130 std::vector<FX_FLOAT> m_FieldSplitArray; 132 std::vector<FX_FLOAT> m_FieldSplitArray;
131 }; 133 };
132 134
133 class CXFA_TextEditData : public CXFA_FieldLayoutData { 135 class CXFA_TextEditData : public CXFA_FieldLayoutData {
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 } 852 }
851 FX_WCHAR wcEnter = '\n'; 853 FX_WCHAR wcEnter = '\n';
852 FX_WCHAR wsLast = wsText.GetAt(wsText.GetLength() - 1); 854 FX_WCHAR wsLast = wsText.GetAt(wsText.GetLength() - 1);
853 if (wsLast == wcEnter) { 855 if (wsLast == wcEnter) {
854 wsText = wsText + wcEnter; 856 wsText = wsText + wcEnter;
855 } 857 }
856 858
857 CXFA_FieldLayoutData* layoutData = 859 CXFA_FieldLayoutData* layoutData =
858 static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()); 860 static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get());
859 if (!layoutData->m_pTextOut) { 861 if (!layoutData->m_pTextOut) {
860 layoutData->m_pTextOut.reset(new CFDE_TextOut); 862 layoutData->m_pTextOut = pdfium::MakeUnique<CFDE_TextOut>();
861 CFDE_TextOut* pTextOut = layoutData->m_pTextOut.get(); 863 CFDE_TextOut* pTextOut = layoutData->m_pTextOut.get();
862 pTextOut->SetFont(GetFDEFont()); 864 pTextOut->SetFont(GetFDEFont());
863 pTextOut->SetFontSize(fFontSize); 865 pTextOut->SetFontSize(fFontSize);
864 pTextOut->SetLineBreakTolerance(fFontSize * 0.2f); 866 pTextOut->SetLineBreakTolerance(fFontSize * 0.2f);
865 pTextOut->SetLineSpace(GetLineHeight()); 867 pTextOut->SetLineSpace(GetLineHeight());
866 uint32_t dwStyles = FDE_TTOSTYLE_LastLineHeight; 868 uint32_t dwStyles = FDE_TTOSTYLE_LastLineHeight;
867 if (GetUIType() == XFA_Element::TextEdit && IsMultiLine()) { 869 if (GetUIType() == XFA_Element::TextEdit && IsMultiLine()) {
868 dwStyles |= FDE_TTOSTYLE_LineWrap; 870 dwStyles |= FDE_TTOSTYLE_LineWrap;
869 } 871 }
870 pTextOut->SetStyles(dwStyles); 872 pTextOut->SetStyles(dwStyles);
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 } 1383 }
1382 fCalcHeight = 0; 1384 fCalcHeight = 0;
1383 return true; 1385 return true;
1384 } 1386 }
1385 void CXFA_WidgetAcc::InitLayoutData() { 1387 void CXFA_WidgetAcc::InitLayoutData() {
1386 if (m_pLayoutData) { 1388 if (m_pLayoutData) {
1387 return; 1389 return;
1388 } 1390 }
1389 switch (GetUIType()) { 1391 switch (GetUIType()) {
1390 case XFA_Element::Text: 1392 case XFA_Element::Text:
1391 m_pLayoutData.reset(new CXFA_TextLayoutData); 1393 m_pLayoutData = pdfium::MakeUnique<CXFA_TextLayoutData>();
1392 return; 1394 return;
1393 case XFA_Element::TextEdit: 1395 case XFA_Element::TextEdit:
1394 m_pLayoutData.reset(new CXFA_TextEditData); 1396 m_pLayoutData = pdfium::MakeUnique<CXFA_TextEditData>();
1395 return; 1397 return;
1396 case XFA_Element::Image: 1398 case XFA_Element::Image:
1397 m_pLayoutData.reset(new CXFA_ImageLayoutData); 1399 m_pLayoutData = pdfium::MakeUnique<CXFA_ImageLayoutData>();
1398 return; 1400 return;
1399 case XFA_Element::ImageEdit: 1401 case XFA_Element::ImageEdit:
1400 m_pLayoutData.reset(new CXFA_ImageEditData); 1402 m_pLayoutData = pdfium::MakeUnique<CXFA_ImageEditData>();
1401 return; 1403 return;
1402 default: 1404 default:
1403 break; 1405 break;
1404 } 1406 }
1405 if (GetElementType() == XFA_Element::Field) { 1407 if (GetElementType() == XFA_Element::Field) {
1406 m_pLayoutData.reset(new CXFA_FieldLayoutData); 1408 m_pLayoutData = pdfium::MakeUnique<CXFA_FieldLayoutData>();
1407 return; 1409 return;
1408 } 1410 }
1409 m_pLayoutData.reset(new CXFA_WidgetLayoutData); 1411 m_pLayoutData = pdfium::MakeUnique<CXFA_WidgetLayoutData>();
1410 } 1412 }
1411 1413
1412 void CXFA_WidgetAcc::StartTextLayout(FX_FLOAT& fCalcWidth, 1414 void CXFA_WidgetAcc::StartTextLayout(FX_FLOAT& fCalcWidth,
1413 FX_FLOAT& fCalcHeight) { 1415 FX_FLOAT& fCalcHeight) {
1414 LoadText(); 1416 LoadText();
1415 CXFA_TextLayout* pTextLayout = 1417 CXFA_TextLayout* pTextLayout =
1416 static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->GetTextLayout(); 1418 static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->GetTextLayout();
1417 FX_FLOAT fTextHeight = 0; 1419 FX_FLOAT fTextHeight = 0;
1418 if (fCalcWidth > 0 && fCalcHeight > 0) { 1420 if (fCalcWidth > 0 && fCalcHeight > 0) {
1419 FX_FLOAT fWidth = GetWidthWithoutMargin(fCalcWidth); 1421 FX_FLOAT fWidth = GetWidthWithoutMargin(fCalcWidth);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 if (pIDNode) { 1684 if (pIDNode) {
1683 pEmbAcc = static_cast<CXFA_WidgetAcc*>(pIDNode->GetWidgetData()); 1685 pEmbAcc = static_cast<CXFA_WidgetAcc*>(pIDNode->GetWidgetData());
1684 } 1686 }
1685 if (pEmbAcc) { 1687 if (pEmbAcc) {
1686 pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display); 1688 pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display);
1687 return true; 1689 return true;
1688 } 1690 }
1689 } 1691 }
1690 return false; 1692 return false;
1691 } 1693 }
OLDNEW
« no previous file with comments | « xfa/fxfa/app/xfa_ffdocview.cpp ('k') | xfa/fxfa/app/xfa_fontmgr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698