diff options
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r-- | xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp | 24 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_layoutpagemgr.cpp | 31 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_layoutprocessor.cpp | 3 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 70 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.h | 12 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h | 9 |
6 files changed, 57 insertions, 92 deletions
diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp index 0b8daa8970..6275650370 100644 --- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp @@ -521,12 +521,8 @@ bool ExistContainerKeep(CXFA_Node* pCurNode, bool bPreFind) { if (!pCurNode || !XFA_ItemLayoutProcessor_IsTakingSpace(pCurNode)) return false; - XFA_NODEITEM eItemType = XFA_NODEITEM_PrevSibling; - if (!bPreFind) - eItemType = XFA_NODEITEM_NextSibling; - - CXFA_Node* pPreContainer = - pCurNode->GetNodeItem(eItemType, XFA_ObjectType::ContainerNode); + CXFA_Node* pPreContainer = bPreFind ? pCurNode->GetPrevContainerSibling() + : pCurNode->GetNextContainerSibling(); if (!pPreContainer) return false; @@ -1470,15 +1466,12 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( CheckNextChildContainer : { CXFA_Node* pNextChildContainer = pChildContainer == XFA_LAYOUT_INVALIDNODE - ? pEntireContainer->GetNodeItem(XFA_NODEITEM_FirstChild, - XFA_ObjectType::ContainerNode) - : pChildContainer->GetNodeItem(XFA_NODEITEM_NextSibling, - XFA_ObjectType::ContainerNode); + ? pEntireContainer->GetFirstContainerChild() + : pChildContainer->GetNextContainerSibling(); while (pNextChildContainer && pNextChildContainer->IsLayoutGeneratedNode()) { CXFA_Node* pSaveNode = pNextChildContainer; - pNextChildContainer = pNextChildContainer->GetNodeItem( - XFA_NODEITEM_NextSibling, XFA_ObjectType::ContainerNode); + pNextChildContainer = pNextChildContainer->GetNextContainerSibling(); if (pSaveNode->IsUnusedNode()) DeleteLayoutGeneratedNode(pSaveNode); } @@ -2171,11 +2164,8 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( bool bFocrTb = false; if (pParentNode && GetLayout(pParentNode, &bFocrTb) == XFA_AttributeEnum::Row) { - CXFA_Node* pChildContainer = m_pFormNode->GetNodeItem( - XFA_NODEITEM_FirstChild, XFA_ObjectType::ContainerNode); - if (pChildContainer && - pChildContainer->GetNodeItem(XFA_NODEITEM_NextSibling, - XFA_ObjectType::ContainerNode)) { + CXFA_Node* pChildContainer = m_pFormNode->GetFirstContainerChild(); + if (pChildContainer && pChildContainer->GetNextContainerSibling()) { containerSize.height = 0; bContainerHeightAutoSize = true; } diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp index c1947cf9cc..35a1bc8283 100644 --- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp +++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp @@ -239,8 +239,7 @@ bool RunBreakTestScript(CXFA_Script* pTestScript) { if (wsExpression.IsEmpty()) return true; return pTestScript->GetDocument()->GetNotify()->RunScript( - pTestScript, pTestScript->GetNodeItem(XFA_NODEITEM_Parent, - XFA_ObjectType::ContainerNode)); + pTestScript, pTestScript->GetContainerParent()); } } // namespace @@ -810,8 +809,7 @@ bool CXFA_LayoutPageMgr::ExecuteBreakBeforeOrAfter( case XFA_Element::BreakAfter: { WideString wsBreakLeader; WideString wsBreakTrailer; - CXFA_Node* pFormNode = pCurNode->GetNodeItem( - XFA_NODEITEM_Parent, XFA_ObjectType::ContainerNode); + CXFA_Node* pFormNode = pCurNode->GetContainerParent(); CXFA_Node* pContainer = pFormNode->GetTemplateNode(); bool bStartNew = pCurNode->JSObject()->GetInteger(XFA_Attribute::StartNew) != 0; @@ -838,12 +836,9 @@ bool CXFA_LayoutPageMgr::ExecuteBreakBeforeOrAfter( if (!m_ProposedContainerRecords.empty() && m_CurrentContainerRecordIter == m_ProposedContainerRecords.begin() && eType == XFA_Element::BreakBefore) { - CXFA_Node* pParentNode = pFormNode->GetNodeItem( - XFA_NODEITEM_Parent, XFA_ObjectType::ContainerNode); + CXFA_Node* pParentNode = pFormNode->GetContainerParent(); if (!pParentNode || - pFormNode != - pParentNode->GetNodeItem(XFA_NODEITEM_FirstChild, - XFA_ObjectType::ContainerNode)) { + pFormNode != pParentNode->GetFirstContainerChild()) { break; } pParentNode = pParentNode->GetParent(); @@ -884,15 +879,13 @@ bool CXFA_LayoutPageMgr::ProcessBreakBeforeOrAfter( bool& bCreatePage) { CXFA_Node* pLeaderTemplate = nullptr; CXFA_Node* pTrailerTemplate = nullptr; - CXFA_Node* pFormNode = pBreakNode->GetNodeItem(XFA_NODEITEM_Parent, - XFA_ObjectType::ContainerNode); + CXFA_Node* pFormNode = pBreakNode->GetContainerParent(); if (XFA_ItemLayoutProcessor_IsTakingSpace(pFormNode)) { bCreatePage = ExecuteBreakBeforeOrAfter(pBreakNode, bBefore, pLeaderTemplate, pTrailerTemplate); CXFA_Document* pDocument = pBreakNode->GetDocument(); CXFA_Node* pDataScope = nullptr; - pFormNode = pFormNode->GetNodeItem(XFA_NODEITEM_Parent, - XFA_ObjectType::ContainerNode); + pFormNode = pFormNode->GetContainerParent(); if (pLeaderTemplate) { if (!pDataScope) pDataScope = XFA_DataMerge_FindDataScope(pFormNode); @@ -921,8 +914,7 @@ bool CXFA_LayoutPageMgr::ProcessBookendLeaderOrTrailer( bool bLeader, CXFA_Node*& pBookendAppendNode) { CXFA_Node* pLeaderTemplate = nullptr; - CXFA_Node* pFormNode = pBookendNode->GetNodeItem( - XFA_NODEITEM_Parent, XFA_ObjectType::ContainerNode); + CXFA_Node* pFormNode = pBookendNode->GetContainerParent(); if (ResolveBookendLeaderOrTrailer(pBookendNode, bLeader, pLeaderTemplate)) { CXFA_Document* pDocument = pBookendNode->GetDocument(); CXFA_Node* pDataScope = nullptr; @@ -945,9 +937,7 @@ CXFA_Node* CXFA_LayoutPageMgr::BreakOverflow(CXFA_Node* pOverflowNode, CXFA_Node*& pTrailerTemplate, bool bCreatePage) { CXFA_Node* pContainer = - pOverflowNode - ->GetNodeItem(XFA_NODEITEM_Parent, XFA_ObjectType::ContainerNode) - ->GetTemplateNode(); + pOverflowNode->GetContainerParent()->GetTemplateNode(); if (pOverflowNode->GetElementType() == XFA_Element::Break) { WideString wsOverflowLeader = pOverflowNode->JSObject()->GetCData(XFA_Attribute::OverflowLeader); @@ -1078,10 +1068,7 @@ bool CXFA_LayoutPageMgr::ResolveBookendLeaderOrTrailer( CXFA_Node* pBookendNode, bool bLeader, CXFA_Node*& pBookendAppendTemplate) { - CXFA_Node* pContainer = - pBookendNode - ->GetNodeItem(XFA_NODEITEM_Parent, XFA_ObjectType::ContainerNode) - ->GetTemplateNode(); + CXFA_Node* pContainer = pBookendNode->GetContainerParent()->GetTemplateNode(); if (pBookendNode->GetElementType() == XFA_Element::Break) { WideString leader = pBookendNode->JSObject()->GetCData( bLeader ? XFA_Attribute::BookendLeader : XFA_Attribute::BookendTrailer); diff --git a/xfa/fxfa/parser/cxfa_layoutprocessor.cpp b/xfa/fxfa/parser/cxfa_layoutprocessor.cpp index 36caa0c0a6..b074de13eb 100644 --- a/xfa/fxfa/parser/cxfa_layoutprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_layoutprocessor.cpp @@ -101,8 +101,7 @@ bool CXFA_LayoutProcessor::IncrementLayout() { return DoLayout() == 100; } for (CXFA_Node* pNode : m_rgChangedContainers) { - CXFA_Node* pParentNode = - pNode->GetNodeItem(XFA_NODEITEM_Parent, XFA_ObjectType::ContainerNode); + CXFA_Node* pParentNode = pNode->GetContainerParent(); if (!pParentNode) return false; if (!CXFA_ItemLayoutProcessor::IncrementRelayoutNode(this, pNode, diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index ad70e94256..6d77f74c4e 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -277,39 +277,38 @@ CXFA_Node* CXFA_Node::GetPrevSibling() const { return nullptr; } -CXFA_Node* CXFA_Node::GetNodeItem(XFA_NODEITEM eItem, - XFA_ObjectType eType) const { - CXFA_Node* pNode = nullptr; - switch (eItem) { - case XFA_NODEITEM_NextSibling: - pNode = m_pNext; - while (pNode && pNode->GetObjectType() != eType) - pNode = pNode->m_pNext; - break; - case XFA_NODEITEM_FirstChild: - pNode = m_pChild; - while (pNode && pNode->GetObjectType() != eType) - pNode = pNode->m_pNext; - break; - case XFA_NODEITEM_Parent: - pNode = m_pParent; - while (pNode && pNode->GetObjectType() != eType) - pNode = pNode->m_pParent; - break; - case XFA_NODEITEM_PrevSibling: - if (m_pParent) { - CXFA_Node* pSibling = m_pParent->m_pChild; - while (pSibling && pSibling != this) { - if (eType == pSibling->GetObjectType()) - pNode = pSibling; - - pSibling = pSibling->m_pNext; - } - } - break; - default: - break; +CXFA_Node* CXFA_Node::GetNextContainerSibling() const { + CXFA_Node* pNode = m_pNext; + while (pNode && pNode->GetObjectType() != XFA_ObjectType::ContainerNode) + pNode = pNode->m_pNext; + return pNode; +} + +CXFA_Node* CXFA_Node::GetPrevContainerSibling() const { + if (!m_pParent || m_pParent->m_pChild == this) + return nullptr; + + CXFA_Node* container = nullptr; + for (CXFA_Node* pNode = m_pParent->m_pChild; pNode; pNode = pNode->m_pNext) { + if (pNode->GetObjectType() == XFA_ObjectType::ContainerNode) + container = pNode; + if (pNode->m_pNext == this) + return container; } + return nullptr; +} + +CXFA_Node* CXFA_Node::GetFirstContainerChild() const { + CXFA_Node* pNode = m_pChild; + while (pNode && pNode->GetObjectType() != XFA_ObjectType::ContainerNode) + pNode = pNode->m_pNext; + return pNode; +} + +CXFA_Node* CXFA_Node::GetContainerParent() const { + CXFA_Node* pNode = m_pParent; + while (pNode && pNode->GetObjectType() != XFA_ObjectType::ContainerNode) + pNode = pNode->m_pParent; return pNode; } @@ -672,8 +671,7 @@ XFA_AttributeEnum CXFA_Node::GetIntact() { if (*intact == XFA_AttributeEnum::None && eLayoutType == XFA_AttributeEnum::Row && m_pDocument->GetCurVersionMode() < XFA_VERSION_208) { - CXFA_Node* pPreviewRow = GetNodeItem(XFA_NODEITEM_PrevSibling, - XFA_ObjectType::ContainerNode); + CXFA_Node* pPreviewRow = GetPrevContainerSibling(); if (pPreviewRow && pPreviewRow->JSObject()->GetEnum(XFA_Attribute::Layout) == XFA_AttributeEnum::Row) { @@ -1583,9 +1581,7 @@ CXFA_Para* CXFA_Node::GetPara() const { } bool CXFA_Node::IsOpenAccess() { - for (auto* pNode = this; pNode; - pNode = pNode->GetNodeItem(XFA_NODEITEM_Parent, - XFA_ObjectType::ContainerNode)) { + for (auto* pNode = this; pNode; pNode = pNode->GetContainerParent()) { XFA_AttributeEnum iAcc = pNode->JSObject()->GetEnum(XFA_Attribute::Access); if (iAcc != XFA_AttributeEnum::Open) return false; diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index fe1c3e007f..c1074ffaad 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h @@ -55,13 +55,6 @@ enum XFA_NodeFlag { XFA_NodeFlag_LayoutGeneratedNode = 1 << 8 }; -enum XFA_NODEITEM { - XFA_NODEITEM_Parent, - XFA_NODEITEM_FirstChild, - XFA_NODEITEM_NextSibling, - XFA_NODEITEM_PrevSibling, -}; - class CXFA_Node : public CXFA_Object { public: struct PropertyData { @@ -188,7 +181,10 @@ class CXFA_Node : public CXFA_Object { CXFA_Node* GetFirstChild() const { return m_pChild; } CXFA_Node* GetParent() const { return m_pParent; } - CXFA_Node* GetNodeItem(XFA_NODEITEM eItem, XFA_ObjectType eType) const; + CXFA_Node* GetNextContainerSibling() const; + CXFA_Node* GetPrevContainerSibling() const; + CXFA_Node* GetFirstContainerChild() const; + CXFA_Node* GetContainerParent() const; std::vector<CXFA_Node*> GetNodeList(uint32_t dwTypeFilter, XFA_Element eTypeFilter); diff --git a/xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h b/xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h index ce6463c700..3ca632a1d1 100644 --- a/xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h +++ b/xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h @@ -13,16 +13,13 @@ class CXFA_TraverseStrategy_XFAContainerNode { public: static CXFA_Node* GetFirstChild(CXFA_Node* pTemplateNode) { - return pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild, - XFA_ObjectType::ContainerNode); + return pTemplateNode->GetFirstContainerChild(); } static CXFA_Node* GetNextSibling(CXFA_Node* pTemplateNode) { - return pTemplateNode->GetNodeItem(XFA_NODEITEM_NextSibling, - XFA_ObjectType::ContainerNode); + return pTemplateNode->GetNextContainerSibling(); } static CXFA_Node* GetParent(CXFA_Node* pTemplateNode) { - return pTemplateNode->GetNodeItem(XFA_NODEITEM_Parent, - XFA_ObjectType::ContainerNode); + return pTemplateNode->GetContainerParent(); } }; |