summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn1
-rw-r--r--core/fxcrt/fx_basic.h72
-rw-r--r--core/fxcrt/fx_basic_list.cpp131
-rw-r--r--xfa/fxfa/parser/cxfa_layoutpagemgr.cpp92
-rw-r--r--xfa/fxfa/parser/cxfa_layoutpagemgr.h20
5 files changed, 53 insertions, 263 deletions
diff --git a/BUILD.gn b/BUILD.gn
index b9f648fa95..1244bccf99 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -729,7 +729,6 @@ static_library("fxcrt") {
"core/fxcrt/fx_basic_buffer.cpp",
"core/fxcrt/fx_basic_coords.cpp",
"core/fxcrt/fx_basic_gcc.cpp",
- "core/fxcrt/fx_basic_list.cpp",
"core/fxcrt/fx_basic_memmgr.cpp",
"core/fxcrt/fx_basic_plex.cpp",
"core/fxcrt/fx_basic_utf.cpp",
diff --git a/core/fxcrt/fx_basic.h b/core/fxcrt/fx_basic.h
index 7096e6f8df..3b09489d71 100644
--- a/core/fxcrt/fx_basic.h
+++ b/core/fxcrt/fx_basic.h
@@ -433,79 +433,7 @@ class CFX_MapPtrTemplate : public CFX_MapPtrToPtr {
rValue = (ValueType)(uintptr_t)pValue;
}
};
-#endif // PDF_ENABLE_XFA
-
-class CFX_PtrList {
- protected:
- struct CNode {
- CNode* pNext;
- CNode* pPrev;
- void* data;
- };
-
- public:
- explicit CFX_PtrList(int nBlockSize = 10);
-
- FX_POSITION GetHeadPosition() const { return (FX_POSITION)m_pNodeHead; }
- FX_POSITION GetTailPosition() const { return (FX_POSITION)m_pNodeTail; }
-
- void* GetNext(FX_POSITION& rPosition) const {
- CNode* pNode = (CNode*)rPosition;
- rPosition = (FX_POSITION)pNode->pNext;
- return pNode->data;
- }
-
- void* GetPrev(FX_POSITION& rPosition) const {
- CNode* pNode = (CNode*)rPosition;
- rPosition = (FX_POSITION)pNode->pPrev;
- return pNode->data;
- }
-
- FX_POSITION GetNextPosition(FX_POSITION pos) const {
- return ((CNode*)pos)->pNext;
- }
-
- FX_POSITION GetPrevPosition(FX_POSITION pos) const {
- return ((CNode*)pos)->pPrev;
- }
-
- void* GetAt(FX_POSITION rPosition) const {
- CNode* pNode = (CNode*)rPosition;
- return pNode->data;
- }
- int GetCount() const { return m_nCount; }
- FX_POSITION AddTail(void* newElement);
- FX_POSITION AddHead(void* newElement);
-
- void SetAt(FX_POSITION pos, void* newElement) {
- CNode* pNode = (CNode*)pos;
- pNode->data = newElement;
- }
- FX_POSITION InsertAfter(FX_POSITION pos, void* newElement);
-
- FX_POSITION Find(void* searchValue, FX_POSITION startAfter = nullptr) const;
- FX_POSITION FindIndex(int index) const;
-
- void RemoveAt(FX_POSITION pos);
- void RemoveAll();
-
- protected:
- CNode* m_pNodeHead;
- CNode* m_pNodeTail;
- int m_nCount;
- CNode* m_pNodeFree;
- struct CFX_Plex* m_pBlocks;
- int m_nBlockSize;
-
- CNode* NewNode(CNode* pPrev, CNode* pNext);
- void FreeNode(CNode* pNode);
-
- public:
- ~CFX_PtrList();
-};
-
-#ifdef PDF_ENABLE_XFA
typedef void (*PD_CALLBACK_FREEDATA)(void* pData);
#endif // PDF_ENABLE_XFA
diff --git a/core/fxcrt/fx_basic_list.cpp b/core/fxcrt/fx_basic_list.cpp
deleted file mode 100644
index 09ad08b281..0000000000
--- a/core/fxcrt/fx_basic_list.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "core/fxcrt/fx_basic.h"
-#include "core/fxcrt/plex.h"
-
-CFX_PtrList::CFX_PtrList(int nBlockSize)
- : m_pNodeHead(nullptr),
- m_pNodeTail(nullptr),
- m_nCount(0),
- m_pNodeFree(nullptr),
- m_pBlocks(nullptr),
- m_nBlockSize(nBlockSize) {}
-FX_POSITION CFX_PtrList::AddTail(void* newElement) {
- CNode* pNewNode = NewNode(m_pNodeTail, nullptr);
- pNewNode->data = newElement;
- if (m_pNodeTail) {
- m_pNodeTail->pNext = pNewNode;
- } else {
- m_pNodeHead = pNewNode;
- }
- m_pNodeTail = pNewNode;
- return (FX_POSITION)pNewNode;
-}
-FX_POSITION CFX_PtrList::AddHead(void* newElement) {
- CNode* pNewNode = NewNode(nullptr, m_pNodeHead);
- pNewNode->data = newElement;
- if (m_pNodeHead) {
- m_pNodeHead->pPrev = pNewNode;
- } else {
- m_pNodeTail = pNewNode;
- }
- m_pNodeHead = pNewNode;
- return (FX_POSITION)pNewNode;
-}
-FX_POSITION CFX_PtrList::InsertAfter(FX_POSITION position, void* newElement) {
- if (!position) {
- return AddTail(newElement);
- }
- CNode* pOldNode = (CNode*)position;
- CNode* pNewNode = NewNode(pOldNode, pOldNode->pNext);
- pNewNode->data = newElement;
- if (pOldNode->pNext) {
- pOldNode->pNext->pPrev = pNewNode;
- } else {
- m_pNodeTail = pNewNode;
- }
- pOldNode->pNext = pNewNode;
- return (FX_POSITION)pNewNode;
-}
-void CFX_PtrList::RemoveAt(FX_POSITION position) {
- CNode* pOldNode = (CNode*)position;
- if (pOldNode == m_pNodeHead) {
- m_pNodeHead = pOldNode->pNext;
- } else {
- pOldNode->pPrev->pNext = pOldNode->pNext;
- }
- if (pOldNode == m_pNodeTail) {
- m_pNodeTail = pOldNode->pPrev;
- } else {
- pOldNode->pNext->pPrev = pOldNode->pPrev;
- }
- FreeNode(pOldNode);
-}
-void CFX_PtrList::FreeNode(CFX_PtrList::CNode* pNode) {
- pNode->pNext = m_pNodeFree;
- m_pNodeFree = pNode;
- m_nCount--;
- if (m_nCount == 0) {
- RemoveAll();
- }
-}
-
-void CFX_PtrList::RemoveAll() {
- m_nCount = 0;
- m_pNodeHead = nullptr;
- m_pNodeTail = nullptr;
- m_pNodeFree = nullptr;
- if (m_pBlocks) {
- m_pBlocks->FreeDataChain();
- m_pBlocks = nullptr;
- }
-}
-
-CFX_PtrList::CNode* CFX_PtrList::NewNode(CFX_PtrList::CNode* pPrev,
- CFX_PtrList::CNode* pNext) {
- if (!m_pNodeFree) {
- CFX_Plex* pNewBlock =
- CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CNode));
- CNode* pNode = (CNode*)pNewBlock->data();
- pNode += m_nBlockSize - 1;
- for (int i = m_nBlockSize - 1; i >= 0; i--, pNode--) {
- pNode->pNext = m_pNodeFree;
- m_pNodeFree = pNode;
- }
- }
- CFX_PtrList::CNode* pNode = m_pNodeFree;
- m_pNodeFree = m_pNodeFree->pNext;
- pNode->pPrev = pPrev;
- pNode->pNext = pNext;
- m_nCount++;
- ASSERT(m_nCount > 0);
- pNode->data = 0;
- return pNode;
-}
-CFX_PtrList::~CFX_PtrList() {
- RemoveAll();
- ASSERT(m_nCount == 0);
-}
-FX_POSITION CFX_PtrList::FindIndex(int nIndex) const {
- if (nIndex >= m_nCount || nIndex < 0) {
- return nullptr;
- }
- CNode* pNode = m_pNodeHead;
- while (nIndex--) {
- pNode = pNode->pNext;
- }
- return (FX_POSITION)pNode;
-}
-FX_POSITION CFX_PtrList::Find(void* searchValue, FX_POSITION startAfter) const {
- CNode* pNode = (CNode*)startAfter;
- pNode = pNode ? pNode->pNext : m_pNodeHead;
- for (; pNode; pNode = pNode->pNext) {
- if (pNode->data == searchValue)
- return (FX_POSITION)pNode;
- }
- return nullptr;
-}
diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
index 1be6d27129..1a3da9ecb3 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp
@@ -243,7 +243,7 @@ CXFA_LayoutPageMgr::CXFA_LayoutPageMgr(CXFA_LayoutProcessor* pLayoutProcessor)
m_pTemplatePageSetRoot(nullptr),
m_pPageSetLayoutItemRoot(nullptr),
m_pPageSetCurRoot(nullptr),
- m_pCurrentContainerRecord(nullptr),
+ m_CurrentContainerRecordIter(m_ProposedContainerRecords.end()),
m_pCurPageArea(nullptr),
m_nAvailPages(0),
m_nCurPageCount(0),
@@ -378,23 +378,26 @@ bool CXFA_LayoutPageMgr::PrepareFirstPage(CXFA_Node* pRootSubform) {
CXFA_Node *pLeader, *pTrailer;
if (pBreakBeforeNode &&
ExecuteBreakBeforeOrAfter(pBreakBeforeNode, true, pLeader, pTrailer)) {
- m_pCurrentContainerRecord = m_rgProposedContainerRecord.GetHeadPosition();
+ m_CurrentContainerRecordIter = m_ProposedContainerRecords.begin();
return true;
}
return AppendNewPage(true);
}
bool CXFA_LayoutPageMgr::AppendNewPage(bool bFirstTemPage) {
- if (m_pCurrentContainerRecord !=
- m_rgProposedContainerRecord.GetTailPosition()) {
+ if (m_CurrentContainerRecordIter != GetTailPosition())
return true;
- }
+
CXFA_Node* pPageNode = GetNextAvailPageArea(nullptr);
if (!pPageNode)
return false;
- if (bFirstTemPage && !m_pCurrentContainerRecord)
- m_pCurrentContainerRecord = m_rgProposedContainerRecord.GetHeadPosition();
- return !bFirstTemPage || m_pCurrentContainerRecord;
+
+ if (bFirstTemPage &&
+ m_CurrentContainerRecordIter == m_ProposedContainerRecords.end()) {
+ m_CurrentContainerRecordIter = m_ProposedContainerRecords.begin();
+ }
+ return !bFirstTemPage ||
+ m_CurrentContainerRecordIter != m_ProposedContainerRecords.end();
}
void CXFA_LayoutPageMgr::RemoveLayoutRecord(CXFA_ContainerRecord* pNewRecord,
@@ -444,11 +447,10 @@ void CXFA_LayoutPageMgr::SubmitContentItem(
if (eStatus != XFA_ItemLayoutProcessorResult_Done) {
if (eStatus == XFA_ItemLayoutProcessorResult_PageFullBreak &&
- m_pCurrentContainerRecord ==
- m_rgProposedContainerRecord.GetTailPosition()) {
+ m_CurrentContainerRecordIter == GetTailPosition()) {
AppendNewPage();
}
- m_pCurrentContainerRecord = m_rgProposedContainerRecord.GetTailPosition();
+ m_CurrentContainerRecordIter = GetTailPosition();
m_pCurPageArea = GetCurrentContainerRecord()->pCurPageArea->m_pFormNode;
}
}
@@ -463,10 +465,8 @@ FX_FLOAT CXFA_LayoutPageMgr::GetAvailHeight() {
pLayoutItem->m_pFormNode->GetMeasure(XFA_ATTRIBUTE_H).ToUnit(XFA_UNIT_Pt);
if (fAvailHeight >= XFA_LAYOUT_FLOAT_PERCISION)
return fAvailHeight;
- if (m_pCurrentContainerRecord ==
- m_rgProposedContainerRecord.GetHeadPosition()) {
+ if (m_CurrentContainerRecordIter == m_ProposedContainerRecords.begin())
return 0.0f;
- }
return XFA_LAYOUT_FLOAT_MAX;
}
@@ -484,10 +484,10 @@ CXFA_ContainerRecord* CXFA_LayoutPageMgr::CreateContainerRecord(
CXFA_Node* pPageNode,
bool bCreateNew) {
CXFA_ContainerRecord* pNewRecord = new CXFA_ContainerRecord();
- if (m_pCurrentContainerRecord) {
+ if (m_CurrentContainerRecordIter != m_ProposedContainerRecords.end()) {
if (!IsPageSetRootOrderedOccurrence() || !pPageNode) {
*pNewRecord = *GetCurrentContainerRecord();
- m_rgProposedContainerRecord.AddTail(pNewRecord);
+ m_ProposedContainerRecords.push_back(pNewRecord);
return pNewRecord;
}
CXFA_Node* pPageSet = pPageNode->GetNodeItem(XFA_NODEITEM_Parent);
@@ -546,7 +546,7 @@ CXFA_ContainerRecord* CXFA_LayoutPageMgr::CreateContainerRecord(
pNewRecord->pCurPageSet = m_pPageSetLayoutItemRoot;
}
}
- m_rgProposedContainerRecord.AddTail(pNewRecord);
+ m_ProposedContainerRecords.push_back(pNewRecord);
return pNewRecord;
}
@@ -748,7 +748,8 @@ bool CXFA_LayoutPageMgr::RunBreak(XFA_Element eBreakType,
case XFA_ATTRIBUTEENUM_ContentArea:
if (pTarget && pTarget->GetElementType() != XFA_Element::ContentArea)
pTarget = nullptr;
- if (!pTarget || !m_pCurrentContainerRecord ||
+ if (!pTarget ||
+ m_CurrentContainerRecordIter == m_ProposedContainerRecords.end() ||
pTarget !=
GetCurrentContainerRecord()->pCurContentArea->m_pFormNode ||
bStartNew) {
@@ -763,7 +764,8 @@ bool CXFA_LayoutPageMgr::RunBreak(XFA_Element eBreakType,
case XFA_ATTRIBUTEENUM_PageArea:
if (pTarget && pTarget->GetElementType() != XFA_Element::PageArea)
pTarget = nullptr;
- if (!pTarget || !m_pCurrentContainerRecord ||
+ if (!pTarget ||
+ m_CurrentContainerRecordIter == m_ProposedContainerRecords.end() ||
pTarget != GetCurrentContainerRecord()->pCurPageArea->m_pFormNode ||
bStartNew) {
CXFA_Node* pPageArea = GetNextAvailPageArea(pTarget, nullptr, true);
@@ -816,9 +818,8 @@ bool CXFA_LayoutPageMgr::ExecuteBreakBeforeOrAfter(
bStartNew)) {
return true;
}
- if (m_rgProposedContainerRecord.GetCount() > 0 &&
- m_pCurrentContainerRecord ==
- m_rgProposedContainerRecord.GetHeadPosition() &&
+ if (!m_ProposedContainerRecords.empty() &&
+ m_CurrentContainerRecordIter == m_ProposedContainerRecords.begin() &&
eType == XFA_Element::BreakBefore) {
CXFA_Node* pParentNode = pFormNode->GetNodeItem(
XFA_NODEITEM_Parent, XFA_ObjectType::ContainerNode);
@@ -1101,9 +1102,10 @@ bool CXFA_LayoutPageMgr::FindPageAreaFromPageSet(CXFA_Node* pPageSet,
pTargetPageArea, pTargetContentArea,
bNewPage, bQuery);
}
- XFA_ATTRIBUTEENUM ePreferredPosition = m_pCurrentContainerRecord
- ? XFA_ATTRIBUTEENUM_Rest
- : XFA_ATTRIBUTEENUM_First;
+ XFA_ATTRIBUTEENUM ePreferredPosition =
+ m_CurrentContainerRecordIter != m_ProposedContainerRecords.end()
+ ? XFA_ATTRIBUTEENUM_Rest
+ : XFA_ATTRIBUTEENUM_First;
return FindPageAreaFromPageSet_SimplexDuplex(
pPageSet, pStartChild, pTargetPageArea, pTargetContentArea, bNewPage,
bQuery, ePreferredPosition);
@@ -1528,21 +1530,18 @@ bool CXFA_LayoutPageMgr::GetNextAvailContentHeight(FX_FLOAT fChildHeight) {
if (m_nCurPageCount == iMax) {
CXFA_Node* pSrcPage = m_pCurPageArea;
int32_t nSrcPageCount = m_nCurPageCount;
- FX_POSITION psSrcRecord = m_rgProposedContainerRecord.GetTailPosition();
+ auto psSrcIter = GetTailPosition();
CXFA_Node* pNextPage =
GetNextAvailPageArea(nullptr, nullptr, false, true);
m_pCurPageArea = pSrcPage;
m_nCurPageCount = nSrcPageCount;
- CXFA_ContainerRecord* pPrevRecord = static_cast<CXFA_ContainerRecord*>(
- m_rgProposedContainerRecord.GetNext(psSrcRecord));
- while (psSrcRecord) {
- FX_POSITION psSaveRecord = psSrcRecord;
- CXFA_ContainerRecord* pInsertRecord =
- static_cast<CXFA_ContainerRecord*>(
- m_rgProposedContainerRecord.GetNext(psSrcRecord));
+ CXFA_ContainerRecord* pPrevRecord = *psSrcIter++;
+ while (psSrcIter != m_ProposedContainerRecords.end()) {
+ auto psSaveIter = psSrcIter;
+ CXFA_ContainerRecord* pInsertRecord = *psSrcIter++;
RemoveLayoutRecord(pInsertRecord, pPrevRecord);
delete pInsertRecord;
- m_rgProposedContainerRecord.RemoveAt(psSaveRecord);
+ m_ProposedContainerRecords.erase(psSaveIter);
}
if (pNextPage) {
CXFA_Node* pContentArea =
@@ -1570,23 +1569,16 @@ bool CXFA_LayoutPageMgr::GetNextAvailContentHeight(FX_FLOAT fChildHeight) {
}
void CXFA_LayoutPageMgr::ClearData() {
- ClearRecordList();
-}
-
-void CXFA_LayoutPageMgr::ClearRecordList() {
if (!m_pTemplatePageSetRoot)
return;
- if (m_rgProposedContainerRecord.GetCount() > 0) {
- FX_POSITION sPos;
- sPos = m_rgProposedContainerRecord.GetHeadPosition();
- while (sPos) {
- CXFA_ContainerRecord* pRecord = static_cast<CXFA_ContainerRecord*>(
- m_rgProposedContainerRecord.GetNext(sPos));
- delete pRecord;
- }
- m_rgProposedContainerRecord.RemoveAll();
+
+ auto sPos = m_ProposedContainerRecords.begin();
+ while (sPos != m_ProposedContainerRecords.end()) {
+ CXFA_ContainerRecord* pRecord = *sPos++;
+ delete pRecord;
}
- m_pCurrentContainerRecord = nullptr;
+ m_ProposedContainerRecords.clear();
+ m_CurrentContainerRecordIter = m_ProposedContainerRecords.end();
m_pCurPageArea = nullptr;
m_nCurPageCount = 0;
m_bCreateOverFlowPage = false;
@@ -1942,7 +1934,7 @@ void CXFA_LayoutPageMgr::SyncLayoutData() {
pNotify->OnPageEvent(pPage, XFA_PAGEVIEWEVENT_PostRemoved);
delete pPage;
}
- ClearRecordList();
+ ClearData();
}
void XFA_ReleaseLayoutItem_NoPageArea(CXFA_LayoutItem* pLayoutItem) {
@@ -1961,7 +1953,7 @@ void CXFA_LayoutPageMgr::PrepareLayout() {
m_pPageSetCurRoot = nullptr;
m_ePageSetMode = XFA_ATTRIBUTEENUM_OrderedOccurrence;
m_nAvailPages = 0;
- ClearRecordList();
+ ClearData();
if (!m_pPageSetLayoutItemRoot)
return;
diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.h b/xfa/fxfa/parser/cxfa_layoutpagemgr.h
index 3f0410f74c..b466f3ad1f 100644
--- a/xfa/fxfa/parser/cxfa_layoutpagemgr.h
+++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.h
@@ -7,6 +7,9 @@
#ifndef XFA_FXFA_PARSER_CXFA_LAYOUTPAGEMGR_H_
#define XFA_FXFA_PARSER_CXFA_LAYOUTPAGEMGR_H_
+#include <iterator>
+#include <list>
+
#include "xfa/fxfa/parser/xfa_layout_itemlayout.h"
class CXFA_ContainerRecord;
@@ -54,12 +57,12 @@ class CXFA_LayoutPageMgr {
CXFA_ContainerRecord* pPrevRecord);
void RemoveLayoutRecord(CXFA_ContainerRecord* pNewRecord,
CXFA_ContainerRecord* pPrevRecord);
- inline CXFA_ContainerRecord* GetCurrentContainerRecord() {
- CXFA_ContainerRecord* result =
- ((CXFA_ContainerRecord*)m_rgProposedContainerRecord.GetAt(
- m_pCurrentContainerRecord));
- ASSERT(result);
- return result;
+ CXFA_ContainerRecord* GetCurrentContainerRecord() {
+ return *m_CurrentContainerRecordIter;
+ }
+ std::list<CXFA_ContainerRecord*>::iterator GetTailPosition() {
+ auto iter = m_ProposedContainerRecords.end();
+ return !m_ProposedContainerRecords.empty() ? std::prev(iter) : iter;
}
CXFA_ContainerRecord* CreateContainerRecord(CXFA_Node* pPageNode = nullptr,
bool bCreateNew = false);
@@ -120,7 +123,6 @@ class CXFA_LayoutPageMgr {
return m_ePageSetMode == XFA_ATTRIBUTEENUM_OrderedOccurrence;
}
void ClearData();
- void ClearRecordList();
void MergePageSetContents();
void LayoutPageSetContents();
void PrepareLayout();
@@ -129,8 +131,8 @@ class CXFA_LayoutPageMgr {
CXFA_Node* m_pTemplatePageSetRoot;
CXFA_ContainerLayoutItem* m_pPageSetLayoutItemRoot;
CXFA_ContainerLayoutItem* m_pPageSetCurRoot;
- FX_POSITION m_pCurrentContainerRecord;
- CFX_PtrList m_rgProposedContainerRecord;
+ std::list<CXFA_ContainerRecord*> m_ProposedContainerRecords;
+ std::list<CXFA_ContainerRecord*>::iterator m_CurrentContainerRecordIter;
CXFA_Node* m_pCurPageArea;
int32_t m_nAvailPages;
int32_t m_nCurPageCount;