From e74ae8c02f6b5efa37ba11bcad6b714046cfc7b0 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 20 Nov 2017 20:28:23 +0000 Subject: Convert calc data and layout item to store in CJX_Node This CL moves the XFA_CalcData and XFA_LayoutItem out of the map'd data for a CJX_Node and stores directly on the node. This makes the object a bit bigger but makes the code a lot more understandable. Change-Id: I8897a52d61d37595181960c23928984aa5d67efc Reviewed-on: https://pdfium-review.googlesource.com/18590 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- xfa/fxfa/parser/cxfa_contentlayoutitem.cpp | 4 ++-- xfa/fxfa/parser/cxfa_contentlayoutitem.h | 2 -- xfa/fxfa/parser/cxfa_document.cpp | 12 ++++------- xfa/fxfa/parser/cxfa_document.h | 1 - xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp | 14 ++++++------ xfa/fxfa/parser/cxfa_layoutpagemgr.cpp | 32 ++++++++++++---------------- xfa/fxfa/parser/cxfa_layoutprocessor.cpp | 3 +-- 7 files changed, 27 insertions(+), 41 deletions(-) (limited to 'xfa/fxfa/parser') diff --git a/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp b/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp index 28871259ce..0c9cab4e2d 100644 --- a/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp +++ b/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp @@ -15,6 +15,6 @@ CXFA_ContentLayoutItem::CXFA_ContentLayoutItem(CXFA_Node* pNode) m_dwStatus(0) {} CXFA_ContentLayoutItem::~CXFA_ContentLayoutItem() { - if (m_pFormNode->JSNode()->GetUserData(XFA_LAYOUTITEMKEY, false) == this) - m_pFormNode->JSNode()->SetUserData(XFA_LAYOUTITEMKEY, nullptr, nullptr); + if (m_pFormNode->JSNode()->GetLayoutItem() == this) + m_pFormNode->JSNode()->SetLayoutItem(nullptr); } diff --git a/xfa/fxfa/parser/cxfa_contentlayoutitem.h b/xfa/fxfa/parser/cxfa_contentlayoutitem.h index 9d1fc2abcf..500d3e4959 100644 --- a/xfa/fxfa/parser/cxfa_contentlayoutitem.h +++ b/xfa/fxfa/parser/cxfa_contentlayoutitem.h @@ -9,8 +9,6 @@ #include "xfa/fxfa/parser/cxfa_layoutitem.h" -#define XFA_LAYOUTITEMKEY (void*)(uintptr_t) FXBSTR_ID('L', 'Y', 'I', 'M') - class CXFA_ContentLayoutItem : public CXFA_LayoutItem { public: explicit CXFA_ContentLayoutItem(CXFA_Node* pNode); diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp index edae6c3837..bdb8d9a0e5 100644 --- a/xfa/fxfa/parser/cxfa_document.cpp +++ b/xfa/fxfa/parser/cxfa_document.cpp @@ -99,7 +99,10 @@ CXFA_Document::~CXFA_Document() { m_pRootNode->ReleaseBindingNodes(); delete m_pRootNode; - PurgeNodes(); + + for (CXFA_Node* pNode : m_PurgeNodes) + delete pNode; + m_PurgeNodes.clear(); } CXFA_LayoutProcessor* CXFA_Document::GetLayoutProcessor() { @@ -238,13 +241,6 @@ bool CXFA_Document::RemovePurgeNode(CXFA_Node* pNode) { return !!m_PurgeNodes.erase(pNode); } -void CXFA_Document::PurgeNodes() { - for (CXFA_Node* pNode : m_PurgeNodes) - delete pNode; - - m_PurgeNodes.clear(); -} - void CXFA_Document::SetFlag(uint32_t dwFlag, bool bOn) { if (bOn) m_dwDocFlags |= dwFlag; diff --git a/xfa/fxfa/parser/cxfa_document.h b/xfa/fxfa/parser/cxfa_document.h index 4be4bb0475..45e9236ee8 100644 --- a/xfa/fxfa/parser/cxfa_document.h +++ b/xfa/fxfa/parser/cxfa_document.h @@ -79,7 +79,6 @@ class CXFA_Document { void AddPurgeNode(CXFA_Node* pNode); bool RemovePurgeNode(CXFA_Node* pNode); - void PurgeNodes(); bool HasFlag(uint32_t dwFlag) { return (m_dwDocFlags & dwFlag) == dwFlag; } void SetFlag(uint32_t dwFlag, bool bOn); diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp index bf63a2a56c..ec610293ce 100644 --- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp @@ -612,8 +612,7 @@ void DeleteLayoutGeneratedNode(CXFA_Node* pGenerateNode) { for (CXFA_Node* pNode = sIterator.GetCurrent(); pNode; pNode = sIterator.MoveToNext()) { CXFA_ContentLayoutItem* pCurLayoutItem = - (CXFA_ContentLayoutItem*)pNode->JSNode()->GetUserData(XFA_LAYOUTITEMKEY, - false); + static_cast(pNode->JSNode()->GetLayoutItem()); CXFA_ContentLayoutItem* pNextLayoutItem = nullptr; while (pCurLayoutItem) { pNextLayoutItem = pCurLayoutItem->m_pNext; @@ -1156,9 +1155,8 @@ CXFA_ItemLayoutProcessor::CXFA_ItemLayoutProcessor(CXFA_Node* pNode, m_bHasAvailHeight(true) { ASSERT(m_pFormNode && (m_pFormNode->IsContainerNode() || m_pFormNode->GetElementType() == XFA_Element::Form)); - m_pOldLayoutItem = - (CXFA_ContentLayoutItem*)m_pFormNode->JSNode()->GetUserData( - XFA_LAYOUTITEMKEY, false); + m_pOldLayoutItem = static_cast( + m_pFormNode->JSNode()->GetLayoutItem()); } CXFA_ItemLayoutProcessor::~CXFA_ItemLayoutProcessor() {} @@ -1178,8 +1176,8 @@ CXFA_ContentLayoutItem* CXFA_ItemLayoutProcessor::CreateContentLayoutItem( ->GetNotify() ->OnCreateLayoutItem(pFormNode); CXFA_ContentLayoutItem* pPrevLayoutItem = - (CXFA_ContentLayoutItem*)pFormNode->JSNode()->GetUserData( - XFA_LAYOUTITEMKEY, false); + static_cast( + pFormNode->JSNode()->GetLayoutItem()); if (pPrevLayoutItem) { while (pPrevLayoutItem->m_pNext) pPrevLayoutItem = pPrevLayoutItem->m_pNext; @@ -1187,7 +1185,7 @@ CXFA_ContentLayoutItem* CXFA_ItemLayoutProcessor::CreateContentLayoutItem( pPrevLayoutItem->m_pNext = pLayoutItem; pLayoutItem->m_pPrev = pPrevLayoutItem; } else { - pFormNode->JSNode()->SetUserData(XFA_LAYOUTITEMKEY, pLayoutItem, nullptr); + pFormNode->JSNode()->SetLayoutItem(pLayoutItem); } return pLayoutItem; } diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp index 7a013a9a9b..2752b35718 100644 --- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp +++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp @@ -285,8 +285,8 @@ bool CXFA_LayoutPageMgr::InitLayoutPage(CXFA_Node* pFormNode) { new CXFA_ContainerLayoutItem(m_pTemplatePageSetRoot); } m_pPageSetCurRoot = m_pPageSetLayoutItemRoot; - m_pTemplatePageSetRoot->JSNode()->SetUserData( - XFA_LAYOUTITEMKEY, (void*)m_pPageSetLayoutItemRoot, nullptr); + m_pTemplatePageSetRoot->JSNode()->SetLayoutItem(m_pPageSetLayoutItemRoot); + XFA_ATTRIBUTEENUM eRelation = m_pTemplatePageSetRoot->JSNode()->GetEnum(XFA_Attribute::Relation); if (eRelation != XFA_ATTRIBUTEENUM_Unknown) @@ -505,7 +505,7 @@ CXFA_ContainerRecord* CXFA_LayoutPageMgr::CreateContainerRecord( } else { CXFA_ContainerLayoutItem* pParentLayoutItem = static_cast( - pPageSet->JSNode()->GetUserData(XFA_LAYOUTITEMKEY, false)); + pPageSet->JSNode()->GetLayoutItem()); if (!pParentLayoutItem) pParentLayoutItem = m_pPageSetCurRoot; @@ -520,12 +520,11 @@ CXFA_ContainerRecord* CXFA_LayoutPageMgr::CreateContainerRecord( pParentPageSetLayout = static_cast( pPageSet->GetNodeItem(XFA_NODEITEM_Parent) ->JSNode() - ->GetUserData(XFA_LAYOUTITEMKEY, false)); + ->GetLayoutItem()); } CXFA_ContainerLayoutItem* pPageSetLayoutItem = new CXFA_ContainerLayoutItem(pPageSet); - pPageSet->JSNode()->SetUserData(XFA_LAYOUTITEMKEY, - (void*)pPageSetLayoutItem, nullptr); + pPageSet->JSNode()->SetLayoutItem(pPageSetLayoutItem); if (!pParentPageSetLayout) { CXFA_ContainerLayoutItem* pPrePageSet = m_pPageSetLayoutItemRoot; while (pPrePageSet->m_pNextSibling) { @@ -548,8 +547,7 @@ CXFA_ContainerRecord* CXFA_LayoutPageMgr::CreateContainerRecord( } else { CXFA_ContainerLayoutItem* pPageSetLayoutItem = new CXFA_ContainerLayoutItem(pPageSet); - pPageSet->JSNode()->SetUserData(XFA_LAYOUTITEMKEY, - (void*)pPageSetLayoutItem, nullptr); + pPageSet->JSNode()->SetLayoutItem(pPageSetLayoutItem); m_pPageSetLayoutItemRoot->AddChild(pPageSetLayoutItem); pNewRecord->pCurPageSet = pPageSetLayoutItem; } @@ -1730,10 +1728,9 @@ void CXFA_LayoutPageMgr::MergePageSetContents() { pPendingPageSet = pRootPageSetContainerItem->m_pFormNode; } } - if (pRootPageSetContainerItem->m_pFormNode->JSNode()->GetUserData( - XFA_LAYOUTITEMKEY, false) == pRootPageSetContainerItem) { - pRootPageSetContainerItem->m_pFormNode->JSNode()->SetUserData( - XFA_LAYOUTITEMKEY, nullptr, nullptr); + if (pRootPageSetContainerItem->m_pFormNode->JSNode()->GetLayoutItem() == + pRootPageSetContainerItem) { + pRootPageSetContainerItem->m_pFormNode->JSNode()->SetLayoutItem(nullptr); } pRootPageSetContainerItem->m_pFormNode = pPendingPageSet; pPendingPageSet->ClearFlag(XFA_NodeFlag_UnusedNode); @@ -1780,8 +1777,8 @@ void CXFA_LayoutPageMgr::MergePageSetContents() { for (CXFA_Node* pIter = sIterator.GetCurrent(); pIter; pIter = sIterator.MoveToNext()) { if (pIter->GetElementType() != XFA_Element::ContentArea) { - CXFA_LayoutItem* pLayoutItem = static_cast( - pIter->JSNode()->GetUserData(XFA_LAYOUTITEMKEY, false)); + CXFA_LayoutItem* pLayoutItem = + pIter->JSNode()->GetLayoutItem(); if (pLayoutItem) { pNotify->OnLayoutItemRemoving(pDocLayout, pLayoutItem); delete pLayoutItem; @@ -1844,16 +1841,15 @@ void CXFA_LayoutPageMgr::MergePageSetContents() { CXFA_ContainerIterator iteChild(pNode); CXFA_Node* pChildNode = iteChild.MoveToNext(); for (; pChildNode; pChildNode = iteChild.MoveToNext()) { - CXFA_LayoutItem* pLayoutItem = static_cast( - pChildNode->JSNode()->GetUserData(XFA_LAYOUTITEMKEY, false)); + CXFA_LayoutItem* pLayoutItem = + pChildNode->JSNode()->GetLayoutItem(); if (pLayoutItem) { pNotify->OnLayoutItemRemoving(pDocLayout, pLayoutItem); delete pLayoutItem; } } } else if (eType != XFA_Element::ContentArea) { - CXFA_LayoutItem* pLayoutItem = static_cast( - pNode->JSNode()->GetUserData(XFA_LAYOUTITEMKEY, false)); + CXFA_LayoutItem* pLayoutItem = pNode->JSNode()->GetLayoutItem(); if (pLayoutItem) { pNotify->OnLayoutItemRemoving(pDocLayout, pLayoutItem); delete pLayoutItem; diff --git a/xfa/fxfa/parser/cxfa_layoutprocessor.cpp b/xfa/fxfa/parser/cxfa_layoutprocessor.cpp index a2494e24b1..b8afd6ec19 100644 --- a/xfa/fxfa/parser/cxfa_layoutprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_layoutprocessor.cpp @@ -122,8 +122,7 @@ CXFA_ContainerLayoutItem* CXFA_LayoutProcessor::GetPage(int32_t index) const { } CXFA_LayoutItem* CXFA_LayoutProcessor::GetLayoutItem(CXFA_Node* pFormItem) { - return static_cast( - pFormItem->JSNode()->GetUserData(XFA_LAYOUTITEMKEY, false)); + return pFormItem->JSNode()->GetLayoutItem(); } void CXFA_LayoutProcessor::AddChangedContainer(CXFA_Node* pContainer) { -- cgit v1.2.3