From b8227824c221733e8636c42c3aee8ccff9efd719 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 24 Mar 2017 13:10:14 -0700 Subject: Use std::vector> in cxfa_ffpageview Change-Id: Ie28afe16c1bcfb6a70c07cd54cc795e0bf5573c4 Reviewed-on: https://pdfium-review.googlesource.com/3216 Commit-Queue: Lei Zhang Reviewed-by: Lei Zhang --- xfa/fxfa/cxfa_ffpageview.cpp | 45 +++++++++++++++++--------------------------- xfa/fxfa/cxfa_ffpageview.h | 2 +- 2 files changed, 18 insertions(+), 29 deletions(-) (limited to 'xfa') diff --git a/xfa/fxfa/cxfa_ffpageview.cpp b/xfa/fxfa/cxfa_ffpageview.cpp index 3eda5a1d4a..e64aee58ba 100644 --- a/xfa/fxfa/cxfa_ffpageview.cpp +++ b/xfa/fxfa/cxfa_ffpageview.cpp @@ -6,6 +6,7 @@ #include "xfa/fxfa/cxfa_ffpageview.h" +#include #include #include @@ -353,18 +354,6 @@ void CXFA_FFTabOrderPageWidgetIterator::CreateTabOrderWidgetArray() { } } -static int32_t XFA_TabOrderWidgetComparator(const void* phWidget1, - const void* phWidget2) { - auto* param1 = *static_cast(const_cast(phWidget1)); - auto* param2 = *static_cast(const_cast(phWidget2)); - CFX_RectF rt1 = param1->m_pWidget->GetWidgetRect(); - CFX_RectF rt2 = param2->m_pWidget->GetWidgetRect(); - float x1 = rt1.left, y1 = rt1.top, x2 = rt2.left, y2 = rt2.top; - if (y1 < y2 || (y1 - y2 < XFA_FLOAT_PERCISION && x1 < x2)) - return -1; - return 1; -} - void CXFA_FFTabOrderPageWidgetIterator::OrderContainer( CXFA_LayoutItemIterator* sIterator, CXFA_LayoutItem* pContainerItem, @@ -372,7 +361,7 @@ void CXFA_FFTabOrderPageWidgetIterator::OrderContainer( bool& bCurrentItem, bool& bContentArea, bool bMarsterPage) { - CFX_ArrayTemplate tabParams; + std::vector> tabParams; CXFA_LayoutItem* pSearchItem = sIterator->MoveToNext(); while (pSearchItem) { if (!pSearchItem->IsContentLayoutItem()) { @@ -393,12 +382,10 @@ void CXFA_FFTabOrderPageWidgetIterator::OrderContainer( bCurrentItem = true; break; } - CXFA_TabParam* pParam = new CXFA_TabParam; - pParam->m_pWidget = hWidget; - tabParams.Add(pParam); + tabParams.push_back(pdfium::MakeUnique(hWidget)); if (IsLayoutElement(pSearchItem->GetFormNode()->GetElementType(), true)) { - OrderContainer(sIterator, pSearchItem, pParam, bCurrentItem, - bContentArea, bMarsterPage); + OrderContainer(sIterator, pSearchItem, tabParams.back().get(), + bCurrentItem, bContentArea, bMarsterPage); } } if (bCurrentItem) { @@ -408,24 +395,26 @@ void CXFA_FFTabOrderPageWidgetIterator::OrderContainer( pSearchItem = sIterator->MoveToNext(); } } - int32_t iChildren = tabParams.GetSize(); - if (iChildren > 1) { - FXSYS_qsort(tabParams.GetData(), iChildren, sizeof(void*), - XFA_TabOrderWidgetComparator); - } - for (int32_t iStart = 0; iStart < iChildren; iStart++) { - std::unique_ptr pParam(tabParams[iStart]); + std::sort(tabParams.begin(), tabParams.end(), + [](const std::unique_ptr& arg1, + const std::unique_ptr& arg2) { + CFX_RectF rt1 = arg1->m_pWidget->GetWidgetRect(); + CFX_RectF rt2 = arg2->m_pWidget->GetWidgetRect(); + if (rt1.top - rt2.top >= XFA_FLOAT_PERCISION) + return rt1.top < rt2.top; + return rt1.left < rt2.left; + }); + for (const auto& pParam : tabParams) { pContainer->m_Children.push_back(pParam->m_pWidget); pContainer->m_Children.insert(pContainer->m_Children.end(), pParam->m_Children.begin(), pParam->m_Children.end()); } - tabParams.RemoveAll(); } void CXFA_FFTabOrderPageWidgetIterator::CreateSpaceOrderWidgetArray( std::vector* WidgetArray) { CXFA_LayoutItemIterator sIterator(m_pPageView); - auto pParam = pdfium::MakeUnique(); + auto pParam = pdfium::MakeUnique(nullptr); bool bCurrentItem = false; bool bContentArea = false; OrderContainer(&sIterator, nullptr, pParam.get(), bCurrentItem, bContentArea); @@ -454,6 +443,6 @@ CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetWidget( return nullptr; } -CXFA_TabParam::CXFA_TabParam() : m_pWidget(nullptr) {} +CXFA_TabParam::CXFA_TabParam(CXFA_FFWidget* pWidget) : m_pWidget(pWidget) {} CXFA_TabParam::~CXFA_TabParam() {} diff --git a/xfa/fxfa/cxfa_ffpageview.h b/xfa/fxfa/cxfa_ffpageview.h index ee1b4e37df..9fcca3add6 100644 --- a/xfa/fxfa/cxfa_ffpageview.h +++ b/xfa/fxfa/cxfa_ffpageview.h @@ -62,7 +62,7 @@ class CXFA_FFPageWidgetIterator : public IXFA_WidgetIterator { class CXFA_TabParam { public: - CXFA_TabParam(); + explicit CXFA_TabParam(CXFA_FFWidget* pWidget); ~CXFA_TabParam(); CXFA_FFWidget* m_pWidget; -- cgit v1.2.3