From 18a6069f5ce332b2bab97bf3a6d8ea9528d69791 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 10 Jan 2018 16:30:56 +0000 Subject: Remove CXFA_Node::GetNodeItem This CL removes the generic CXFA_Node::GetNodeItem(type) method for specific calls to get the parent, child or siblings. Change-Id: Ief68284ac7b954aaa4ed7120dd82a39f8b52656a Reviewed-on: https://pdfium-review.googlesource.com/22650 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- fxjs/xfa/cjx_field.cpp | 3 +- fxjs/xfa/cjx_instancemanager.cpp | 3 +- fxjs/xfa/cjx_layoutpseudomodel.cpp | 2 +- fxjs/xfa/cjx_node.cpp | 14 ++--- fxjs/xfa/cjx_object.cpp | 122 ++++++++++++++++--------------------- fxjs/xfa/cjx_tree.cpp | 2 +- 6 files changed, 63 insertions(+), 83 deletions(-) (limited to 'fxjs/xfa') diff --git a/fxjs/xfa/cjx_field.cpp b/fxjs/xfa/cjx_field.cpp index b04d8de26a..0007bad592 100644 --- a/fxjs/xfa/cjx_field.cpp +++ b/fxjs/xfa/cjx_field.cpp @@ -272,8 +272,7 @@ void CJX_Field::defaultValue(CFXJSE_Value* pValue, } CXFA_Node* pUIChild = pWidgetAcc->GetUIChild(); - CXFA_Node* pNode = - xfaNode->GetFormValue()->GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_Node* pNode = xfaNode->GetFormValue()->GetFirstChild(); if (pNode && pNode->GetElementType() == XFA_Element::Decimal) { if (pUIChild->GetElementType() == XFA_Element::NumericEdit && (pNode->JSObject()->GetInteger(XFA_Attribute::FracDigits) == -1)) { diff --git a/fxjs/xfa/cjx_instancemanager.cpp b/fxjs/xfa/cjx_instancemanager.cpp index 4bb09dfd9f..f6aef37c16 100644 --- a/fxjs/xfa/cjx_instancemanager.cpp +++ b/fxjs/xfa/cjx_instancemanager.cpp @@ -60,8 +60,7 @@ int32_t CJX_InstanceManager::SetInstances(int32_t iDesired) { CXFA_Node* pPrevSibling = iDesired == 0 ? GetXFANode() : GetXFANode()->GetItem(iDesired - 1); while (iCount > iDesired) { - CXFA_Node* pRemoveInstance = - pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling); + CXFA_Node* pRemoveInstance = pPrevSibling->GetNextSibling(); if (pRemoveInstance->GetElementType() != XFA_Element::Subform && pRemoveInstance->GetElementType() != XFA_Element::SubformSet) { continue; diff --git a/fxjs/xfa/cjx_layoutpseudomodel.cpp b/fxjs/xfa/cjx_layoutpseudomodel.cpp index c275970744..384bd09d63 100644 --- a/fxjs/xfa/cjx_layoutpseudomodel.cpp +++ b/fxjs/xfa/cjx_layoutpseudomodel.cpp @@ -403,7 +403,7 @@ CJS_Return CJX_LayoutPseudoModel::relayout( CXFA_Node* pRootNode = GetDocument()->GetRoot(); CXFA_Form* pFormRoot = pRootNode->GetFirstChildByClass(XFA_Element::Form); - CXFA_Node* pContentRootNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_Node* pContentRootNode = pFormRoot->GetFirstChild(); CXFA_LayoutProcessor* pLayoutProcessor = GetDocument()->GetLayoutProcessor(); if (pContentRootNode) pLayoutProcessor->AddChangedContainer(pContentRootNode); diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp index 581d3281ef..e8fa44eb17 100644 --- a/fxjs/xfa/cjx_node.cpp +++ b/fxjs/xfa/cjx_node.cpp @@ -267,11 +267,11 @@ CJS_Return CJX_Node::loadXML(CJS_V8* runtime, return CJS_Return(true); if (bOverwrite) { - CXFA_Node* pChild = GetXFANode()->GetNodeItem(XFA_NODEITEM_FirstChild); - CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_Node* pChild = GetXFANode()->GetFirstChild(); + CXFA_Node* pNewChild = pFakeRoot->GetFirstChild(); int32_t index = 0; while (pNewChild) { - CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling); + CXFA_Node* pItem = pNewChild->GetNextSibling(); pFakeRoot->RemoveChild(pNewChild, true); GetXFANode()->InsertChild(index++, pNewChild); pNewChild->SetFlag(XFA_NodeFlag_Initialized, true); @@ -279,7 +279,7 @@ CJS_Return CJX_Node::loadXML(CJS_V8* runtime, } while (pChild) { - CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); + CXFA_Node* pItem = pChild->GetNextSibling(); GetXFANode()->RemoveChild(pChild, true); pFakeRoot->InsertChild(pChild, nullptr); pChild = pItem; @@ -297,9 +297,9 @@ CJS_Return CJX_Node::loadXML(CJS_V8* runtime, } MoveBufferMapData(pFakeRoot, GetXFANode()); } else { - CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_Node* pChild = pFakeRoot->GetFirstChild(); while (pChild) { - CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); + CXFA_Node* pItem = pChild->GetNextSibling(); pFakeRoot->RemoveChild(pChild, true); GetXFANode()->InsertChild(pChild, nullptr); pChild->SetFlag(XFA_NodeFlag_Initialized, true); @@ -483,7 +483,7 @@ int32_t CJX_Node::execSingleEventByName(const WideStringView& wsEventName, if (eType != XFA_Element::ExclGroup && eType != XFA_Element::Field) return XFA_EVENTERROR_NotExist; - CXFA_Node* pParentNode = GetXFANode()->GetNodeItem(XFA_NODEITEM_Parent); + CXFA_Node* pParentNode = GetXFANode()->GetParent(); if (pParentNode && pParentNode->GetElementType() == XFA_Element::ExclGroup) { // TODO(dsinclair): This seems like a bug, we do the same work twice? diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp index 45089f68da..f1b863ddc1 100644 --- a/fxjs/xfa/cjx_object.cpp +++ b/fxjs/xfa/cjx_object.cpp @@ -152,9 +152,8 @@ void CJX_Object::className(CFXJSE_Value* pValue, int32_t CJX_Object::Subform_and_SubformSet_InstanceIndex() { int32_t index = 0; - for (CXFA_Node* pNode = - ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_PrevSibling); - pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { + for (CXFA_Node* pNode = ToNode(GetXFAObject())->GetPrevSibling(); pNode; + pNode = pNode->GetPrevSibling()) { if ((pNode->GetElementType() != XFA_Element::Subform) && (pNode->GetElementType() != XFA_Element::SubformSet)) { break; @@ -452,7 +451,8 @@ bool CJX_Object::SetCData(XFA_Attribute eAttr, const WideString& wsValue, bool bNotify, bool bScriptModify) { - void* pKey = GetMapKey_Element(GetXFAObject()->GetElementType(), eAttr); + CXFA_Node* xfaObj = ToNode(GetXFAObject()); + void* pKey = GetMapKey_Element(xfaObj->GetElementType(), eAttr); OnChanging(eAttr, bNotify); if (eAttr == XFA_Attribute::Value) { WideString* pClone = new WideString(wsValue); @@ -460,40 +460,35 @@ bool CJX_Object::SetCData(XFA_Attribute eAttr, } else { SetMapModuleString(pKey, wsValue.AsStringView()); if (eAttr == XFA_Attribute::Name) - ToNode(GetXFAObject())->UpdateNameHash(); + xfaObj->UpdateNameHash(); } OnChanged(eAttr, bNotify, bScriptModify); - if (!ToNode(GetXFAObject())->IsNeedSavingXMLNode() || - eAttr == XFA_Attribute::QualifiedName || + if (!xfaObj->IsNeedSavingXMLNode() || eAttr == XFA_Attribute::QualifiedName || eAttr == XFA_Attribute::BindingNode) { return true; } if (eAttr == XFA_Attribute::Name && - (GetXFAObject()->GetElementType() == XFA_Element::DataValue || - GetXFAObject()->GetElementType() == XFA_Element::DataGroup)) { + (xfaObj->GetElementType() == XFA_Element::DataValue || + xfaObj->GetElementType() == XFA_Element::DataGroup)) { return true; } - auto* elem = - static_cast(ToNode(GetXFAObject())->GetXMLMappingNode()); + auto* elem = static_cast(xfaObj->GetXMLMappingNode()); if (eAttr == XFA_Attribute::Value) { FX_XMLNODETYPE eXMLType = elem->GetType(); switch (eXMLType) { case FX_XMLNODE_Element: - if (ToNode(GetXFAObject())->IsAttributeInXML()) { + if (xfaObj->IsAttributeInXML()) { elem->SetString(WideString(GetCData(XFA_Attribute::QualifiedName)), wsValue); } else { bool bDeleteChildren = true; - if (ToNode(GetXFAObject())->GetPacketType() == - XFA_PacketType::Datasets) { - for (CXFA_Node* pChildDataNode = - ToNode(GetXFAObject()) - ->GetNodeItem(XFA_NODEITEM_FirstChild); - pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( - XFA_NODEITEM_NextSibling)) { + if (xfaObj->GetPacketType() == XFA_PacketType::Datasets) { + for (CXFA_Node* pChildDataNode = xfaObj->GetFirstChild(); + pChildDataNode; + pChildDataNode = pChildDataNode->GetNextSibling()) { if (!pChildDataNode->GetBindItems()->empty()) { bDeleteChildren = false; break; @@ -507,7 +502,7 @@ bool CJX_Object::SetCData(XFA_Attribute eAttr, } break; case FX_XMLNODE_Text: - static_cast(ToNode(GetXFAObject())->GetXMLMappingNode()) + static_cast(xfaObj->GetXMLMappingNode()) ->SetText(wsValue); break; default: @@ -529,31 +524,30 @@ void CJX_Object::SetAttributeValue(const WideString& wsValue, const WideString& wsXMLValue, bool bNotify, bool bScriptModify) { + auto* xfaObj = ToNode(GetXFAObject()); + void* pKey = - GetMapKey_Element(GetXFAObject()->GetElementType(), XFA_Attribute::Value); + GetMapKey_Element(xfaObj->GetElementType(), XFA_Attribute::Value); OnChanging(XFA_Attribute::Value, bNotify); WideString* pClone = new WideString(wsValue); SetUserData(pKey, pClone, &deleteWideStringCallBack); OnChanged(XFA_Attribute::Value, bNotify, bScriptModify); - if (!ToNode(GetXFAObject())->IsNeedSavingXMLNode()) + if (!xfaObj->IsNeedSavingXMLNode()) return; - auto* elem = - static_cast(ToNode(GetXFAObject())->GetXMLMappingNode()); + auto* elem = static_cast(xfaObj->GetXMLMappingNode()); FX_XMLNODETYPE eXMLType = elem->GetType(); switch (eXMLType) { case FX_XMLNODE_Element: - if (ToNode(GetXFAObject())->IsAttributeInXML()) { + if (xfaObj->IsAttributeInXML()) { elem->SetString(WideString(GetCData(XFA_Attribute::QualifiedName)), wsXMLValue); } else { bool bDeleteChildren = true; - if (ToNode(GetXFAObject())->GetPacketType() == - XFA_PacketType::Datasets) { - for (CXFA_Node* pChildDataNode = - ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_FirstChild); - pChildDataNode; pChildDataNode = pChildDataNode->GetNodeItem( - XFA_NODEITEM_NextSibling)) { + if (xfaObj->GetPacketType() == XFA_PacketType::Datasets) { + for (CXFA_Node* pChildDataNode = xfaObj->GetFirstChild(); + pChildDataNode; + pChildDataNode = pChildDataNode->GetNextSibling()) { if (!pChildDataNode->GetBindItems()->empty()) { bDeleteChildren = false; break; @@ -567,7 +561,7 @@ void CJX_Object::SetAttributeValue(const WideString& wsValue, } break; case FX_XMLNODE_Text: - static_cast(ToNode(GetXFAObject())->GetXMLMappingNode()) + static_cast(xfaObj->GetXMLMappingNode()) ->SetText(wsXMLValue); break; default: @@ -633,7 +627,7 @@ bool CJX_Object::SetContent(const WideString& wsContent, if (!pValue) break; - CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_Node* pChildValue = pValue->GetFirstChild(); ASSERT(pChildValue); pChildValue->JSObject()->SetCData(XFA_Attribute::ContentType, L"text/xml", false, false); @@ -664,8 +658,7 @@ bool CJX_Object::SetContent(const WideString& wsContent, iSize = wsSaveTextArray.size(); } if (iSize == 0) { - while (CXFA_Node* pChildNode = - pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) { + while (CXFA_Node* pChildNode = pBind->GetFirstChild()) { pBind->RemoveChild(pChildNode, true); } } else { @@ -687,15 +680,12 @@ bool CJX_Object::SetContent(const WideString& wsContent, } else if (iDatas > iSize) { size_t iDelNodes = iDatas - iSize; while (iDelNodes-- > 0) { - pBind->RemoveChild(pBind->GetNodeItem(XFA_NODEITEM_FirstChild), - true); + pBind->RemoveChild(pBind->GetFirstChild(), true); } } int32_t i = 0; - for (CXFA_Node* pValueNode = - pBind->GetNodeItem(XFA_NODEITEM_FirstChild); - pValueNode; pValueNode = pValueNode->GetNodeItem( - XFA_NODEITEM_NextSibling)) { + for (CXFA_Node* pValueNode = pBind->GetFirstChild(); pValueNode; + pValueNode = pValueNode->GetNextSibling()) { pValueNode->JSObject()->SetAttributeValue( wsSaveTextArray[i], wsSaveTextArray[i], false, false); i++; @@ -718,7 +708,7 @@ bool CJX_Object::SetContent(const WideString& wsContent, if (!pValue) break; - CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_Node* pChildValue = pValue->GetFirstChild(); ASSERT(pChildValue); pChildValue->JSObject()->SetContent(wsContent, wsContent, bNotify, bScriptModify, false); @@ -751,8 +741,7 @@ bool CJX_Object::SetContent(const WideString& wsContent, } } - CXFA_Node* pContentRawDataNode = - ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_Node* pContentRawDataNode = ToNode(GetXFAObject())->GetFirstChild(); if (!pContentRawDataNode) { pContentRawDataNode = ToNode(GetXFAObject()) @@ -772,13 +761,12 @@ bool CJX_Object::SetContent(const WideString& wsContent, pNode = ToNode(GetXFAObject()); if (bSyncData && ToNode(GetXFAObject())->GetPacketType() == XFA_PacketType::Form) { - CXFA_Node* pParent = - ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_Parent); + CXFA_Node* pParent = ToNode(GetXFAObject())->GetParent(); if (pParent) { - pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); + pParent = pParent->GetParent(); } if (pParent && pParent->GetElementType() == XFA_Element::Value) { - pParent = pParent->GetNodeItem(XFA_NODEITEM_Parent); + pParent = pParent->GetParent(); if (pParent && pParent->IsContainerNode()) { pBindNode = pParent->GetBindData(); if (pBindNode) { @@ -826,7 +814,7 @@ Optional CJX_Object::TryContent(bool bScriptModify, bool bProto) { if (!pValue) return {}; - CXFA_Node* pChildValue = pValue->GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_Node* pChildValue = pValue->GetFirstChild(); if (pChildValue && XFA_FieldIsMultiListBox(ToNode(GetXFAObject()))) { pChildValue->JSObject()->SetAttribute(XFA_Attribute::ContentType, L"text/xml", false); @@ -837,8 +825,7 @@ Optional CJX_Object::TryContent(bool bScriptModify, bool bProto) { } break; case XFA_ObjectType::ContentNode: { - CXFA_Node* pContentRawDataNode = - ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_Node* pContentRawDataNode = ToNode(GetXFAObject())->GetFirstChild(); if (!pContentRawDataNode) { XFA_Element element = XFA_Element::Sharptext; if (ToNode(GetXFAObject())->GetElementType() == XFA_Element::ExData) { @@ -917,7 +904,7 @@ std::pair CJX_Object::GetPropertyInternal( int32_t iCount = 0; for (CXFA_Node* pNode = xfaNode->GetChildNode(); pNode; - pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + pNode = pNode->GetNextSibling()) { if (pNode->GetElementType() == eProperty) { iCount++; if (iCount > index) @@ -941,7 +928,7 @@ CXFA_Node* CJX_Object::GetOrCreatePropertyInternal(int32_t index, if (xfaNode->HasPropertyFlags(eProperty, XFA_PROPERTYFLAG_OneOf)) { for (CXFA_Node* pNode = xfaNode->GetChildNode(); pNode; - pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { + pNode = pNode->GetNextSibling()) { if (xfaNode->HasPropertyFlags(pNode->GetElementType(), XFA_PROPERTYFLAG_OneOf)) { return nullptr; @@ -1185,15 +1172,13 @@ void CJX_Object::MoveBufferMapData(CXFA_Object* pSrcModule, if (!pSrcModule || !pDstModule) return; - CXFA_Node* pSrcChild = - ToNode(pSrcModule)->GetNodeItem(XFA_NODEITEM_FirstChild); - CXFA_Node* pDstChild = - ToNode(pDstModule)->GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_Node* pSrcChild = ToNode(pSrcModule)->GetFirstChild(); + CXFA_Node* pDstChild = ToNode(pDstModule)->GetFirstChild(); while (pSrcChild && pDstChild) { MoveBufferMapData(pSrcChild, pDstChild); - pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling); - pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling); + pSrcChild = pSrcChild->GetNextSibling(); + pDstChild = pDstChild->GetNextSibling(); } ToNode(pSrcModule)->JSObject()->MoveBufferMapData(pDstModule); } @@ -1270,18 +1255,17 @@ void CJX_Object::Script_Attribute_String(CFXJSE_Value* pValue, if (!pProtoNode) return; - CXFA_Node* pHeadChild = - ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_Node* pHeadChild = ToNode(GetXFAObject())->GetFirstChild(); while (pHeadChild) { - CXFA_Node* pSibling = pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); + CXFA_Node* pSibling = pHeadChild->GetNextSibling(); ToNode(GetXFAObject())->RemoveChild(pHeadChild, true); pHeadChild = pSibling; } std::unique_ptr pProtoForm(pProtoNode->CloneTemplateToForm(true)); - pHeadChild = pProtoForm->GetNodeItem(XFA_NODEITEM_FirstChild); + pHeadChild = pProtoForm->GetFirstChild(); while (pHeadChild) { - CXFA_Node* pSibling = pHeadChild->GetNodeItem(XFA_NODEITEM_NextSibling); + CXFA_Node* pSibling = pHeadChild->GetNextSibling(); pProtoForm->RemoveChild(pHeadChild, true); ToNode(GetXFAObject())->InsertChild(pHeadChild, nullptr); pHeadChild = pSibling; @@ -1619,9 +1603,8 @@ void CJX_Object::Script_Som_InstanceIndex(CFXJSE_Value* pValue, int32_t iTo = pValue->ToInteger(); int32_t iFrom = Subform_and_SubformSet_InstanceIndex(); CXFA_Node* pManagerNode = nullptr; - for (CXFA_Node* pNode = - ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_PrevSibling); - pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { + for (CXFA_Node* pNode = ToNode(GetXFAObject())->GetPrevSibling(); pNode; + pNode = pNode->GetPrevSibling()) { if (pNode->GetElementType() == XFA_Element::InstanceManager) { pManagerNode = pNode; break; @@ -1658,9 +1641,8 @@ void CJX_Object::Script_Subform_InstanceManager(CFXJSE_Value* pValue, WideString wsName = GetCData(XFA_Attribute::Name); CXFA_Node* pInstanceMgr = nullptr; - for (CXFA_Node* pNode = - ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_PrevSibling); - pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_PrevSibling)) { + for (CXFA_Node* pNode = ToNode(GetXFAObject())->GetPrevSibling(); pNode; + pNode = pNode->GetPrevSibling()) { if (pNode->GetElementType() == XFA_Element::InstanceManager) { WideString wsInstMgrName = pNode->JSObject()->GetCData(XFA_Attribute::Name); diff --git a/fxjs/xfa/cjx_tree.cpp b/fxjs/xfa/cjx_tree.cpp index 4a7a2fcc17..e20115b9bc 100644 --- a/fxjs/xfa/cjx_tree.cpp +++ b/fxjs/xfa/cjx_tree.cpp @@ -159,7 +159,7 @@ void CJX_Tree::parent(CFXJSE_Value* pValue, return; } - CXFA_Node* pParent = ToNode(GetXFAObject())->GetNodeItem(XFA_NODEITEM_Parent); + CXFA_Node* pParent = ToNode(GetXFAObject())->GetParent(); if (!pParent) { pValue->SetNull(); return; -- cgit v1.2.3