From 990c09373b733346a06b03167ca43252cb93e986 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 31 Jan 2018 19:54:25 +0000 Subject: Create CXFA_Node::PresenceRequiresSpace This CL replaces XFA_ItemLayoutProcessor_IsTakingSpace with a PresenceRequiresSpace call on CXFA_Node. Change-Id: Ibf570f25eeb3404d72e87cb62e06a7ad70f0916f Reviewed-on: https://pdfium-review.googlesource.com/24850 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp | 68 ++++++++++------------------ xfa/fxfa/parser/cxfa_itemlayoutprocessor.h | 2 - xfa/fxfa/parser/cxfa_layoutpagemgr.cpp | 8 ++-- xfa/fxfa/parser/cxfa_node.cpp | 8 ++++ xfa/fxfa/parser/cxfa_node.h | 2 + 5 files changed, 37 insertions(+), 51 deletions(-) (limited to 'xfa/fxfa') diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp index 98e3234e40..f5392a584c 100644 --- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp +++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.cpp @@ -239,7 +239,7 @@ void RelocateTableRowCells(CXFA_ContentLayoutItem* pLayoutRow, pLayoutChild->m_sPos = CFX_PointF(fCurrentColX, 0); pLayoutChild->m_sSize.width = fColSpanWidth; - if (!XFA_ItemLayoutProcessor_IsTakingSpace(pLayoutChild->m_pFormNode)) + if (!pLayoutChild->m_pFormNode->PresenceRequiresSpace()) continue; fCurrentColX += fColSpanWidth; @@ -520,7 +520,7 @@ XFA_AttributeEnum GetLayout(CXFA_Node* pFormNode, bool* bRootForceTb) { } bool ExistContainerKeep(CXFA_Node* pCurNode, bool bPreFind) { - if (!pCurNode || !XFA_ItemLayoutProcessor_IsTakingSpace(pCurNode)) + if (!pCurNode || !pCurNode->PresenceRequiresSpace()) return false; CXFA_Node* pPreContainer = bPreFind ? pCurNode->GetPrevContainerSibling() @@ -666,8 +666,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( bool* bForceEndPage, CXFA_LayoutContext* pLayoutContext, bool bNewRow) { - bool bTakeSpace = - XFA_ItemLayoutProcessor_IsTakingSpace(pProcessor->m_pFormNode); + bool bTakeSpace = pProcessor->m_pFormNode->PresenceRequiresSpace(); uint8_t uHAlign = HAlignEnumToInt( pThis->m_pCurChildNode->JSObject()->GetEnum(XFA_Attribute::HAlign)); if (bContainerWidthAutoSize) @@ -1580,14 +1579,6 @@ bool CXFA_ItemLayoutProcessor::ProcessKeepNodesForBreakBefore( return FindBreakNode(pBreakAfterNode, pCurActionNode, &nCurStage, false); } -bool XFA_ItemLayoutProcessor_IsTakingSpace(CXFA_Node* pNode) { - XFA_AttributeEnum ePresence = pNode->JSObject() - ->TryEnum(XFA_Attribute::Presence, true) - .value_or(XFA_AttributeEnum::Visible); - return ePresence == XFA_AttributeEnum::Visible || - ePresence == XFA_AttributeEnum::Invisible; -} - bool CXFA_ItemLayoutProcessor::IncrementRelayoutNode( CXFA_LayoutProcessor* pLayoutProcessor, CXFA_Node* pNode, @@ -1714,7 +1705,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutPositionedContainer( CFX_SizeF size = pProcessor->GetCurrentComponentSize(); bool bChangeParentSize = false; - if (XFA_ItemLayoutProcessor_IsTakingSpace(m_pCurChildNode)) + if (m_pCurChildNode->PresenceRequiresSpace()) bChangeParentSize = true; CFX_PointF absolutePos; @@ -1847,7 +1838,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { pLayoutChild->m_pNextSibling)) { if (pLayoutChild->m_pFormNode->GetElementType() != XFA_Element::Subform) continue; - if (!XFA_ItemLayoutProcessor_IsTakingSpace(pLayoutChild->m_pFormNode)) + if (!pLayoutChild->m_pFormNode->PresenceRequiresSpace()) continue; XFA_AttributeEnum eLayout = @@ -1873,13 +1864,13 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { bMoreColumns = false; bool bAutoCol = false; for (int32_t i = 0; i < iRowCount; i++) { - while (rgRowItems[i] && (rgRowItemsSpan[i] <= 0 || - !XFA_ItemLayoutProcessor_IsTakingSpace( - rgRowItems[i]->m_pFormNode))) { + while (rgRowItems[i] && + (rgRowItemsSpan[i] <= 0 || + !rgRowItems[i]->m_pFormNode->PresenceRequiresSpace())) { CXFA_ContentLayoutItem* pNewCell = (CXFA_ContentLayoutItem*)rgRowItems[i]->m_pNextSibling; - if (rgRowItemsSpan[i] < 0 && XFA_ItemLayoutProcessor_IsTakingSpace( - rgRowItems[i]->m_pFormNode)) { + if (rgRowItemsSpan[i] < 0 && + rgRowItems[i]->m_pFormNode->PresenceRequiresSpace()) { pNewCell = nullptr; } rgRowItems[i] = pNewCell; @@ -1933,7 +1924,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { (CXFA_ContentLayoutItem*)m_pLayoutItem->m_pFirstChild; pLayoutChild; pLayoutChild = (CXFA_ContentLayoutItem*)pLayoutChild->m_pNextSibling) { - if (!XFA_ItemLayoutProcessor_IsTakingSpace(pLayoutChild->m_pFormNode)) + if (!pLayoutChild->m_pFormNode->PresenceRequiresSpace()) continue; if (pLayoutChild->m_pFormNode->GetElementType() == XFA_Element::Subform) { @@ -2222,7 +2213,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( pLayoutTempChild != pLayoutChild; pLayoutTempChild = (CXFA_ContentLayoutItem*)pLayoutTempChild->m_pNextSibling) { - if (!XFA_ItemLayoutProcessor_IsTakingSpace(pLayoutTempChild->m_pFormNode)) + if (!pLayoutTempChild->m_pFormNode->PresenceRequiresSpace()) continue; fContentCalculatedWidth = std::max( @@ -2281,7 +2272,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( } else if (uHAlign < uCurHAlignState) { uCurHAlignState = uHAlign; } - if (XFA_ItemLayoutProcessor_IsTakingSpace(pLayoutNext->m_pFormNode)) { + if (pLayoutNext->m_pFormNode->PresenceRequiresSpace()) { if (pLayoutNext->m_sSize.height > fContentCurRowHeight) fContentCurRowHeight = pLayoutNext->m_sSize.height; fContentCurRowAvailWidth -= pLayoutNext->m_sSize.width; @@ -2489,7 +2480,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( if (m_pCurChildNode->GetElementType() == XFA_Element::Variables) break; if (fContentCurRowY >= fHeightLimit + XFA_LAYOUT_FLOAT_PERCISION && - XFA_ItemLayoutProcessor_IsTakingSpace(m_pCurChildNode)) { + m_pCurChildNode->PresenceRequiresSpace()) { bForceEndPage = true; goto SuspendAndCreateNewRow; } @@ -2602,10 +2593,8 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( nGroupLengths[i] = pdfium::CollectionSize(rgCurLineLayoutItems[i]); for (int32_t c = nGroupLengths[i], j = 0; j < c; j++) { nTotalLength++; - if (XFA_ItemLayoutProcessor_IsTakingSpace( - rgCurLineLayoutItems[i][j]->m_pFormNode)) { + if (rgCurLineLayoutItems[i][j]->m_pFormNode->PresenceRequiresSpace()) fGroupWidths[i] += rgCurLineLayoutItems[i][j]->m_sSize.width; - } } } if (!nTotalLength) { @@ -2629,10 +2618,8 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( } else { rgCurLineLayoutItems[0][j]->m_sPos = CFX_PointF(fCurPos, *fContentCurRowY); - if (XFA_ItemLayoutProcessor_IsTakingSpace( - rgCurLineLayoutItems[0][j]->m_pFormNode)) { + if (rgCurLineLayoutItems[0][j]->m_pFormNode->PresenceRequiresSpace()) fCurPos += rgCurLineLayoutItems[0][j]->m_sSize.width; - } } m_pLayoutItem->AddChild(rgCurLineLayoutItems[0][j]); m_fLastRowWidth = fCurPos; @@ -2648,10 +2635,8 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( } else { rgCurLineLayoutItems[1][j]->m_sPos = CFX_PointF(fCurPos, *fContentCurRowY); - if (XFA_ItemLayoutProcessor_IsTakingSpace( - rgCurLineLayoutItems[1][j]->m_pFormNode)) { + if (rgCurLineLayoutItems[1][j]->m_pFormNode->PresenceRequiresSpace()) fCurPos += rgCurLineLayoutItems[1][j]->m_sSize.width; - } } m_pLayoutItem->AddChild(rgCurLineLayoutItems[1][j]); m_fLastRowWidth = fCurPos; @@ -2665,10 +2650,8 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( } else { rgCurLineLayoutItems[2][j]->m_sPos = CFX_PointF(fCurPos, *fContentCurRowY); - if (XFA_ItemLayoutProcessor_IsTakingSpace( - rgCurLineLayoutItems[2][j]->m_pFormNode)) { + if (rgCurLineLayoutItems[2][j]->m_pFormNode->PresenceRequiresSpace()) fCurPos += rgCurLineLayoutItems[2][j]->m_sSize.width; - } } m_pLayoutItem->AddChild(rgCurLineLayoutItems[2][j]); m_fLastRowWidth = fCurPos; @@ -2677,10 +2660,9 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( float fCurPos; fCurPos = fGroupWidths[0]; for (int32_t c = nGroupLengths[0], j = 0; j < c; j++) { - if (XFA_ItemLayoutProcessor_IsTakingSpace( - rgCurLineLayoutItems[0][j]->m_pFormNode)) { + if (rgCurLineLayoutItems[0][j]->m_pFormNode->PresenceRequiresSpace()) fCurPos -= rgCurLineLayoutItems[0][j]->m_sSize.width; - } + rgCurLineLayoutItems[0][j]->m_sPos = CFX_PointF(fCurPos, *fContentCurRowY); m_pLayoutItem->AddChild(rgCurLineLayoutItems[0][j]); @@ -2690,10 +2672,9 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( fGroupWidths[2]) / 2; for (int32_t c = nGroupLengths[1], j = 0; j < c; j++) { - if (XFA_ItemLayoutProcessor_IsTakingSpace( - rgCurLineLayoutItems[1][j]->m_pFormNode)) { + if (rgCurLineLayoutItems[1][j]->m_pFormNode->PresenceRequiresSpace()) fCurPos -= rgCurLineLayoutItems[1][j]->m_sSize.width; - } + rgCurLineLayoutItems[1][j]->m_sPos = CFX_PointF(fCurPos, *fContentCurRowY); m_pLayoutItem->AddChild(rgCurLineLayoutItems[1][j]); @@ -2701,10 +2682,9 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( } fCurPos = fContentWidthLimit; for (int32_t c = nGroupLengths[2], j = 0; j < c; j++) { - if (XFA_ItemLayoutProcessor_IsTakingSpace( - rgCurLineLayoutItems[2][j]->m_pFormNode)) { + if (rgCurLineLayoutItems[2][j]->m_pFormNode->PresenceRequiresSpace()) fCurPos -= rgCurLineLayoutItems[2][j]->m_sSize.width; - } + rgCurLineLayoutItems[2][j]->m_sPos = CFX_PointF(fCurPos, *fContentCurRowY); m_pLayoutItem->AddChild(rgCurLineLayoutItems[2][j]); diff --git a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.h b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.h index e178095207..7dbc754ec6 100644 --- a/xfa/fxfa/parser/cxfa_itemlayoutprocessor.h +++ b/xfa/fxfa/parser/cxfa_itemlayoutprocessor.h @@ -46,8 +46,6 @@ enum class XFA_ItemLayoutProcessorStages { Done, }; -bool XFA_ItemLayoutProcessor_IsTakingSpace(CXFA_Node* pNode); - class CXFA_ItemLayoutProcessor { public: static bool IncrementRelayoutNode(CXFA_LayoutProcessor* pLayoutProcessor, diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp index 123cafb1e9..f921d8014f 100644 --- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp +++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp @@ -398,8 +398,7 @@ bool CXFA_LayoutPageMgr::PrepareFirstPage(CXFA_Node* pRootSubform) { bProBreakBefore = true; pRootSubform = pRootSubform->GetFirstChildByClass(XFA_Element::Subform); - while (pRootSubform && - !XFA_ItemLayoutProcessor_IsTakingSpace(pRootSubform)) { + while (pRootSubform && !pRootSubform->PresenceRequiresSpace()) { pRootSubform = pRootSubform->GetNextSameClassSibling( XFA_Element::Subform); } @@ -885,7 +884,7 @@ bool CXFA_LayoutPageMgr::ProcessBreakBeforeOrAfter( CXFA_Node* pLeaderTemplate = nullptr; CXFA_Node* pTrailerTemplate = nullptr; CXFA_Node* pFormNode = pBreakNode->GetContainerParent(); - if (XFA_ItemLayoutProcessor_IsTakingSpace(pFormNode)) { + if (pFormNode->PresenceRequiresSpace()) { bCreatePage = ExecuteBreakBeforeOrAfter(pBreakNode, bBefore, pLeaderTemplate, pTrailerTemplate); CXFA_Document* pDocument = pBreakNode->GetDocument(); @@ -1760,8 +1759,7 @@ void CXFA_LayoutPageMgr::MergePageSetContents() { pFormLayout = pFormLayout->m_pFirstChild; if (iLevel == 2) { while (pFormLayout && - !XFA_ItemLayoutProcessor_IsTakingSpace( - pFormLayout->m_pFormNode)) { + !pFormLayout->m_pFormNode->PresenceRequiresSpace()) { pFormLayout = pFormLayout->m_pNextSibling; } } diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index ec9be78a5c..7cda5cae25 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -4673,3 +4673,11 @@ WideString CXFA_Node::NumericLimit(const WideString& wsValue) { } return wsRet; } + +bool CXFA_Node::PresenceRequiresSpace() const { + XFA_AttributeEnum ePresence = JSObject() + ->TryEnum(XFA_Attribute::Presence, true) + .value_or(XFA_AttributeEnum::Visible); + return ePresence == XFA_AttributeEnum::Visible || + ePresence == XFA_AttributeEnum::Invisible; +} diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index 415ad94fb8..22b5192264 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h @@ -136,6 +136,8 @@ class CXFA_Node : public CXFA_Object { return HasFlag(XFA_NodeFlag_LayoutGeneratedNode); } + bool PresenceRequiresSpace() const; + void SetBindingNode(CXFA_Node* node) { binding_nodes_.clear(); if (node) -- cgit v1.2.3