From 649e059f5fe93c0de53aaa48a74068703df46301 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 30 Jul 2018 20:27:21 +0000 Subject: Return unique_ptr from CXFA_FFNotify::OnCreate{Container,Content}LayoutItem() ... and then immediately release it, but it is a step in the right direction. Change-Id: Ib52972c6789d8f98a576d1c69f8019541c96ac51 Reviewed-on: https://pdfium-review.googlesource.com/39152 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- xfa/fxfa/cxfa_ffnotify.cpp | 68 +++++++++++++++------------- xfa/fxfa/cxfa_ffnotify.h | 8 +++- xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp | 7 +-- xfa/fxfa/parser/cxfa_layoutpagemgr.cpp | 3 +- 4 files changed, 48 insertions(+), 38 deletions(-) (limited to 'xfa/fxfa') diff --git a/xfa/fxfa/cxfa_ffnotify.cpp b/xfa/fxfa/cxfa_ffnotify.cpp index 586b048b8a..715877c620 100644 --- a/xfa/fxfa/cxfa_ffnotify.cpp +++ b/xfa/fxfa/cxfa_ffnotify.cpp @@ -6,7 +6,6 @@ #include "xfa/fxfa/cxfa_ffnotify.h" -#include #include #include "xfa/fxfa/cxfa_ffapp.h" @@ -91,101 +90,106 @@ void CXFA_FFNotify::OnWidgetListItemRemoved(CXFA_Node* pSender, } } -CXFA_ContainerLayoutItem* CXFA_FFNotify::OnCreateContainerLayoutItem( - CXFA_Node* pNode) { +std::unique_ptr +CXFA_FFNotify::OnCreateContainerLayoutItem(CXFA_Node* pNode) { XFA_Element type = pNode->GetElementType(); - ASSERT(type == XFA_Element::ContentArea || type == XFA_Element::PageArea); - if (type == XFA_Element::PageArea) { CXFA_LayoutProcessor* pLayout = m_pDoc->GetXFADoc()->GetLayoutProcessor(); - return new CXFA_FFPageView(m_pDoc->GetDocView(pLayout), pNode); + return pdfium::MakeUnique(m_pDoc->GetDocView(pLayout), + pNode); } - return new CXFA_ContainerLayoutItem(pNode); + if (type == XFA_Element::ContentArea) + return pdfium::MakeUnique(pNode); + + NOTREACHED(); + return nullptr; } -CXFA_ContentLayoutItem* CXFA_FFNotify::OnCreateContentLayoutItem( - CXFA_Node* pNode) { +std::unique_ptr +CXFA_FFNotify::OnCreateContentLayoutItem(CXFA_Node* pNode) { ASSERT(pNode->GetElementType() != XFA_Element::ContentArea); ASSERT(pNode->GetElementType() != XFA_Element::PageArea); // We only need to create the widget for certain types of objects. if (!pNode->HasCreatedUIWidget()) - return new CXFA_ContentLayoutItem(pNode); + return pdfium::MakeUnique(pNode); - CXFA_FFWidget* pWidget = nullptr; + std::unique_ptr pWidget; switch (pNode->GetFFWidgetType()) { case XFA_FFWidgetType::kBarcode: { CXFA_Node* child = pNode->GetUIChildNode(); - if (child->GetElementType() == XFA_Element::Barcode) - pWidget = new CXFA_FFBarcode(pNode, static_cast(child)); + if (child->GetElementType() == XFA_Element::Barcode) { + pWidget = pdfium::MakeUnique( + pNode, static_cast(child)); + } break; } case XFA_FFWidgetType::kButton: { CXFA_Node* child = pNode->GetUIChildNode(); if (child->GetElementType() == XFA_Element::Button) { - pWidget = - new CXFA_FFPushButton(pNode, static_cast(child)); + pWidget = pdfium::MakeUnique( + pNode, static_cast(child)); } break; } case XFA_FFWidgetType::kCheckButton: { CXFA_Node* child = pNode->GetUIChildNode(); if (child->GetElementType() == XFA_Element::CheckButton) { - pWidget = new CXFA_FFCheckButton(pNode, - static_cast(child)); + pWidget = pdfium::MakeUnique( + pNode, static_cast(child)); } break; } case XFA_FFWidgetType::kChoiceList: { if (pNode->IsListBox()) - pWidget = new CXFA_FFListBox(pNode); + pWidget = pdfium::MakeUnique(pNode); else - pWidget = new CXFA_FFComboBox(pNode); + pWidget = pdfium::MakeUnique(pNode); break; } case XFA_FFWidgetType::kDateTimeEdit: - pWidget = new CXFA_FFDateTimeEdit(pNode); + pWidget = pdfium::MakeUnique(pNode); break; case XFA_FFWidgetType::kImageEdit: - pWidget = new CXFA_FFImageEdit(pNode); + pWidget = pdfium::MakeUnique(pNode); break; case XFA_FFWidgetType::kNumericEdit: - pWidget = new CXFA_FFNumericEdit(pNode); + pWidget = pdfium::MakeUnique(pNode); break; case XFA_FFWidgetType::kPasswordEdit: { CXFA_Node* child = pNode->GetUIChildNode(); if (child->GetElementType() == XFA_Element::PasswordEdit) { - pWidget = new CXFA_FFPasswordEdit( + pWidget = pdfium::MakeUnique( pNode, static_cast(child)); } break; } case XFA_FFWidgetType::kSignature: - pWidget = new CXFA_FFSignature(pNode); + pWidget = pdfium::MakeUnique(pNode); break; case XFA_FFWidgetType::kTextEdit: - pWidget = new CXFA_FFTextEdit(pNode); + pWidget = pdfium::MakeUnique(pNode); break; case XFA_FFWidgetType::kArc: - pWidget = new CXFA_FFArc(pNode); + pWidget = pdfium::MakeUnique(pNode); break; case XFA_FFWidgetType::kLine: - pWidget = new CXFA_FFLine(pNode); + pWidget = pdfium::MakeUnique(pNode); break; case XFA_FFWidgetType::kRectangle: - pWidget = new CXFA_FFRectangle(pNode); + pWidget = pdfium::MakeUnique(pNode); break; case XFA_FFWidgetType::kText: - pWidget = new CXFA_FFText(pNode); + pWidget = pdfium::MakeUnique(pNode); break; case XFA_FFWidgetType::kImage: - pWidget = new CXFA_FFImage(pNode); + pWidget = pdfium::MakeUnique(pNode); break; case XFA_FFWidgetType::kSubform: - pWidget = new CXFA_FFWidget(pNode); + pWidget = pdfium::MakeUnique(pNode); break; case XFA_FFWidgetType::kExclGroup: - pWidget = new CXFA_FFExclGroup(pNode); + pWidget = pdfium::MakeUnique(pNode); break; case XFA_FFWidgetType::kNone: return nullptr; diff --git a/xfa/fxfa/cxfa_ffnotify.h b/xfa/fxfa/cxfa_ffnotify.h index 6715f825ff..298a10123d 100644 --- a/xfa/fxfa/cxfa_ffnotify.h +++ b/xfa/fxfa/cxfa_ffnotify.h @@ -7,6 +7,8 @@ #ifndef XFA_FXFA_CXFA_FFNOTIFY_H_ #define XFA_FXFA_CXFA_FFNOTIFY_H_ +#include + #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/parser/cxfa_document.h" @@ -39,8 +41,10 @@ class CXFA_FFNotify { void OnChildAdded(CXFA_Node* pSender); void OnChildRemoved(); - CXFA_ContainerLayoutItem* OnCreateContainerLayoutItem(CXFA_Node* pNode); - CXFA_ContentLayoutItem* OnCreateContentLayoutItem(CXFA_Node* pNode); + std::unique_ptr OnCreateContainerLayoutItem( + CXFA_Node* pNode); + std::unique_ptr OnCreateContentLayoutItem( + CXFA_Node* pNode); void OnLayoutItemAdded(CXFA_LayoutProcessor* pLayout, CXFA_LayoutItem* pSender, diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp index 60dd8a37a5..e09b17d730 100644 --- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp @@ -652,9 +652,10 @@ CXFA_ContentLayoutItem* CXFA_ItemLayoutProcessor::CreateContentLayoutItem( m_pOldLayoutItem = m_pOldLayoutItem->m_pNext; return pLayoutItem; } - pLayoutItem = - pFormNode->GetDocument()->GetNotify()->OnCreateContentLayoutItem( - pFormNode); + pLayoutItem = pFormNode->GetDocument() + ->GetNotify() + ->OnCreateContentLayoutItem(pFormNode) + .release(); CXFA_ContentLayoutItem* pPrevLayoutItem = ToContentLayoutItem(pFormNode->JSObject()->GetLayoutItem()); if (pPrevLayoutItem) { diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp index b6c95c1d56..411ad24e45 100644 --- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp +++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp @@ -582,7 +582,8 @@ void CXFA_LayoutPageMgr::AddPageAreaLayoutItem(CXFA_ContainerRecord* pNewRecord, pNewPageAreaLayoutItem = pContainerItem; } else { CXFA_FFNotify* pNotify = pNewPageArea->GetDocument()->GetNotify(); - auto* pContainerItem = pNotify->OnCreateContainerLayoutItem(pNewPageArea); + auto* pContainerItem = + pNotify->OnCreateContainerLayoutItem(pNewPageArea).release(); m_PageArray.push_back(pContainerItem); m_nAvailPages++; pNotify->OnPageEvent(pContainerItem, XFA_PAGEVIEWEVENT_PostRemoved); -- cgit v1.2.3