summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-01 18:39:27 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-01 18:39:27 +0000
commit4ac35f239938877b15e6bbe1a5c73aab14a2ae5d (patch)
tree46541fbdad75ed9273e7f90cab3028b606dcf7b9
parenta85e5ca5f2dfadcf9f3812a8ef039d1f206833a4 (diff)
downloadpdfium-4ac35f239938877b15e6bbe1a5c73aab14a2ae5d.tar.xz
Move the item methods into CXFA_Node propertly
When CreateInstance, GetCount, GetItem, RemoveItem and InsertItem were moved out of the anonymous namespace they were not updated to remove the first parameter. This Cl removes the first parameter and uses the CXFA_Node as the thing to operate on. Change-Id: I1b6dc956844786c8ba88ae508547c9cf6e91242a Reviewed-on: https://pdfium-review.googlesource.com/17311 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r--fxjs/cjx_node.cpp53
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp50
-rw-r--r--xfa/fxfa/parser/cxfa_node.h13
3 files changed, 51 insertions, 65 deletions
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp
index 08b32e12bd..b7175bcb48 100644
--- a/fxjs/cjx_node.cpp
+++ b/fxjs/cjx_node.cpp
@@ -352,7 +352,7 @@ int32_t CJX_Node::InstanceManager_SetInstances(int32_t iDesired) {
ThrowTooManyOccurancesException(L"max");
return 2;
}
- int32_t iCount = GetXFANode()->GetCount(GetXFANode());
+ int32_t iCount = GetXFANode()->GetCount();
if (iDesired == iCount)
return 0;
@@ -365,8 +365,7 @@ int32_t CJX_Node::InstanceManager_SetInstances(int32_t iDesired) {
uint32_t dInstanceNameHash =
FX_HashCode_GetW(wsInstanceName.AsStringView(), false);
CXFA_Node* pPrevSibling =
- (iDesired == 0) ? GetXFANode()
- : GetXFANode()->GetItem(GetXFANode(), iDesired - 1);
+ (iDesired == 0) ? GetXFANode() : GetXFANode()->GetItem(iDesired - 1);
while (iCount > iDesired) {
CXFA_Node* pRemoveInstance =
pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
@@ -379,16 +378,14 @@ int32_t CJX_Node::InstanceManager_SetInstances(int32_t iDesired) {
break;
}
if (pRemoveInstance->GetNameHash() == dInstanceNameHash) {
- GetXFANode()->RemoveItem(GetXFANode(), pRemoveInstance);
+ GetXFANode()->RemoveItem(pRemoveInstance);
iCount--;
}
}
- } else if (iDesired > iCount) {
+ } else {
while (iCount < iDesired) {
- CXFA_Node* pNewInstance =
- GetXFANode()->CreateInstance(GetXFANode(), true);
- GetXFANode()->InsertItem(GetXFANode(), pNewInstance, iCount, iCount,
- false);
+ CXFA_Node* pNewInstance = GetXFANode()->CreateInstance(true);
+ GetXFANode()->InsertItem(pNewInstance, iCount, iCount, false);
iCount++;
CXFA_FFNotify* pNotify = GetXFANode()->GetDocument()->GetNotify();
if (!pNotify) {
@@ -408,7 +405,7 @@ int32_t CJX_Node::InstanceManager_SetInstances(int32_t iDesired) {
}
int32_t CJX_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
- int32_t iCount = GetXFANode()->GetCount(GetXFANode());
+ int32_t iCount = GetXFANode()->GetCount();
if (iFrom > iCount || iTo > iCount - 1) {
ThrowIndexOutOfBoundsException();
return 1;
@@ -416,9 +413,9 @@ int32_t CJX_Node::InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom) {
if (iFrom < 0 || iTo < 0 || iFrom == iTo)
return 0;
- CXFA_Node* pMoveInstance = GetXFANode()->GetItem(GetXFANode(), iFrom);
- GetXFANode()->RemoveItem(GetXFANode(), pMoveInstance, false);
- GetXFANode()->InsertItem(GetXFANode(), pMoveInstance, iTo, iCount - 1, true);
+ CXFA_Node* pMoveInstance = GetXFANode()->GetItem(iFrom);
+ GetXFANode()->RemoveItem(pMoveInstance, false);
+ GetXFANode()->InsertItem(pMoveInstance, iTo, iCount - 1, true);
CXFA_LayoutProcessor* pLayoutPro =
GetXFANode()->GetDocument()->GetLayoutProcessor();
if (pLayoutPro) {
@@ -2196,12 +2193,12 @@ void CJX_Node::Script_Som_InstanceIndex(CFXJSE_Value* pValue,
if (!pNotify) {
return;
}
- CXFA_Node* pToInstance = GetXFANode()->GetItem(pManagerNode, iTo);
+ CXFA_Node* pToInstance = pManagerNode->GetItem(iTo);
if (pToInstance &&
pToInstance->GetElementType() == XFA_Element::Subform) {
pNotify->RunSubformIndexChange(pToInstance);
}
- CXFA_Node* pFromInstance = GetXFANode()->GetItem(pManagerNode, iFrom);
+ CXFA_Node* pFromInstance = pManagerNode->GetItem(iFrom);
if (pFromInstance &&
pFromInstance->GetElementType() == XFA_Element::Subform) {
pNotify->RunSubformIndexChange(pFromInstance);
@@ -2475,7 +2472,7 @@ void CJX_Node::Script_InstanceManager_Count(CFXJSE_Value* pValue,
int32_t iDesired = pValue->ToInteger();
InstanceManager_SetInstances(iDesired);
} else {
- pValue->SetInteger(GetXFANode()->GetCount(GetXFANode()));
+ pValue->SetInteger(GetXFANode()->GetCount());
}
}
@@ -2492,11 +2489,11 @@ void CJX_Node::Script_InstanceManager_MoveInstance(
if (!pNotify) {
return;
}
- CXFA_Node* pToInstance = GetXFANode()->GetItem(GetXFANode(), iTo);
+ CXFA_Node* pToInstance = GetXFANode()->GetItem(iTo);
if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) {
pNotify->RunSubformIndexChange(pToInstance);
}
- CXFA_Node* pFromInstance = GetXFANode()->GetItem(GetXFANode(), iFrom);
+ CXFA_Node* pFromInstance = GetXFANode()->GetItem(iFrom);
if (pFromInstance &&
pFromInstance->GetElementType() == XFA_Element::Subform) {
pNotify->RunSubformIndexChange(pFromInstance);
@@ -2510,7 +2507,7 @@ void CJX_Node::Script_InstanceManager_RemoveInstance(
return;
}
int32_t iIndex = pArguments->GetInt32(0);
- int32_t iCount = GetXFANode()->GetCount(GetXFANode());
+ int32_t iCount = GetXFANode()->GetCount();
if (iIndex < 0 || iIndex >= iCount) {
ThrowIndexOutOfBoundsException();
return;
@@ -2521,12 +2518,12 @@ void CJX_Node::Script_InstanceManager_RemoveInstance(
ThrowTooManyOccurancesException(L"min");
return;
}
- CXFA_Node* pRemoveInstance = GetXFANode()->GetItem(GetXFANode(), iIndex);
- GetXFANode()->RemoveItem(GetXFANode(), pRemoveInstance);
+ CXFA_Node* pRemoveInstance = GetXFANode()->GetItem(iIndex);
+ GetXFANode()->RemoveItem(pRemoveInstance);
CXFA_FFNotify* pNotify = GetXFANode()->GetDocument()->GetNotify();
if (pNotify) {
for (int32_t i = iIndex; i < iCount - 1; i++) {
- CXFA_Node* pSubformInstance = GetXFANode()->GetItem(GetXFANode(), i);
+ CXFA_Node* pSubformInstance = GetXFANode()->GetItem(i);
if (pSubformInstance &&
pSubformInstance->GetElementType() == XFA_Element::Subform) {
pNotify->RunSubformIndexChange(pSubformInstance);
@@ -2563,15 +2560,15 @@ void CJX_Node::Script_InstanceManager_AddInstance(
if (argc == 1) {
fFlags = pArguments->GetInt32(0) == 0 ? false : true;
}
- int32_t iCount = GetXFANode()->GetCount(GetXFANode());
+ int32_t iCount = GetXFANode()->GetCount();
CXFA_Occur nodeOccur(GetXFANode()->GetOccurNode());
int32_t iMax = nodeOccur.GetMax();
if (iMax >= 0 && iCount >= iMax) {
ThrowTooManyOccurancesException(L"max");
return;
}
- CXFA_Node* pNewInstance = GetXFANode()->CreateInstance(GetXFANode(), fFlags);
- GetXFANode()->InsertItem(GetXFANode(), pNewInstance, iCount, iCount, false);
+ CXFA_Node* pNewInstance = GetXFANode()->CreateInstance(fFlags);
+ GetXFANode()->InsertItem(pNewInstance, iCount, iCount, false);
pArguments->GetReturnValue()->Assign(
GetXFANode()->GetDocument()->GetScriptContext()->GetJSValueFromMap(
pNewInstance));
@@ -2602,7 +2599,7 @@ void CJX_Node::Script_InstanceManager_InsertInstance(
bBind = pArguments->GetInt32(1) == 0 ? false : true;
}
CXFA_Occur nodeOccur(GetXFANode()->GetOccurNode());
- int32_t iCount = GetXFANode()->GetCount(GetXFANode());
+ int32_t iCount = GetXFANode()->GetCount();
if (iIndex < 0 || iIndex > iCount) {
ThrowIndexOutOfBoundsException();
return;
@@ -2612,8 +2609,8 @@ void CJX_Node::Script_InstanceManager_InsertInstance(
ThrowTooManyOccurancesException(L"max");
return;
}
- CXFA_Node* pNewInstance = GetXFANode()->CreateInstance(GetXFANode(), bBind);
- GetXFANode()->InsertItem(GetXFANode(), pNewInstance, iIndex, iCount, true);
+ CXFA_Node* pNewInstance = GetXFANode()->CreateInstance(bBind);
+ GetXFANode()->InsertItem(pNewInstance, iIndex, iCount, true);
pArguments->GetReturnValue()->Assign(
GetXFANode()->GetDocument()->GetScriptContext()->GetJSValueFromMap(
pNewInstance));
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 6b3859e0d2..457b8dd436 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -1782,12 +1782,11 @@ bool CXFA_Node::IsNeedSavingXMLNode() {
GetElementType() == XFA_Element::Xfa);
}
-CXFA_Node* CXFA_Node::GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
- ASSERT(pInstMgrNode);
+CXFA_Node* CXFA_Node::GetItem(int32_t iIndex) {
int32_t iCount = 0;
uint32_t dwNameHash = 0;
- for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
- pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
+ for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
+ pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
XFA_Element eCurType = pNode->GetElementType();
if (eCurType == XFA_Element::InstanceManager)
break;
@@ -1797,8 +1796,7 @@ CXFA_Node* CXFA_Node::GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
}
if (iCount == 0) {
WideStringView wsName = pNode->JSNode()->GetCData(XFA_ATTRIBUTE_Name);
- WideStringView wsInstName =
- pInstMgrNode->JSNode()->GetCData(XFA_ATTRIBUTE_Name);
+ WideStringView wsInstName = JSNode()->GetCData(XFA_ATTRIBUTE_Name);
if (wsInstName.GetLength() < 1 || wsInstName[0] != '_' ||
wsInstName.Right(wsInstName.GetLength() - 1) != wsName) {
return nullptr;
@@ -1815,12 +1813,11 @@ CXFA_Node* CXFA_Node::GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex) {
return nullptr;
}
-int32_t CXFA_Node::GetCount(CXFA_Node* pInstMgrNode) {
- ASSERT(pInstMgrNode);
+int32_t CXFA_Node::GetCount() {
int32_t iCount = 0;
uint32_t dwNameHash = 0;
- for (CXFA_Node* pNode = pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
- pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
+ for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
+ pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
XFA_Element eCurType = pNode->GetElementType();
if (eCurType == XFA_Element::InstanceManager)
break;
@@ -1830,8 +1827,7 @@ int32_t CXFA_Node::GetCount(CXFA_Node* pInstMgrNode) {
}
if (iCount == 0) {
WideStringView wsName = pNode->JSNode()->GetCData(XFA_ATTRIBUTE_Name);
- WideStringView wsInstName =
- pInstMgrNode->JSNode()->GetCData(XFA_ATTRIBUTE_Name);
+ WideStringView wsInstName = JSNode()->GetCData(XFA_ATTRIBUTE_Name);
if (wsInstName.GetLength() < 1 || wsInstName[0] != '_' ||
wsInstName.Right(wsInstName.GetLength() - 1) != wsName) {
return iCount;
@@ -1846,22 +1842,19 @@ int32_t CXFA_Node::GetCount(CXFA_Node* pInstMgrNode) {
return iCount;
}
-void CXFA_Node::InsertItem(CXFA_Node* pInstMgrNode,
- CXFA_Node* pNewInstance,
+void CXFA_Node::InsertItem(CXFA_Node* pNewInstance,
int32_t iPos,
int32_t iCount,
bool bMoveDataBindingNodes) {
if (iCount < 0)
- iCount = GetCount(pInstMgrNode);
+ iCount = GetCount();
if (iPos < 0)
iPos = iCount;
if (iPos == iCount) {
CXFA_Node* pNextSibling =
- iCount > 0 ? pInstMgrNode->GetItem(pInstMgrNode, iCount - 1)
- ->GetNodeItem(XFA_NODEITEM_NextSibling)
- : pInstMgrNode->GetNodeItem(XFA_NODEITEM_NextSibling);
- pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
- ->InsertChild(pNewInstance, pNextSibling);
+ iCount > 0 ? GetItem(iCount - 1)->GetNodeItem(XFA_NODEITEM_NextSibling)
+ : GetNodeItem(XFA_NODEITEM_NextSibling);
+ GetNodeItem(XFA_NODEITEM_Parent)->InsertChild(pNewInstance, pNextSibling);
if (bMoveDataBindingNodes) {
std::set<CXFA_Node*> sNew;
std::set<CXFA_Node*> sAfter;
@@ -1890,8 +1883,8 @@ void CXFA_Node::InsertItem(CXFA_Node* pInstMgrNode,
ReorderDataNodes(sNew, sAfter, false);
}
} else {
- CXFA_Node* pBeforeInstance = GetItem(pInstMgrNode, iPos);
- pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)
+ CXFA_Node* pBeforeInstance = GetItem(iPos);
+ GetNodeItem(XFA_NODEITEM_Parent)
->InsertChild(pNewInstance, pBeforeInstance);
if (bMoveDataBindingNodes) {
std::set<CXFA_Node*> sNew;
@@ -1923,10 +1916,9 @@ void CXFA_Node::InsertItem(CXFA_Node* pInstMgrNode,
}
}
-void CXFA_Node::RemoveItem(CXFA_Node* pInstMgrNode,
- CXFA_Node* pRemoveInstance,
+void CXFA_Node::RemoveItem(CXFA_Node* pRemoveInstance,
bool bRemoveDataBinding) {
- pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
+ GetNodeItem(XFA_NODEITEM_Parent)->RemoveChild(pRemoveInstance);
if (!bRemoveDataBinding)
return;
@@ -1948,10 +1940,10 @@ void CXFA_Node::RemoveItem(CXFA_Node* pInstMgrNode,
}
}
-CXFA_Node* CXFA_Node::CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge) {
- CXFA_Document* pDocument = pInstMgrNode->GetDocument();
- CXFA_Node* pTemplateNode = pInstMgrNode->GetTemplateNode();
- CXFA_Node* pFormParent = pInstMgrNode->GetNodeItem(XFA_NODEITEM_Parent);
+CXFA_Node* CXFA_Node::CreateInstance(bool bDataMerge) {
+ CXFA_Document* pDocument = GetDocument();
+ CXFA_Node* pTemplateNode = GetTemplateNode();
+ CXFA_Node* pFormParent = GetNodeItem(XFA_NODEITEM_Parent);
CXFA_Node* pDataScope = nullptr;
for (CXFA_Node* pRootBoundNode = pFormParent;
pRootBoundNode && pRootBoundNode->IsContainerNode();
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index 02326d933a..e7eafe3a29 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -60,14 +60,11 @@ class CXFA_Node : public CXFA_Object {
CXFA_Node* GetParent() { return m_pParent; }
CXFA_Node* GetChildNode() { return m_pChild; }
- CXFA_Node* CreateInstance(CXFA_Node* pInstMgrNode, bool bDataMerge);
- int32_t GetCount(CXFA_Node* pInstMgrNode);
- CXFA_Node* GetItem(CXFA_Node* pInstMgrNode, int32_t iIndex);
- void RemoveItem(CXFA_Node* pInstMgrNode,
- CXFA_Node* pRemoveInstance,
- bool bRemoveDataBinding = true);
- void InsertItem(CXFA_Node* pInstMgrNode,
- CXFA_Node* pNewInstance,
+ CXFA_Node* CreateInstance(bool bDataMerge);
+ int32_t GetCount();
+ CXFA_Node* GetItem(int32_t iIndex);
+ void RemoveItem(CXFA_Node* pRemoveInstance, bool bRemoveDataBinding = true);
+ void InsertItem(CXFA_Node* pNewInstance,
int32_t iPos,
int32_t iCount = -1,
bool bMoveDataBindingNodes = true);