summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-20 20:28:23 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-20 20:28:23 +0000
commite74ae8c02f6b5efa37ba11bcad6b714046cfc7b0 (patch)
tree1c5353b26b58732e5bda616ba5d9fc8f414a7037 /xfa/fxfa
parent68c77592f25f9173d2166fa01fb34b4155f4cfcb (diff)
downloadpdfium-e74ae8c02f6b5efa37ba11bcad6b714046cfc7b0.tar.xz
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 <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/cxfa_ffdocview.cpp18
-rw-r--r--xfa/fxfa/cxfa_ffwidget.h1
-rw-r--r--xfa/fxfa/cxfa_widgetacc.cpp16
-rw-r--r--xfa/fxfa/parser/cxfa_contentlayoutitem.cpp4
-rw-r--r--xfa/fxfa/parser/cxfa_contentlayoutitem.h2
-rw-r--r--xfa/fxfa/parser/cxfa_document.cpp12
-rw-r--r--xfa/fxfa/parser/cxfa_document.h1
-rw-r--r--xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp14
-rw-r--r--xfa/fxfa/parser/cxfa_layoutpagemgr.cpp32
-rw-r--r--xfa/fxfa/parser/cxfa_layoutprocessor.cpp3
10 files changed, 35 insertions, 68 deletions
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp
index 3895d54569..928bc1e0d4 100644
--- a/xfa/fxfa/cxfa_ffdocview.cpp
+++ b/xfa/fxfa/cxfa_ffdocview.cpp
@@ -33,8 +33,6 @@
#include "xfa/fxfa/parser/cxfa_layoutprocessor.h"
#include "xfa/fxfa/parser/xfa_resolvenode_rs.h"
-#define XFA_CalcRefCount (void*)(uintptr_t) FXBSTR_ID('X', 'F', 'A', 'R')
-
const XFA_ATTRIBUTEENUM gs_EventActivity[] = {
XFA_ATTRIBUTEENUM_Click, XFA_ATTRIBUTEENUM_Change,
XFA_ATTRIBUTEENUM_DocClose, XFA_ATTRIBUTEENUM_DocReady,
@@ -616,8 +614,7 @@ void CXFA_FFDocView::AddCalculateWidgetAcc(CXFA_WidgetAcc* pWidgetAcc) {
}
void CXFA_FFDocView::AddCalculateNodeNotify(CXFA_Node* pNodeChange) {
- auto* pGlobalData = static_cast<CXFA_CalcData*>(
- pNodeChange->JSNode()->GetUserData(XFA_CalcData, false));
+ CXFA_CalcData* pGlobalData = pNodeChange->JSNode()->GetCalcData();
if (!pGlobalData)
return;
@@ -631,13 +628,9 @@ size_t CXFA_FFDocView::RunCalculateRecursive(size_t index) {
while (index < m_CalculateAccs.size()) {
CXFA_WidgetAcc* pCurAcc = m_CalculateAccs[index];
AddCalculateNodeNotify(pCurAcc->GetNode());
- int32_t iRefCount =
- (int32_t)(uintptr_t)pCurAcc->GetNode()->JSNode()->GetUserData(
- XFA_CalcRefCount, false);
- iRefCount++;
- pCurAcc->GetNode()->JSNode()->SetUserData(
- XFA_CalcRefCount, (void*)(uintptr_t)iRefCount, nullptr);
- if (iRefCount > 11)
+ size_t recurse = pCurAcc->GetNode()->JSNode()->GetCalcRecursionCount() + 1;
+ pCurAcc->GetNode()->JSNode()->SetCalcRecursionCount(recurse);
+ if (recurse > 11)
break;
if (pCurAcc->ProcessCalculate() == XFA_EVENTERROR_Success)
AddValidateWidget(pCurAcc);
@@ -654,8 +647,7 @@ int32_t CXFA_FFDocView::RunCalculateWidgets() {
RunCalculateRecursive(0);
for (CXFA_WidgetAcc* pCurAcc : m_CalculateAccs)
- pCurAcc->GetNode()->JSNode()->SetUserData(XFA_CalcRefCount, nullptr,
- nullptr);
+ pCurAcc->GetNode()->JSNode()->SetCalcRecursionCount(0);
m_CalculateAccs.clear();
return XFA_EVENTERROR_Success;
diff --git a/xfa/fxfa/cxfa_ffwidget.h b/xfa/fxfa/cxfa_ffwidget.h
index 7bc3d6b682..2c20f1d33b 100644
--- a/xfa/fxfa/cxfa_ffwidget.h
+++ b/xfa/fxfa/cxfa_ffwidget.h
@@ -26,7 +26,6 @@ inline float XFA_UnitPx2Pt(float fPx, float fDpi) {
}
#define XFA_FLOAT_PERCISION 0.001f
-#define XFA_CalcData (void*)(uintptr_t) FXBSTR_ID('X', 'F', 'A', 'C')
enum XFA_WIDGETITEM {
XFA_WIDGETITEM_Parent,
diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp
index b019bf636c..6f852f3321 100644
--- a/xfa/fxfa/cxfa_widgetacc.cpp
+++ b/xfa/fxfa/cxfa_widgetacc.cpp
@@ -36,14 +36,6 @@ class CXFA_WidgetLayoutData {
namespace {
-void FFDeleteCalcData(void* pData) {
- if (pData)
- delete ((CXFA_CalcData*)pData);
-}
-
-static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADeleteCalcData = {FFDeleteCalcData,
- nullptr};
-
class CXFA_TextLayoutData : public CXFA_WidgetLayoutData {
public:
CXFA_TextLayoutData() {}
@@ -644,12 +636,10 @@ std::pair<int32_t, bool> CXFA_WidgetAcc::ExecuteBoolScript(
if (static_cast<CXFA_WidgetAcc*>(pRefNode->GetWidgetData()) == this)
continue;
- auto* pGlobalData = static_cast<CXFA_CalcData*>(
- pRefNode->JSNode()->GetUserData(XFA_CalcData, false));
+ CXFA_CalcData* pGlobalData = pRefNode->JSNode()->GetCalcData();
if (!pGlobalData) {
- pGlobalData = new CXFA_CalcData;
- pRefNode->JSNode()->SetUserData(XFA_CalcData, pGlobalData,
- &gs_XFADeleteCalcData);
+ pRefNode->JSNode()->SetCalcData(pdfium::MakeUnique<CXFA_CalcData>());
+ pGlobalData = pRefNode->JSNode()->GetCalcData();
}
if (!pdfium::ContainsValue(pGlobalData->m_Globals, this))
pGlobalData->m_Globals.push_back(this);
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<CXFA_ContentLayoutItem*>(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<CXFA_ContentLayoutItem*>(
+ 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<CXFA_ContentLayoutItem*>(
+ 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<CXFA_ContainerLayoutItem*>(
- 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<CXFA_ContainerLayoutItem*>(
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<CXFA_LayoutItem*>(
- 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<CXFA_LayoutItem*>(
- 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<CXFA_LayoutItem*>(
- 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<CXFA_LayoutItem*>(
- pFormItem->JSNode()->GetUserData(XFA_LAYOUTITEMKEY, false));
+ return pFormItem->JSNode()->GetLayoutItem();
}
void CXFA_LayoutProcessor::AddChangedContainer(CXFA_Node* pContainer) {