diff options
author | tsepez <tsepez@chromium.org> | 2017-01-23 11:32:36 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2017-01-23 11:32:36 -0800 |
commit | a0b2d23d1121202d3821291483943a47a3c9e32e (patch) | |
tree | 1b98cf96e6a9c5849c3030a7beba529882a03539 /xfa/fxfa/app | |
parent | c757d9a6f90bb879ce2cdd4a756b7b0e1885eb25 (diff) | |
download | pdfium-a0b2d23d1121202d3821291483943a47a3c9e32e.tar.xz |
Replace CXFA_StrokeArray and CXFA_WidgetArray with std::vector
Review-Url: https://codereview.chromium.org/2648773003
Diffstat (limited to 'xfa/fxfa/app')
-rw-r--r-- | xfa/fxfa/app/xfa_ffpageview.cpp | 136 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_ffwidget.cpp | 18 |
2 files changed, 87 insertions, 67 deletions
diff --git a/xfa/fxfa/app/xfa_ffpageview.cpp b/xfa/fxfa/app/xfa_ffpageview.cpp index 5ef108693a..3dfa237c0f 100644 --- a/xfa/fxfa/app/xfa_ffpageview.cpp +++ b/xfa/fxfa/app/xfa_ffpageview.cpp @@ -6,6 +6,11 @@ #include "xfa/fxfa/xfa_ffpageview.h" +#include <memory> +#include <vector> + +#include "third_party/base/ptr_util.h" +#include "third_party/base/stl_util.h" #include "xfa/fde/fde_render.h" #include "xfa/fxfa/app/xfa_ffcheckbutton.h" #include "xfa/fxfa/app/xfa_ffchoicelist.h" @@ -228,32 +233,34 @@ void CXFA_FFTabOrderPageWidgetIterator::Reset() { CreateTabOrderWidgetArray(); m_iCurWidget = -1; } + CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToFirst() { - if (m_TabOrderWidgetArray.GetSize() > 0) { - for (int32_t i = 0; i < m_TabOrderWidgetArray.GetSize(); i++) { - if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true, - m_bIgnorerelevant)) { - m_iCurWidget = i; - return m_TabOrderWidgetArray[m_iCurWidget]; - } + for (int32_t i = 0; + i < pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray); i++) { + if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true, + m_bIgnorerelevant)) { + m_iCurWidget = i; + return m_TabOrderWidgetArray[m_iCurWidget]; } } return nullptr; } + CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToLast() { - if (m_TabOrderWidgetArray.GetSize() > 0) { - for (int32_t i = m_TabOrderWidgetArray.GetSize() - 1; i >= 0; i--) { - if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true, - m_bIgnorerelevant)) { - m_iCurWidget = i; - return m_TabOrderWidgetArray[m_iCurWidget]; - } + for (int32_t i = pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray) - 1; + i >= 0; i--) { + if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true, + m_bIgnorerelevant)) { + m_iCurWidget = i; + return m_TabOrderWidgetArray[m_iCurWidget]; } } return nullptr; } + CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToNext() { - for (int32_t i = m_iCurWidget + 1; i < m_TabOrderWidgetArray.GetSize(); i++) { + for (int32_t i = m_iCurWidget + 1; + i < pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray); i++) { if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true, m_bIgnorerelevant)) { m_iCurWidget = i; @@ -263,6 +270,7 @@ CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToNext() { m_iCurWidget = -1; return nullptr; } + CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToPrevious() { for (int32_t i = m_iCurWidget - 1; i >= 0; i--) { if (PageWidgetFilter(m_TabOrderWidgetArray[i], m_dwFilter, true, @@ -274,21 +282,22 @@ CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::MoveToPrevious() { m_iCurWidget = -1; return nullptr; } + CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetCurrentWidget() { - if (m_iCurWidget >= 0) { - return m_TabOrderWidgetArray[m_iCurWidget]; - } - return nullptr; + return m_iCurWidget >= 0 ? m_TabOrderWidgetArray[m_iCurWidget] : nullptr; } + bool CXFA_FFTabOrderPageWidgetIterator::SetCurrentWidget( CXFA_FFWidget* hWidget) { - int32_t iWidgetIndex = m_TabOrderWidgetArray.Find(hWidget); - if (iWidgetIndex >= 0) { - m_iCurWidget = iWidgetIndex; - return true; - } - return false; + auto it = std::find(m_TabOrderWidgetArray.begin(), + m_TabOrderWidgetArray.end(), hWidget); + if (it == m_TabOrderWidgetArray.end()) + return false; + + m_iCurWidget = it - m_TabOrderWidgetArray.begin(); + return true; } + CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetTraverseWidget( CXFA_FFWidget* pWidget) { CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc(); @@ -309,29 +318,36 @@ CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::FindWidgetByName( CXFA_FFWidget* pRefWidget) { return pRefWidget->GetDocView()->GetWidgetByName(wsWidgetName, pRefWidget); } + void CXFA_FFTabOrderPageWidgetIterator::CreateTabOrderWidgetArray() { - m_TabOrderWidgetArray.RemoveAll(); - CXFA_WidgetArray SpaceOrderWidgetArray; - CreateSpaceOrderWidgetArray(SpaceOrderWidgetArray); - int32_t nWidgetCount = SpaceOrderWidgetArray.GetSize(); - if (nWidgetCount < 1) { + m_TabOrderWidgetArray.clear(); + + std::vector<CXFA_FFWidget*> SpaceOrderWidgetArray; + CreateSpaceOrderWidgetArray(&SpaceOrderWidgetArray); + if (SpaceOrderWidgetArray.empty()) return; - } + + int32_t nWidgetCount = pdfium::CollectionSize<int32_t>(SpaceOrderWidgetArray); CXFA_FFWidget* hWidget = SpaceOrderWidgetArray[0]; - for (; m_TabOrderWidgetArray.GetSize() < nWidgetCount;) { - if (m_TabOrderWidgetArray.Find(hWidget) < 0) { - m_TabOrderWidgetArray.Add(hWidget); + while (pdfium::CollectionSize<int32_t>(m_TabOrderWidgetArray) < + nWidgetCount) { + if (!pdfium::ContainsValue(m_TabOrderWidgetArray, hWidget)) { + m_TabOrderWidgetArray.push_back(hWidget); CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc(); if (pWidgetAcc->GetUIType() == XFA_Element::ExclGroup) { - int32_t iWidgetIndex = SpaceOrderWidgetArray.Find(hWidget) + 1; + auto it = std::find(SpaceOrderWidgetArray.begin(), + SpaceOrderWidgetArray.end(), hWidget); + int32_t iWidgetIndex = it != SpaceOrderWidgetArray.end() + ? it - SpaceOrderWidgetArray.begin() + 1 + : 0; while (true) { CXFA_FFWidget* pRadio = - SpaceOrderWidgetArray[(iWidgetIndex) % nWidgetCount]; + SpaceOrderWidgetArray[iWidgetIndex % nWidgetCount]; if (pRadio->GetDataAcc()->GetExclGroup() != pWidgetAcc) { break; } - if (m_TabOrderWidgetArray.Find(hWidget) < 0) { - m_TabOrderWidgetArray.Add(pRadio); + if (!pdfium::ContainsValue(m_TabOrderWidgetArray, hWidget)) { + m_TabOrderWidgetArray.push_back(pRadio); } iWidgetIndex++; } @@ -341,10 +357,15 @@ void CXFA_FFTabOrderPageWidgetIterator::CreateTabOrderWidgetArray() { continue; } } - int32_t iWidgetIndex = SpaceOrderWidgetArray.Find(hWidget); - hWidget = SpaceOrderWidgetArray[(iWidgetIndex + 1) % nWidgetCount]; + auto it = std::find(SpaceOrderWidgetArray.begin(), + SpaceOrderWidgetArray.end(), hWidget); + int32_t iWidgetIndex = it != SpaceOrderWidgetArray.end() + ? it - SpaceOrderWidgetArray.begin() + 1 + : 0; + hWidget = SpaceOrderWidgetArray[iWidgetIndex % nWidgetCount]; } } + static int32_t XFA_TabOrderWidgetComparator(const void* phWidget1, const void* phWidget2) { CXFA_FFWidget* pWidget1 = (*(CXFA_TabParam**)phWidget1)->m_pWidget; @@ -407,36 +428,35 @@ void CXFA_FFTabOrderPageWidgetIterator::OrderContainer( XFA_TabOrderWidgetComparator); } for (int32_t iStart = 0; iStart < iChildren; iStart++) { - CXFA_TabParam* pParam = tabParams[iStart]; - pContainer->m_Children.Add(pParam->m_pWidget); - if (pParam->m_Children.GetSize() > 0) { - pContainer->m_Children.Append(pParam->m_Children); - } - delete pParam; + std::unique_ptr<CXFA_TabParam> pParam(tabParams[iStart]); + 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( - CXFA_WidgetArray& WidgetArray) { + std::vector<CXFA_FFWidget*>* WidgetArray) { CXFA_LayoutItemIterator sIterator; sIterator.Init(m_pPageView); - CXFA_TabParam* pParam = new CXFA_TabParam; + auto pParam = pdfium::MakeUnique<CXFA_TabParam>(); bool bCurrentItem = false; bool bContentArea = false; - OrderContainer(&sIterator, nullptr, pParam, bCurrentItem, bContentArea); - if (pParam->m_Children.GetSize() > 0) { - WidgetArray.Append(pParam->m_Children); - } + OrderContainer(&sIterator, nullptr, pParam.get(), bCurrentItem, bContentArea); + WidgetArray->insert(WidgetArray->end(), pParam->m_Children.begin(), + pParam->m_Children.end()); + sIterator.Reset(); bCurrentItem = false; bContentArea = false; - pParam->m_Children.RemoveAll(); - OrderContainer(&sIterator, nullptr, pParam, bCurrentItem, bContentArea, true); - if (pParam->m_Children.GetSize() > 0) { - WidgetArray.Append(pParam->m_Children); - } - delete pParam; + pParam->m_Children.clear(); + OrderContainer(&sIterator, nullptr, pParam.get(), bCurrentItem, bContentArea, + true); + WidgetArray->insert(WidgetArray->end(), pParam->m_Children.begin(), + pParam->m_Children.end()); } + CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetWidget( CXFA_LayoutItem* pLayoutItem) { if (CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pLayoutItem)) { diff --git a/xfa/fxfa/app/xfa_ffwidget.cpp b/xfa/fxfa/app/xfa_ffwidget.cpp index 64aed4f328..c1822470e0 100644 --- a/xfa/fxfa/app/xfa_ffwidget.cpp +++ b/xfa/fxfa/app/xfa_ffwidget.cpp @@ -1217,7 +1217,7 @@ static void XFA_BOX_GetPath_Arc(CXFA_Box box, startAngle, sweepAngle); } static void XFA_BOX_GetPath(CXFA_Box box, - const CXFA_StrokeArray& strokes, + const std::vector<CXFA_Stroke>& strokes, CFX_RectF rtWidget, CFX_Path& path, int32_t nIndex, @@ -1385,7 +1385,7 @@ static void XFA_BOX_GetPath(CXFA_Box box, } } static void XFA_BOX_GetFillPath(CXFA_Box box, - const CXFA_StrokeArray& strokes, + const std::vector<CXFA_Stroke>& strokes, CFX_RectF rtWidget, CFX_Path& fillPath, uint16_t dwFlags) { @@ -1631,7 +1631,7 @@ static void XFA_BOX_Fill_Linear(CXFA_Box box, pGS->FillPath(&fillPath, FXFILL_WINDING, pMatrix); } static void XFA_BOX_Fill(CXFA_Box box, - const CXFA_StrokeArray& strokes, + const std::vector<CXFA_Stroke>& strokes, CFX_Graphics* pGS, const CFX_RectF& rtWidget, CFX_Matrix* pMatrix, @@ -1870,7 +1870,7 @@ static void XFA_BOX_Stroke_3DRect_Embossed(CFX_Graphics* pGS, XFA_Draw3DRect(pGS, rtInner, fHalfWidth, pMatrix, 0xFF000000, 0xFF808080); } static void XFA_BOX_Stroke_Rect(CXFA_Box box, - const CXFA_StrokeArray& strokes, + const std::vector<CXFA_Stroke>& strokes, CFX_Graphics* pGS, CFX_RectF rtWidget, CFX_Matrix* pMatrix) { @@ -1961,7 +1961,7 @@ static void XFA_BOX_Stroke_Rect(CXFA_Box box, } } static void XFA_BOX_Stroke(CXFA_Box box, - const CXFA_StrokeArray& strokes, + const std::vector<CXFA_Stroke>& strokes, CFX_Graphics* pGS, CFX_RectF rtWidget, CFX_Matrix* pMatrix, @@ -2038,10 +2038,10 @@ void XFA_DrawBox(CXFA_Box box, eType != XFA_Element::Rectangle) { return; } - CXFA_StrokeArray strokes; - if (!(dwFlags & XFA_DRAWBOX_ForceRound) && eType != XFA_Element::Arc) { - box.GetStrokes(strokes); - } + std::vector<CXFA_Stroke> strokes; + if (!(dwFlags & XFA_DRAWBOX_ForceRound) && eType != XFA_Element::Arc) + box.GetStrokes(&strokes); + XFA_BOX_Fill(box, strokes, pGS, rtWidget, pMatrix, dwFlags); XFA_BOX_Stroke(box, strokes, pGS, rtWidget, pMatrix, dwFlags); } |